diff options
| author | ruki <[email protected]> | 2023-05-02 21:05:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-05-02 21:05:45 +0800 |
| commit | 13d11b2929915f3118cd91845b31d2a6e0d55015 (patch) | |
| tree | e21b48902319183607ec787c81e81a87f8a052ba | |
| parent | 3df1ad8688967a638f3ef5825a0011505c02dc55 (diff) | |
generate conan build info
| -rw-r--r-- | xmake/scripts/conan/extensions/generators/xmake_generator.py | 92 |
1 files changed, 83 insertions, 9 deletions
diff --git a/xmake/scripts/conan/extensions/generators/xmake_generator.py b/xmake/scripts/conan/extensions/generators/xmake_generator.py index f95164acc..c7c4b2a0d 100644 --- a/xmake/scripts/conan/extensions/generators/xmake_generator.py +++ b/xmake/scripts/conan/extensions/generators/xmake_generator.py @@ -11,31 +11,105 @@ from conans.model.build_info import CppInfo class XmakeGenerator: def __init__(self, conanfile): self._conanfile = conanfile + + def filename(self): + return "conanbuildinfo.xmake.lua" + def generate(self): print("XmakeGenerator: generating build info ..") - # Extract all dependencies + # extract all dependencies host_req = self._conanfile.dependencies.host test_req = self._conanfile.dependencies.test build_req = self._conanfile.dependencies.build - # Merge into one list full_req = list(host_req.items()) \ + list(test_req.items()) \ + list(build_req.items()) - # Process dependencies and accumulate globally required data - pkg_files = [] - dep_names = [] for require, dep in full_req: - dep_name = require.ref.name - dep_names.append(dep_name) - print("dep_name", dep_name) + #dep_name = require.ref.name - # Convert and aggregate dependency's + # get aggregate dependency's cppinfo dep_cppinfo = dep.cpp_info.copy() dep_cppinfo.set_relative_base_folder(dep.package_folder) dep_aggregate = dep_cppinfo.aggregated_components() print("dep_aggregate", dep_aggregate) + # format deps + deps = XmakeDepsFormatter(dep_aggregate) + + # make template + plat = "Linux" + arch = "x86_64" + mode = "Release" + template = (' {plat}_{arch}_{mode} = \n' + ' {{\n' + ' includedirs = {{{deps.include_paths}}},\n' + ' linkdirs = {{{deps.lib_paths}}},\n' + ' links = {{{deps.libs}}},\n' + ' frameworkdirs = {{{deps.framework_paths}}},\n' + ' frameworks = {{{deps.frameworks}}},\n' + ' syslinks = {{{deps.system_libs}}},\n' + ' defines = {{{deps.defines}}},\n' + ' cxxflags = {{{deps.cppflags}}},\n' + ' cflags = {{{deps.cflags}}},\n' + ' shflags = {{{deps.sharedlinkflags}}},\n' + ' ldflags = {{{deps.exelinkflags}}},\n' + ' __bindirs = {{{deps.bin_paths}}},\n' + ' __resdirs = {{{deps.res_paths}}},\n' + ' __srcdirs = {{{deps.src_paths}}}\n' + ' }}') + + # make sections + sections = [] + sections.append(template.format(plat = plat, arch = arch, mode = mode, deps = deps)) + + # make content + content = "{\n" + ",\n".join(sections) + "\n}" + print(content) + + # save content to file + with open(self.filename(), 'w') as file: + file.write(content) + +class XmakeDepsFormatter(object): + def __prepare_process_escape_character(self, raw_string): + if raw_string.find('\"') != -1: + raw_string = raw_string.replace("\"","\\\"") + return raw_string + + def __filter_char(self, raw_string): + return self.__prepare_process_escape_character(raw_string) + + def __init__(self, deps_cpp_info): + includedirs = deps_cpp_info._includedirs if deps_cpp_info._includedirs else [] + libdirs = deps_cpp_info._libdirs if deps_cpp_info._libdirs else [] + bindirs = deps_cpp_info._bindirs if deps_cpp_info._bindirs else [] + resdirs = deps_cpp_info._resdirs if deps_cpp_info._resdirs else [] + srcdirs = deps_cpp_info._srcdirs if deps_cpp_info._srcdirs else [] + frameworkdirs = deps_cpp_info._frameworkdirs if deps_cpp_info._frameworkdirs else [] + libs = deps_cpp_info._libs if deps_cpp_info._libs else [] + frameworks = deps_cpp_info._frameworks if deps_cpp_info._frameworks else [] + system_libs = deps_cpp_info._system_libs if deps_cpp_info._system_libs else [] + defines = deps_cpp_info._defines if deps_cpp_info._defines else [] + cxxflags = deps_cpp_info._cxxflags if deps_cpp_info._cxxflags else [] + cflags = deps_cpp_info._cflags if deps_cpp_info._cflags else [] + sharedlinkflags = deps_cpp_info._sharedlinkflags if deps_cpp_info._sharedlinkflags else [] + exelinkflags = deps_cpp_info._exelinkflags if deps_cpp_info._exelinkflags else [] + + self.include_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in includedirs) + self.lib_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in libdirs) + self.bin_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in bindirs) + self.res_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in resdirs) + self.src_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in srcdirs) + self.framework_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in frameworkdirs) + self.libs = ", ".join('"%s"' % p for p in libs) + self.frameworks = ", ".join('"%s"' % p for p in frameworks) + self.system_libs = ", ".join('"%s"' % p for p in system_libs) + self.defines = ", ".join('"%s"' % self.__filter_char(p) for p in defines) + self.cppflags = ", ".join('"%s"' % p for p in cxxflags) + self.cflags = ", ".join('"%s"' % p for p in cflags) + self.sharedlinkflags = ", ".join('"%s"' % p for p in sharedlinkflags) + self.exelinkflags = ", ".join('"%s"' % p for p in exelinkflags) |
