From 41d1104c8142ad55042fecee41eacd8100513d01 Mon Sep 17 00:00:00 2001 From: xwx1135370 Date: Mon, 5 Aug 2024 18:44:12 +0800 Subject: [PATCH] [R&D][Build][Windows][AArch64]Exclude some cross-platform python files. Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/IAH5E0?from=project-issue Test: Toolchain compilation and packaging confirmation Signed-off-by: xwx1135370 --- llvm-build/ohos_toolchain_builder.py | 1 + llvm-build/python_builder.py | 36 ++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/llvm-build/ohos_toolchain_builder.py b/llvm-build/ohos_toolchain_builder.py index 2a1ca0bda39b..0c6aefc090a1 100644 --- a/llvm-build/ohos_toolchain_builder.py +++ b/llvm-build/ohos_toolchain_builder.py @@ -205,6 +205,7 @@ class OHOSToolchainBuilder: self._llvm_libs.build_libedit(self._llvm_path, self._llvm_install, self._llvm_triple) if self._build_config.build_python: self._python_builder.build() + self._python_builder.prepare_for_package() self._build_utils.invoke_cmake( self._llvm_project_path, diff --git a/llvm-build/python_builder.py b/llvm-build/python_builder.py index d09ae7a4cbe3..a6d62f496ad1 100755 --- a/llvm-build/python_builder.py +++ b/llvm-build/python_builder.py @@ -162,15 +162,28 @@ class PythonBuilder: pkgconfig_dir = python_lib_dir / 'pkgconfig' self._remove_dir(pkgconfig_dir) - def _remove_pycache(self) -> None: - pycaches = [] - for dir_path, dirnames, _ in os.walk(self._install_dir / 'lib'): - for dirname in dirnames: - if dirname == '__pycache__': - pycaches.append(os.path.join(dir_path, dirname)) - - for cache_dir in pycaches: - shutil.rmtree(cache_dir) + def _remove_exclude(self) -> None: + exclude_dirs_tuple = ( + 'config-' + self._lldb_py_version, + '__pycache__', # EXCLUDE_FROM_LIB + 'idlelib', # IDLE_DIRS_ONLY + 'tkinter', 'turtledemo', # TCLTK_DIRS_ONLY + 'test', 'tests' # TEST_DIRS_ONLY + ) + exclude_files_tuple = ( + 'bdist_wininst.py', # BDIST_WININST_FILES_ONLY + 'turtle.py', # TCLTK_FILES_ONLY + '.whl', + '.pyc', '.pickle' # EXCLUDE_FROM_LIB + ) + + for root, dirs, files in os.walk(self._install_dir / 'lib'): + for item in dirs: + if item.startswith(exclude_dirs_tuple): + shutil.rmtree(os.path.join(root, item)) + for item in files: + if item.endswith(exclude_files_tuple): + os.remove(os.path.join(root, item)) @property def install_dir(self) -> str: @@ -241,7 +254,7 @@ class MinGWPythonBuilder(PythonBuilder): self._clean_bin_dir() self._clean_share_dir() self._clean_lib_dir() - self._remove_pycache() + self._remove_exclude() def package(self) -> None: archive = self._out_dir / f'cpython-mingw-clang-{self._version}.tar.gz' @@ -326,3 +339,6 @@ class OHOSPythonBuilder(PythonBuilder): shutil.copyfile(os.path.join(self._install_dir, "lib", libpython), os.path.join(install_dir, 'lib', libpython)) self.build_utils.check_copy_tree(self._install_dir, os.path.join(install_dir, self.build_utils.build_config.LLDB_PYTHON)) + + def prepare_for_package(self) -> None: + self._remove_exclude() -- Gitee