@@ -101,6 +101,34 @@ static std::string lock_identity(const mcpp::lockfile::LockedPackage& p) {
101101 return p.namespace_ + " \x1f " + lock_short_name (p);
102102}
103103
104+ // THE IDENTITY THIS CONFIGURATION'S REQUEST WAS GIVEN (SPEC-016 §4.5), into
105+ // `lock`, and the other requests' as the lock had them. Returns what the lock
106+ // had for this request.
107+ static std::optional<mcpp::lockfile::LockedTarget> lock_targets (const PrepareState& state,
108+ mcpp::lockfile::Lockfile& lock) {
109+ std::optional<mcpp::lockfile::LockedTarget> priorTarget;
110+ auto const & c = state.targetChoice ;
111+ if (auto prior = mcpp::lockfile::load (state.workRoot / " mcpp.lock" ))
112+ for (auto const & t : prior->targets ) {
113+ if (!c.request .empty () && t.request == c.request ) priorTarget = t;
114+ else lock.targets .push_back (t);
115+ }
116+ if (!c.request .empty ()) lock.targets .push_back ({ c.request , c.identity , c.provider });
117+ std::ranges::sort (lock.targets , {}, &mcpp::lockfile::LockedTarget::request);
118+ return priorTarget;
119+ }
120+
121+ // The drift line of a request the lock gave another identity, if it did.
122+ static std::optional<std::string> target_drift (const PrepareState& state,
123+ const std::optional<mcpp::lockfile::LockedTarget>& prior) {
124+ auto const & c = state.targetChoice ;
125+ if (!prior || prior->identity == c.identity ) return std::nullopt ;
126+ return std::format (" target {}: {} ({}) -> {} ({}){}" , c.request , prior->identity ,
127+ prior->provider .empty () ? " the platform's" : prior->provider ,
128+ c.identity , c.provider .empty () ? " the platform's" : c.provider ,
129+ c.why .empty () ? std::string{} : " ; " + c.why );
130+ }
131+
104132std::expected<void , std::string> step13_lockfile (PrepareState& state, BuildContext& ctx) {
105133 // Write/update mcpp.lock for any version-based deps that succeeded.
106134 // Path deps are intentionally NOT locked — their source is local filesystem.
@@ -413,19 +441,7 @@ std::expected<void, std::string> step13_lockfile(PrepareState& state, BuildConte
413441 }
414442 // One order whichever configuration wrote the file last: by identity.
415443 std::ranges::stable_sort (lock.packages , {}, [](auto const & p) { return lock_identity (p); });
416- // THE IDENTITY THIS CONFIGURATION'S REQUEST WAS GIVEN (SPEC-016 §4.5),
417- // and the other requests' as the lock had them.
418- std::optional<mcpp::lockfile::LockedTarget> priorTarget;
419- {
420- auto const & c = state.targetChoice ;
421- if (auto prior = mcpp::lockfile::load (state.workRoot / " mcpp.lock" ))
422- for (auto const & t : prior->targets ) {
423- if (!c.request .empty () && t.request == c.request ) priorTarget = t;
424- else lock.targets .push_back (t);
425- }
426- if (!c.request .empty ()) lock.targets .push_back ({ c.request , c.identity , c.provider });
427- std::ranges::sort (lock.targets , {}, &mcpp::lockfile::LockedTarget::request);
428- }
444+ const auto priorTarget = lock_targets (state, lock);
429445 if (!lock.packages .empty () || !lock.indices .empty ()) {
430446 auto lockPath = state.workRoot / " mcpp.lock" ;
431447 // `--locked` ASSERTS THAT THIS RESOLUTION IS THE RECORDED ONE.
@@ -459,12 +475,7 @@ std::expected<void, std::string> step13_lockfile(PrepareState& state, BuildConte
459475 for (auto const & p : prior->packages ) was[key (p)] = p.version ;
460476 for (auto const & p : lock.packages ) now[key (p)] = p.version ;
461477 std::vector<std::string> drift;
462- if (auto const & c = state.targetChoice ; priorTarget && priorTarget->identity != c.identity )
463- drift.push_back (std::format (
464- " target {}: {} ({}) -> {} ({}){}" , c.request , priorTarget->identity ,
465- priorTarget->provider .empty () ? " the platform's" : priorTarget->provider ,
466- c.identity , c.provider .empty () ? " the platform's" : c.provider ,
467- c.why .empty () ? std::string{} : " ; " + c.why ));
478+ if (auto d = target_drift (state, priorTarget)) drift.push_back (std::move (*d));
468479 for (auto const & [k, v] : now) {
469480 auto it = was.find (k);
470481 if (it == was.end ()) drift.push_back (k + " " + v + " (not in the lock)" );
0 commit comments