Skip to content

Commit

Permalink
proposing conan lock bundle clean-modified command (#8726)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Mar 29, 2021
1 parent 55323dc commit 9032904
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions conans/client/command.py
Expand Up @@ -1937,6 +1937,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()

Expand All @@ -1949,6 +1953,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)
Expand Down
7 changes: 7 additions & 0 deletions conans/client/conan_api.py
Expand Up @@ -1404,6 +1404,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,
Expand Down
15 changes: 15 additions & 0 deletions conans/model/lock_bundle.py
Expand Up @@ -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())
8 changes: 8 additions & 0 deletions conans/test/integration/graph_lock/test_lock_bundle.py
Expand Up @@ -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()
Expand Down

0 comments on commit 9032904

Please sign in to comment.