def vcvars_constrained_test(self): text = """os: [Windows] compiler: Visual Studio: version: ["14"] """ settings = Settings.loads(text) settings.os = "Windows" settings.compiler = "Visual Studio" with self.assertRaisesRegexp(ConanException, "compiler.version setting required for vcvars not defined"): tools.vcvars_command(settings) new_out = StringIO() tools.set_global_instances(ConanOutput(new_out), None) settings.compiler.version = "14" with tools.environment_append({"vs140comntools": "path/to/fake"}): tools.vcvars_command(settings) with tools.environment_append({"VisualStudioVersion": "12"}): with self.assertRaisesRegexp(ConanException, "Error, Visual environment already set to 12"): tools.vcvars_command(settings) with tools.environment_append({"VisualStudioVersion": "12"}): # Not raising tools.vcvars_command(settings, force=True)
def run_in_bash_test(self): if platform.system() != "Windows": return class MockConanfile(object): def __init__(self): self.output = namedtuple("output", "info")(lambda x: None) # @UnusedVariable self.env = {"PATH": "/path/to/somewhere"} class MyRun(object): def __call__(self, command, output, log_filepath=None, cwd=None, subprocess=False): # @UnusedVariable self.command = command self._runner = MyRun() conanfile = MockConanfile() tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin") self.assertIn("bash", conanfile._runner.command) self.assertIn("--login -c", conanfile._runner.command) self.assertIn("^&^& a_command.bat ^", conanfile._runner.command) with tools.environment_append({"CONAN_BASH_PATH": "path\\to\\mybash.exe"}): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin") self.assertIn('path\\to\\mybash.exe --login -c', conanfile._runner.command) with tools.environment_append({"CONAN_BASH_PATH": "path with spaces\\to\\mybash.exe"}): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin") self.assertIn('"path with spaces\\to\\mybash.exe" --login -c', conanfile._runner.command) # try to append more env vars conanfile = MockConanfile() tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin", env={"PATH": "/other/path", "MYVAR": "34"}) self.assertIn('^&^& PATH=\\^"/cygdrive/other/path:/cygdrive/path/to/somewhere:$PATH\\^" ' '^&^& MYVAR=34 ^&^& a_command.bat ^', conanfile._runner.command)
def test_environment_nested(self): with tools.environment_append({"A": "1", "Z": "40"}): with tools.environment_append({"A": "1", "B": "2"}): with tools.environment_append({"A": "2", "B": "2"}): self.assertEquals(os.getenv("A"), "2") self.assertEquals(os.getenv("B"), "2") self.assertEquals(os.getenv("Z"), "40") self.assertEquals(os.getenv("A", None), "1") self.assertEquals(os.getenv("B", None), "2") self.assertEquals(os.getenv("A", None), "1") self.assertEquals(os.getenv("Z", None), "40") self.assertEquals(os.getenv("A", None), None) self.assertEquals(os.getenv("B", None), None) self.assertEquals(os.getenv("Z", None), None)
def test_disable_linter(self): client = TestClient() client.save({CONANFILE: conanfile}) with tools.environment_append({"CONAN_RECIPE_LINTER": "False"}): client.run("export . lasote/stable") self.assertNotIn("ERROR: Py3 incompatibility", client.user_io.out) self.assertNotIn("WARN: Linter", client.user_io.out)
def _package_conanfile(self, conan_ref, conan_file, package_reference, build_folder, package_folder, output): """Generate the info txt files and calls the conanfile package method""" # FIXME: Is weak to assign here the recipe_hash conan_file.info.recipe_hash = self._client_cache.load_manifest(conan_ref).summary_hash # Creating ***info.txt files save(os.path.join(build_folder, CONANINFO), conan_file.info.dumps()) output.info("Generated %s" % CONANINFO) save(os.path.join(build_folder, BUILD_INFO), TXTGenerator(conan_file).content) output.info("Generated %s" % BUILD_INFO) save(os.path.join(build_folder, CONANENV), ConanEnvGenerator(conan_file).content) output.info("Generated %s" % CONANENV) os.chdir(build_folder) if getattr(conan_file, 'no_copy_source', False): source_folder = self._client_cache.source(package_reference.conan, conan_file.short_paths) else: source_folder = build_folder with environment_append(conan_file.env): create_package(conan_file, source_folder, build_folder, package_folder, output, False) self._remote_proxy.handle_package_manifest(package_reference, installed=True)
def _init_collaborators(self, user_io=None): output = TestBufferConanOutput() self.user_io = user_io or MockedUserIO(self.users, out=output) self.runner = TestRunner(output, runner=self.conan_runner) # Check if servers are real real_servers = False for server in self.servers.values(): if isinstance(server, str): # Just URI real_servers = True with tools.environment_append(self.client_cache.conan_config.env_vars): if real_servers: requester = requests.Session() else: if self.requester_class: requester = self.requester_class(self.servers) else: requester = TestRequester(self.servers) self.requester = ConanRequester(requester, self.client_cache, get_request_timeout()) self.localdb, self.rest_api_client, self.remote_manager = Conan.instance_remote_manager( self.requester, self.client_cache, self.user_io, self.client_version, self.min_server_compatible_version) set_global_instances(output, self.requester)
def trace_command_test(self): from conans.build_info.command import run trace_file = os.path.join(temp_folder(), "conan_trace.log") # Generate some traces with tools.environment_append({"CONAN_TRACE_FILE": trace_file}): files = cpp_hello_conan_files("Hello0", "1.0", deps=[], build=False) self.client.save(files) self.client.run("export . lasote/stable") self.client.run("install Hello0/1.0@lasote/stable --build") self.client.run("upload '*' --all -c") # Get json from file output = os.path.join(temp_folder(), "build_info.json") sys.argv = ['conan_build_info', trace_file, '--output', output] run() the_json = json.loads(load(output)) self.assertTrue(the_json["modules"][0]["id"], "Hello0/1.0@lasote/stable") # Now get from stdout sys.argv = ['conan_build_info', trace_file] run() try: # in IDEs or with --nocapture it will fail stdout_value = sys.stdout.getvalue() except AttributeError: pass else: the_json = json.loads(stdout_value) self.assertTrue(the_json["modules"][0]["id"], "Hello0/1.0@lasote/stable")
def test_cross_remotes(self): # Upload to alternative server Hello0 but Hello1 to the default files = cpp_hello_conan_files("Hello0", "1.0", deps=[], build=False) self.client.save(files) self.client.run("export . lasote/stable") files = cpp_hello_conan_files("Hello1", "1.0", deps=["Hello0/1.0@lasote/stable"], build=False) self.client.save(files) self.client.run("export . lasote/stable") self.client.run("export . lasote/stable") self.client.run("install Hello1/1.0@lasote/stable --build missing") self.client.run("upload 'Hello0*' -c --all -r alternative") self.client.run("upload 'Hello1*' -c --all -r default") trace_file = os.path.join(temp_folder(), "conan_trace.log") with tools.environment_append({"CONAN_TRACE_FILE": trace_file}): # Will retrieve the Hello0 deps from the alternative self.client.run("install Hello1/1.0@lasote/stable --build") # Upload to the default, not matching the Hello0 remote self.client.run("upload 'Hello1*' -c --all -r default") data = get_build_info(trace_file).serialize() self.assertEquals(len(data["modules"]), 2) module = _get_module(data, "Hello1/1.0@lasote/stable") self.assertEquals(0, len(module["dependencies"]))
def _upload_with_credentials(credentials): cli = TestClient(servers=self.servers, users={}) save(os.path.join(cli.current_folder, CONANFILE), conan_content) cli.run("export . lasote/testing") with tools.environment_append(credentials): cli.run("upload %s" % str(self.conan_reference)) return cli
def build(self, conanfile_path, source_folder, build_folder, test=False): """ Call to build() method saved on the conanfile.py param conanfile_path: the original source directory of the user containing a conanfile.py """ logger.debug("Building in %s" % build_folder) logger.debug("Conanfile in %s" % conanfile_path) try: # Append env_vars to execution environment and clear when block code ends output = ScopedOutput("Project", self._user_io.out) conan_file = load_consumer_conanfile(conanfile_path, build_folder, self._client_cache.settings, self._runner, output) except NotFoundException: # TODO: Auto generate conanfile from requirements file raise ConanException("'%s' file is needed for build.\n" "Create a '%s' and move manually the " "requirements and generators from '%s' file" % (CONANFILE, CONANFILE, CONANFILE_TXT)) try: os.chdir(build_folder) conan_file._conanfile_directory = source_folder conan_file.build_folder = build_folder conan_file.source_folder = source_folder with environment_append(conan_file.env): conan_file.build() if test: conan_file.test() except ConanException: raise # Raise but not let to reach the Exception except (not print traceback) except Exception: import traceback trace = traceback.format_exc().split('\n') raise ConanException("Unable to build it successfully\n%s" % '\n'.join(trace[3:]))
def detect_default_in_mac_os_using_gcc_as_default_test(self): """ Test if gcc in Mac OS X is using apple-clang as frontend """ # See: https://github.com/conan-io/conan/issues/2231 if platform.system() != "Darwin": return try: output = subprocess.check_output(["gcc", "--version"], stderr=subprocess.STDOUT) except subprocess.CalledProcessError: # gcc is not installed or there is any error (no test scenario) return if b"clang" not in output: # Not test scenario gcc should display clang in output # see: https://stackoverflow.com/questions/19535422/os-x-10-9-gcc-links-to-clang raise Exception("Apple gcc doesn't point to clang with gcc frontend anymore! please check") output = TestBufferConanOutput() with tools.environment_append({"CC": "gcc"}): result = detect_defaults_settings(output) # result is a list of tuples (name, value) so converting it to dict result = dict(result) # No compiler should be detected self.assertIsNone(result.get("compiler", None)) self.assertIn("gcc detected as a frontend using apple-clang", output) self.assertIsNotNone(output.error)
def build(self): if self.settings.os == "Linux" or self.settings.os == "Macos": env_build = AutoToolsBuildEnvironment(self) env_vars = env_build.vars.copy() # Configure script creates conftest that cannot execute without shared openssl binaries. # Ways to solve the problem: # 1. set *LD_LIBRARY_PATH (works with Linux but does not work on OS X 10.11 with SIP) # 2. copying dylib's to the build directory (fortunately works on OS X) # 3. set rpath (dangerous) imported_libs = [] if self.options.with_openssl and self.options.shared: if self.settings.os == "Macos": imported_libs = os.listdir(self.deps_cpp_info['OpenSSL'].lib_paths[0]) for imported_lib in imported_libs: shutil.copy(self.deps_cpp_info['OpenSSL'].lib_paths[0] + '/' + imported_lib, self.FOLDER_NAME) self.output.warn("Copying OpenSSL libraries to fix conftest") if self.settings.os == "Linux": if 'LD_LIBRARY_PATH' in env_vars: env_vars['LD_LIBRARY_PATH'] = ':'.join([env_vars['LD_LIBRARY_PATH']] + self.deps_cpp_info.libdirs) else: env_vars['LD_LIBRARY_PATH'] = ':'.join(self.deps_cpp_info.libdirs) # required to correctly find static libssl on Linux if self.options.with_openssl and self.settings.os == "Linux": env_vars['OPENSSL_LIBADD'] = '-ldl' # disable rpath build old_str = "-install_name \$rpath/" new_str = "-install_name " replace_in_file("%s/configure" % self.FOLDER_NAME, old_str, new_str) # compose configure options suffix = '' if not self.options.shared: suffix += " --disable-shared " if self.options.with_openssl: suffix += "--enable-openssl " else: suffix += "--disable-openssl " if self.options.disable_threads: suffix += "--disable-thread-support " self.output.warn('Using env vars: ' + repr(env_vars)) with environment_append(env_vars): cmd = 'cd %s && ./configure %s' % (self.FOLDER_NAME, suffix) self.output.warn('Running: ' + cmd) self.run(cmd) cmd = 'cd %s && make' % (self.FOLDER_NAME) self.output.warn('Running: ' + cmd) self.run(cmd) # now clean imported libs if imported_libs: for imported_lib in imported_libs: os.unlink(self.FOLDER_NAME + '/' + imported_lib)
def system_package_tool_try_multiple_test(self): class RunnerMultipleMock(object): def __init__(self, expected=None): self.calls = 0 self.expected = expected def __call__(self, command, output): # @UnusedVariable self.calls += 1 return 0 if command in self.expected else 1 packages = ["a_package", "another_package", "yet_another_package"] with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}): runner = RunnerMultipleMock(["dpkg -s another_package"]) spt = SystemPackageTool(runner=runner, tool=AptTool()) spt.install(packages) self.assertEquals(2, runner.calls) runner = RunnerMultipleMock(["sudo apt-get update", "sudo apt-get install -y --no-install-recommends yet_another_package"]) spt = SystemPackageTool(runner=runner, tool=AptTool()) spt.install(packages) self.assertEquals(7, runner.calls) runner = RunnerMultipleMock(["sudo apt-get update"]) spt = SystemPackageTool(runner=runner, tool=AptTool()) with self.assertRaises(ConanException): spt.install(packages) self.assertEquals(7, runner.calls)
def build(self): if self.settings.os == "Windows" and self.version == "master": raise ConanException("Trunk builds are not supported on Windows (cannot build directly from master git repository).") if self.settings.compiler == "Visual Studio": env = VisualStudioBuildEnvironment(self) with tools.environment_append(env.vars): version = min(12, int(self.settings.compiler.version.value)) version = 10 if version == 11 else version cd_build = "cd %s\\%s\\build\\vc%s" % (self.conanfile_directory, self.source_directory, version) build_command = build_sln_command(self.settings, "glew.sln") vcvars = vcvars_command(self.settings) self.run("%s && %s && %s" % (vcvars, cd_build, build_command.replace("x86", "Win32"))) else: if self.settings.os == "Windows": replace_in_file("%s/build/cmake/CMakeLists.txt" % self.source_directory, \ "if(WIN32 AND (NOT MSVC_VERSION LESS 1600)", \ "if(WIN32 AND MSVC AND (NOT MSVC_VERSION LESS 1600)") if self.version == "master": self.run("make extensions") cmake = CMake(self) cmake.configure(source_dir="%s/build/cmake" % self.source_directory, defs={"BUILD_UTILS": "OFF"}) cmake.build()
def _build_mingw(self, args): env_build = AutoToolsBuildEnvironment(self) env = {'PATH': ['%s/bin' % self.conanfile_directory, '%s/qtbase/bin' % self.conanfile_directory, '%s/gnuwin32/bin' % self.conanfile_directory, '%s/qtrepotools/bin' % self.conanfile_directory], 'QMAKESPEC': 'win32-g++'} env.update(env_build.vars) with tools.environment_append(env): # Workaround for configure using clang first if in the path new_path = [] for item in os.environ['PATH'].split(';'): if item != 'C:\\Program Files\\LLVM\\bin': new_path.append(item) os.environ['PATH'] = ';'.join(new_path) # end workaround args += ["-developer-build", "-opengl %s" % self.options.opengl, "-platform win32-g++"] self.output.info("Using '%s' threads" % str(cpu_count())) self.run("cd %s && configure.bat %s" % (self.source_dir, " ".join(args))) self.run("cd %s && mingw32-make -j %s" % (self.source_dir, str(cpu_count()))) self.run("cd %s && mingw32-make install" % (self.source_dir))
def test_global_tools_overrided(self): client = TestClient() conanfile = """ from conans import ConanFile, tools class HelloConan(ConanFile): name = "Hello" version = "0.1" def build(self): assert(tools.net._global_requester != None) assert(tools.files._global_output != None) """ client.save({"conanfile.py": conanfile}) client.run("install .") client.run("build .") # Not test the real commmand get_command if it's setting the module global vars tmp = temp_folder() conf = default_client_conf.replace("\n[proxies]", "\n[proxies]\nhttp = http://myproxy.com") os.mkdir(os.path.join(tmp, ".conan")) save(os.path.join(tmp, ".conan", CONAN_CONF), conf) with tools.environment_append({"CONAN_USER_HOME": tmp}): conan_api, _, _ = ConanAPIV1.factory() conan_api.remote_list() self.assertEquals(tools.net._global_requester.proxies, {"http": "http://myproxy.com"}) self.assertIsNotNone(tools.files._global_output.warn)
def build(self): glog_build = AutoToolsBuildEnvironment(self) #glog_build.libs.append("pthread") with tools.environment_append(glog_build.vars): self.run("autoreconf -fi ./glog") self.run("./glog/configure --prefix=`pwd`/build") self.run("make -j2 && make install")
def test_which_positive(self): tmp_dir = temp_folder() ext = ".sh" if platform.system() != "Windows" else ".bat" fullname = os.path.join(tmp_dir, 'example%s' % ext) self._touch(fullname) self._add_executable_bit(fullname) with tools.environment_append({'PATH': tmp_dir}): self.assertEqual(tools.which('example').lower(), fullname.lower())
def test_previous_env(self): settings = MockSettings({"arch": "x86", "os": "Linux", "compiler": "gcc"}) conanfile = MockConanfile(settings) with tools.environment_append({"CPPFLAGS": "MyCppFlag"}): be = AutoToolsBuildEnvironment(conanfile) self.assertEquals(be.vars["CPPFLAGS"], "MyCppFlag")
def test_which_non_executable(self): if platform.system() == "Windows": """on Windows we always have executable permissions by default""" return tmp_dir = temp_folder() fullname = os.path.join(tmp_dir, 'example.sh') self._touch(fullname) with tools.environment_append({'PATH': tmp_dir}): self.assertIsNone(tools.which('example.sh'))
def build(self, conanfile_path, current_path, test=False, filename=None, profile_name=None): """ Call to build() method saved on the conanfile.py param conanfile_path: the original source directory of the user containing a conanfile.py """ logger.debug("Building in %s" % current_path) logger.debug("Conanfile in %s" % conanfile_path) if filename and filename.endswith(".txt"): raise ConanException("A conanfile.py is needed to call 'conan build'") conanfile_file = os.path.join(conanfile_path, filename or CONANFILE) try: output = ScopedOutput("Project", self._user_io.out) conan_file = self._loader(current_path).load_conan(conanfile_file, output, consumer=True) except NotFoundException: # TODO: Auto generate conanfile from requirements file raise ConanException("'%s' file is needed for build.\n" "Create a '%s' and move manually the " "requirements and generators from '%s' file" % (CONANFILE, CONANFILE, CONANFILE_TXT)) try: build_info_file = os.path.join(current_path, BUILD_INFO) if os.path.exists(build_info_file): try: deps_cpp_info = DepsCppInfo.loads(load(build_info_file)) conan_file.deps_cpp_info = deps_cpp_info except: pass env_file = os.path.join(current_path, "conanenv.txt") if os.path.exists(env_file): try: deps_env_info = DepsEnvInfo.loads(load(env_file)) conan_file.deps_env_info = deps_env_info except: pass os.chdir(current_path) conan_file._conanfile_directory = conanfile_path # Append env_vars to execution environment and clear when block code ends profile = self._read_profile(profile_name) env_vars = self._read_profile_env_vars(profile) with environment_append(env_vars): conan_file.build() if test: conan_file.test() except ConanException: raise # Raise but not let to reach the Exception except (not print traceback) except Exception: import traceback trace = traceback.format_exc().split('\n') raise ConanException("Unable to build it successfully\n%s" % '\n'.join(trace[3:]))
def make(self, args="", make_program=None, target=None, vars=None): if not self._conanfile.should_build: return make_program = os.getenv("CONAN_MAKE_PROGRAM") or make_program or "make" with environment_append(vars or self.vars): str_args = args_to_string(args) cpu_count_option = ("-j%s" % cpu_count()) if "-j" not in str_args else None self._conanfile.run("%s" % join_arguments([make_program, target, str_args, cpu_count_option]), win_bash=self._win_bash, subsystem=self.subsystem)
def build(self): if self.settings.os == "Linux" or self.settings.os == "Macos": autotools = AutoToolsBuildEnvironment(self) env_vars = autotools.vars.copy() # required to correctly find static libssl on Linux if self.options.with_openssl and self.settings.os == "Linux": env_vars['OPENSSL_LIBADD'] = '-ldl' # disable rpath build tools.replace_in_file(os.path.join(self._source_subfolder, "configure"), r"-install_name \$rpath/", "-install_name ") # compose configure options configure_args = [] if not self.options.shared: configure_args.append("--disable-shared") configure_args.append("--enable-openssl" if self.options.with_openssl else "--disable-openssl") if self.options.disable_threads: configure_args.append("--disable-thread-support") with tools.environment_append(env_vars): with tools.chdir(self._source_subfolder): # set LD_LIBRARY_PATH with tools.environment_append(RunEnvironment(self).vars): autotools.configure(args=configure_args) autotools.make() elif self.settings.os == "Windows": vcvars = tools.vcvars_command(self.settings) suffix = '' if self.options.with_openssl: suffix = "OPENSSL_DIR=" + self.deps_cpp_info['OpenSSL'].rootpath # add runtime directives to runtime-unaware nmakefile tools.replace_in_file(os.path.join(self._source_subfolder, "Makefile.nmake"), 'LIBFLAGS=/nologo', 'LIBFLAGS=/nologo\n' 'CFLAGS=$(CFLAGS) /%s' % str(self.settings.compiler.runtime)) # do not build tests. static_libs is the only target, no shared libs at all make_command = "nmake %s -f Makefile.nmake static_libs" % suffix with tools.chdir(self._source_subfolder): self.run("%s && %s" % (vcvars, make_command))
def _config_node(self, conanfile, conanref, down_reqs, down_ref, down_options): """ update settings and option in the current ConanFile, computing actual requirement values, cause they can be overriden by downstream requires param settings: dict of settings values => {"os": "windows"} """ try: with environment_append(conanfile.env): if hasattr(conanfile, "config"): if not conanref: output = ScopedOutput(str("PROJECT"), self._output) output.warn("config() has been deprecated." " Use config_options and configure") with conanfile_exception_formatter(str(conanfile), "config"): conanfile.config() with conanfile_exception_formatter(str(conanfile), "config_options"): conanfile.config_options() conanfile.options.propagate_upstream(down_options, down_ref, conanref, self._output) if hasattr(conanfile, "config"): with conanfile_exception_formatter(str(conanfile), "config"): conanfile.config() with conanfile_exception_formatter(str(conanfile), "configure"): conanfile.configure() conanfile.settings.validate() # All has to be ok! conanfile.options.validate() # Update requirements (overwrites), computing new upstream if hasattr(conanfile, "requirements"): # If re-evaluating the recipe, in a diamond graph, with different options, # it could happen that one execution path of requirements() defines a package # and another one a different package raising Duplicate dependency error # Or the two consecutive calls, adding 2 different dependencies for the two paths # So it is necessary to save the "requires" state and restore it before a second # execution of requirements(). It is a shallow copy, if first iteration is # RequireResolve'd or overridden, the inner requirements are modified if not hasattr(conanfile, "_original_requires"): conanfile._original_requires = conanfile.requires.copy() else: conanfile.requires = conanfile._original_requires.copy() with conanfile_exception_formatter(str(conanfile), "requirements"): conanfile.requirements() new_options = conanfile.options.deps_package_values new_down_reqs = conanfile.requires.update(down_reqs, self._output, conanref, down_ref) except ConanExceptionInUserConanfileMethod: raise except ConanException as e: raise ConanException("%s: %s" % (conanref or "Conanfile", str(e))) except Exception as e: raise ConanException(e) return new_down_reqs, new_options
def do_build(self): build_dir = "{staging_dir}/src".format(staging_dir=self.staging_dir) tools.untargz("snappy-{v}.tar.gz".format(v=self.version), build_dir) shared_definition = "--enable-static --disable-shared" if self.options.shared: shared_definition = "--enable-shared --disable-static" env_build = AutoToolsBuildEnvironment(self) with tools.environment_append(env_build.vars): self.run("cd {build_dir}/snappy-{v} && ./configure --disable-gtest prefix=\"{staging}\" {shared}".format( v = self.version, staging=self.staging_dir, shared=shared_definition, build_dir=build_dir)) self.run("cd {build_dir}/snappy-{v} && make install".format(v = self.version, build_dir = build_dir))
def test_override_setting_with_env_variables(self): files = cpp_hello_conan_files(name="VisualBuild", version="0.1", build=False, deps=["MinGWBuild/0.1@lasote/testing"]) self._patch_build_to_print_compiler(files) self.client.save(files) self.client.run("export . lasote/testing") with tools.environment_append({"CONAN_ENV_COMPILER": "Visual Studio", "CONAN_ENV_COMPILER_VERSION": "14", "CONAN_ENV_COMPILER_RUNTIME": "MD"}): self.client.run("install VisualBuild/0.1@lasote/testing --build missing") self.assertIn("COMPILER=> MinGWBuild Visual Studio", self.client.user_io.out)
def _build_msvc(self, args): build_command = find_executable("jom.exe") if build_command: build_args = ["-j", str(cpu_count())] else: build_command = "nmake.exe" build_args = [] self.output.info("Using '%s %s' to build" % (build_command, " ".join(build_args))) env = {} env.update({'PATH': ['%s/qtbase/bin' % self.conanfile_directory, '%s/gnuwin32/bin' % self.conanfile_directory, '%s/qtrepotools/bin' % self.conanfile_directory]}) # it seems not enough to set the vcvars for older versions if self.settings.compiler == "Visual Studio": if self.settings.compiler.version == "14": env.update({'QMAKESPEC': 'win32-msvc2015'}) args += ["-platform win32-msvc2015"] if self.settings.compiler.version == "12": env.update({'QMAKESPEC': 'win32-msvc2013'}) args += ["-platform win32-msvc2013"] if self.settings.compiler.version == "11": env.update({'QMAKESPEC': 'win32-msvc2012'}) args += ["-platform win32-msvc2012"] if self.settings.compiler.version == "10": env.update({'QMAKESPEC': 'win32-msvc2010'}) args += ["-platform win32-msvc2010"] env_build = VisualStudioBuildEnvironment(self) env.update(env_build.vars) # Workaround for conan-io/conan#1408 for name, value in env.items(): if not value: del env[name] with tools.environment_append(env): vcvars = tools.vcvars_command(self.settings) args += ["-opengl %s" % self.options.opengl] if self.options.openssl == "no": args += ["-no-openssl"] elif self.options.openssl == "yes": args += ["-openssl"] else: args += ["-openssl-linked"] self.run("cd %s && %s && set" % (self.source_dir, vcvars)) self.run("cd %s && %s && configure %s" % (self.source_dir, vcvars, " ".join(args))) self.run("cd %s && %s && %s %s" % (self.source_dir, vcvars, build_command, " ".join(build_args))) self.run("cd %s && %s && %s install" % (self.source_dir, vcvars, build_command))
def build(self, conanfile_path, current_path, test=False, filename=None, profile_name=None, env=None, package_env=None): """ Call to build() method saved on the conanfile.py param conanfile_path: the original source directory of the user containing a conanfile.py """ logger.debug("Building in %s" % current_path) logger.debug("Conanfile in %s" % conanfile_path) if filename and filename.endswith(".txt"): raise ConanException("A conanfile.py is needed to call 'conan build'") conanfile_file = os.path.join(conanfile_path, filename or CONANFILE) try: # Append env_vars to execution environment and clear when block code ends profile = self.read_profile(profile_name, current_path) output = ScopedOutput("Project", self._user_io.out) if profile: profile.update_env(env) profile.update_packages_env(package_env) env = profile.env package_env = profile.package_env env = profile.env if profile else None package_env = profile.package_env if profile else None loader = self._loader(current_path, env=env, package_env=package_env) conan_file = loader.load_conan(conanfile_file, output, consumer=True) except NotFoundException: # TODO: Auto generate conanfile from requirements file raise ConanException("'%s' file is needed for build.\n" "Create a '%s' and move manually the " "requirements and generators from '%s' file" % (CONANFILE, CONANFILE, CONANFILE_TXT)) try: self._load_deps_info(current_path, conan_file, output) os.chdir(current_path) conan_file._conanfile_directory = conanfile_path with environment_append(conan_file.env): conan_file.build() if test: conan_file.test() except ConanException: raise # Raise but not let to reach the Exception except (not print traceback) except Exception: import traceback trace = traceback.format_exc().split('\n') raise ConanException("Unable to build it successfully\n%s" % '\n'.join(trace[3:]))
def factory(): """Factory""" def instance_remote_manager(client_cache): requester = get_basic_requester(client_cache) # Verify client version against remotes version_checker_requester = VersionCheckerRequester(requester, Version(CLIENT_VERSION), Version(MIN_SERVER_COMPATIBLE_VERSION), out) # To handle remote connections put_headers = client_cache.read_put_headers() rest_api_client = RestApiClient(out, requester=version_checker_requester, put_headers=put_headers) # To store user and token localdb = LocalDB(client_cache.localdb) # Wraps RestApiClient to add authentication support (same interface) auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb) # Handle remote connections remote_manager = RemoteManager(client_cache, auth_manager, out) return remote_manager use_color = get_env("CONAN_COLOR_DISPLAY", 1) if use_color and hasattr(sys.stdout, "isatty") and sys.stdout.isatty(): import colorama colorama.init() color = True else: color = False out = ConanOutput(sys.stdout, color) user_io = UserIO(out=out) user_folder = os.getenv("CONAN_USER_HOME", conan_expand_user("~")) try: client_cache = migrate_and_get_client_cache(user_folder, out) except Exception as e: out.error(str(e)) raise with tools.environment_append(client_cache.conan_config.env_vars): # Adjust CONAN_LOGGING_LEVEL with the env readed conans.util.log.logger = configure_logger() # Get the new command instance after migrations have been done remote_manager = instance_remote_manager(client_cache) # Get a search manager search_adapter = DiskSearchAdapter() search_manager = DiskSearchManager(client_cache, search_adapter) conan = Conan(client_cache, user_io, get_conan_runner(), remote_manager, search_manager) return conan
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): with tools.environment_append(self.build_env.vars): # Path for custom properties file props_file_contents = self._get_props_file_contents() with tmp_file(props_file_contents) as props_file_path: vcvars = vcvars_command(self._conanfile.settings, force=force_vcvars) command = self.get_command(project_file, props_file_path, targets=targets, upgrade_project=upgrade_project, build_type=build_type, arch=arch, parallel=parallel, toolset=toolset, platforms=platforms, use_env=use_env) command = "%s && %s" % (vcvars, command) return self._conanfile.run(command)
def run(self): client_version = get_client_version() if self._config_url: ConfigManager(self._conan_api, self.printer).install(url=self._config_url) context = tools.no_op() compiler = self.settings.get("compiler", None) if not self._exclude_vcvars_precommand: if compiler == "Visual Studio" and "compiler.version" in self.settings: compiler_set = namedtuple("compiler", "version")( self.settings["compiler.version"]) mock_sets = namedtuple( "mock_settings", "arch compiler get_safe")( self.settings["arch"], compiler_set, lambda x: self.settings.get(x, None)) context = tools.vcvars(mock_sets) with context: self.printer.print_rule() self.printer.print_profile(tools.load(self._profile_abs_path)) with self.printer.foldable_output("conan_create"): if client_version < Version("1.10.0"): name, version, user, channel = self._reference else: name, version, user, channel, _ = self._reference if self._build_policy: self._build_policy = [self._build_policy] # https://github.com/conan-io/conan-package-tools/issues/184 with tools.environment_append({"_CONAN_CREATE_COMMAND_": "1"}): params = { "name": name, "version": version, "user": user, "channel": channel, "build_modes": self._build_policy, "profile_name": self._profile_abs_path } self.printer.print_message("Calling 'conan create'") self.printer.print_dict(params) with tools.chdir(self._cwd): if Version(client_version) >= "1.8.0": from conans.errors import ConanInvalidConfiguration exc_class = ConanInvalidConfiguration else: exc_class = None try: if client_version < Version("1.12.0"): r = self._conan_api.create( self._conanfile, name=name, version=version, user=user, channel=channel, build_modes=self._build_policy, profile_name=self._profile_abs_path, test_folder=self._test_folder) else: r = self._conan_api.create( self._conanfile, name=name, version=version, user=user, channel=channel, build_modes=self._build_policy, profile_names=[self._profile_abs_path], test_folder=self._test_folder) except exc_class as e: self.printer.print_rule() self.printer.print_message( "Skipped configuration by the recipe: " "%s" % str(e)) self.printer.print_rule() return for installed in r['installed']: reference = installed["recipe"]["id"] if client_version >= Version("1.10.0"): reference = ConanFileReference.loads(reference) reference = str(reference.copy_clear_rev()) if ((reference == str(self._reference)) or \ (reference in self._upload_dependencies) or \ ("all" in self._upload_dependencies)) and \ installed['packages']: package_id = installed['packages'][0]['id'] if installed['packages'][0]["built"]: if self._upload_only_recipe: self._uploader.upload_recipe( reference, self._upload) else: self._uploader.upload_packages( reference, self._upload, package_id) else: self.printer.print_message( "Skipping upload for %s, " "it hasn't been built" % package_id)
def _autotools_build_environment(self): with tools.chdir(self._source_subfolder): with tools.run_environment(self): with tools.environment_append( {"PKG_CONFIG_PATH": tools.unix_path(self.build_folder)}): yield
def build(self): self._patch_sources() with tools.environment_append(tools.RunEnvironment(self).vars): meson = self._configure_meson() meson.build()
def system_package_tool_test(self): with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}): runner = RunnerMock() # fake os info to linux debian, default sudo os_info = OSInfo() os_info.is_macos = False os_info.is_linux = True os_info.is_windows = False os_info.linux_distro = "debian" spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "sudo -A apt-get update") os_info.linux_distro = "ubuntu" spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "sudo -A apt-get update") os_info.linux_distro = "knoppix" spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "sudo -A apt-get update") os_info.linux_distro = "neon" spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "sudo -A apt-get update") os_info.linux_distro = "fedora" spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "sudo -A yum check-update -y") os_info.linux_distro = "opensuse" spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "sudo -A zypper --non-interactive ref") os_info.linux_distro = "redhat" spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.install("a_package", force=False) self.assertEqual(runner.command_called, "rpm -q a_package") spt.install("a_package", force=True) self.assertEqual(runner.command_called, "sudo -A yum install -y a_package") settings = MockSettings({"arch": "x86", "arch_build": "x86_64", "os": "Linux", "os_build": "Linux"}) conanfile = MockConanfile(settings) spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out, conanfile=conanfile) spt.install("a_package", force=False) self.assertEqual(runner.command_called, "rpm -q a_package.i?86") spt.install("a_package", force=True) self.assertEqual(runner.command_called, "sudo -A yum install -y a_package.i?86") os_info.linux_distro = "debian" spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) with self.assertRaises(ConanException): runner.return_ok = False spt.install("a_package") self.assertEqual(runner.command_called, "sudo -A apt-get install -y --no-install-recommends a_package") runner.return_ok = True spt.install("a_package", force=False) self.assertEqual(runner.command_called, 'dpkg-query -W -f=\'${Status}\' a_package | grep -q "ok installed"') os_info.is_macos = True os_info.is_linux = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "brew update") spt.install("a_package", force=True) self.assertEqual(runner.command_called, "brew install a_package") os_info.is_freebsd = True os_info.is_macos = False spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "sudo -A pkg update") spt.install("a_package", force=True) self.assertEqual(runner.command_called, "sudo -A pkg install -y a_package") spt.install("a_package", force=False) self.assertEqual(runner.command_called, "pkg info a_package") # Chocolatey is an optional package manager on Windows if platform.system() == "Windows" and which("choco.exe"): os_info.is_freebsd = False os_info.is_windows = True spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out, tool=ChocolateyTool(output=self.out)) spt.update() self.assertEqual(runner.command_called, "choco outdated") spt.install("a_package", force=True) self.assertEqual(runner.command_called, "choco install --yes a_package") spt.install("a_package", force=False) self.assertEqual(runner.command_called, 'choco search --local-only --exact a_package | ' 'findstr /c:"1 packages installed."') with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "False"}): os_info = OSInfo() os_info.is_linux = True os_info.linux_distro = "redhat" spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.install("a_package", force=True) self.assertEqual(runner.command_called, "yum install -y a_package") spt.update() self.assertEqual(runner.command_called, "yum check-update -y") os_info.linux_distro = "ubuntu" spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.install("a_package", force=True) self.assertEqual(runner.command_called, "apt-get install -y --no-install-recommends a_package") spt.update() self.assertEqual(runner.command_called, "apt-get update") for arch, distro_arch in {"x86_64": "", "x86": ":i386", "ppc32": ":powerpc", "ppc64le": ":ppc64el", "armv7": ":arm", "armv7hf": ":armhf", "armv8": ":arm64", "s390x": ":s390x"}.items(): settings = MockSettings({"arch": arch, "arch_build": "x86_64", "os": "Linux", "os_build": "Linux"}) conanfile = MockConanfile(settings) spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out, conanfile=conanfile) spt.install("a_package", force=True) self.assertEqual(runner.command_called, "apt-get install -y --no-install-recommends a_package%s" % distro_arch) for arch, distro_arch in {"x86_64": "", "x86": ":all"}.items(): settings = MockSettings({"arch": arch, "arch_build": "x86_64", "os": "Linux", "os_build": "Linux"}) conanfile = MockConanfile(settings) spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out, conanfile=conanfile) spt.install("a_package", force=True, arch_names={"x86": "all"}) self.assertEqual(runner.command_called, "apt-get install -y --no-install-recommends a_package%s" % distro_arch) os_info.is_macos = True os_info.is_linux = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "brew update") spt.install("a_package", force=True) self.assertEqual(runner.command_called, "brew install a_package") os_info.is_freebsd = True os_info.is_macos = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "pkg update") spt.install("a_package", force=True) self.assertEqual(runner.command_called, "pkg install -y a_package") spt.install("a_package", force=False) self.assertEqual(runner.command_called, "pkg info a_package") os_info.is_solaris = True os_info.is_freebsd = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out) spt.update() self.assertEqual(runner.command_called, "pkgutil --catalog") spt.install("a_package", force=True) self.assertEqual(runner.command_called, "pkgutil --install --yes a_package") with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}): # Chocolatey is an optional package manager on Windows if platform.system() == "Windows" and which("choco.exe"): os_info.is_solaris = False os_info.is_windows = True spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out, tool=ChocolateyTool(output=self.out)) spt.update() self.assertEqual(runner.command_called, "choco outdated") spt.install("a_package", force=True) self.assertEqual(runner.command_called, "choco install --yes a_package") spt.install("a_package", force=False) self.assertEqual(runner.command_called, 'choco search --local-only --exact a_package | ' 'findstr /c:"1 packages installed."')
def _mingw_build_environment(self): with tools.chdir(os.path.join(self._source_subfolder, "win32")): with tools.environment_append( AutoToolsBuildEnvironment(self).vars): yield
def build(self): if self.options.header_only: self.output.warn("Header only package, skipping build") return toolset = "darwin" if self.settings.os == "Macos" else self.settings.compiler # command = "bootstrap" if self.settings.os == "Windows" else "./bootstrap.sh --with-toolset=%s" % self.settings.compiler command = "" if self.settings.os == "Windows": if self.settings.compiler == "gcc": command = "bootstrap gcc" else: command = "bootstrap" else: command = "./bootstrap.sh --with-toolset=%s" % toolset try: self.run("cd %s && %s" % (self.FOLDER_NAME, command)) except: self.run("cd %s && type bootstrap.log" % self.FOLDER_NAME if self.settings.os == "Windows" else "cd %s && cat bootstrap.log" % self.FOLDER_NAME) raise flags = [] if self.settings.compiler == "Visual Studio": flags.append("toolset=msvc-%s" % self._msvc_version()) elif self.settings.compiler == "gcc": # For GCC we only need the major version otherwhise Boost doesn't find the compiler #flags.append("toolset=%s-%s"% (self.settings.compiler, self._gcc_short_version(self.settings.compiler.version))) flags.append("toolset=gcc") elif str(self.settings.compiler) in ["clang"]: flags.append( "toolset=%s-%s" % (self.settings.compiler, self.settings.compiler.version)) flags.append("link=%s" % ("static" if not self.options.shared else "shared")) if self.settings.compiler == "Visual Studio" and self.settings.compiler.runtime: flags.append("runtime-link=%s" % ("static" if "MT" in str( self.settings.compiler.runtime) else "shared")) flags.append("variant=%s" % str(self.settings.build_type).lower()) flags.append("address-model=%s" % ("32" if self.settings.arch == "x86" else "64")) option_names = { "--without-atomic": self.options.without_atomic, "--without-chrono": self.options.without_chrono, "--without-container": self.options.without_container, "--without-context": self.options.without_context, "--without-coroutine": self.options.without_coroutine, "--without-date_time": self.options.without_date_time, "--without-exception": self.options.without_exception, "--without-fiber": self.options.without_fiber, "--without-filesystem": self.options.without_filesystem, "--without-graph": self.options.without_graph, "--without-graph_parallel": self.options.without_graph_parallel, "--without-iostreams": self.options.without_iostreams, "--without-locale": self.options.without_locale, "--without-log": self.options.without_log, "--without-math": self.options.without_math, "--without-metaparse": self.options.without_metaparse, "--without-mpi": self.options.without_mpi, "--without-program_options": self.options.without_program_options, "--without-random": self.options.without_random, "--without-regex": self.options.without_regex, "--without-serialization": self.options.without_serialization, "--without-signals": self.options.without_signals, "--without-system": self.options.without_system, "--without-test": self.options.without_test, "--without-thread": self.options.without_thread, "--without-timer": self.options.without_timer, "--without-type_erasure": self.options.without_type_erasure, "--without-wave": self.options.without_wave } for option_name, activated in option_names.items(): if activated: flags.append(option_name) cxx_flags = [] # fPIC DEFINITION if self.settings.compiler != "Visual Studio": if self.options.fPIC: cxx_flags.append("-fPIC") # LIBCXX DEFINITION FOR BOOST B2 try: #if str(self.settings.compiler.libcxx) == "libstdc++": # print("define=_GLIBCXX_USE_CXX11_ABI=0") # flags.append("define=_GLIBCXX_USE_CXX11_ABI=0") #elif str(self.settings.compiler.libcxx) == "libstdc++11": # print("define=_GLIBCXX_USE_CXX11_ABI=1") # flags.append("define=_GLIBCXX_USE_CXX11_ABI=1") #flags.append("define=_GLIBCXX_USE_CXX11_ABI=1") cxx_flags.append("-std=c++11") # always C++11 (at minimum) cxx_flags.append("-Wno-deprecated-declarations") if self.settings.compiler == "gcc": if float(self.settings.compiler.version) >= 5: flags.append("define=_GLIBCXX_USE_CXX11_ABI=1") else: flags.append("define=_GLIBCXX_USE_CXX11_ABI=0") if "clang" in str(self.settings.compiler): if str(self.settings.compiler.libcxx) == "libc++": cxx_flags.append("-stdlib=libc++") cxx_flags.append("-std=c++11") flags.append('linkflags="-stdlib=libc++"') else: cxx_flags.append("-stdlib=libstdc++") cxx_flags.append("-std=c++11") except BaseException as e: self.output.warn(str(e)) cxx_flags = 'cxxflags="%s"' % " ".join(cxx_flags) if cxx_flags else "" flags.append(cxx_flags) flags.append("--without-python") flags.append("-d 2") #Verbosity (from 1 to 13) # JOIN ALL FLAGS b2_flags = " ".join(flags) command = "b2" if self.settings.os == "Windows" else "./b2" full_command = "cd %s && %s %s -j%s" % (self.FOLDER_NAME, command, b2_flags, tools.cpu_count()) self.output.warn(full_command) envs = self.prepare_deps_options_env() with tools.environment_append(envs): self.run(full_command) #, output=False)
def _build_msvc(self): with tools.chdir(os.path.join(self._source_subfolder, "win32")): debug = "yes" if self.settings.build_type == "Debug" else "no" static = "no" if self.options.shared else "yes" with tools.vcvars(self): args = [ "cscript", "configure.js", "compiler=msvc", "prefix={}".format(self.package_folder), "cruntime=/{}".format(msvc_runtime_flag(self)), "debug={}".format(debug), "static={}".format(static), "include=\"{}\"".format(";".join( self.deps_cpp_info.include_paths)), "lib=\"{}\"".format(";".join( self.deps_cpp_info.lib_paths)), "iconv=no", "xslt_debug=no", ] for name in self._option_names: cname = {"plugins": "modules"}.get(name, name) value = getattr(self.options, name) value = "yes" if value else "no" args.append("%s=%s" % (cname, value)) configure_command = ' '.join(args) self.output.info(configure_command) self.run(configure_command) # Fix library names because they can be not just zlib.lib def format_libs(package): libs = [] for lib in self.deps_cpp_info[package].libs: libname = lib if not libname.endswith('.lib'): libname += '.lib' libs.append(libname) for lib in self.deps_cpp_info[package].system_libs: libname = lib if not libname.endswith('.lib'): libname += '.lib' libs.append(libname) return ' '.join(libs) def fix_library(option, package, old_libname): if option: tools.replace_in_file( "Makefile.msvc", "LIBS = %s" % old_libname, "LIBS = %s" % format_libs(package)) if "icu" in self.deps_cpp_info.deps: fix_library(True, 'icu', 'wsock32.lib') tools.replace_in_file("Makefile.msvc", "libxml2.lib", format_libs("libxml2")) tools.replace_in_file("Makefile.msvc", "libxml2_a.lib", format_libs("libxml2")) with tools.environment_append( VisualStudioBuildEnvironment(self).vars): targets = "libxslt{0} libexslt{0}".format( "" if self.options.shared else "a") self.run("nmake /f Makefile.msvc {}".format(targets))
def build(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) if self.settings.compiler == "Visual Studio": # https://www.postgresql.org/docs/8.3/install-win32-libpq.html # https://github.com/postgres/postgres/blob/master/src/tools/msvc/README if not self.options.shared: tools.replace_in_file( os.path.join(self._source_subfolder, "src", "tools", "msvc", "MKvcbuild.pm"), "$libpq = $solution->AddProject('libpq', 'dll', 'interfaces',", "$libpq = $solution->AddProject('libpq', 'lib', 'interfaces'," ) system_libs = ", ".join([ "'{}.lib'".format(lib) for lib in self.deps_cpp_info.system_libs ]) tools.replace_in_file( os.path.join(self._source_subfolder, "src", "tools", "msvc", "Project.pm"), "libraries => [],", "libraries => [{}],".format(system_libs)) runtime = { 'MT': 'MultiThreaded', 'MTd': 'MultiThreadedDebug', 'MD': 'MultiThreadedDLL', 'MDd': 'MultiThreadedDebugDLL' }.get(str(self.settings.compiler.runtime)) msbuild_project_pm = os.path.join(self._source_subfolder, "src", "tools", "msvc", "MSBuildProject.pm") tools.replace_in_file( msbuild_project_pm, "</Link>", """</Link> <Lib> <TargetMachine>$targetmachine</TargetMachine> </Lib>""") tools.replace_in_file(msbuild_project_pm, "'MultiThreadedDebugDLL'", "'%s'" % runtime) tools.replace_in_file(msbuild_project_pm, "'MultiThreadedDLL'", "'%s'" % runtime) config_default_pl = os.path.join(self._source_subfolder, "src", "tools", "msvc", "config_default.pl") solution_pm = os.path.join(self._source_subfolder, "src", "tools", "msvc", "Solution.pm") if self.options.with_openssl: for ssl in ["VC\libssl32", "VC\libssl64", "libssl"]: tools.replace_in_file( solution_pm, "%s.lib" % ssl, "%s.lib" % self.deps_cpp_info["openssl"].libs[0]) for crypto in [ "VC\libcrypto32", "VC\libcrypto64", "libcrypto" ]: tools.replace_in_file( solution_pm, "%s.lib" % crypto, "%s.lib" % self.deps_cpp_info["openssl"].libs[1]) tools.replace_in_file( config_default_pl, "openssl => undef", "openssl => '%s'" % self.deps_cpp_info["openssl"].rootpath.replace("\\", "/")) with tools.vcvars(self.settings): config = "DEBUG" if self.settings.build_type == "Debug" else "RELEASE" with tools.environment_append({"CONFIG": config}): with tools.chdir( os.path.join(self._source_subfolder, "src", "tools", "msvc")): self.run("perl build.pl libpq") if not self.options.shared: self.run("perl build.pl libpgport") else: autotools = self._configure_autotools() with tools.chdir( os.path.join(self._source_subfolder, "src", "backend")): autotools.make(args=self._make_args, target="generated-headers") with tools.chdir( os.path.join(self._source_subfolder, "src", "common")): autotools.make(args=self._make_args) if tools.Version(self.version) >= "12": with tools.chdir( os.path.join(self._source_subfolder, "src", "port")): autotools.make(args=self._make_args) with tools.chdir( os.path.join(self._source_subfolder, "src", "include")): autotools.make(args=self._make_args) with tools.chdir( os.path.join(self._source_subfolder, "src", "interfaces", "libpq")): autotools.make(args=self._make_args) with tools.chdir( os.path.join(self._source_subfolder, "src", "bin", "pg_config")): autotools.make(args=self._make_args)
def build(self): with tools.chdir(self._source_subfolder): env_build = dict() env_build["PYTHON_BIN_PATH"] = sys.executable env_build["USE_DEFAULT_PYTHON_LIB_PATH"] = "1" env_build["TF_NEED_GCP"] = "1" if self.options.need_gcp else "0" env_build["TF_NEED_CUDA"] = "1" if self.options.need_cuda else "0" # If we want to use CUDA, we need the following environment variables set: # CUDA_TOOLKIT_PATH # CUDNN_INSTALL_PATH # TF_CUDA_VERSION # TF_CUDA_COMPUTE_CAPABILITIES # TF_CUDNN_VERSION env_build["TF_DOWNLOAD_CLANG"] = "0" env_build["TF_NEED_HDFS"] = "1" if self.options.need_hdfs else "0" env_build[ "TF_NEED_OPENCL"] = "1" if self.options.need_opencl else "0" env_build[ "TF_NEED_JEMALLOC"] = "1" if self.options.need_jemalloc else "0" env_build[ "TF_ENABLE_XLA"] = "1" if self.options.enable_xla else "0" env_build[ "TF_NEED_VERBS"] = "1" if self.options.need_verbs else "0" env_build[ "TF_DOWNLOAD_MKL"] = "1" if self.options.download_mkl else "0" env_build["TF_NEED_MKL"] = "1" if self.options.need_mkl else "0" env_build[ "TF_NEED_NGRAPH"] = "1" if self.options.need_ngraph else "0" env_build["TF_NEED_AWS"] = "1" if self.options.need_aws else "0" env_build["TF_NEED_MPI"] = "1" if self.options.need_mpi else "0" env_build["TF_NEED_GDR"] = "1" if self.options.need_gdr else "0" env_build["TF_NEED_S3"] = "1" if self.options.need_s3 else "0" env_build[ "TF_NEED_OPENCL_SYCL"] = "1" if self.options.need_opencl_sycl else "0" env_build[ "TF_NEED_COMPUTECPP"] = "1" if self.options.need_computecpp else "0" env_build[ "TF_NEED_KAFKA"] = "1" if self.options.need_kafka else "0" env_build["TF_NEED_TENSORRT"] = "1" if ( self.options.need_tensorrt and self.options.need_cuda) else "0" env_build[ "TF_NEED_IGNITE"] = "1" if self.options.need_ignite else "0" env_build["TF_NEED_ROCM"] = "1" if self.options.need_rocm else "0" env_build[ "CC_OPT_FLAGS"] = "/arch:AVX" if self.settings.compiler == "Visual Studio" else "-march=native" env_build[ "TF_CONFIGURE_IOS"] = "1" if self.settings.os == "iOS" else "0" env_build[ "TF_SET_ANDROID_WORKSPACE"] = "1" if self.options.set_android_workspace else "0" env_build["TF_CONFIGURE_APPLE_BAZEL_RULES"] = "1" with tools.environment_append(env_build): self.run("python configure.py" if tools.os_info. is_windows else "./configure") self.run("bazel shutdown") bazel_config_flags = "" if self.options.need_mkl: bazel_config_flags += "--config=mkl " if self.options.need_gdr: bazel_config_flags += "--config=gdr " if self.options.need_verbs: bazel_config_flags += "--config=verbs " if self.options.need_ngraph: bazel_config_flags += "--config=ngraph " if self.options.need_numa: bazel_config_flags += "--config=numa " if self.options.build_dynamic_kernels: bazel_config_flags += "--config=build_dynamic_kernels " if self.options.need_cuda == True: bazel_config_flags += "--config=cuda" os_name = str(self.settings.os).lower() optim_flags = "" safe_flags = "" if os_name == "macos": optim_flags = "-c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-msse4.1 --copt=-msse4.2" safe_flags = "" elif os_name == "linux": optim_flags = "-c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2" safe_flags = "-c opt --copt=-march=native --copt=-mfpmath=both" elif os_name == "windows": opt_flags = "-c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2" safe_flags = "-c opt --copt=-march=native --copt=-mfpmath=both" bazel_config_flags = optim_flags if self.options.build_optimized else safe_flags try: print("Attempting to build libtensorflow_cc BEFORE patch") self._build_bazel_target( bazel_config_flags, "//tensorflow:libtensorflow_cc.so") except Exception as inst: print( "Exception caught building libtensorflow_cc, attempting to PATCH" ) print(inst) if self._grpc_version < Version("1.22.0"): # Patch gRPC before proceeding # TF uses OLD versions: gRPC V1.19.1 and protobuf 3.8.0 self._patch_grpc(self._bazel_cache_dir) else: # Fix up the gRPC version self._fix_grpc_version() self._build_bazel_target( bazel_config_flags, "//tensorflow:libtensorflow_cc.so") self._build_bazel_target(bazel_config_flags, "//tensorflow/core:tensorflow") self._build_bazel_target(bazel_config_flags, "//tensorflow:libtensorflow.so") self._build_bazel_target(bazel_config_flags, "//tensorflow/c:c_api") self._build_bazel_target( bazel_config_flags, "//tensorflow:libtensorflow_framework.so") self._build_bazel_target(bazel_config_flags, "//tensorflow/java:tensorflow") self._build_bazel_target( bazel_config_flags, "//tensorflow/java:libtensorflow_jni") self._build_bazel_target( bazel_config_flags, "//tensorflow/core:framework_internal_impl") self._build_bazel_target(bazel_config_flags, "//tensorflow/core:tensorflow") self._build_bazel_target(bazel_config_flags, "//tensorflow/cc:cc_ops") self._build_bazel_target(bazel_config_flags, "//tensorflow/cc:client_session") self._build_bazel_target( bazel_config_flags, "//tensorflow/tools/graph_transforms:transform_utils", ) self._build_bazel_target( bazel_config_flags, "//tensorflow/tools/graph_transforms:file_utils") self._build_bazel_target(bazel_config_flags, "//tensorflow:install_headers") return
def build(self): self.output.info("") self.output.info("---------- build ----------") self.output.info("") self.output.info("os : " + str(self.settings.os)) self.output.info("arch : " + str(self.settings.arch)) self.output.info("build_type: " + str(self.settings.build_type)) if self.settings.compiler == "Visual Studio": self.output.info("runtime : " + str(self.settings.compiler.runtime)) if self.settings.os == "Linux" or self.settings.os == "Macos": suffix = " --without-libidn " if not self.options.with_libidn else "--with-libidn" suffix += " --without-libssh2 " if not self.options.with_libssh2 else "--with-libssh2" suffix += " --without-librtmp " if not self.options.with_librtmp else "--with-librtmp" suffix += " --without-libmetalink " if not self.options.with_libmetalink else "--with-libmetalink" if self.settings.compiler == "gcc" and self.settings.arch == "armv7hf" and not re.match( "arm.*", platform.machine()): suffix += " --host=arm-linux-gnueabihf " if self.options.with_openssl: if self.settings.os == "Macos" and self.options.darwin_ssl: suffix += "--with-darwinssl " else: suffix += "--with-ssl " else: suffix += "--without-ssl " if not self.options.shared: suffix += " --disable-shared" if self.options.disable_threads: suffix += " --disable-thread" if not self.options.with_ldap: suffix += " --disable-ldap" if self.options.custom_cacert: suffix += ' --with-ca-bundle=cacert.pem' env = AutoToolsBuildEnvironment(self) # Hack for configure, don't know why fails because it's not able to find libefence.so if "efence" in env.libs: env.libs.remove("efence") old_str = r"-install_name \$rpath/" new_str = "-install_name " replace_in_file("%s/configure" % self.ZIP_FOLDER_NAME, old_str, new_str) with tools.environment_append(env.vars): with tools.chdir(self.ZIP_FOLDER_NAME): configure = "./configure " + suffix self.output.warn(configure) self.run(configure) self.run("make -j" + str(tools.cpu_count())) else: # Do not compile curl tool, just library conan_magic_lines = '''project(CURL) cmake_minimum_required(VERSION 3.0) include(../conanbuildinfo.cmake) CONAN_BASIC_SETUP() ''' replace_in_file("%s/CMakeLists.txt" % self.ZIP_FOLDER_NAME, "cmake_minimum_required(VERSION 2.8 FATAL_ERROR)", conan_magic_lines) replace_in_file("%s/CMakeLists.txt" % self.ZIP_FOLDER_NAME, "project( CURL C )", "") replace_in_file("%s/src/CMakeLists.txt" % self.ZIP_FOLDER_NAME, "add_executable(", "IF(0)\n add_executable(") replace_in_file("%s/src/CMakeLists.txt" % self.ZIP_FOLDER_NAME, "install(TARGETS ${EXE_NAME} DESTINATION bin)", "ENDIF()") # EOF cmake = CMake(self) opts = dict() opts["BUILD_SHARED_LIBS"] = self.options.shared opts["CURL_STATICLIB"] = not self.options.shared opts["CURL_DISABLE_LDAP"] = not self.options.with_ldap buildDir = os.path.join(self.ZIP_FOLDER_NAME, "_build") os.makedirs(buildDir) cmake.configure(defs=opts, source_dir=os.pardir, build_dir=buildDir) cmake.build()
def build(self): with tools.chdir(self._source_subfolder): env_build = dict() env_build["PYTHON_BIN_PATH"] = sys.executable env_build["USE_DEFAULT_PYTHON_LIB_PATH"] = "1" env_build["TF_NEED_GCP"] = "1" if self.options.need_gcp else "0" env_build["TF_NEED_CUDA"] = "1" if (self.options.need_cuda and not self.options.need_mkl) else "0" env_build["TF_DOWNLOAD_CLANG"] = "1" if self.options.download_clang else "0" env_build["TF_CUDA_CLANG"] = "1" if self.options.cuda_clang else "0" env_build["TF_NEED_HDFS"] = "1" if self.options.need_hdfs else "0" env_build["TF_NEED_OPENCL"] = "1" if self.options.need_opencl else "0" env_build["TF_NEED_JEMALLOC"] = "1" if self.options.need_jemalloc else "0" env_build["TF_ENABLE_XLA"] = "1" if self.options.enable_xla else "0" env_build["TF_NEED_VERBS"] = "1" if self.options.need_verbs else "0" env_build["TF_DOWNLOAD_MKL"] = "1" if self.options.download_mkl else "0" env_build["TF_NEED_MKL"] = "1" if (self.options.need_mkl and not self.options.need_cuda) else "0" env_build["TF_NEED_NGRAPH"] = "1" if self.options.need_ngraph else "0" env_build["TF_NEED_AWS"] = ( "1" if self.options.need_aws else "0" ) # Does not work if AWS is set and we are putting in our own SSL env_build["TF_NEED_MPI"] = "1" if self.options.need_mpi else "0" env_build["TF_NEED_GDR"] = "1" if self.options.need_gdr else "0" env_build["TF_NEED_S3"] = "1" if self.options.need_s3 else "0" env_build["TF_NEED_OPENCL_SYCL"] = "1" if self.options.need_opencl_sycl else "0" env_build["TF_NEED_COMPUTECPP"] = "1" if self.options.need_computecpp else "0" env_build["TF_NEED_KAFKA"] = "1" if self.options.need_kafka else "0" env_build["TF_NEED_TENSORRT"] = "1" if (self.options.need_tensorrt and self.options.need_cuda) else "0" env_build["TF_NEED_IGNITE"] = "1" if self.options.need_ignite else "0" env_build["TF_NEED_ROCM"] = "1" if self.options.need_rocm else "0" env_build["TF_CONFIGURE_IOS"] = "1" if self.settings.os == "iOS" else "0" env_build["TF_SET_ANDROID_WORKSPACE"] = "1" if self.options.set_android_workspace else "0" env_build["TF_CONFIGURE_APPLE_BAZEL_RULES"] = "1" env_build["CC_OPT_FLAGS"] = "-march=native -Wno-sign-compare" env_build["GCC_HOST_COMPILER_PATH"] = ( tools.which("clang") if self.options.cuda_clang else tools.which("gcc") ) env_build["HOST_CXX_COMPILER"] = tools.which("clang++") if self.options.cuda_clang else tools.which("g++") # We want TF to use our versions of openssl, protobuf, and grpc self._add_lib_to_env("protobuf", "com_google_protobuf", env_build) self._add_lib_to_env("grpc", "grpc", env_build) self._add_lib_to_env("OpenSSL", "boringssl", env_build) # Patch the configure script and other files self._patch_tf_files() with tools.environment_append(env_build): self.run("python configure.py" if tools.os_info.is_windows else "./configure") self.run("bazel shutdown") bazel_config_flags = "" # if (self.options.need_mkl and not self.options.need_cuda): # bazel_config_flags += "--config=mkl " if self.options.need_gdr: bazel_config_flags += "--config=gdr " if self.options.need_verbs: bazel_config_flags += "--config=verbs " if self.options.need_ngraph: bazel_config_flags += "--config=ngraph " if self.options.need_numa: bazel_config_flags += "--config=numa " if self.options.build_dynamic_kernels: bazel_config_flags += "--config=build_dynamic_kernels " # if (self.options.need_cuda and not self.options.need_mkl): # bazel_config_flags += "--config=cuda " if self.options.need_aws == False: bazel_config_flags += "--config=noaws " if self.options.need_gcp == False: bazel_config_flags += "--config=nogcp " if self.options.need_hdfs == False: bazel_config_flags += "--config=nohdfs " optim_flags = "" safe_flags = "" os_name = str(self.settings.os).lower() if os_name == "macos": optim_flags = "-c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-msse4.1 --copt=-msse4.2" safe_flags = "-c opt --copt=-march=native" elif os_name == "linux": optim_flags = "-c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2" safe_flags = "-c opt" elif os_name == "windows": optim_flags = "-c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2" safe_flags = "-c opt --copt=-march=native --copt=-mfpmath=both" if self.options.build_optimized == "all": bazel_config_flags += optim_flags elif self.options.build_optimized == "safe": bazel_config_flags += safe_flags # This is a s***e, ugly hack. Linking with devtoolset on Bazel is jacked: we need to link stdc++ statically # https://github.com/bazelbuild/bazel/issues/10327 static_link_stdcpp = False if (os_name == "linux") and ( subprocess.check_output(["gcc", "-v"], encoding="UTF-8", stderr=subprocess.STDOUT).find( "devtoolset" ) != -1 ): print("build(): linking stdcpp statically on platform {}".format(platform.platform())) static_link_stdcpp = True self._build_bazel_target(bazel_config_flags, "//tensorflow:libtensorflow_cc.so", static_link_stdcpp) self._build_bazel_target(bazel_config_flags, "//tensorflow:libtensorflow.so", static_link_stdcpp) self._build_bazel_target(bazel_config_flags, "//tensorflow/core:tensorflow", static_link_stdcpp) self._build_bazel_target(bazel_config_flags, "//tensorflow/c:c_api", static_link_stdcpp) self._build_bazel_target( bazel_config_flags, "//tensorflow:libtensorflow_framework.so", static_link_stdcpp ) self._build_bazel_target(bazel_config_flags, "//tensorflow/java:libtensorflow_jni", static_link_stdcpp) self._build_bazel_target(bazel_config_flags, "//tensorflow/java:tensorflow", static_link_stdcpp) self._build_bazel_target( bazel_config_flags, "//tensorflow/core:framework_internal_impl", static_link_stdcpp ) self._build_bazel_target(bazel_config_flags, "//tensorflow/cc:cc_ops", static_link_stdcpp) self._build_bazel_target(bazel_config_flags, "//tensorflow/cc:client_session", static_link_stdcpp) self._build_bazel_target( bazel_config_flags, "//tensorflow/tools/graph_transforms:transform_utils", static_link_stdcpp ) self._build_bazel_target( bazel_config_flags, "//tensorflow/tools/graph_transforms:file_utils", static_link_stdcpp ) self._build_bazel_target(bazel_config_flags, "//tensorflow:install_headers", static_link_stdcpp) return
def build_autotools(self): prefix = os.path.abspath(self.package_folder) win_bash = False rc = None host = None build = None if self.is_mingw or self.is_msvc: prefix = prefix.replace('\\', '/') win_bash = True build = False if self.settings.arch == "x86": host = "i686-w64-mingw32" rc = "windres --target=pe-i386" elif self.settings.arch == "x86_64": host = "x86_64-w64-mingw32" rc = "windres --target=pe-x86-64" env_build = AutoToolsBuildEnvironment(self, win_bash=win_bash) if self.settings.os != "Windows": env_build.fpic = self.options.fPIC configure_args = ['--prefix=%s' % prefix] if self.options.shared: configure_args.extend(['--disable-static', '--enable-shared']) else: configure_args.extend(['--enable-static', '--disable-shared']) env_vars = {} if self.is_mingw: configure_args.extend([ 'CPPFLAGS=-I%s/include' % prefix, 'LDFLAGS=-L%s/lib' % prefix, 'RANLIB=:' ]) if self.is_msvc: runtime = str(self.settings.compiler.runtime) configure_args.extend([ 'CC=$PWD/build-aux/compile cl -nologo', 'CFLAGS=-%s' % runtime, 'CXX=$PWD/build-aux/compile cl -nologo', 'CXXFLAGS=-%s' % runtime, 'CPPFLAGS=-D_WIN32_WINNT=0x0600 -I%s/include' % prefix, 'LDFLAGS=-L%s/lib' % prefix, 'LD=link', 'NM=dumpbin -symbols', 'STRIP=:', 'AR=$PWD/build-aux/ar-lib lib', 'RANLIB=:' ]) env_vars['win32_target'] = '_WIN32_WINNT_VISTA' with tools.chdir(self.archive_name): tools.run_in_windows_bash( self, 'chmod +x build-aux/ar-lib build-aux/compile') if rc: configure_args.extend(['RC=%s' % rc, 'WINDRES=%s' % rc]) with tools.chdir(self.archive_name): with tools.environment_append(env_vars): env_build.configure(args=configure_args, host=host, build=build) env_build.make() env_build.make(args=["install"])
def system_package_tool_mode_test(self): """ System Package Tool mode is defined by CONAN_SYSREQUIRES_MODE env variable. Allowed values: (enabled, verify, disabled). Parser accepts it in lower/upper case or any combination. """ class RunnerMultipleMock(object): def __init__(self, expected=None): self.calls = 0 self.expected = expected def __call__(self, command, *args, **kwargs): # @UnusedVariable self.calls += 1 return 0 if command in self.expected else 1 packages = ["a_package", "another_package", "yet_another_package"] # Check invalid mode raises ConanException with tools.environment_append({ "CONAN_SYSREQUIRES_MODE": "test_not_valid_mode", "CONAN_SYSREQUIRES_SUDO": "True" }): runner = RunnerMultipleMock([]) spt = SystemPackageTool(runner=runner, tool=AptTool()) with self.assertRaises(ConanException) as exc: spt.install(packages) self.assertIn( "CONAN_SYSREQUIRES_MODE=test_not_valid_mode is not allowed", str(exc.exception)) self.assertEquals(0, runner.calls) # Check verify mode, a package report should be displayed in output and ConanException raised. # No system packages are installed with tools.environment_append({ "CONAN_SYSREQUIRES_MODE": "VeRiFy", "CONAN_SYSREQUIRES_SUDO": "True" }): packages = [ "verify_package", "verify_another_package", "verify_yet_another_package" ] runner = RunnerMultipleMock(["sudo apt-get update"]) spt = SystemPackageTool(runner=runner, tool=AptTool()) with self.assertRaises(ConanException) as exc: spt.install(packages) self.assertIn("Aborted due to CONAN_SYSREQUIRES_MODE=", str(exc.exception)) self.assertIn('\n'.join(packages), tools.system_pm._global_output) self.assertEquals(3, runner.calls) # Check disabled mode, a package report should be displayed in output. # No system packages are installed with tools.environment_append({ "CONAN_SYSREQUIRES_MODE": "DiSaBlEd", "CONAN_SYSREQUIRES_SUDO": "True" }): packages = [ "disabled_package", "disabled_another_package", "disabled_yet_another_package" ] runner = RunnerMultipleMock(["sudo apt-get update"]) spt = SystemPackageTool(runner=runner, tool=AptTool()) spt.install(packages) self.assertIn('\n'.join(packages), tools.system_pm._global_output) self.assertEquals(0, runner.calls) # Check enabled, default mode, system packages must be installed. with tools.environment_append({ "CONAN_SYSREQUIRES_MODE": "EnAbLeD", "CONAN_SYSREQUIRES_SUDO": "True" }): runner = RunnerMultipleMock(["sudo apt-get update"]) spt = SystemPackageTool(runner=runner, tool=AptTool()) with self.assertRaises(ConanException) as exc: spt.install(packages) self.assertNotIn("CONAN_SYSREQUIRES_MODE", str(exc.exception)) self.assertEquals(7, runner.calls)
subprocess.check_call([sys.executable, "manage.py", "gen"]) subprocess.check_call([sys.executable, "manage.py", "groups"]) with open("groups.json") as json_file: json_data = json.load(json_file) conan_instance, _, _ = conan_api.Conan.factory() env_vars = {} entry_script = None if tools.os_info.is_linux: cache_dir = "data" tools.rmdir(cache_dir) tools.mkdir(cache_dir) path = os.path.abspath(cache_dir) docker_args = "-v {}:/home/conan/.conan/data".format(path) entry_script = ".ci/entry.py" env_vars["CONAN_DOCKER_RUN_OPTIONS"] = docker_args elif tools.os_info.is_macos: export_recipes() for package in json_data["6"]: recipe = "conanfile-{}.py".format(package.lower()) test_package_folder = "test_package-{}".format(package.lower()) env_vars["CONAN_VERSION"] = conan_instance.inspect(path=recipe, attributes=["version"])["version"] env_vars["CONAN_CONANFILE"] = recipe with tools.environment_append(env_vars): builder = build_template_default.get_builder(docker_entry_script=entry_script) builder.update_build_if(lambda build: True, new_env_vars={"MAKEFLAGS": "--silent"}) builder.run()
def test_visual(self): settings = MockSettings({ "build_type": "Debug", "compier": "Visual Studio", "compiler.runtime": "MDd" }) conanfile = MockConanfile(settings) conanfile.deps_cpp_info.include_paths.append("/one/include/path") conanfile.deps_cpp_info.include_paths.append("/two/include/path") conanfile.deps_cpp_info.lib_paths.append("/one/lib/path") conanfile.deps_cpp_info.lib_paths.append("/two/lib/path") conanfile.deps_cpp_info.cflags.append("-mycflag") conanfile.deps_cpp_info.cflags.append("-mycflag2") conanfile.deps_cpp_info.cppflags.append("-mycppflag") conanfile.deps_cpp_info.cppflags.append("-mycppflag2") conanfile.deps_cpp_info.exelinkflags.append("-myexelinkflag") conanfile.deps_cpp_info.sharedlinkflags.append("-mysharedlinkflag") tool = VisualStudioBuildEnvironment(conanfile) self.assertEquals( tool.vars_dict, { "CL": [ "-I/one/include/path", "-I/two/include/path", '-MDd', '-mycflag', '-mycflag2', '-Zi', '-mycppflag', '-mycppflag2', '-myexelinkflag', '-mysharedlinkflag' ], "LIB": ["/one/lib/path", "/two/lib/path"], }) # Now alter the paths before the vars_dict call tool.include_paths.append("/three/include/path") tool.lib_paths.append("/three/lib/path") self.assertEquals( tool.vars_dict, { "CL": [ "-I/one/include/path", "-I/two/include/path", "-I/three/include/path", '-MDd', '-mycflag', '-mycflag2', '-Zi', '-mycppflag', '-mycppflag2', '-myexelinkflag', '-mysharedlinkflag' ], "LIB": ["/one/lib/path", "/two/lib/path", "/three/lib/path"], }) # Now try appending to environment with tools.environment_append({ "CL": "-I/four/include/path -I/five/include/path", "LIB": "/four/lib/path;/five/lib/path" }): self.assertEquals( tool.vars_dict, { "CL": [ "-I/one/include/path", "-I/two/include/path", "-I/three/include/path", '-MDd', '-mycflag', '-mycflag2', '-Zi', '-mycppflag', '-mycppflag2', '-myexelinkflag', '-mysharedlinkflag', "-I/four/include/path -I/five/include/path" ], "LIB": [ "/one/lib/path", "/two/lib/path", "/three/lib/path", "/four/lib/path;/five/lib/path" ], }) self.assertEquals( tool.vars, { "CL": '-I"/one/include/path" -I"/two/include/path" -I"/three/include/path" -MDd ' '-mycflag -mycflag2 -Zi ' '-mycppflag -mycppflag2 -myexelinkflag -mysharedlinkflag ' '-I/four/include/path -I/five/include/path', "LIB": "/one/lib/path;/two/lib/path;/three/lib/path;/four/lib/path;/five/lib/path", })
def test(self): new_path = os.environ['PATH'] + os.pathsep + self.deps_env_info['msys2_installer'].MSYS_BIN with tools.environment_append({'PATH': new_path}): self.run('%MSYS_BIN%\\bash -c ^"make --version^"')
def build(self): self._patch_sources() with tools.environment_append(RunEnvironment(self).vars): cmake = self._configure_cmake() cmake.build()
def system_package_tool_test(self): with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}): runner = RunnerMock() # fake os info to linux debian, default sudo os_info = OSInfo() os_info.is_macos = False os_info.is_linux = True os_info.is_windows = False os_info.linux_distro = "debian" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo apt-get update") os_info.linux_distro = "ubuntu" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo apt-get update") os_info.linux_distro = "knoppix" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo apt-get update") os_info.linux_distro = "fedora" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo yum check-update") os_info.linux_distro = "opensuse" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo zypper --non-interactive ref") os_info.linux_distro = "redhat" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.install("a_package", force=False) self.assertEquals(runner.command_called, "rpm -q a_package") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "sudo yum install -y a_package") os_info.linux_distro = "debian" spt = SystemPackageTool(runner=runner, os_info=os_info) with self.assertRaises(ConanException): runner.return_ok = False spt.install("a_package") self.assertEquals( runner.command_called, "sudo apt-get install -y --no-install-recommends a_package" ) runner.return_ok = True spt.install("a_package", force=False) self.assertEquals(runner.command_called, "dpkg -s a_package") os_info.is_macos = True os_info.is_linux = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "brew update") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "brew install a_package") os_info.is_freebsd = True os_info.is_macos = False spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo pkg update") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "sudo pkg install -y a_package") spt.install("a_package", force=False) self.assertEquals(runner.command_called, "pkg info a_package") # Chocolatey is an optional package manager on Windows if platform.system() == "Windows" and which("choco.exe"): os_info.is_freebsd = False os_info.is_windows = True spt = SystemPackageTool(runner=runner, os_info=os_info, tool=ChocolateyTool()) spt.update() self.assertEquals(runner.command_called, "choco outdated") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "choco install --yes a_package") spt.install("a_package", force=False) self.assertEquals( runner.command_called, 'choco search --local-only --exact a_package | findstr /c:"1 packages installed."' ) with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "False"}): os_info = OSInfo() os_info.is_linux = True os_info.linux_distro = "redhat" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.install("a_package", force=True) self.assertEquals(runner.command_called, "yum install -y a_package") spt.update() self.assertEquals(runner.command_called, "yum check-update") os_info.linux_distro = "ubuntu" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.install("a_package", force=True) self.assertEquals( runner.command_called, "apt-get install -y --no-install-recommends a_package") spt.update() self.assertEquals(runner.command_called, "apt-get update") os_info.is_macos = True os_info.is_linux = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "brew update") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "brew install a_package") os_info.is_freebsd = True os_info.is_macos = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "pkg update") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "pkg install -y a_package") spt.install("a_package", force=False) self.assertEquals(runner.command_called, "pkg info a_package") os_info.is_solaris = True os_info.is_freebsd = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "pkgutil --catalog") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "pkgutil --install --yes a_package") with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}): # Chocolatey is an optional package manager on Windows if platform.system() == "Windows" and which("choco.exe"): os_info.is_solaris = False os_info.is_windows = True spt = SystemPackageTool(runner=runner, os_info=os_info, tool=ChocolateyTool()) spt.update() self.assertEquals(runner.command_called, "choco outdated") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "choco install --yes a_package") spt.install("a_package", force=False) self.assertEquals( runner.command_called, 'choco search --local-only --exact a_package | findstr /c:"1 packages installed."' )
def build(self): with tools.environment_append(RunEnvironment(self).vars): cmake = CMake(self, set_cmake_flags=True) cmake.configure() cmake.build()
def build(self): self._apply_patches() with tools.environment_append({"PKG_CONFIG_PATH": [os.getcwd()]}): meson = self._configure_meson() meson.build()
def build_with_autotools(self): configure_suffix = self.get_configure_command_suffix() env_build = AutoToolsBuildEnvironment(self, win_bash=self.is_mingw) env_build_vars = env_build.vars # tweaks for mingw if self.is_mingw: # patch autotools files self.patch_mingw_files() env_build.defines.append('_AMD64_') env_build_vars['RCFLAGS'] = '-O COFF' if self.settings.arch == "x86": env_build_vars['RCFLAGS'] += ' --target=pe-i386' else: env_build_vars['RCFLAGS'] += ' --target=pe-x86-64' del env_build_vars['LIBS'] self.output.info(repr(env_build_vars)) if self.settings.os != "Windows": env_build.fpic = self.options.fPIC with tools.environment_append(env_build_vars): # temporary fix for xcode9 # extremely fragile because make doesn't see CFLAGS from env, only from cmdline if self.settings.os == "Macos": make_suffix = "CFLAGS=\"-Wno-unguarded-availability " + env_build.vars[ 'CFLAGS'] + "\"" else: make_suffix = '' env_run = RunEnvironment(self) # run configure with *LD_LIBRARY_PATH env vars # it allows to pick up shared openssl self.output.info(repr(env_run.vars)) with tools.environment_append(env_run.vars): with tools.chdir(self.source_subfolder): # autoreconf self.run('./buildconf', win_bash=self.is_mingw) # fix generated autotools files tools.replace_in_file("configure", "-install_name \\$rpath/", "-install_name ") # BUG: https://github.com/curl/curl/commit/bd742adb6f13dc668ffadb2e97a40776a86dc124 # fixed in 7.54.1: https://github.com/curl/curl/commit/338f427a24f78a717888c7c2b6b91fa831bea28e if self.version_components[ 0] == 7 and self.version_components[1] < 55: tools.replace_in_file( "configure", 'LDFLAGS="`$PKGCONFIG --libs-only-L zlib` $LDFLAGS"', 'LDFLAGS="$LDFLAGS `$PKGCONFIG --libs-only-L zlib`"' ) self.run("chmod +x configure") self.run("./configure " + configure_suffix, win_bash=self.is_mingw) self.run("make %s" % make_suffix, win_bash=self.is_mingw) self.run("make %s install" % make_suffix, win_bash=self.is_mingw)
def build(self): for f in glob.glob("*.cmake"): tools.replace_in_file( f, "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:>", "", strict=False) tools.replace_in_file( f, "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:>", "", strict=False) tools.replace_in_file( f, "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:>", "", strict=False) tools.replace_in_file( f, "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:-Wl,--export-dynamic>", "", strict=False) tools.replace_in_file( f, "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:-Wl,--export-dynamic>", "", strict=False) with tools.vcvars( self.settings ) if self.settings.compiler == "Visual Studio" else tools.no_op(): # next lines force cmake package to be in PATH before the one provided by visual studio (vcvars) build_env = tools.RunEnvironment( self ).vars if self.settings.compiler == "Visual Studio" else {} build_env["MAKEFLAGS"] = "j%d" % tools.cpu_count() build_env["PKG_CONFIG_PATH"] = [self.build_folder] if self.settings.os == "Windows": if not "PATH" in build_env: build_env["PATH"] = [] build_env["PATH"].append( os.path.join(self.source_folder, "qt6", "gnuwin32", "bin")) if self.settings.compiler == "Visual Studio": # this avoids cmake using gcc from strawberryperl build_env["CC"] = "cl" build_env["CXX"] = "cl" with tools.environment_append(build_env): if tools.os_info.is_macos: open(".qmake.stash", "w").close() open(".qmake.super", "w").close() cmake = self._configure_cmake() if tools.os_info.is_macos: with open("bash_env", "w") as f: f.write('export DYLD_LIBRARY_PATH="%s"' % ":".join( RunEnvironment(self).vars["DYLD_LIBRARY_PATH"])) with tools.environment_append( {"BASH_ENV": os.path.abspath("bash_env") }) if tools.os_info.is_macos else tools.no_op(): with tools.run_environment(self): cmake.build()
def test(self): with tools.environment_append(RunEnvironment(self).vars): self.run(os.path.join(self.build_folder, "app"))
def test(self): run_env = RunEnvironment(self) hdf5_file = os.path.join(self.source_folder, "sample.h5") os.chdir("bin") with tools.environment_append(run_env.vars): self.run(".%sexample %s" % (os.sep, hdf5_file))
def _build_android(self, args): # end workaround args += ["--disable-rpath", "-skip qtserialport"] if tools.os_info.is_windows: args += ["-platform win32-g++"] if self.settings.compiler == 'gcc': args += ["-xplatform android-g++"] else: args += ["-xplatform android-clang"] args += [ "-android-ndk-platform android-%s" % (str(self.settings.os.api_level)) ] args += [ "-android-ndk " + self._toUnixPath(self.deps_env_info['android-ndk'].NDK_ROOT) ] args += [ "-android-sdk " + self._toUnixPath(self.deps_env_info['android-sdk'].SDK_ROOT) ] args += [ "-android-ndk-host %s-%s" % (str( self.settings_build.os).lower(), str(self.settings_build.arch)) ] #args += ["-android-toolchain-version " + self.deps_env_info['android-ndk'].TOOLCHAIN_VERSION] #args += ["-sysroot " + tools.unix_path(self.deps_env_info['android-ndk'].SYSROOT)] args += [ "-device-option CROSS_COMPILE=" + self.deps_env_info['android-ndk'].CHOST + "-" ] if str(self.settings.arch).startswith('x86_64'): args.append('-android-arch x86_64') elif str(self.settings.arch).startswith('x86'): args.append('-android-arch x86') elif str(self.settings.arch).startswith('armv6'): args.append('-android-arch armeabi') elif str(self.settings.arch).startswith('armv7'): args.append("-android-arch armeabi-v7a") elif str(self.settings.arch).startswith('armv8'): args.append("-android-arch arm64-v8a") self.output.info("Using '%d' threads" % tools.cpu_count()) with tools.environment_append({ # The env. vars set by conan android-ndk. Configure doesn't read them (on windows they contain backslashes). "NDK_ROOT": self._toUnixPath(tools.get_env("NDK_ROOT")), "ANDROID_NDK_ROOT": self._toUnixPath(tools.get_env("NDK_ROOT")), "SYSROOT": self._toUnixPath(tools.get_env("SYSROOT")), "MAKEFLAGS": "-j %d" % tools.cpu_count() }): self.run( self._toUnixPath("%s/qt5/configure " % self.source_folder) + " ".join(args), win_bash=tools.os_info.is_windows) self.run("make", win_bash=tools.os_info.is_windows) self.run("make install", win_bash=tools.os_info.is_windows)
def build(self): # self.output.info('def build(self):') if self.options.header_only: self.output.warn("Header only package, skipping build") return if self.options.use_icu and self.use_icu: boost_build_folder = os.path.join(self.build_folder, self.folder_name) self.output.info(self.build_folder) self.output.info(boost_build_folder) replace_str = "int main() { return 0; }" # REGEX_TEST="libs/regex/build/has_icu_test.cpp" # LOCALE_TEST="libs/locale/build/has_icu_test.cpp" regex_test = os.path.join(boost_build_folder, 'libs', 'regex', 'build', 'has_icu_test.cpp') locale_test = os.path.join(boost_build_folder, 'libs', 'locale', 'build', 'has_icu_test.cpp') self.output.info(regex_test) self.output.info(locale_test) # with open(regex_test, 'r') as fin: # print(fin.read()) # with open(locale_test, 'r') as fin: # print(fin.read()) with open(regex_test, "w") as f: f.write(replace_str) with open(locale_test, "w") as f: f.write(replace_str) # with open(regex_test, 'r') as fin: # print(fin.read()) # with open(locale_test, 'r') as fin: # print(fin.read()) b2_exe = self.bootstrap() flags = self.get_build_flags() # Help locating bzip2 and zlib # self.create_user_config_jam(self.build_folder) # JOIN ALL FLAGS b2_flags = " ".join(flags) # command = "b2" if self.settings.os == "Windows" else "./b2" # full_command = "cd %s && %s %s -j%s" % ( # self.FOLDER_NAME, # command, # b2_flags, # tools.cpu_count()) # self.output.warn(full_command) # envs = self.prepare_deps_options_env() # with tools.environment_append(envs): # self.run(full_command)#, output=False) full_command = "%s %s -j%s --abbreviate-paths -d2" % ( b2_exe, b2_flags, tools.cpu_count()) # -d2 is to print more debug info and avoid travis timing out without output sources = os.path.join(self.source_folder, self.folder_name) full_command += ' --debug-configuration --build-dir="%s"' % self.build_folder self.output.warn(full_command) with tools.vcvars( self.settings ) if self.settings.compiler == "Visual Studio" else tools.no_op(): with tools.chdir(sources): # to locate user config jam (BOOST_BUILD_PATH) with tools.environment_append( {"BOOST_BUILD_PATH": self.build_folder}): # To show the libraries *1 # self.run("%s --show-libraries" % b2_exe) self.run(full_command)
def cpu_count_test(self): cpus = tools.cpu_count() self.assertIsInstance(cpus, int) self.assertGreaterEqual(cpus, 1) with tools.environment_append({"CONAN_CPU_COUNT": "34"}): self.assertEquals(tools.cpu_count(), 34)
def test(self): env_build = RunEnvironment(self) print env_build.vars with tools.environment_append(env_build.vars): self.run("./bin/test")
def _msvc_build_environment(self): with tools.chdir(self._source_subfolder): with tools.vcvars(self.settings): with tools.environment_append( VisualStudioBuildEnvironment(self).vars): yield
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 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) 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)