diff --git a/llvm-build/build.py b/llvm-build/build.py index 1ecf6ec561ffeb6a0bb0f519df8c5e58b6039433..14274efaed1951f183749a8797edf6db84530dd2 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