Skip to content

Commit

Permalink
[develop2][poc] decouple test_package from create (#12046)
Browse files Browse the repository at this point in the history
* decouple test_package from create

* wip

* fixing tests

* wip

* simplify

* review

* fixes
  • Loading branch information
memsharded authored Sep 9, 2022
1 parent 082703e commit 47cd3a5
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 34 deletions.
31 changes: 14 additions & 17 deletions conan/cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from conan.cli.formatters.graph import print_graph_basic, print_graph_packages
from conans.client.conanfile.build import run_build_method
from conans.errors import ConanException, conanfile_exception_formatter
from conans.model.graph_lock import Lockfile
from conans.util.files import chdir, mkdir


Expand Down Expand Up @@ -60,19 +61,7 @@ def create(conan_api, parser, *args):
out.info("Profile build:")
out.info(profile_build.dumps())

if args.test_folder == "None":
# Now if parameter --test-folder=None (string None) we have to skip tests
args.test_folder = False
test_conanfile_path = _get_test_conanfile_path(args.test_folder, path)
if test_conanfile_path:
if args.build_require:
raise ConanException("--build-require should not be specified, test_package does it")
root_node = conan_api.graph.load_root_test_conanfile(test_conanfile_path, ref,
profile_host, profile_build,
remotes=remotes,
update=args.update,
lockfile=lockfile)
else:
if True: # just to keep diff shorter now
requires = [ref] if not args.build_require else None
tool_requires = [ref] if args.build_require else None
scope_options(profile_host, requires=requires, tool_requires=tool_requires)
Expand Down Expand Up @@ -100,11 +89,19 @@ def create(conan_api, parser, *args):
out.title("Installing packages")
conan_api.install.install_binaries(deps_graph=deps_graph, remotes=remotes, update=args.update)

save_lockfile_out(args, deps_graph, lockfile, cwd)

if args.test_folder == "None":
# Now if parameter --test-folder=None (string None) we have to skip tests
args.test_folder = False
test_conanfile_path = _get_test_conanfile_path(args.test_folder, path)
if test_conanfile_path:
_check_tested_reference_matches(deps_graph, ref, out)
test_package(conan_api, deps_graph, test_conanfile_path)
# TODO: We need arguments for:
# - decide build policy for test_package deps "--test_package_build=missing"
# - decide update policy "--test_package_update"
from conan.cli.commands.test import run_test
deps_graph = run_test(conan_api, test_conanfile_path, ref, profile_host, profile_build,
remotes, lockfile, update=False, build_modes=None)

save_lockfile_out(args, deps_graph, lockfile, cwd)

return deps_graph

Expand Down
1 change: 1 addition & 0 deletions conan/cli/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def save_lockfile_out(args, graph, lockfile, cwd):
lockfile.update_lock(graph, args.lockfile_packages)
lockfile.save(lockfile_out)
ConanOutput().info(f"Generated lockfile: {lockfile_out}")
return lockfile


def get_multiple_remotes(conan_api, remote_names=None):
Expand Down
1 change: 1 addition & 0 deletions conans/client/graph/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def _get_recipe(self, reference):
recipe_layout = self._cache.ref_layout(ref)
conanfile_path = recipe_layout.conanfile()

# TODO: If the revision is given, then we don't need to check for updates?
if self._conan_app.check_updates or self._conan_app.update:

remote, remote_ref = self._find_newest_recipe_in_remotes(reference)
Expand Down
2 changes: 1 addition & 1 deletion conans/test/functional/subsystems_build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test(self):
"test_package/conanfile.py": test_conanfile,
"myprofile": profile})

client.run("create . --name foo --version 1.0 --profile:build myprofile")
client.run("create . --name foo --version 1.0 --profile:build myprofile --build-require")
assert "__MINGW64__" in client.out
assert "__CYGWIN__" not in client.out

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ def test(self):
"test_package/conanfile.py": test_conanfile,
'test_package/CMakeLists.txt': test_cmake,
"test_package/timer.cpp": timer_cpp})
# First build it as build_require in the build-context, no testing
# the UX could be improved, but the simplest could be:
# - Have users 2 test_packages, one for the host and other for the build, with some naming
# convention. CI launches one after the other if found
client.run("create . %s -tf=None --build-require" % settings)
client.run("create . %s" % settings)
if not len(settings):
assert "Hello World Release!" in client.out
Expand Down
24 changes: 13 additions & 11 deletions conans/test/integration/build_requires/test_toolchain_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ def test(self):
c.save({"test_package/conanfile.py": test})

# Creating the NDK packages for Windows, Linux
c.run("create . -pr:b=windows -pr:h=android")
c.run("create . -pr:b=windows -pr:h=android --build-require")
c.assert_listed_binary({"androidndk/0.1": ("522dcea5982a3f8a5b624c16477e47195da2f84f", "Build")},
build=True)
assert "androidndk/0.1 (test package): NDK LIBS: ['libndklib-armv7']!!!" in c.out
assert "androidndk/0.1 (test package): MYNDK-Windows-x86_64 exe!" in c.out
assert "androidndk/0.1 (test package): MY-VAR: android-armv7" in c.out
# The same NDK can be used for different architectures, this should not require a new NDK build
c.run("create . -pr:b=windows -pr:h=android -s:h arch=armv8 --build=missing")
c.run("create . -pr:b=windows -pr:h=android -s:h arch=armv8 --build=missing --build-require")
c.assert_listed_binary({"androidndk/0.1": ("522dcea5982a3f8a5b624c16477e47195da2f84f", "Cache")},
build=True)
assert "androidndk/0.1: Already installed!" in c.out
Expand All @@ -123,7 +123,7 @@ def test(self):
assert "androidndk/0.1 (test package): MY-VAR: android-armv8" in c.out

# But a different build architecture is a different NDK executable
c.run("create . -pr:b=windows -s:b arch=x86 -pr:h=android --build=missing")
c.run("create . -pr:b=windows -s:b arch=x86 -pr:h=android --build=missing --build-require")
c.assert_listed_binary({"androidndk/0.1": ("c11e463c49652ba9c5adc62573ee49f966bd8417", "Build")},
build=True)
assert "androidndk/0.1: Calling build()" in c.out
Expand All @@ -132,7 +132,7 @@ def test(self):
assert "androidndk/0.1 (test package): MY-VAR: android-armv7" in c.out

# But a different build OS is a different NDK executable
c.run("create . -pr:b=linux -pr:h=android --build=missing")
c.run("create . -pr:b=linux -pr:h=android --build=missing --build-require")
c.assert_listed_binary({"androidndk/0.1": ("63fead0844576fc02943e16909f08fcdddd6f44b", "Build")},
build=True)
assert "androidndk/0.1: Calling build()" in c.out
Expand Down Expand Up @@ -237,28 +237,30 @@ def test(self):
"macos": macos,
"ios": ios})

c.run("create . -pr:b=macos -pr:h=ios")
c.run("create . -pr:b=macos -pr:h=ios --build-require")
c.assert_listed_binary({"libcxx/0.1": ("cd83035dfa71d83329e31a13b54b03fd38836815", "Build")},
build=True)
assert "libcxx/0.1 (test package): LIBCXX LIBS: libcxx-armv7!!!" in c.out
assert "libcxx/0.1 (test package): libcxxiphoneos-iOS-armv7!" in c.out

# Same host profile should be same binary, the build profile is not factored in
c.run("create . -pr:b=macos -s:b build_type=Debug -s:b arch=armv8 -pr:h=ios --build=missing")
c.run("create . -pr:b=macos -s:b build_type=Debug -s:b arch=armv8 -pr:h=ios "
"--build=missing --build-require")
c.assert_listed_binary({"libcxx/0.1": ("cd83035dfa71d83329e31a13b54b03fd38836815", "Cache")},
build=True)
assert "libcxx/0.1 (test package): LIBCXX LIBS: libcxx-armv7!!!" in c.out
assert "libcxx/0.1 (test package): libcxxiphoneos-iOS-armv7!" in c.out

# But every change in host, is a different binary
c.run("create . -pr:b=macos -pr:h=ios -s:h arch=armv8 --build=missing")
c.run("create . -pr:b=macos -pr:h=ios -s:h arch=armv8 --build=missing --build-require")
c.assert_listed_binary({"libcxx/0.1": ("af2d5e0458816f1d7e61c82315d143c20e3db2e3", "Build")},
build=True)
assert "libcxx/0.1 (test package): LIBCXX LIBS: libcxx-armv8!!!" in c.out
assert "libcxx/0.1 (test package): libcxxiphoneos-iOS-armv8!" in c.out

# But every change in host, is a different binary
c.run("create . -pr:b=macos -pr:h=ios -s:h arch=armv8 -s:h os.sdk=iphonesimulator ")
c.run("create . -pr:b=macos -pr:h=ios -s:h arch=armv8 -s:h os.sdk=iphonesimulator "
"--build-require")
c.assert_listed_binary({"libcxx/0.1": ("c7e3b0fbb4fac187f59bf97e7958631b96fda2a6", "Build")},
build=True)
assert "libcxx/0.1 (test package): LIBCXX LIBS: libcxx-armv8!!!" in c.out
Expand Down Expand Up @@ -351,23 +353,23 @@ def test(self):
"linux": linux,
"rpi": rpi})

c.run("create . -pr:b=linux -pr:h=rpi")
c.run("create . -pr:b=linux -pr:h=rpi --build-require")
c.assert_listed_binary({"gcc/0.1": ("6190ea2804cd4777609ec7174ccfdee22c6318c3", "Build")},
build=True)
assert "gcc/0.1 (test package): LIBCXX LIBS: libcxx-armv7!!!" in c.out
assert "gcc/0.1 (test package): libcxx-Linux-armv7!" in c.out
assert "gcc/0.1 (test package): gcc-Linux-x86_64" in c.out

# Same host profile, but different build profile is a different binary
c.run("create . -pr:b=linux -s:b os=Windows -s:b arch=armv8 -pr:h=rpi")
c.run("create . -pr:b=linux -s:b os=Windows -s:b arch=armv8 -pr:h=rpi --build-require")
c.assert_listed_binary({"gcc/0.1": ("687fdc5f43017300a98643948869b4c5560ca82c", "Build")},
build=True)
assert "gcc/0.1 (test package): LIBCXX LIBS: libcxx-armv7!!!" in c.out
assert "gcc/0.1 (test package): libcxx-Linux-armv7!" in c.out
assert "gcc/0.1 (test package): gcc-Windows-armv8" in c.out

# Same build but different host is also a new binary
c.run("create . -pr:b=linux -pr:h=rpi -s:h arch=armv8 --build=missing")
c.run("create . -pr:b=linux -pr:h=rpi -s:h arch=armv8 --build=missing --build-require")
c.assert_listed_binary({"gcc/0.1": ("0521de9a6b94083bd47474a51570a3b856b77406", "Build")},
build=True)
assert "gcc/0.1 (test package): LIBCXX LIBS: libcxx-armv8!!!" in c.out
Expand Down
7 changes: 3 additions & 4 deletions conans/test/integration/cross_building/test_package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def test_command(self):
'profile_host': '[settings]\nos=Host',
'profile_build': '[settings]\nos=Build', })
t.run("export br.py --name=br1 --version=version")
t.run("export br.py --name=br2 --version=version")
# It is necessary to build first the test_package build_requires br2
t.run("create br.py --name=br2 --version=version -tf=None --build-require "
"--profile:host=profile_host --profile:build=profile_build")

t.run("create conanfile.py --name=name --version=version --build=missing"
" --profile:host=profile_host --profile:build=profile_build")
Expand All @@ -68,9 +70,6 @@ def test_command(self):
self.assertIn("br1/version: >> settings.os: Build", t.out)
self.assertIn("br1/version: >> settings_build.os: Build", t.out)

self.assertIn("br2/version: >> settings.os: Build", t.out)
self.assertIn("br2/version: >> settings_build.os: Build", t.out)

# Package 'name' is built for the 'host' context (br1 as build_requirement)
self.assertIn("name/version: >> settings.os: Host", t.out)
self.assertIn("name/version: >> settings_build.os: Build", t.out)
Expand Down
2 changes: 1 addition & 1 deletion conans/test/integration/graph/core/test_build_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def test(self):
""")

client.save({"test_package/conanfile.py": test})
client.run("create . -s:b os=Windows -s:h os=Linux")
client.run("create . -s:b os=Windows -s:h os=Linux --build-require")
assert "This is the binary for OS=Linux" not in client.out
assert "This is in context=host" not in client.out
client.assert_listed_require({"consumer/1.0": "Cache"}, build=True)
Expand Down

0 comments on commit 47cd3a5

Please sign in to comment.