def package(self): self.copy("COPYING-*", src=self._source_subfolder, dst="licenses") with self._build_context(): autotools = self._configure_autotools() autotools.install() pc_data = {} for fn in glob.glob( os.path.join(self.package_folder, "share", "pkgconfig", "*.pc")): pc_text = load(self, fn) filename = os.path.basename(fn)[:-3] name = next( re.finditer("^Name: ([^\n$]+)[$\n]", pc_text, flags=re.MULTILINE)).group(1) version = next( re.finditer("^Version: ([^\n$]+)[$\n]", pc_text, flags=re.MULTILINE)).group(1) pc_data[filename] = { "version": version, "name": name, } mkdir(self, os.path.dirname(self._pc_data_path)) save(self, self._pc_data_path, yaml.dump(pc_data)) rmdir(self, os.path.join(self.package_folder, "share"))
def generate_args(self): configure_args = [] configure_args.extend(self.configure_args) if self.default_configure_install_args: # If someone want arguments but not the defaults can pass them in args manually configure_args.extend([ "--prefix=%s" % self._conanfile.package_folder.replace("\\", "/"), "--bindir=${prefix}/bin", "--sbindir=${prefix}/bin", "--libdir=${prefix}/lib", "--includedir=${prefix}/include", "--oldincludedir=${prefix}/include", "--datarootdir=${prefix}/share" ]) user_args_str = args_to_string(self.configure_args) for flag, var in (("host", self._host), ("build", self._build), ("target", self._target)): if var and flag not in user_args_str: configure_args.append('--{}={}'.format(flag, var)) args = { "configure_args": args_to_string(configure_args), "make_args": args_to_string(self.make_args) } save(self._conanfile, CONAN_TOOLCHAIN_ARGS_FILE, json.dumps(args))
def _create_cmake_module_alias_targets(self, module_file, targets): content = "" for alias, aliased in targets.items(): content += textwrap.dedent("""\ if(TARGET {aliased} AND NOT TARGET {alias}) add_library({alias} INTERFACE IMPORTED) set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased}) endif() """.format(alias=alias, aliased=aliased)) save(self, module_file, content)
def build(self): # some compilers (e.g. clang) do not like UTF-16 sources rc = os.path.join(self._source_subfolder, "kernels", "embree.rc") content = load(self, rc, encoding="utf_16_le") if content[0] == '\ufeff': content = content[1:] content = "#pragma code_page(65001)\n" + content save(self, rc, content) os.remove(os.path.join(self._source_subfolder, "common", "cmake", "FindTBB.cmake")) cmake = self._configure_cmake() cmake.build()
def build(self): save( self, os.path.join(self._source_subfolder, "libkmod", "docs", "gtk-doc.make"), "") self.run("{} -fiv".format(tools.get_env("AUTORECONF") or "autoreconf"), win_bash=tools.os_info.is_windows, run_environment=True, cwd=self._source_subfolder) autotools = Autotools(self) autotools.configure(build_script_folder=self._source_subfolder) autotools.make()
def test_replace_in_file(): conanfile = MockConanfile({}) tmp = temp_folder() file_path = os.path.join(tmp, "file.txt") # By default utf-8 is used save(conanfile, file_path, "你很重,伙計") replace_in_file(conanfile, file_path, "重", "0") contents = load(conanfile, file_path) assert contents == "你很0,伙計" # Replacing with other encodings is also possible save(conanfile, file_path, "Ö¼", encoding="cp1252") replace_in_file(conanfile, file_path, "¼", "0", encoding="cp1252") contents = load(conanfile, file_path, encoding="cp1252") assert contents == "Ö0" save(conanfile, file_path, bytes("Ö¼", "ISO-8859-1")) replace_in_file(conanfile, file_path, "¼", "0", encoding="ISO-8859-1") contents = load(conanfile, file_path, encoding="ISO-8859-1") assert contents == "Ö0" # Replacing utf-16 is also possible but using "utf-16LE" (without BOM) to search and replace # otherwise the "search" string is not found because it contains also a BOM (header) save(conanfile, file_path, bytes("你很重,伙計", "utf-16")) replace_in_file(conanfile, file_path, "重", "0", encoding="utf-16") contents = load(conanfile, file_path, encoding="utf-16") assert contents == "你很0,伙計"
def generate(self): tc = MesonToolchain(self) tc.project_options["libdir"] = "lib" tc.project_options["datadir"] = "res" tc.project_options["libraries"] = self.options.enable_libraries tc.project_options[ "dtd_validation"] = self.options.enable_dtd_validation tc.project_options["documentation"] = False if Version(self.version) >= "1.18.91": tc.project_options["scanner"] = True # Generate PC files for the tool_requires wayland package to ensure wayland-scanner is found for build machine. if cross_building(self): native_generators_folder = os.path.join( self.generators_folder, "native") mkdir(self, native_generators_folder) for pc_name, pc_content in get_pc_files_and_content( self, self.dependencies.build["wayland"]).items(): save(self, os.path.join(native_generators_folder, pc_name), pc_content) tc.project_options[ "build.pkg_config_path"] = native_generators_folder tc.generate()
def test_save_and_load_encoding(): conanfile = MockConanfile({}) tmp = temp_folder() file_path = os.path.join(tmp, "file.txt") # By default utf-8 is used save(conanfile, file_path, "你很重,伙計") contents = load(conanfile, file_path) assert isinstance(contents, str) assert contents == "你很重,伙計" # But you can save bytes directly with an encoding save(conanfile, file_path, bytes("你很重,伙計", "utf-16")) contents = load(conanfile, file_path, encoding="utf-16") assert contents == "你很重,伙計" # And you can specify different encoding save(conanfile, file_path, "你很重,伙計", encoding="utf-16") contents = load(conanfile, file_path, encoding="utf-16") assert contents == "你很重,伙計" save(conanfile, file_path, "regular contents") contents = load(conanfile, file_path) assert contents == "regular contents"
def build(self): save(self, os.path.join(self.source_folder, "libkmod", "docs", "gtk-doc.make"), "") autotools = Autotools(self) autotools.autoreconf() autotools.configure() autotools.make()