def vcvars(*args, **kwargs): if platform.system() == "Windows": new_env = vcvars_dict(*args, **kwargs) with environment_append(new_env): yield else: yield
def run_in_windows_bash(conanfile, bashcmd, cwd=None, subsystem=None, msys_mingw=True, env=None): """ Will run a unix command inside a bash terminal It requires to have MSYS2, CYGWIN, or WSL """ env = env or {} if platform.system() != "Windows": raise ConanException("Command only for Windows operating system") subsystem = subsystem or os_info.detect_windows_subsystem() if not subsystem: raise ConanException("Cannot recognize the Windows subsystem, install MSYS2/cygwin or specify a build_require " "to apply it.") if subsystem == MSYS2 and msys_mingw: # This needs to be set so that msys2 bash profile will set up the environment correctly. env_vars = {"MSYSTEM": "MINGW32" if conanfile.settings.get_safe("arch") == "x86" else "MINGW64", "MSYS2_PATH_TYPE": "inherit"} else: env_vars = {} with environment_append(env_vars): hack_env = "" if subsystem != WSL: # In the bash.exe from WSL this trick do not work, always the /usr/bin etc at first place inherited_path = conanfile.env.get("PATH", None) if isinstance(inherited_path, list): paths = [unix_path(path, path_flavor=subsystem) for path in inherited_path] inherited_path = ":".join(paths) else: inherited_path = unix_path(inherited_path, path_flavor=subsystem) if "PATH" in env: tmp = unix_path(env["PATH"].replace(";", ":"), path_flavor=subsystem) inherited_path = "%s:%s" % (tmp, inherited_path) if inherited_path else tmp # Put the build_requires and requires path at the first place inside the shell hack_env = ' && PATH="%s:$PATH"' % inherited_path if inherited_path else "" for var_name, value in env.items(): if var_name == "PATH": continue hack_env += ' && %s=%s' % (var_name, value) # Needed to change to that dir inside the bash shell if cwd and not os.path.isabs(cwd): cwd = os.path.join(get_cwd(), cwd) curdir = unix_path(cwd or get_cwd(), path_flavor=subsystem) to_run = 'cd "%s"%s && %s ' % (curdir, hack_env, bashcmd) bash_path = os_info.bash_path() bash_path = '"%s"' % bash_path if " " in bash_path else bash_path wincmd = '%s --login -c %s' % (bash_path, escape_windows_cmd(to_run)) conanfile.output.info('run_in_windows_bash: %s' % wincmd) # https://github.com/conan-io/conan/issues/2839 (subprocess=True) return conanfile._runner(wincmd, output=conanfile.output, subprocess=True)
def uname(options=None): options = " %s" % options if options else "" if platform.system() != "Windows": raise ConanException("Command only for Windows operating system") custom_bash_path = OSInfo.bash_path() if not custom_bash_path: raise ConanException("bash is not in the path") command = '"%s" -c "uname%s"' % (custom_bash_path, options) try: # the uname executable is many times located in the same folder as bash.exe with environment_append({"PATH": [os.path.dirname(custom_bash_path)]}): ret = subprocess.check_output(command, shell=True, ).decode().strip().lower() return ret except Exception: return None
def get_env_context_manager(conanfile, without_python=False): if not conanfile.apply_env: return no_op() if without_python: return environment_append(conanfile.env) return _env_and_python(conanfile)
def upload_no_overwrite_recipe_test(self): conanfile_new = """from conans import ConanFile, tools class MyPkg(ConanFile): name = "Hello0" version = "1.2.1" exports_sources = "*" options = {"shared": [True, False]} default_options = "shared=False" def build(self): if tools.get_env("MY_VAR", False): open("file.h", 'w').close() def package(self): self.copy("*.h") """ client = self._client() client.save({ "conanfile.py": conanfile_new, "hello.h": "", "hello.cpp": "" }) client.run("create . frodo/stable") # First time upload client.run( "upload Hello0/1.2.1@frodo/stable --all --no-overwrite recipe") self.assertNotIn("Forbidden overwrite", client.out) self.assertIn("Uploading Hello0/1.2.1@frodo/stable", client.out) # Upload again client.run( "upload Hello0/1.2.1@frodo/stable --all --no-overwrite recipe") self.assertIn("Recipe is up to date, upload skipped", client.out) self.assertIn("Package is up to date, upload skipped", client.out) self.assertNotIn("Forbidden overwrite", client.out) # Create without changes # *1 client.run("create . frodo/stable") client.run( "upload Hello0/1.2.1@frodo/stable --all --no-overwrite recipe") self.assertIn("Recipe is up to date, upload skipped", client.out) self.assertIn("Package is up to date, upload skipped", client.out) self.assertNotIn("Forbidden overwrite", client.out) # Create with recipe and package changes new_recipe = conanfile_new.replace( "self.copy(\"*.h\")", "self.copy(\"*.h\")\n self.copy(\"*.cpp\")") client.save({"conanfile.py": new_recipe}) client.run("create . frodo/stable") # upload recipe and packages error = client.run( "upload Hello0/1.2.1@frodo/stable --all --no-overwrite recipe", ignore_error=True) if not client.revisions: self.assertTrue(error) self.assertIn("Forbidden overwrite", client.out) self.assertNotIn("Uploading package", client.out) # Create with package changes client.run("upload Hello0/1.2.1@frodo/stable --all") with environment_append({"MY_VAR": "True"}): client.run("create . frodo/stable") # upload recipe and packages client.run( "upload Hello0/1.2.1@frodo/stable --all --no-overwrite recipe") self.assertIn("Recipe is up to date, upload skipped", client.out) self.assertIn("Uploading conan_package.tgz", client.out) self.assertNotIn("Forbidden overwrite", client.out) else: self.assertIn("Uploading conan_package.tgz", client.out)
def test_upload_no_overwrite_all(self): conanfile_new = """from conans import ConanFile, tools class MyPkg(ConanFile): name = "Hello0" version = "1.2.1" exports_sources = "*" options = {"shared": [True, False]} default_options = "shared=False" def build(self): if tools.get_env("MY_VAR", False): open("file.h", 'w').close() def package(self): self.copy("*.h") """ client = TestClient(default_server_user=True) client.save({"conanfile.py": conanfile_new, "hello.h": "", "hello.cpp": ""}) client.run("create . frodo/stable") # First time upload client.run("upload Hello0/1.2.1@frodo/stable --all --no-overwrite") self.assertNotIn("Forbidden overwrite", client.out) self.assertIn("Uploading Hello0/1.2.1@frodo/stable", client.out) # CASE: Upload again client.run("upload Hello0/1.2.1@frodo/stable --all --no-overwrite") self.assertIn("Recipe is up to date, upload skipped", client.out) self.assertIn("Package is up to date, upload skipped", client.out) self.assertNotIn("Forbidden overwrite", client.out) # CASE: Without changes client.run("create . frodo/stable") # upload recipe and packages client.run("upload Hello0/1.2.1@frodo/stable --all --no-overwrite") self.assertIn("Recipe is up to date, upload skipped", client.out) self.assertIn("Package is up to date, upload skipped", client.out) self.assertNotIn("Forbidden overwrite", client.out) # CASE: When recipe and package changes new_recipe = conanfile_new.replace("self.copy(\"*.h\")", "self.copy(\"*.h\")\n self.copy(\"*.cpp\")") client.save({"conanfile.py": new_recipe}) client.run("create . frodo/stable") # upload recipe and packages # *1 client.run("upload Hello0/1.2.1@frodo/stable --all --no-overwrite", assert_error=not client.cache.config.revisions_enabled) if not client.cache.config.revisions_enabled: # The --no-overwrite makes no sense with revisions self.assertIn("Forbidden overwrite", client.out) self.assertNotIn("Uploading conan_package.tgz", client.out) # CASE: When package changes client.run("upload Hello0/1.2.1@frodo/stable --all") with environment_append({"MY_VAR": "True"}): client.run("create . frodo/stable") # upload recipe and packages client.run("upload Hello0/1.2.1@frodo/stable --all --no-overwrite", assert_error=not client.cache.config.revisions_enabled) if not client.cache.config.revisions_enabled: self.assertIn("Recipe is up to date, upload skipped", client.out) self.assertIn("ERROR: Hello0/1.2.1@frodo/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9" ": Upload package to 'default' failed: " "Local package is different from the remote package", client.out) self.assertIn("Forbidden overwrite", client.out) self.assertNotIn("Uploading conan_package.tgz", client.out) else: self.assertIn("Uploading conan_package.tgz", client.out)
def run_in_windows_bash(conanfile, bashcmd, cwd=None, subsystem=None, msys_mingw=True, env=None, with_login=True): """ Will run a unix command inside a bash terminal It requires to have MSYS2, CYGWIN, or WSL """ env = env or {} if platform.system() != "Windows": raise ConanException("Command only for Windows operating system") subsystem = subsystem or OSInfo.detect_windows_subsystem() if not subsystem: raise ConanException( "Cannot recognize the Windows subsystem, install MSYS2/cygwin " "or specify a build_require to apply it.") if subsystem == MSYS2 and msys_mingw: # This needs to be set so that msys2 bash profile will set up the environment correctly. env_vars = { "MSYSTEM": ("MINGW32" if conanfile.settings.get_safe("arch") == "x86" else "MINGW64"), "MSYS2_PATH_TYPE": "inherit" } else: env_vars = {} with environment_append(env_vars): hack_env = "" # In the bash.exe from WSL this trick do not work, always the /usr/bin etc at first place if subsystem != WSL: def get_path_value(container, subsystem_name): """Gets the path from the container dict and returns a string with the path for the subsystem_name""" _path_key = next( (name for name in container.keys() if "path" == name.lower()), None) if _path_key: _path_value = container.get(_path_key) if isinstance(_path_value, list): return ":".join([ unix_path(path, path_flavor=subsystem_name) for path in _path_value ]) else: return unix_path(_path_value, path_flavor=subsystem_name) # First get the PATH from the conanfile.env inherited_path = get_path_value(conanfile.env, subsystem) # Then get the PATH from the real env env_path = get_path_value(env, subsystem) # Both together full_env = ":".join(v for v in [env_path, inherited_path] if v) # Put the build_requires and requires path at the first place inside the shell hack_env = ' && PATH="%s:$PATH"' % full_env if full_env else "" for var_name, value in env.items(): if var_name == "PATH": continue hack_env += ' && %s=%s' % (var_name, value) # Needed to change to that dir inside the bash shell if cwd and not os.path.isabs(cwd): cwd = os.path.join(get_cwd(), cwd) curdir = unix_path(cwd or get_cwd(), path_flavor=subsystem) to_run = 'cd "%s"%s && %s ' % (curdir, hack_env, bashcmd) bash_path = OSInfo.bash_path() bash_path = '"%s"' % bash_path if " " in bash_path else bash_path login = "******" if with_login else "" wincmd = '%s %s -c %s' % (bash_path, login, escape_windows_cmd(to_run)) conanfile.output.info('run_in_windows_bash: %s' % wincmd) # If is there any other env var that we know it contains paths, convert it to unix_path used_special_vars = [ var for var in ["AR", "AS", "RANLIB", "LD", "STRIP", "CC", "CXX"] if var in conanfile.env.keys() ] normalized_env = { p: unix_path(conanfile.env[p], path_flavor=subsystem) for p in used_special_vars } # https://github.com/conan-io/conan/issues/2839 (subprocess=True) with environment_append(normalized_env): return conanfile._conan_runner(wincmd, output=conanfile.output, subprocess=True)
def test_environment_append_unsetting_non_existing_variables(self): with mock.patch.dict('os.environ', {'env_var2': 'value2'}),\ env.environment_append({'env_var1': None}): self.assertNotIn('env_var1', os.environ)
def run_in_windows_bash(conanfile, bashcmd, cwd=None, subsystem=None, msys_mingw=True, env=None): """ Will run a unix command inside a bash terminal It requires to have MSYS2, CYGWIN, or WSL """ env = env or {} if platform.system() != "Windows": raise ConanException("Command only for Windows operating system") subsystem = subsystem or os_info.detect_windows_subsystem() if not subsystem: raise ConanException( "Cannot recognize the Windows subsystem, install MSYS2/cygwin or specify a build_require " "to apply it.") if subsystem == MSYS2 and msys_mingw: # This needs to be set so that msys2 bash profile will set up the environment correctly. env_vars = { "MSYSTEM": "MINGW32" if conanfile.settings.get_safe("arch") == "x86" else "MINGW64", "MSYS2_PATH_TYPE": "inherit" } else: env_vars = {} with environment_append(env_vars): hack_env = "" if subsystem != WSL: # In the bash.exe from WSL this trick do not work, always the /usr/bin etc at first place inherited_path = conanfile.env.get("PATH", None) if isinstance(inherited_path, list): paths = [ unix_path(path, path_flavor=subsystem) for path in inherited_path ] inherited_path = ":".join(paths) else: inherited_path = unix_path(inherited_path, path_flavor=subsystem) if "PATH" in env: tmp = unix_path(env["PATH"].replace(";", ":"), path_flavor=subsystem) inherited_path = "%s:%s" % ( tmp, inherited_path) if inherited_path else tmp # Put the build_requires and requires path at the first place inside the shell hack_env = ' && PATH="%s:$PATH"' % inherited_path if inherited_path else "" for var_name, value in env.items(): if var_name == "PATH": continue hack_env += ' && %s=%s' % (var_name, value) # Needed to change to that dir inside the bash shell if cwd and not os.path.isabs(cwd): cwd = os.path.join(get_cwd(), cwd) curdir = unix_path(cwd or get_cwd(), path_flavor=subsystem) to_run = 'cd "%s"%s && %s ' % (curdir, hack_env, bashcmd) bash_path = os_info.bash_path() bash_path = '"%s"' % bash_path if " " in bash_path else bash_path wincmd = '%s --login -c %s' % (bash_path, escape_windows_cmd(to_run)) conanfile.output.info('run_in_windows_bash: %s' % wincmd) # https://github.com/conan-io/conan/issues/2839 (subprocess=True) return conanfile._runner(wincmd, output=conanfile.output, subprocess=True)
def configure(self, configure_dir=None, args=None, build=None, host=None, target=None, pkg_config_paths=None, vars=None, use_default_install_dirs=True): """ :param pkg_config_paths: Optional paths to locate the *.pc files :param configure_dir: Absolute or relative path to the configure script :param args: Optional arguments to pass to configure. :param build: In which system the program will be built. "False" skips the --build flag :param host: In which system the generated program will run. "False" skips the --host flag :param target: This option is only used to build a cross-compiling toolchain. "False" skips the --target flag When the tool chain generates executable program, in which target system the program will run. http://jingfenghanmax.blogspot.com.es/2010/09/configure-with-host-target-and-build.html https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html :param use_default_install_dirs: Use or not the defaulted installation dirs """ if not self._conanfile.should_configure: return if configure_dir: configure_dir = configure_dir.rstrip("/") else: configure_dir = "." triplet_args = [] if build is not False: # Skipped by user if build or self.build: # User specified value or automatic triplet_args.append("--build=%s" % (build or self.build)) if host is not False: # Skipped by user if host or self.host: # User specified value or automatic triplet_args.append("--host=%s" % (host or self.host)) if target is not False: # Skipped by user if target or self.target: # User specified value or automatic triplet_args.append("--target=%s" % (target or self.target)) if pkg_config_paths: pkg_env = { "PKG_CONFIG_PATH": [ os.pathsep.join( get_abs_path(f, self._conanfile.install_folder) for f in pkg_config_paths) ] } else: # If we are using pkg_config generator automate the pcs location, otherwise it could # read wrong files pkg_env = {"PKG_CONFIG_PATH": [self._conanfile.install_folder]} \ if "pkg_config" in self._conanfile.generators else None configure_dir = self._adjust_path(configure_dir) if self._conanfile.package_folder is not None: if not args: args = [ "--prefix=%s" % self._conanfile.package_folder.replace("\\", "/") ] elif not self._is_flag_in_args("prefix", args): args.append("--prefix=%s" % self._conanfile.package_folder.replace("\\", "/")) all_flags = [ "bindir", "sbindir", "libexecdir", "libdir", "includedir", "oldincludedir", "datarootdir" ] help_output = self._configure_help_output(configure_dir) available_flags = [ flag for flag in all_flags if "--%s" % flag in help_output ] if use_default_install_dirs: for varname in ["bindir", "sbindir", "libexecdir"]: if self._valid_configure_flag(varname, args, available_flags): args.append("--%s=${prefix}/%s" % (varname, DEFAULT_BIN)) if self._valid_configure_flag("libdir", args, available_flags): args.append("--libdir=${prefix}/%s" % DEFAULT_LIB) for varname in ["includedir", "oldincludedir"]: if self._valid_configure_flag(varname, args, available_flags): args.append("--%s=${prefix}/%s" % (varname, DEFAULT_INCLUDE)) if self._valid_configure_flag("datarootdir", args, available_flags): args.append("--datarootdir=${prefix}/%s" % DEFAULT_SHARE) with environment_append(pkg_env): with environment_append(vars or self.vars): command = '%s/configure %s %s' % (configure_dir, args_to_string(args), " ".join(triplet_args)) self._conanfile.output.info("Calling:\n > %s" % command) self._conanfile.run(command, win_bash=self._win_bash, subsystem=self.subsystem)
def compilervars(*args, **kwargs): new_env = compilervars_dict(*args, **kwargs) with environment_append(new_env): yield
def test_environment_append_variables_without_values(self): with mock.patch.dict('os.environ', {'env_var1': 'value', 'env_var2': 'value2'}), env.environment_append({}): self.assertEqual(os.environ['env_var1'], 'value') self.assertEqual(os.environ['env_var2'], 'value2')
def test_environment_append_overwriting(self): with mock.patch.dict('os.environ', {'env_var1': 'value'}),\ env.environment_append({'env_var1': 'new_value'}): self.assertEqual(os.environ['env_var1'], 'new_value')
def _env_and_python(conanfile): with environment_append(conanfile.env): with pythonpath(conanfile): yield
def test_already_set(self): with environment_append({"PSTLROOT": "1"}): settings = Settings.loads(get_default_settings_yml()) cvars = compilervars_command(MockConanfile(settings)) self.assertEqual("echo Conan:compilervars already set", cvars)
def build(self, project_file, targets=None, upgrade_project=True, build_type=None, arch=None, parallel=True, force_vcvars=False, toolset=None, platforms=None, use_env=True, vcvars_ver=None, winsdk_version=None, properties=None, output_binary_log=None, property_file_name=None, verbosity=None, definitions=None, user_property_file_name=None): """ :param project_file: Path to the .sln file. :param targets: List of targets to build. :param upgrade_project: Will call devenv to upgrade the solution to your current Visual Studio. :param build_type: Use a custom build type instead of the default settings.build_type one. :param arch: Use a custom architecture name instead of the settings.arch one. It will be used to build the /p:Configuration= parameter of MSBuild. It can be used as the key of the platforms parameter. E.g. arch="x86", platforms={"x86": "i386"} :param parallel: Will use the configured number of cores in the conan.conf file or tools.cpu_count(): In the solution: Building the solution with the projects in parallel. (/m: parameter). CL compiler: Building the sources in parallel. (/MP: compiler flag) :param force_vcvars: Will ignore if the environment is already set for a different Visual Studio version. :param toolset: Specify a toolset. Will append a /p:PlatformToolset option. :param platforms: Dictionary with the mapping of archs/platforms from Conan naming to another one. It is useful for Visual Studio solutions that have a different naming in architectures. Example: platforms={"x86":"Win32"} (Visual solution uses "Win32" instead of "x86"). This dictionary will update the default one: msvc_arch = {'x86': 'x86', 'x86_64': 'x64', 'armv7': 'ARM', 'armv8': 'ARM64'} :param use_env: Applies the argument /p:UseEnv=true to the MSBuild call. :param vcvars_ver: Specifies the Visual Studio compiler toolset to use. :param winsdk_version: Specifies the version of the Windows SDK to use. :param properties: Dictionary with new properties, for each element in the dictionary {name: value} it will append a /p:name="value" option. :param output_binary_log: If set to True then MSBuild will output a binary log file called msbuild.binlog in the working directory. It can also be used to set the name of log file like this output_binary_log="my_log.binlog". This parameter is only supported starting from MSBuild version 15.3 and onwards. :param property_file_name: When None it will generate a file named conan_build.props. You can specify a different name for the generated properties file. :param verbosity: Specifies verbosity level (/verbosity: parameter) :param definitions: Dictionary with additional compiler definitions to be applied during the build. Use value of None to set compiler definition with no value. :param user_property_file_name: Specify a user provided .props file with custom definitions :return: status code of the MSBuild command invocation """ property_file_name = property_file_name or "conan_build.props" self.build_env.parallel = parallel with environment_append(self.build_env.vars): # Path for custom properties file props_file_contents = self._get_props_file_contents(definitions) property_file_name = os.path.abspath(property_file_name) save(property_file_name, props_file_contents) vcvars = vcvars_command(self._conanfile.settings, arch=arch, force=force_vcvars, vcvars_ver=vcvars_ver, winsdk_version=winsdk_version, output=self._output) command = self.get_command( project_file, property_file_name, targets=targets, upgrade_project=upgrade_project, build_type=build_type, arch=arch, parallel=parallel, toolset=toolset, platforms=platforms, use_env=use_env, properties=properties, output_binary_log=output_binary_log, verbosity=verbosity, user_property_file_name=user_property_file_name) command = "%s && %s" % (vcvars, command) context = no_op() if self._conanfile.settings.get_safe("compiler") == "Intel" and \ self._conanfile.settings.get_safe("compiler.base") == "Visual Studio": context = intel_compilervars(self._conanfile.settings, arch) with context: return self._conanfile.run(command)
def _env_and_python(conanfile): with environment_append(conanfile.env): # FIXME Conan 2.0, Remove old ways of reusing python code with pythonpath(conanfile): yield
def reuse_test(self): ref = ConanFileReference.loads("stringutil/0.1@lasote/stable") files = { 'conanfile.py': stringutil_conanfile, 'reverse.go': reverse, 'reverse_test.go': reverse_test, 'reverse.txt': reverse, 'hello/helloreverse.txt': reverse } files_without_conanfile = set(files.keys()) - set(["conanfile.py"]) self.client.save(files) self.client.run("export . lasote/stable") self.client.run("install %s --build missing" % str(ref)) # Check compilation ok package_ids = self.client.cache.conan_packages(ref) self.assertEquals(len(package_ids), 1) pref = PackageReference(ref, package_ids[0]) self._assert_package_exists(pref, self.client.cache, files_without_conanfile) # Upload conans self.client.run("upload %s" % str(ref)) # Check that conans exists on server server_paths = self.servers["default"].server_store rev = server_paths.get_last_revision(ref).revision conan_path = server_paths.export(ref.copy_with_rev(rev)) self.assertTrue(os.path.exists(conan_path)) # Upload package self.client.run("upload %s -p %s" % (str(ref), str(package_ids[0]))) # Check library on server self._assert_package_exists_in_server(pref, server_paths, files_without_conanfile) # Now from other "computer" install the uploaded conans with same options (nothing) other_conan = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) other_conan.run("install %s --build missing" % str(ref)) # Build should be empty build_path = other_conan.cache.build(pref) self.assertFalse(os.path.exists(build_path)) # Lib should exist self._assert_package_exists(pref, other_conan.cache, files_without_conanfile) reuse_conan = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) files = {'conanfile.py': reuse_conanfile, 'src/hello/main.go': main} reuse_conan.save(files) reuse_conan.run("install . --build missing") with environment_append({ "PATH": ['$GOPATH/bin'], 'GOPATH': reuse_conan.current_folder }): if platform.system() == "Windows": command = "hello" else: command = './hello' reuse_conan.runner('go install hello', cwd=reuse_conan.current_folder) reuse_conan.runner(command, cwd=os.path.join(reuse_conan.current_folder, 'bin')) self.assertIn("Hello, Go!", reuse_conan.user_io.out)
def test_environment_repeated_list(self): with mock.patch.dict('os.environ', {}),\ env.environment_append({'env_var1': ['value1', 'value2', 'value1']}): self.assertEqual(os.environ['env_var1'], 'value1' + os.pathsep + 'value2')
def _build(): env_build = AutoToolsBuildEnvironment(self._conanfile) with environment_append(env_build.vars): self._conanfile.run(command)
def test_environment_append_unsetting_some_variables(self): with mock.patch.dict('os.environ', {'env_var1': 'value'}),\ env.environment_append({'env_var1': None, 'env_var2': 'value2'}): self.assertNotIn('env_var1', os.environ) self.assertEqual(os.environ['env_var2'], 'value2')
def reuse_test(self): self._export_upload("hello0/0.1@lasote/stable") self._export_upload("hello1/0.1@lasote/stable", 1, [0]) self._export_upload("hello2/0.1@lasote/stable", 2, [0]) self._export_upload("hello3/0.1@lasote/stable", 3, [1, 2]) client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) ref = ConanFileReference.loads("hello4/0.2@lasote/stable") files3 = hello_conan_files(ref=ref, number=4, deps=[3], lang='go') client.save(files3) client.run("install . --build missing") client.run("build .") with environment_append({ "PATH": ['$GOPATH/bin'], 'GOPATH': client.current_folder }): client.runner('go install hello4_main', cwd=os.path.join(client.current_folder, 'src')) if platform.system() == "Windows": command = "hello4_main" else: command = './hello4_main' client.runner(command, cwd=os.path.join(client.current_folder, 'bin')) self.assertEqual( ['Hello 4', 'Hello 3', 'Hello 1', 'Hello 0', 'Hello 2', 'Hello 0'], str(client.user_io.out).splitlines()[-6:]) # Try to upload and reuse the binaries client.run("upload hello3/0.1@lasote/stable --all") self.assertEqual(str(client.user_io.out).count("Uploading package"), 1) client.run("upload hello1/0.1@lasote/stable --all") self.assertEqual(str(client.user_io.out).count("Uploading package"), 1) client.run("upload hello2/0.1@lasote/stable --all") self.assertEqual(str(client.user_io.out).count("Uploading package"), 1) client.run("upload hello0/0.1@lasote/stable --all") self.assertEqual(str(client.user_io.out).count("Uploading package"), 1) # client2 = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) ref = ConanFileReference.loads("hello4/0.2@lasote/stable") files3 = hello_conan_files(ref=ref, number=4, deps=[3], lang='go') client2.save(files3) client2.run("install . --build missing") with environment_append({ "PATH": ['$GOPATH/bin'], 'GOPATH': client2.current_folder }): client2.runner('go install hello4_main', cwd=os.path.join(client2.current_folder, 'src')) if platform.system() == "Windows": command = "hello4_main" else: command = './hello4_main' client2.runner(command, cwd=os.path.join(client2.current_folder, 'bin')) self.assertEqual( ['Hello 4', 'Hello 3', 'Hello 1', 'Hello 0', 'Hello 2', 'Hello 0'], str(client2.user_io.out).splitlines()[-6:])