Repository navigation
Revert "chore: migrate linglong deps to declarative buildext.apt" #643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+253
−16
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # SPDX-FileCopyrightText: 2023-2024 UnionTech Software Technology Co., Ltd. | ||
| # | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # 生成安装目录/文件和运行时依赖的必要库 | ||
| # 获取应用id | ||
| ID_VALUE=$(awk -F ': ' '/^ id: / {print $2}' linglong.yaml) | ||
|
|
||
| ## 获取安装的文件列表并写入安装脚本(排除头文件、pc和cmake文件) | ||
| # cmake 安装 | ||
| if ! grep -- "-- Installing:" install.log | awk '{print $NF}' | grep -vE '\.(h|cmake|pc)$' > ${ID_VALUE}.install; then | ||
| echo "cmake install files are empty!" | ||
| fi | ||
| # qmake 安装 | ||
| if ! grep -- "-install qinstall" install.log | awk '{print $NF}' | grep -vE '\.(h|cmake|pc)$' >> ${ID_VALUE}.install; then | ||
| echo "qmake install files are empty!" | ||
| fi | ||
| # 动态库软连接 | ||
| if ! grep -- "^ln -f -s " install.log | awk '{print $NF}' >> ${ID_VALUE}.install; then | ||
| echo "Get library softlink empty!" | ||
| fi | ||
|
|
||
| # glib-compile-schemas 文件添加到 install 文件 | ||
| for SCHEMAS in "${PREFIX}"/share/glib-2.0/schemas/gschema*; do | ||
| if [[ -f "$SCHEMAS" ]]; then | ||
| echo "$SCHEMAS" >> "${ID_VALUE}.install" | ||
| fi | ||
| done | ||
|
|
||
| # 获取依赖的所有文件 | ||
| for LDFILE in "$@"; do | ||
|
|
||
| # 判断文件是否以 .so 结尾 | ||
| if [[ "$LDFILE" == *.so ]]; then | ||
| FILE_PATH="${PREFIX}/lib/${TRIPLET}/$LDFILE" | ||
|
|
||
| # 添加依赖库到 install 文件 | ||
| for SOFILE in "${PREFIX}/lib/${TRIPLET}"/${LDFILE}*; do | ||
| if [[ -f "$SOFILE" ]]; then | ||
| echo "$SOFILE" >> "${ID_VALUE}.install" | ||
| fi | ||
| done | ||
| else | ||
| FILE_PATH="${PREFIX}/bin/$LDFILE" | ||
| fi | ||
|
|
||
| # 获取依赖库 | ||
| DEPENDENCIES=$(ldd "$FILE_PATH" | grep "$PREFIX") || continue | ||
| if [[ ! -z "$DEPENDENCIES" ]]; then | ||
| echo "$DEPENDENCIES" | while IFS= read -r line; do | ||
| LIB_PATH=${line##*=> } | ||
| LIB_PATH=${LIB_PATH%%(*} | ||
|
|
||
| # 获取基本库名并匹配相关库 | ||
| LIB_DIR=$(dirname "$LIB_PATH") | ||
| BASE_LIB_NAME=$(basename "$LIB_PATH") | ||
|
|
||
| # 使用通配符查找相关库文件并将结果倒序存储到 install 文件 | ||
| for FILE in "$LIB_DIR"/${BASE_LIB_NAME%.*}*; do | ||
| if [[ -f "$FILE" ]]; then | ||
| echo "$FILE" | ||
| fi | ||
| done | sort -r >> "${ID_VALUE}.install" | ||
|
|
||
| done | ||
| fi | ||
| done | ||
|
|
||
| # 排除静态链接库 | ||
| #echo '^'${PREFIX}'/'${TRIPLET}'/.+(?<!\.a)$' >> "${ID_VALUE}.install" | ||
| #echo '^'${PREFIX}'/lib/.+(?<!\.a|\.pc|\.cmake|\.h|\.sh|\.prf|\.inc)$' >> "${ID_VALUE}.install" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| # SPDX-FileCopyrightText: 2023-2024 UnionTech Software Technology Co., Ltd. | ||
| # | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #!/bin/bash | ||
| set -e | ||
| project_dir=$PWD | ||
| cache_dir=${LINGLONG_FETCH_CACHE:-$PWD/linglong/cache} | ||
| mkdir -p "$cache_dir" | ||
| # 文件名 deb-source.bash | ||
| # 包含要解压的deb目录 | ||
| deb_dir=$(realpath "$1") | ||
| # 将deb解压到输出目录 | ||
| target=$(realpath "$2") | ||
| # 默认会跳过base已安装的包,可以强制解压已安装的包 | ||
| include="$3" | ||
| # 临时目录,将内容处理后再移动到 target | ||
| out_dir="$(mktemp -d)" | ||
| cd "$out_dir" | ||
| # 临时文件,用于记录deb文件列表 | ||
| deb_list_file="$out_dir/deb.list" | ||
| # 临时文件,用于记录强制安装的包名 | ||
| include_list_file="$out_dir/include.packages.list" | ||
| # 临时文件,用于记录跳过安装的包名 | ||
| exclude_list_file="$out_dir/exclude.packages.list" | ||
| # 包数据存放的临时目录 | ||
| data_list_dir="$out_dir/data" | ||
| # 生成文件列表 | ||
| find "$deb_dir" -type f -name "*.deb" >"$deb_list_file" | ||
| echo "$include" | tr ',' '\n' >"$include_list_file" | ||
| # 用于记录安装的所有文件来自哪个包 | ||
| mkdir /tmp/deb-source-file || true | ||
|
|
||
| # 如果base和runtime已安装则跳过,旧版本base没有/packages.list文件就使用/var/lib/dpkg/status | ||
| grep 'Package: ' /var/lib/dpkg/status >"$exclude_list_file" || true | ||
| # 跳过base和runtime已安装的包,也可使用install_dep_skip.list文件控制跳过哪些包 | ||
| cat /packages.list /runtime/packages.list "$PREFIX/packages.list" "$project_dir/install_dep_skip.list" >>"$exclude_list_file" || true | ||
|
|
||
| # 遍历文件列表 | ||
| while IFS= read -r deb_file; do | ||
| # 输出deb名,但不换行,便于在包名后面加skip | ||
| echo -n "$deb_file" | ||
| # 提取control文件 | ||
| control_file=$(ar -t "$deb_file" | grep control.tar) | ||
| ar -x "$deb_file" "$control_file" | ||
| # 获取包名 | ||
| pkg=$(tar -xf "$control_file" ./control -O | grep '^Package:' | awk '{print $2}') | ||
| rm "$control_file" | ||
| # 如果在base和runtime中已安装,并且不包含在include(强制安装)列表则跳过安装,否则安装到$PREFIX目录 | ||
| if grep -q "^Package: $pkg$" "$exclude_list_file" && ! grep -q "^$pkg$" "$include_list_file"; then | ||
| echo " skip" | ||
| echo "$deb_file" >>/tmp/deb-source-file/skip.list | ||
| continue | ||
| fi | ||
| # 记录到 packages.list | ||
| echo "Package: $pkg" >>"$PREFIX/packages.list" | ||
| # 换行 | ||
| echo "" | ||
| # 缓存解压后的data.tar文件,便于在下次使用时,加快安装速度 | ||
| deb_sha=$(sha256sum "$deb_file" | awk '{print $1}') | ||
| data_cache="$cache_dir/install_dep_$deb_sha" | ||
| if [ ! -e "$data_cache" ]; then | ||
| data_cache_tmp="$cache_dir/install_dep_tmp_$deb_sha" | ||
| # 查找data.tar文件,文件会因为压缩格式不同,有不同的后缀,例如data.tar.xz、data.tar.gz | ||
| data_file=$(ar -t "$deb_file" | grep data.tar) | ||
| case "$data_file" in | ||
| *.xz) ar -p "$deb_file" "$data_file" | unxz >"$data_cache_tmp" ;; | ||
| *.gz) ar -p "$deb_file" "$data_file" | gunzip >"$data_cache_tmp" ;; | ||
| *.zst) ar -p "$deb_file" "$data_file" | unzstd >"$data_cache_tmp" ;; | ||
| *) | ||
| echo "unknown file type" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| mv "$data_cache_tmp" "$data_cache" | ||
| fi | ||
| # 解压data.tar文件到输出目录 | ||
| mkdir "$data_list_dir" | ||
| tar -xvf "$data_cache" -C "$data_list_dir" >>"/tmp/deb-source-file/$(basename "$deb_file").list" | ||
| # 清理不需要复制的目录 | ||
| rm -r "${data_list_dir:?}/usr/share/applications"* 2>/dev/null || true | ||
| # 修改pc文件的prefix | ||
| sed -i "s#/usr#$PREFIX#g" "$data_list_dir"/usr/lib/"$TRIPLET"/pkgconfig/*.pc 2>/dev/null || true | ||
| sed -i "s#/usr#$PREFIX#g" "$data_list_dir"/usr/share/pkgconfig/*.pc 2>/dev/null || true | ||
| # 修改指向/lib的绝对路径的软链接 | ||
| find "$data_list_dir" -type l | while IFS= read -r file; do | ||
| linkTarget=$(readlink "$file") | ||
| # 如果指向的路径以/lib开头,并且文件不存在,则添加 /runtime 前缀 | ||
| # 部分 dev 包会创建 so 文件的绝对链接指向 /lib 目录下 | ||
| if echo "$linkTarget" | grep -q ^/lib && ! [ -f "$linkTarget" ]; then | ||
| ln -sf "$target$linkTarget" "$file" | ||
| echo " FIX LINK" "$linkTarget" "=>" "$target$linkTarget" | ||
| fi | ||
| done | ||
|
|
||
| # 修复动态库的RUNPATH | ||
| find "$data_list_dir" -type f | while IFS= read -r file; do | ||
| fileinfo=$(file "$file") | ||
| # skip non-dynamic librarie | ||
| if ! echo "$fileinfo" | grep -q 'shared object'; then | ||
| continue | ||
| fi | ||
| # skip debug file | ||
| if echo "$fileinfo" | grep -q 'with debug_info'; then | ||
| continue | ||
| fi | ||
| runpath=$(readelf -d "$file" | grep RUNPATH | awk '{print $NF}') | ||
| # skip without runpath | ||
| if ! echo "$runpath" | grep -q '^\[/'; then | ||
| continue | ||
| fi | ||
| # 如果RUNPATH使用绝对路径,则添加/runtime前缀 | ||
| runpath=${runpath#[} | ||
| runpath=${runpath%]} | ||
| newRunpath=${runpath//usr\/lib/runtime\/lib} | ||
| newRunpath=${newRunpath//usr/runtime} | ||
| patchelf --set-rpath "$newRunpath" "$file" | ||
| echo " FIX RUNPATH" "$file" "$runpath" "=>" "$newRunpath" | ||
| done | ||
| # 复制/lib,/bin,/usr目录 | ||
| cp -rP "$data_list_dir/lib" "$target" 2>/dev/null || true | ||
| cp -rP "$data_list_dir/bin" "$target" 2>/dev/null || true | ||
| cp -rP "$data_list_dir"/usr/* "$target" || true | ||
| rm -r "$data_list_dir" | ||
| done <"$deb_list_file" | ||
|
|
||
| # 修复相对路径的软链接(dev包内的软连接尝试修复指向base) | ||
| find "$target" -type l | while IFS= read -r file; do | ||
| # 获取链接的绝对路径 | ||
| linkTarget=$(readlink -m "$file") | ||
| # 如果链接指向的文件不存在 | ||
| if [ ! -e "$linkTarget" ]; then | ||
| # 去掉前缀查看/lib下是否存在 | ||
| linkTarget="${linkTarget#$target}" | ||
| if [ -e "$linkTarget" ]; then | ||
| ln -sf "$linkTarget" "$file" | ||
| echo " FIX LINK" "$file" "=>" "$target$linkTarget" | ||
| fi | ||
| # 添加usr前缀查看/usr/lib下是否存在 | ||
| linkTarget="/usr$target" | ||
| if [ -e "$linkTarget" ]; then | ||
| ln -sf "$target$linkTarget" "$file" | ||
| echo " FIX LINK" "$file" "=>" "$target$linkTarget" | ||
| fi | ||
| # 添加 /runtime 前缀查看是否存在 | ||
| linkTarget=$(readlink -m "$file") | ||
| linkTargetNoPrefix="${linkTarget#$target}" | ||
| runtimeLib="/runtime$linkTargetNoPrefix" | ||
| if [ -e "$runtimeLib" ]; then | ||
| ln -sf "$runtimeLib" "$file" | ||
| echo " FIX LINK" "$file" "=>" "$runtimeLib" | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| # 更新ld.so.cache | ||
| if [ -n "$LINGLONG_LD_SO_CACHE" ]; then | ||
| ldconfig -C "$LINGLONG_LD_SO_CACHE" | ||
| fi | ||
|
|
||
| # 清理临时目录 | ||
| rm -r "$out_dir" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Stale archives alter the prefix
When the apt archive directory contains older versions of requested packages or unrelated
.debfiles,install_depprocesses every.debin the archive directory, so an older package can overwrite the requested version and unrelated packages can be copied into$PREFIXand recorded inpackages.list.Restrict extraction to the requested packages and select the requested version before copying files.
Also at
linglong.yaml:24.Prompt for AI agents