From f5006aee986fe1b476d1c7777190146885e61351 Mon Sep 17 00:00:00 2001 From: HsuYao Date: Wed, 14 May 2025 06:22:56 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!740=20:?= =?UTF-8?q?=20[BUILD][Linux/Mac/OHOS][LLDB]Upgrade=20lldb=20dependency=20l?= =?UTF-8?q?ibraries=20ncurses=20and=20libedit'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- llvm-build/build.py | 54 ++++++++++++++++----------- llvm-build/build_libedit.sh | 41 +++++++++++--------- llvm-build/build_ncurses.sh | 33 ++++++++-------- llvm-build/cross_toolchain_builder.py | 19 +++++----- 4 files changed, 82 insertions(+), 65 deletions(-) diff --git a/llvm-build/build.py b/llvm-build/build.py index d8c72488c7c4..9cd476a17b89 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -685,12 +685,18 @@ class BuildUtils(object): def merge_build_dir(self, name, platform_triple, *args): return self.merge_out_path('third_party', name, 'build', platform_triple, *args) + def merge_ncurses_install_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'ncurses', 'install', platform_triple, *args) + def get_ncurses_dependence_libs(self, platform_triple): ncurses_libs = ['libncurses', 'libpanel', 'libform'] if self.use_platform() != platform_triple: ncurses_libs.append('libtinfo') return ncurses_libs + def merge_ncurses_build_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'ncurses', 'build', platform_triple, *args) + def get_libxml2_version(self): version_file = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'libxml2', 'libxml2.spec') if os.path.isfile(version_file): @@ -727,6 +733,12 @@ class BuildUtils(object): return None + def merge_libedit_install_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'libedit', 'install', platform_triple, *args) + + def merge_libedit_build_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'libedit', 'build', platform_triple, *args) + def merge_python_install_dir(self, platform_triple, *args): return self.merge_out_path('third_party', 'python', 'install', platform_triple, *args) @@ -827,8 +839,7 @@ class LlvmCore(BuildUtils): llvm_defines['LLDB_PYTHON_EXT_SUFFIX'] = '.dylib' if self.build_config.build_ncurses: ncurses_libs = ';'.join([ - self.merge_install_dir( - 'ncurses', + self.merge_ncurses_install_dir( self.use_platform(), 'lib', f'{lib_name}.6.dylib') for lib_name in self.get_ncurses_dependence_libs(self.use_platform())]) @@ -840,7 +851,7 @@ class LlvmCore(BuildUtils): if self.build_config.build_libedit: llvm_defines['LibEdit_LIBRARIES'] = \ - self.merge_install_dir('libedit', self.use_platform(), 'lib', 'libedit.0.dylib') + self.merge_libedit_install_dir(self.use_platform(), 'lib', 'libedit.0.dylib') if self.build_config.build_libxml2: llvm_defines['LIBXML2_LIBRARIES'] = \ @@ -872,8 +883,7 @@ class LlvmCore(BuildUtils): if self.build_config.build_ncurses and ncurses_version is not None: ncurses_libs = ";".join( [ - self.merge_install_dir( - 'ncurses', + self.merge_ncurses_install_dir( self.use_platform(), "lib", f"{lib_name}.so.{ncurses_version}", @@ -891,7 +901,7 @@ class LlvmCore(BuildUtils): if self.build_config.build_libedit: llvm_defines['LibEdit_LIBRARIES'] = \ - self.merge_install_dir('libedit', self.use_platform(), 'lib', 'libedit.so.0.0.75') + self.merge_libedit_install_dir(self.use_platform(), 'lib', 'libedit.so.0.0.68') if not build_instrumented and not no_lto and not debug_build: llvm_defines['LLVM_ENABLE_LTO'] = 'Thin' @@ -939,7 +949,7 @@ class LlvmCore(BuildUtils): if self.build_config.build_ncurses and self.get_ncurses_version() is not None: llvm_defines['LLDB_ENABLE_CURSES'] = 'ON' - llvm_defines['CURSES_INCLUDE_DIRS'] = self.merge_install_dir('ncurses', self.use_platform(), 'include') + llvm_defines['CURSES_INCLUDE_DIRS'] = self.merge_ncurses_install_dir(self.use_platform(), 'include') if self.build_config.enable_lzma_7zip: llvm_defines['LLDB_ENABLE_LZMA'] = 'ON' @@ -948,7 +958,7 @@ class LlvmCore(BuildUtils): if self.build_config.build_libedit: llvm_defines['LLDB_ENABLE_LIBEDIT'] = 'ON' - llvm_defines['LibEdit_INCLUDE_DIRS'] = self.merge_install_dir('libedit', self.use_platform(), 'include') + llvm_defines['LibEdit_INCLUDE_DIRS'] = self.merge_libedit_install_dir(self.use_platform(), 'include') if self.build_config.build_libxml2: llvm_defines['LLDB_ENABLE_LIBXML2'] = 'ON' @@ -1963,7 +1973,7 @@ class LlvmLibs(BuildUtils): if self.build_config.build_ncurses: self.build_ncurses(None, llvm_install, llvm_triple, True) lldb_defines['LLDB_ENABLE_CURSES'] = 'ON' - ncurses_install_path = self.merge_install_dir('ncurses', llvm_triple) + ncurses_install_path = self.merge_ncurses_install_dir(llvm_triple) lldb_defines['CURSES_INCLUDE_DIRS'] = os.path.join(ncurses_install_path, 'include') lldb_defines['CURSES_HAVE_NCURSES_CURSES_H'] = 'ON' ncurses_lib_path = os.path.join(ncurses_install_path, 'lib') @@ -1977,7 +1987,7 @@ class LlvmLibs(BuildUtils): if self.build_config.build_libedit: self.build_libedit(None, llvm_install, llvm_triple, True) lldb_defines['LLDB_ENABLE_LIBEDIT'] = 'ON' - libedit_install_path = self.merge_install_dir('libedit', llvm_triple) + libedit_install_path = self.merge_libedit_install_dir(llvm_triple) lldb_defines['LibEdit_INCLUDE_DIRS'] = os.path.join(libedit_install_path, 'include') lldb_defines['LibEdit_LIBRARIES'] = os.path.join(libedit_install_path, 'lib', 'libedit.a') @@ -2061,8 +2071,8 @@ class LlvmLibs(BuildUtils): self.logger().info('Building ncurses.') libncurses_src_dir = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'ncurses')) - libncurses_install_path = self.merge_install_dir('ncurses', platform_triple) - libncurses_build_path = self.merge_build_dir('ncurses', platform_triple) + libncurses_install_path = self.merge_ncurses_install_dir(platform_triple) + libncurses_build_path = self.merge_ncurses_build_dir(platform_triple) prebuilts_path = os.path.join(self.buildtools_path) self.check_rm_tree(libncurses_build_path) @@ -2076,11 +2086,12 @@ class LlvmLibs(BuildUtils): ncurses_version = self.get_ncurses_version() if ncurses_version is not None: + libncurses_untar_path = self.merge_out_path('third_party', 'ncurses', 'ncurses-' + ncurses_version) args = ['./build_ncurses.sh', libncurses_src_dir, libncurses_build_path, libncurses_install_path, - prebuilts_path, clang_version, ncurses_version, platform_triple] + prebuilts_path, clang_version, ncurses_version, platform_triple, libncurses_untar_path] if static: args.append('static') - args.append(self.merge_install_dir('ncurses', self.use_platform())) + args.append(self.merge_ncurses_install_dir(self.use_platform())) self.check_call(args) os.chdir(cur_dir) @@ -2141,8 +2152,8 @@ class LlvmLibs(BuildUtils): self.logger().info('Building libedit') libedit_src_dir = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'libedit')) - libedit_build_path = self.merge_build_dir('libedit', platform_triple) - libedit_install_path = self.merge_install_dir('libedit', platform_triple) + libedit_build_path = self.merge_libedit_build_dir(platform_triple) + libedit_install_path = self.merge_libedit_install_dir(platform_triple) prebuilts_path = os.path.join(self.buildtools_path) self.check_rm_tree(libedit_build_path) @@ -2150,12 +2161,13 @@ class LlvmLibs(BuildUtils): self.check_rm_tree(libedit_install_path) self.rm_cmake_cache(libedit_install_path) - libncurses_path = self.merge_install_dir('ncurses', platform_triple) + libncurses_path = self.merge_ncurses_install_dir(platform_triple) cur_dir = os.getcwd() os.chdir(self.build_config.LLVM_BUILD_DIR) clang_version = self.build_config.CLANG_VERSION - args = ['./build_libedit.sh', libedit_src_dir, libedit_build_path , libedit_install_path, libncurses_path, prebuilts_path, clang_version, platform_triple] + libedit_untar_path = self.merge_out_path('third_party', 'libedit', 'libedit-' + self.get_libedit_version()) + args = ['./build_libedit.sh', libedit_src_dir, libedit_build_path , libedit_install_path, libncurses_path, prebuilts_path, clang_version, platform_triple, libedit_untar_path] self.check_call(args) os.chdir(cur_dir) @@ -2788,7 +2800,7 @@ class LlvmPackage(BuildUtils): lib_dst_path = os.path.join(install_dir, 'lib') lib_names = self.get_ncurses_dependence_libs(platform_triple) - lib_srcs = [self.merge_install_dir('ncurses', platform_triple, 'lib', + lib_srcs = [self.merge_ncurses_install_dir(platform_triple, 'lib', f'{name}{shlib_ext}') for name in lib_names] lib_dsts = [os.path.join(install_dir, 'lib', f'{name}{shlib_ext}') for name in lib_names] @@ -2797,7 +2809,7 @@ class LlvmPackage(BuildUtils): os.makedirs(lib_dst_path) for lib_file in lib_srcs: - self.update_lib_id_link(self.merge_install_dir('ncurses', platform_triple, 'lib'), lib_file) + self.update_lib_id_link(self.merge_ncurses_install_dir(platform_triple, 'lib'), lib_file) # Clear historical libraries for lib in lib_dsts: @@ -2815,7 +2827,7 @@ class LlvmPackage(BuildUtils): if self.host_is_linux(): shlib_ext = '.so.0' - libedit_lib_path = self.merge_install_dir('libedit', platform_triple, 'lib') + libedit_lib_path = self.merge_libedit_install_dir(platform_triple, 'lib') libedit_src = os.path.join(libedit_lib_path, 'libedit%s' % shlib_ext) lib_dst_path = os.path.join(install_dir, 'lib') diff --git a/llvm-build/build_libedit.sh b/llvm-build/build_libedit.sh index 1cd0bbd800b0..86dfbb43e4d1 100755 --- a/llvm-build/build_libedit.sh +++ b/llvm-build/build_libedit.sh @@ -11,8 +11,15 @@ NCURSES_PATH=$4 PREBUILT_PATH=$5 CLANG_VERSION=$6 TARGET=$7 +LIBEDIT_UNTAR_PATH=$8 +# Get version and date form libedit.spec (Compatible with Linux and Mac) +# The format in the libedit.spec is as follows: +# Version: 3.1 +# %global _date 20210910 SPECFILE="${LIBEDIT_SRC_DIR}/libedit.spec" +LIBEDIT_VERSION=$(grep -E '^Version:*' ${SPECFILE} | awk '{print $2}') +DATE=$(grep -E '^%global _date' ${SPECFILE} | sed 's/^.*\(20[0-9]\{6\}\).*$/\1/') case $(uname -s) in Linux) @@ -39,22 +46,23 @@ esac CC_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_VERSION}/bin/clang CXX_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_VERSION}/bin/clang++ -if [ -d ${LIBEDIT_SRC_DIR} ]; then - cd ${LIBEDIT_SRC_DIR} - - if [ "${host_platform}" = "linux" ]; then - autoreconf -vfi - patches=($(grep -E '^Patch[0-9]+:' "${SPECFILE}" | sed 's/^[^:]*: *//')) - # Apply patches in order - for patch in "${patches[@]}" - do - patch -Np1 < ${LIBEDIT_SRC_DIR}/$patch - done +libedit_package=${LIBEDIT_SRC_DIR}/libedit-${DATE}-${LIBEDIT_VERSION}.tar.gz +if [ -e ${libedit_package} ]; then + if [ ! -b ${LIBEDIT_UNTAR_PATH} ]; then + mkdir -p ${LIBEDIT_UNTAR_PATH} fi + tar -xzvf ${libedit_package} --strip-components 1 -C ${LIBEDIT_UNTAR_PATH} + cd ${LIBEDIT_UNTAR_PATH} - if [ ! -d ${LIBEDIT_BUILD_PATH} ]; then + if [ ! -b ${LIBEDIT_BUILD_PATH} ]; then mkdir -p ${LIBEDIT_BUILD_PATH} fi + patches=($(grep -E '^Patch[0-9]+:' "${SPECFILE}" | sed 's/^[^:]*: *//')) + # Apply patches in order + for patch in "${patches[@]}" + do + patch -Np1 < ${LIBEDIT_SRC_DIR}/$patch + done # build libedit cd ${LIBEDIT_BUILD_PATH} @@ -78,7 +86,7 @@ if [ -d ${LIBEDIT_SRC_DIR} ]; then export CFLAGS="$CFLAGS $ncuses_flags $stack_flags" fi - ${LIBEDIT_SRC_DIR}/configure \ + ${LIBEDIT_UNTAR_PATH}/configure \ --prefix=${LIBEDIT_INSTALL_PATH} \ CC=${CC_PATH} \ CXX=${CXX_PATH} @@ -89,7 +97,7 @@ if [ -d ${LIBEDIT_SRC_DIR} ]; then C_FLAGS="$C_FLAGS -march=armv7-a -mfloat-abi=soft" fi C_FLAGS="$C_FLAGS $stack_flags" - ${LIBEDIT_SRC_DIR}/configure \ + ${LIBEDIT_UNTAR_PATH}/configure \ --prefix=${LIBEDIT_INSTALL_PATH} \ --host="${TARGET}" \ CC="${PREBUILT_PATH}/../out/llvm-install/bin/clang --target=${TARGET}" \ @@ -98,7 +106,6 @@ if [ -d ${LIBEDIT_SRC_DIR} ]; then make -j$(nproc --all) install | tee build_libedit_${TARGET}.log fi - cd ${LIBEDIT_SRC_DIR} - git reset --hard HEAD - git clean -df fi + + diff --git a/llvm-build/build_ncurses.sh b/llvm-build/build_ncurses.sh index 4d26f8ec4a3e..e143c43f1ffd 100755 --- a/llvm-build/build_ncurses.sh +++ b/llvm-build/build_ncurses.sh @@ -11,7 +11,8 @@ PREBUILT_PATH=$4 CLANG_VERSION=$5 NCURSES_VERSION=$6 TARGET=$7 -IS_STATIC=$8 +NCURSES_UNTAR_PATH=$8 +IS_STATIC=$9 SPECFILE="${NCURSES_SRC_DIR}/ncurses.spec" @@ -40,8 +41,13 @@ esac CC_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_VERSION}/bin/clang CXX_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_VERSION}/bin/clang++ -if [ -d ${NCURSES_SRC_DIR} ]; then - cd ${NCURSES_SRC_DIR} +ncurses_package=${NCURSES_SRC_DIR}/ncurses-${NCURSES_VERSION}.tar.gz +if [ -e ${ncurses_package} ]; then + if [ ! -b ${NCURSES_UNTAR_PATH} ]; then + mkdir -p ${NCURSES_UNTAR_PATH} + fi + tar -xvzf ${ncurses_package} --strip-components 1 -C ${NCURSES_UNTAR_PATH} + cd ${NCURSES_UNTAR_PATH} # Get the list of patch files for ncurses.spec # The format in the ncurses.spec is as follows: @@ -55,7 +61,7 @@ if [ -d ${NCURSES_SRC_DIR} ]; then patch -Np1 < ${NCURSES_SRC_DIR}/$patch done - if [ ! -d ${NCURSES_BUILD_PATH} ]; then + if [ ! -b ${NCURSES_BUILD_PATH} ]; then mkdir -p ${NCURSES_BUILD_PATH} fi cd ${NCURSES_BUILD_PATH} @@ -71,11 +77,10 @@ if [ -d ${NCURSES_SRC_DIR} ]; then export CPPFLAGS="$CPPFALGS -I${SDKROOT}/usr/include -I${SDKROOT}/usr/include/i368" export CFLAGS="$CFLAGS -isysroot${SDKROOT} $flags $stack_flags" - ${NCURSES_SRC_DIR}/configure \ + ${NCURSES_UNTAR_PATH}/configure \ --with-shared \ - --with-terminfo-dirs=${NCURSES_INSTALL_PATH}/share/terminfo:/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ + --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ --disable-mixed-case \ - --disable-widec \ --prefix=${NCURSES_INSTALL_PATH} \ CC=${CC_PATH} \ CXX=${CXX_PATH} @@ -84,12 +89,10 @@ if [ -d ${NCURSES_SRC_DIR} ]; then if [ "${host_platform}" == "linux" ]; then export LDFLAGS="-Wl,-rpath,\$$ORIGIN/../lib $got_ldflags" export CFLAGS="$CFLAGS $stack_flags" - ${NCURSES_SRC_DIR}/configure \ + ${NCURSES_UNTAR_PATH}/configure \ --with-shared \ - --disable-widec \ + --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ --prefix=${NCURSES_INSTALL_PATH} \ - --datadir=${NCURSES_INSTALL_PATH}/share \ - --with-terminfo-dirs=${NCURSES_INSTALL_PATH}/share/terminfo:/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ CC=${CC_PATH} \ CXX=${CXX_PATH} make -j$(nproc --all) install | tee build_ncurses.log @@ -103,28 +106,24 @@ if [ -d ${NCURSES_SRC_DIR} ]; then C_FLAGS="$C_FLAGS $stack_flags" export LDFLAGS="$LDFLAGS $got_ldflags" if [[ ${IS_STATIC} == "static" ]]; then - NCURSES_HOST_INSTALL_PATH=${9} + NCURSES_HOST_INSTALL_PATH=${10} export LD_LIBRARY_PATH="${NCURSES_HOST_INSTALL_PATH}/lib:$LD_LIBRARY_PATH" EXTRA_ARGS="--with-fallbacks=linux,vt100,xterm \ --with-tic-path=${NCURSES_HOST_INSTALL_PATH}/bin/tic \ --with-infocmp-path=${NCURSES_HOST_INSTALL_PATH}/bin/infocmp" fi - ${NCURSES_SRC_DIR}/configure \ + ${NCURSES_UNTAR_PATH}/configure \ --host="${TARGET}" \ --with-shared \ --prefix=${NCURSES_INSTALL_PATH} \ --with-termlib \ --without-manpages \ --with-strip-program="${PREBUILT_PATH}/../out/llvm-install/bin/llvm-strip" \ - --disable-widec \ ${EXTRA_ARGS} \ CC=${PREBUILT_PATH}/../out/llvm-install/bin/clang \ CXX=${PREBUILT_PATH}/../out/llvm-install/bin/clang++ \ CFLAGS="${C_FLAGS}" make -j$(nproc --all) install | tee build_ncurses_${TARGET}.log fi - cd ${NCURSES_SRC_DIR} - git reset --hard HEAD - git clean -df fi diff --git a/llvm-build/cross_toolchain_builder.py b/llvm-build/cross_toolchain_builder.py index 24b573d4b89c..7f2bb792fa78 100644 --- a/llvm-build/cross_toolchain_builder.py +++ b/llvm-build/cross_toolchain_builder.py @@ -128,18 +128,17 @@ class CrossToolchainBuilder: lldb_defines["LLDB_ENABLE_CURSES"] = "ON" lldb_defines["CURSES_INCLUDE_DIRS"] = ";".join( [ - self._build_utils.merge_install_dir( - "ncurses", self._llvm_triple, "include" + self._build_utils.merge_ncurses_install_dir( + self._llvm_triple, "include" ), - self._build_utils.merge_install_dir( - "ncurses", self._llvm_triple, "include", "ncurses" + self._build_utils.merge_ncurses_install_dir( + self._llvm_triple, "include", "ncurses" ), ] ) ncurses_libs = [] for library in self._build_utils.get_ncurses_dependence_libs(self._llvm_triple): - library_path = self._build_utils.merge_install_dir( - "ncurses", + library_path = self._build_utils.merge_ncurses_install_dir( self._llvm_triple, "lib", f"{library}.so.%s" % self._build_utils.get_ncurses_version(), @@ -168,13 +167,13 @@ class CrossToolchainBuilder: if self._build_config.build_libedit: lldb_defines["LLDB_ENABLE_LIBEDIT"] = "ON" lldb_defines["LibEdit_INCLUDE_DIRS"] = ( - self._build_utils.merge_install_dir( - "libedit", self._llvm_triple, "include" + self._build_utils.merge_libedit_install_dir( + self._llvm_triple, "include" ) ) lldb_defines["LibEdit_LIBRARIES"] = ( - self._build_utils.merge_install_dir( - "libedit", self._llvm_triple, "lib", "libedit.so.0.0.75" + self._build_utils.merge_libedit_install_dir( + self._llvm_triple, "lib", "libedit.so.0.0.68" ) ) -- Gitee