From f2c5073202f6de8008425d19b6e46bfea8ab5762 Mon Sep 17 00:00:00 2001 From: zhengweiwei Date: Wed, 12 Apr 2023 16:27:28 +0800 Subject: [PATCH] Use python static lib by default Description: Add build process for static python lib and enable static link python of lldb build by default Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I6EQVA Test: local compilation test Signed-off-by: zhengweiwei Change-Id: Iab593dfa7bddf3761b6197cdee872881f1b1712a --- llvm-build/build.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/llvm-build/build.py b/llvm-build/build.py index 1ecf6ec561ff..14274efaed19 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -275,6 +275,39 @@ class BuildUtils(object): self.check_create_dir(out_path) self.check_call([cmake_bin_path] + flags, cwd=out_path, env=env) + + def python_build(self): + python_path = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'python') + if not os.path.exists(python_path): + return '' + generated_path = os.path.join(python_path, 'build', 'libpython') + static_lib_path = os.path.join(generated_path, 'libpython3.10.a') + if not os.path.exists(static_lib_path): + os.makedirs(generated_path, exist_ok=True) + Setup_path = os.path.join(python_path, 'Modules', 'Setup') + self.replace_line(r"^[^#]*_locale -DPy_BUILD_CORE_BUILTIN _localemodule.c # -lintl*", r"#\g<0>", Setup_path) + build_args = [ + os.path.join(python_path, 'configure'), + '--prefix={}'.format(generated_path), + '--bindir={}'.format(os.path.join(generated_path, 'bin')), + '--libdir={}'.format(os.path.join(generated_path, 'lib')), + '--includedir={}'.format(os.path.join(generated_path, 'include')), + '--datarootdir={}'.format(os.path.join(generated_path, 'share')) + ] + self.check_call(build_args, cwd=generated_path) + self.check_call('make', cwd=generated_path) + self.check_call(['make', 'install'], cwd=generated_path) + self.replace_line(r'\$\{Python3_LIBRARIES\}', f'"{static_lib_path}"', + os.path.join(self.build_config.REPOROOT_DIR, 'toolchain', 'llvm-project', + 'lldb', 'source', 'Plugins', 'ScriptInterpreter', 'Python', 'CMakeLists.txt')) + return generated_path + + def replace_line(self, pattern, replace, file_path): + with open(file_path, 'r') as f: + content = f.read() + content = re.sub(pattern, replace, content, flags=re.MULTILINE) + with open(file_path, 'w') as f: + f.write(content) @staticmethod def logger(): @@ -376,6 +409,14 @@ class BuildUtils(object): defines['CMAKE_OSX_DEPLOYMENT_TARGET'] = mac_min_version defines['LLDB_INCLUDE_TESTS'] = 'OFF' defines['LIBCXX_INCLUDE_TESTS'] = 'OFF' + static_python_path = self.python_build() + if os.path.exists(static_python_path): + defines['LLDB_PYTHON_EXE_RELATIVE_PATH'] = static_python_path + defines['LLDB_PYTHON_RELATIVE_PATH'] = static_python_path + else: + raise Exception( + "Unable to find third_party/python folder." + ) defines['COMPILER_RT_BUILD_XRAY'] = 'OFF' return defines -- Gitee