From fa002aac4c3cb75722d973d199a73231062b890c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 23 Sep 2021 20:51:45 +0300 Subject: Make database ordering consistent across runs --- bpkg/database.cxx | 8 ++++++++ bpkg/database.hxx | 7 ++++--- bpkg/package.cxx | 7 +++++++ bpkg/package.hxx | 8 +------- bpkg/types.hxx | 10 ++++++++-- tests/pkg-build.testscript | 2 +- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/bpkg/database.cxx b/bpkg/database.cxx index 451ade3..aec3459 100644 --- a/bpkg/database.cxx +++ b/bpkg/database.cxx @@ -1074,4 +1074,12 @@ namespace bpkg { return *this == main_database (); } + + // compare_lazy_ptr + // + bool compare_lazy_ptr:: + less (const odb::database& x, const odb::database& y) const + { + return static_cast (x) < static_cast (y); + } } diff --git a/bpkg/database.hxx b/bpkg/database.hxx index 889f8a0..c9ef590 100644 --- a/bpkg/database.hxx +++ b/bpkg/database.hxx @@ -518,10 +518,11 @@ namespace bpkg inline bool operator< (const database& x, const database& y) { - // Note that if we ever need the ordering to be consistent across runs, - // then we can compare the config paths or uuids. + // Note that we used to compare the database addresses here (as for the + // equality operator) until we needed the database ordering to be + // consistent across runs (to support --rebuild-checksum, etc). // - return &x < &y; + return x.config < y.config; } inline ostream& diff --git a/bpkg/package.cxx b/bpkg/package.cxx index 894051a..9a8068c 100644 --- a/bpkg/package.cxx +++ b/bpkg/package.cxx @@ -60,6 +60,13 @@ namespace bpkg return !s.empty () ? name.string () + ' ' + s : name.string (); } + bool config_package:: + operator< (const config_package& v) const + { + int r (name.compare (v.name)); + return r != 0 ? (r < 0) : (db < v.db); + } + // available_package // const version* available_package:: diff --git a/bpkg/package.hxx b/bpkg/package.hxx index 13efcd4..9a42f62 100644 --- a/bpkg/package.hxx +++ b/bpkg/package.hxx @@ -1370,13 +1370,7 @@ namespace bpkg } bool - operator< (const config_package& v) const - { - // See operator==(database, database). - // - int r (name.compare (v.name)); - return r != 0 ? (r < 0) : (&db < &v.db); - } + operator< (const config_package&) const; std::string string () const; diff --git a/bpkg/types.hxx b/bpkg/types.hxx index d8ffa79..8f6d9df 100644 --- a/bpkg/types.hxx +++ b/bpkg/types.hxx @@ -180,9 +180,15 @@ namespace bpkg // return x.object_id () != y.object_id () ? (x.object_id () < y.object_id ()) - : (&static_cast (x).database () < - &static_cast (y).database ()); + : less (static_cast (x).database (), + static_cast (y).database ()); } + + private: + // Defined in database.cxx. + // + bool + less (const odb::database&, const odb::database&) const; }; // Compare two lazy pointers via the pointed-to object ids. diff --git a/tests/pkg-build.testscript b/tests/pkg-build.testscript index 13f63c8..4da7747 100644 --- a/tests/pkg-build.testscript +++ b/tests/pkg-build.testscript @@ -6225,7 +6225,7 @@ else y EOI % new libbaz/1.0.0 \[cfg.\] \(required by foo \[cfg.\]\)% - % new libbuild2-bar/1.0.0 \[cfg3.\] \(required by (foo \[cfg2.\], foo \[cfg.\]\)|foo \[cfg.\], foo \[cfg2.\]\))% + % new libbuild2-bar/1.0.0 \[cfg3.\] \(required by foo \[cfg.\], foo \[cfg2.\]\)% % new foo/1.0.0 \[cfg.\]% % new libbaz/1.0.0 \[cfg2.\] \(required by foo \[cfg2.\]\)% % new foo/1.0.0 \[cfg2.\]% -- cgit v1.1