def run_in_windows_bash_inject_env_test(self): with tools.remove_from_path("bash.exe"): with msys2_in_path(): conanfile = ''' import os from conans import ConanFile, tools, __version__ as conan_version class ConanBash(ConanFile): name = "bash" version = "0.1" settings = "os", "compiler", "build_type", "arch" def build(self): vs_path = tools.vcvars_dict(self.settings)["PATH"] if conan_version >= "1.7.0": vs_path = os.pathsep.join(vs_path) tools.run_in_windows_bash(self, "link", env={"PATH": vs_path}) ''' client = TestClient() client.save({CONANFILE: conanfile}) client.run("export %s lasote/stable" % path_dot()) client.run("install bash/0.1@lasote/stable --build" ) # Link will fail, but run self.assertIn("Microsoft (R) Incremental Linker Version", client.user_io.out)
def diamond_mingw_test(self): use_cmake = cmake_targets = False self._export("Hello0", "0.1", use_cmake=use_cmake, cmake_targets=cmake_targets) self._export("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], use_cmake=use_cmake, cmake_targets=cmake_targets) self._export("Hello2", "0.1", ["Hello0/0.1@lasote/stable"], use_cmake=use_cmake, cmake_targets=cmake_targets) self._export("Hello3", "0.1", ["Hello1/0.1@lasote/stable", "Hello2/0.1@lasote/stable"], use_cmake=use_cmake, cmake_targets=cmake_targets) files3 = cpp_hello_conan_files("Hello4", "0.1", ["Hello3/0.1@lasote/stable"], language=1, use_cmake=use_cmake, cmake_targets=cmake_targets) self.client.save(files3) with tools.remove_from_path("bash.exe"): with mingw_in_path(): not_env = os.system("g++ --version > nul") if not_env != 0: raise Exception("This platform does not support G++ command") install = "install %s -s compiler=gcc -s compiler.libcxx=libstdc++ " \ "-s compiler.version=4.9" % path_dot() self.client.run("install %s -s compiler=gcc -s compiler.libcxx=libstdc++ " "-s compiler.version=4.9 --build=missing" % path_dot()) self.client.run("build .") command = os.sep.join([".", "bin", "say_hello"]) self.client.run_command(command) self.assertEqual(['Hola Hello4', 'Hola Hello3', 'Hola Hello1', 'Hola Hello0', 'Hola Hello2', 'Hola Hello0'], str(self.client.out).splitlines()[-6:])
def run_in_windows_bash_inject_env_test(self): if Version(conan_version) < Version( "1.0.0-beta.4") or platform.system() != "Windows": raise nose.SkipTest('Only windows test') with tools.remove_from_path("bash.exe"): with msys2_in_path(): conanfile = ''' from conans import ConanFile, tools class ConanBash(ConanFile): name = "bash" version = "0.1" settings = "os", "compiler", "build_type", "arch" def build(self): vs_path = tools.vcvars_dict(self.settings)["PATH"] tools.run_in_windows_bash(self, "link", env={"PATH": vs_path}) ''' client = TestClient() client.save({CONANFILE: conanfile}) client.run("export %s lasote/stable" % path_dot()) client.run("install bash/0.1@lasote/stable --build", ignore_error=True) # Link will fail, but run self.assertIn("Microsoft (R) Incremental Linker Version", client.user_io.out)
def configure(self, args=None, defs=None, source_dir=None, build_dir=None, source_folder=None, build_folder=None, cache_build_folder=None): # TODO: Deprecate source_dir and build_dir in favor of xxx_folder args = args or [] defs = defs or {} source_dir, self.build_dir = self._get_dirs(source_folder, build_folder, source_dir, build_dir, cache_build_folder) mkdir(self.build_dir) arg_list = join_arguments([ self.command_line, args_to_string(args), defs_to_string(defs), args_to_string([source_dir]) ]) command = "cd %s && cmake %s" % (args_to_string([self.build_dir ]), arg_list) if platform.system( ) == "Windows" and self.generator == "MinGW Makefiles": with tools.remove_from_path("sh"): self._conanfile.run(command) else: self._conanfile.run(command)
def run_in_windows_bash_test(self): with tools.remove_from_path("bash.exe"): with msys2_in_path(): conanfile = ''' from conans import ConanFile, tools class ConanBash(ConanFile): name = "bash" version = "0.1" settings = "os", "compiler", "build_type", "arch" def build(self): tools.run_in_windows_bash(self, "pwd") ''' client = TestClient() client.save({CONANFILE: conanfile}) client.run("export %s lasote/stable" % path_dot()) client.run("install bash/0.1@lasote/stable --build") if Version(conan_version) < Version("1.12.0"): cache = client.client_cache else: cache = client.cache ref = ConanFileReference.loads("bash/0.1@lasote/stable") if Version(conan_version) > Version("1.14.10"): tmp = cache.package_layout(ref).base_folder() else: tmp = cache.conan(ref) expected_curdir_base = unix_path(tmp) self.assertIn(expected_curdir_base, client.out)
def run_in_windows_bash_test(self): if Version(conan_version) < Version( "1.0.0-beta.1") or platform.system() != "Windows": raise nose.SkipTest('Only windows test') with tools.remove_from_path("bash.exe"): with msys2_in_path(): conanfile = ''' from conans import ConanFile, tools class ConanBash(ConanFile): name = "bash" version = "0.1" settings = "os", "compiler", "build_type", "arch" def build(self): tools.run_in_windows_bash(self, "pwd") ''' client = TestClient() client.save({CONANFILE: conanfile}) client.run("export %s lasote/stable" % path_dot()) client.run("install bash/0.1@lasote/stable --build") expected_curdir_base = unix_path( client.client_cache.conan( ConanFileReference.loads("bash/0.1@lasote/stable"))) self.assertIn(expected_curdir_base, client.user_io.out)
def _configure(self, args=None, defs=None, source_dir=None, build_dir=None, source_folder=None, build_folder=None, cache_build_folder=None, pkg_config_paths=None): # TODO: Deprecate source_dir and build_dir in favor of xxx_folder if not self._conanfile.should_configure: return args = args or [] defs = defs or {} source_dir, self.build_dir = self._get_dirs(source_folder, build_folder, source_dir, build_dir, cache_build_folder) mkdir(self.build_dir) arg_list = join_arguments([ self.command_line, args_to_string(args), defs_to_string(defs), args_to_string([source_dir]) ]) 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 set_env = "pkg_config" in self._conanfile.generators \ and "PKG_CONFIG_PATH" not in os.environ pkg_env = { "PKG_CONFIG_PATH": self._conanfile.install_folder } if set_env else {} with tools.environment_append(pkg_env): compiler = self._settings.get_safe("compiler") command = "cd %s && cmake %s" % (args_to_string([self.build_dir ]), arg_list) if compiler == 'emcc': self._conanfile.output.warn('Used hacked CMake in emcc build') command = "cd %s && emcmake cmake %s" % (args_to_string( [self.build_dir]), arg_list) if platform.system( ) == "Windows" and self.generator == "MinGW Makefiles": with tools.remove_from_path("sh"): self._conanfile.run(command) else: self._conanfile.run(command)
def _build_vs(self): with tools.chdir(self._source_subfolder): with tools.vcvars(self.settings, force=True): with tools.remove_from_path('mkdir'): tools.replace_in_file('Makefile.vc', 'CFLAGS = /nologo /W3 /Ox /MT', 'CFLAGS = /nologo /W3 /Ox /%s' % str(self.settings.compiler.runtime)) self.run('nmake -f Makefile.vc') self.run('nmake -f Makefile.vc prefix="%s" install' % os.path.abspath(self.package_folder))
def build_mingw_test(self): with tools.remove_from_path("bash.exe"): with mingw_in_path(): not_env = os.system("c++ --version > nul") if not_env != 0: raise Exception("This platform does not support G++ command") install = "install %s -s compiler=gcc -s compiler.libcxx=libstdc++ " \ "-s compiler.version=4.9" % path_dot() for cmd, lang, static, pure_c in [(install, 0, True, True), (install + " -o language=1 -o static=False", 1, False, False)]: from conans.test.functional.basic_build_test import build build(self, cmd, static, pure_c, use_cmake=False, lang=lang)
def diamond_mingw_test(self): if Version(client_version) < Version("0.31"): raise nose.SkipTest('Only >= 1.0 version') with tools.remove_from_path("bash.exe"): with mingw_in_path(): not_env = os.system("g++ --version > nul") if not_env != 0: raise Exception( "This platform does not support G++ command") install = "install %s -s compiler=gcc -s compiler.libcxx=libstdc++ " \ "-s compiler.version=4.9" % path_dot() self.diamond_tester.test(install=install, use_cmake=False)
def cmake_multi_find_test(self): if platform.system() not in ["Windows", "Linux"]: return client = TestClient() conanfile = """from conans import ConanFile, CMake class HelloConan(ConanFile): name = "Hello" version = "0.1" settings = "build_type" exports = '*' def package(self): self.copy(pattern="*", src="%s" % self.settings.build_type) """ client.save({"conanfile.py": conanfile, "Debug/FindHello.cmake": 'message(STATUS "FIND HELLO DEBUG!")', "Release/FindHello.cmake": 'message(STATUS "FIND HELLO RELEASE!")'}) client.run("export . lasote/testing") cmake = """set(CMAKE_CXX_COMPILER_WORKS 1) project(MyHello CXX) cmake_minimum_required(VERSION 2.8) include(conanbuildinfo_multi.cmake) conan_basic_setup() find_package(Hello) """ conanfile = """from conans import ConanFile, CMake class HelloConan(ConanFile): requires = "Hello/0.1@lasote/testing" settings = "build_type" generators = "cmake_multi" """ client.save({"conanfile.py": conanfile, "CMakeLists.txt": cmake}, clean_first=True) client.run("install . --build=missing ") client.run("install . -s build_type=Debug --build=missing ") with tools.remove_from_path("sh"): generator = "MinGW Makefiles" if platform.system() == "Windows" else "Unix Makefiles" client.runner('cmake . -G "%s" -DCMAKE_BUILD_TYPE=Debug' % generator, cwd=client.current_folder) self.assertIn("FIND HELLO DEBUG!", client.user_io.out) self.assertNotIn("FIND HELLO RELEASE!", client.user_io.out) client.init_dynamic_vars() # to reset output client.runner('cmake . -G "%s" -DCMAKE_BUILD_TYPE=Release' % generator, cwd=client.current_folder) self.assertIn("FIND HELLO RELEASE!", client.user_io.out) self.assertNotIn("FIND HELLO DEBUG!", client.user_io.out)
def build(self): # Hiermit bauen wir das Basistool für den Installer. Aber nur für # Release bzw. für Windows Visual Studio Compiler. if self.settings.build_type != "Release": raise Exception( "Cannot build installer framework with build type {0}!".format( self.settings.build_type)) if self.settings.compiler != "Visual Studio": raise Exception( "Cannot build on platform {0} and compiler {1}!".format( self.settings.os, self.settings.compiler)) self.remove_debug_directory() # Jetzt schreiben wir die Versions- und Git-Informationen in ein .h File. Dieses # liegt unter src/sdk und nennt sich build_info.h. Leider war es in nützlicher Frist nicht anders möglich. git_infos = read_git_information() print(git_infos) with open("src/sdk/build_info.h", "w") as q: q.write( "#ifndef BUILD_INFO_H\n#define BUILD_INFO_H\n // Info: This file is auto-generated by conanfile.py\n" ) q.write("#define SQP_IFW_VERSION_STRING \"v{0}\"\n".format( self.version)) q.write("#define SQP_GIT_BRANCH \"{0}\"\n".format( git_infos["branch"])) q.write("#define SQP_GIT_AUTHOR \"{0}\"\n".format( git_infos["author"])) q.write("#define SQP_GIT_HASH \"{0}\"\n".format( git_infos["commit_hash"])) q.write("#endif // BUILD_INFO_H\n") # Damit qmake den Kompiler findet, müssen die Umgebungsvariabeln korrekt # aufgesetzt werden. Dies können wir über die Klasse VisualStudioBuildEnvironment # abdecken. Diese Klasse generiert ein Statement, das vor die Ausführung des Tools # gestellt wird. Die Variablen werden über das korrekte bat-File von Visual Studio # dann für die Umgebung vorbereitet. env_build = VisualStudioBuildEnvironment(self) with tools.remove_from_path("qmake"): path = os.environ["PATH"] + os.pathsep + self.deps_cpp_info[ 'QtStatic'].rootpath + '\\bin' with tools.environment_append(env_build.vars): with tools.environment_append({"PATH": path}): vcvars = tools.vcvars_command(self.settings) self.run( "{0} && qmake.exe installerfw.pro CONFIG+=release -spec win32-msvc" .format(vcvars)) self.run("{0} && set CL=/MP && nmake.exe".format(vcvars)) self.remove_debug_directory()
def run_in_windows_bash_env_var_test(self): if Version(conan_version) < Version( "1.0.0-beta.1") or platform.system() != "Windows": raise nose.SkipTest('Only windows test') with tools.remove_from_path("bash.exe"): with msys2_in_path(): conanfile = ''' from conans import ConanFile, tools import os class ConanBash(ConanFile): name = "THEPACKAGE" version = "0.1" def package_info(self): self.env_info.PATH.append(self.package_folder) tools.save(os.path.join(self.package_folder, "myrun.bat"), 'echo "HELLO PARENT!') ''' client = TestClient() client.save({CONANFILE: conanfile}) client.run("create %s lasote/stable" % path_dot()) conanfile = ''' from conans import ConanFile, tools class ConanBash(ConanFile): name = "bash" version = "0.1" settings = "os", "compiler", "build_type", "arch" requires = "THEPACKAGE/0.1@lasote/stable" def build(self): with tools.environment_append({"MYVAR": "Hello MYVAR"}): tools.run_in_windows_bash(self, "echo $MYVAR") tools.run_in_windows_bash(self, 'myrun.bat') ''' client.save({CONANFILE: conanfile}, clean_first=True) client.run("export %s lasote/stable" % path_dot()) client.run("install bash/0.1@lasote/stable --build") self.assertIn("Hello MYVAR", client.user_io.out) self.assertIn("HELLO PARENT!", client.user_io.out)
def run_in_windows_bash_relative_path_test(self): with tools.remove_from_path("bash.exe"): with msys2_in_path(): conanfile = ''' import os from conans import ConanFile, tools class ConanBash(ConanFile): name = "bash" version = "0.1" def build(self): tools.mkdir("relative") tools.run_in_windows_bash(self, "pwd", "relative") ''' client = TestClient() client.save({CONANFILE: conanfile}) client.run("create %s bash/0.1@lasote/stable" % path_dot()) self.assertIn( "build/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/relative", client.user_io.out)
def configure(self, args=None, defs=None, source_dir=None, build_dir=None, source_folder=None, build_folder=None, cache_build_folder=None): # TODO: Deprecate source_dir and build_dir in favor of xxx_folder if not self._conanfile.should_configure: return args = args or [] defs = defs or {} source_dir, self.build_dir = self._get_dirs(source_folder, build_folder, source_dir, build_dir, cache_build_folder) mkdir(self.build_dir) arg_list = join_arguments([ self.command_line, args_to_string(args), defs_to_string(defs), args_to_string([source_dir]) ]) command = "cd %s && cmake %s" % (args_to_string([self.build_dir]), arg_list) if platform.system() == "Windows" and self.generator == "MinGW Makefiles": with tools.remove_from_path("sh"): self._conanfile.run(command) else: self._conanfile.run(command)
def test(self): with tools.chdir(self.source_folder), tools.remove_from_path("make"): env_build = AutoToolsBuildEnvironment(self) env_build.make(args=["love"])
def cmake_multi_find_test(self): if platform.system() not in ["Windows", "Linux"]: return client = TestClient() conanfile = """from conans import ConanFile, CMake class HelloConan(ConanFile): name = "Hello" version = "0.1" settings = "build_type" exports = '*' def package(self): self.copy(pattern="*", src="%s" % self.settings.build_type) """ client.save({ "conanfile.py": conanfile, "Debug/FindHello.cmake": 'message(STATUS "FIND HELLO DEBUG!")', "Release/FindHello.cmake": 'message(STATUS "FIND HELLO RELEASE!")' }) client.run("export . lasote/testing") cmake = """set(CMAKE_CXX_COMPILER_WORKS 1) project(MyHello CXX) cmake_minimum_required(VERSION 2.8) include(conanbuildinfo_multi.cmake) conan_basic_setup() find_package(Hello) """ conanfile = """from conans import ConanFile, CMake class HelloConan(ConanFile): requires = "Hello/0.1@lasote/testing" settings = "build_type" generators = "cmake_multi" """ client.save({ "conanfile.py": conanfile, "CMakeLists.txt": cmake }, clean_first=True) client.run("install . --build=missing ") client.run("install . -s build_type=Debug --build=missing ") with tools.remove_from_path("sh"): generator = "MinGW Makefiles" if platform.system( ) == "Windows" else "Unix Makefiles" client.runner('cmake . -G "%s" -DCMAKE_BUILD_TYPE=Debug' % generator, cwd=client.current_folder) self.assertIn("FIND HELLO DEBUG!", client.user_io.out) self.assertNotIn("FIND HELLO RELEASE!", client.user_io.out) client.init_dynamic_vars() # to reset output client.runner('cmake . -G "%s" -DCMAKE_BUILD_TYPE=Release' % generator, cwd=client.current_folder) self.assertIn("FIND HELLO RELEASE!", client.user_io.out) self.assertNotIn("FIND HELLO DEBUG!", client.user_io.out)