Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve build_scripts context issue with lockfiles #15802

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions conan/cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ def create(conan_api, parser, *args):
lockfile=lockfile,
remotes=remotes)

# FIXME: Dirty: package type still raw, not processed yet
is_build = args.build_require or conanfile.package_type == "build-scripts"
# The package_type is not fully processed at export
is_python_require = conanfile.package_type == "python-require"
lockfile = conan_api.lockfile.update_lockfile_export(lockfile, conanfile, ref,
args.build_require)
lockfile = conan_api.lockfile.update_lockfile_export(lockfile, conanfile, ref, is_build)

print_profiles(profile_host, profile_build)
if args.build is not None and args.build_test is None:
Expand All @@ -66,13 +67,8 @@ def create(conan_api, parser, *args):
remotes=remotes, update=args.update,
python_requires=[ref])
else:
requires = [ref] if not args.build_require else None
tool_requires = [ref] if args.build_require else None
# FIXME: Dirty: package type still raw, not processed yet
# TODO: Why not for package_type = "application" like cmake to be used as build-require?
if conanfile.package_type == "build-scripts" and not args.build_require:
# swap them
requires, tool_requires = tool_requires, requires
requires = [ref] if not is_build else None
tool_requires = [ref] if is_build else None
deps_graph = conan_api.graph.load_graph_requires(requires, tool_requires,
profile_host=profile_host,
profile_build=profile_build,
Expand Down
16 changes: 16 additions & 0 deletions conans/test/integration/lockfile/test_lock_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,19 @@ def test_error_test_explicit():
"test_package/conanfile.py": test})
client.run("lock create conanfile.py --lockfile-out=my.lock")
client.run("create . --lockfile=my.lock")


def test_lock_error_create():
# https://github.com/conan-io/conan/issues/15801
c = TestClient()
c.save({"conanfile.py": GenConanfile("pkg", "0.1").with_package_type("build-scripts")})
c.run("lock create . -u --lockfile-out=none.lock")
lock = json.loads(c.load("none.lock"))
assert lock["requires"] == []
assert lock["build_requires"] == []
c.run("create . --lockfile=none.lock --lockfile-out=none_updated.lock")
# It doesn't crash, it used to
lock = json.loads(c.load("none_updated.lock"))
assert lock["requires"] == []
assert len(lock["build_requires"]) == 1
assert "pkg/0.1#4e9dba5c3041ba4c87724486afdb7eb4" in lock["build_requires"][0]