From 654212c314a4851cebda5021ef18f9f35b128df8 Mon Sep 17 00:00:00 2001 From: memsharded Date: Mon, 29 Mar 2021 17:14:42 +0200 Subject: [PATCH] proposing ``conan lock bundle clean-modified`` command --- conans/client/command.py | 6 ++++++ conans/client/conan_api.py | 7 +++++++ conans/model/lock_bundle.py | 15 +++++++++++++++ .../integration/graph_lock/test_lock_bundle.py | 8 ++++++++ 4 files changed, 36 insertions(+) diff --git a/conans/client/command.py b/conans/client/command.py index e5ddce6e764..4d53b968731 100644 --- a/conans/client/command.py +++ b/conans/client/command.py @@ -1924,6 +1924,10 @@ def lock(self, *args): update_bundle_cmd = bundle_subparsers.add_parser('update', help=update_help) update_bundle_cmd.add_argument('bundle', help='Path to lockfile bundle') + clean_modified_bundle_cmd = bundle_subparsers.add_parser('clean-modified', + help='Clean modified flag') + clean_modified_bundle_cmd.add_argument('bundle', help='Path to lockfile bundle') + args = parser.parse_args(*args) self._warn_python_version() @@ -1934,6 +1938,8 @@ def lock(self, *args): self._conan.lock_bundle_create(args.lockfiles, args.bundle_out) elif args.bundlecommand == "update": self._conan.lock_bundle_update(args.bundle) + elif args.bundlecommand == "clean-modified": + self._conan.lock_bundle_clean_modified(args.bundle) elif args.bundlecommand == "build-order": build_order = self._conan.lock_bundle_build_order(args.bundle) self._out.writeln(build_order) diff --git a/conans/client/conan_api.py b/conans/client/conan_api.py index 8f462718b88..c433a8cb597 100644 --- a/conans/client/conan_api.py +++ b/conans/client/conan_api.py @@ -1367,6 +1367,13 @@ def lock_bundle_update(self, lock_bundle_path, cwd=None): revisions_enabled = self.app.cache.config.revisions_enabled LockBundle.update_bundle(lock_bundle_path, revisions_enabled) + @api_method + def lock_bundle_clean_modified(self, lock_bundle_path, cwd=None): + cwd = cwd or os.getcwd() + lock_bundle_path = _make_abs_path(lock_bundle_path, cwd) + revisions_enabled = self.app.cache.config.revisions_enabled + LockBundle.clean_modified(lock_bundle_path, revisions_enabled) + @api_method def lock_create(self, path, lockfile_out, reference=None, name=None, version=None, user=None, channel=None, diff --git a/conans/model/lock_bundle.py b/conans/model/lock_bundle.py index fa0815e4d15..0be44bfc587 100644 --- a/conans/model/lock_bundle.py +++ b/conans/model/lock_bundle.py @@ -161,3 +161,18 @@ def update_bundle(bundle_path, revisions_enabled): graph_lock_conf.save(lockfile) save(bundle_path, bundle.dumps()) + + @staticmethod + def clean_modified(bundle_path, revisions_enabled): + bundle = LockBundle() + bundle.loads(load(bundle_path)) + for node in bundle._nodes.values(): + for pkg in node["packages"]: + pkg["modified"] = None + + for lockfile, nodes_ids in pkg["lockfiles"].items(): + graph_lock_conf = GraphLockFile.load(lockfile, revisions_enabled) + graph_lock_conf.graph_lock.clean_modified() + graph_lock_conf.save(lockfile) + + save(bundle_path, bundle.dumps()) diff --git a/conans/test/integration/graph_lock/test_lock_bundle.py b/conans/test/integration/graph_lock/test_lock_bundle.py index 8f524e4b390..82dc809ae4c 100644 --- a/conans/test/integration/graph_lock/test_lock_bundle.py +++ b/conans/test/integration/graph_lock/test_lock_bundle.py @@ -103,6 +103,14 @@ def test_basic(): assert nodes["3"].package_id == "cb054d0b3e1ca595dc66bc2339d40f1f8f04ab31" assert nodes["3"].prev == "9e99cfd92d0d7df79d687b01512ce844" + client.run("lock bundle clean-modified lock1.bundle") + bundle = client.load("lock1.bundle") + assert '"modified": true' not in bundle + lock1 = client.load("app1_windows.lock") + assert '"modified": true' not in lock1 + lock2 = client.load("app2_linux.lock") + assert '"modified": true' not in lock2 + def test_build_requires(): client = TestClient()