new: allow file in sources

This commit is contained in:
2025-12-23 00:18:23 -05:00
parent bd21ccaf48
commit a27c131158
2 changed files with 48 additions and 28 deletions

View File

@@ -63,8 +63,8 @@
- pkgdesc 字符串, 软件描述
- pkgurl 字符串, 软件主页/上游地址
- license 数组, 软件许可证
- sources 数组, 构建过程使用到的所有源码包和补丁
- urls 数组, `sources` 各项对应的地址, 当前仅限使用 `wget` 获取
- sources 数组, 构建过程使用到的所有源码包和补丁,可以是 `https://...` 也可以是文件相对路径
- urls 数组, `sources` 各项对应的地址, 当前仅限使用 `wget` 获取或复制文件
- md5sums 数组, `sources` 各项对应的 md5 checksum
- options 数组, 构建选项, 详见第4小节
- srcdir 字符串, 构建路径(在leaf主程序中定义)

72
leaf
View File

@@ -379,34 +379,54 @@ leaf_update_environment() {
}
leaf_prepare_package() {
local url sourcefile index _md5sum
distdir="${DIST_DIR}"
mkdir -pv "${distdir}"
pushd "${distdir}"
for index in "${!sources[@]}"; do
sourcefile="${sources[$index]}"
url="${urls[$index]}"
local url sourcefile index _md5sum local_src pkg_src_root
if [ -f "${sourcefile}" ]; then
echo "${sourcefile} exits, checking..."
_md5sum=$(md5sum ${sourcefile} | awk '{print $1}')
if [ "${_md5sum}" == "${md5sums[$index]}" ]; then
echo "md5sum match, skip ${sourcefile}."
else
echo "md5sum does not match, redownloading..."
rm -rf "${sourcefile}"
wget -O "${sourcefile}" "${url}"
fi
else
echo "Downloading ${sourcefile}..."
wget -O "${sourcefile}" "${url}"
fi
_md5sum=$(md5sum "${sourcefile}" | awk '{print $1}')
if [ "${_md5sum}" != "${md5sums[$index]}" ]; then
leaf_error "md5sums of ${sourcefile}(${_md5sum}) does not match with ${md5sums[$index]}!"
distdir="${DIST_DIR}"
mkdir -pv -- "${distdir}"
pkg_src_root="${PKGBUILD_DIR}/${PKG_PREFIX}/${PKG_NAME}"
pushd "${distdir}" >/dev/null || leaf_error "cannot enter distdir: ${distdir}"
for index in "${!sources[@]}"; do
sourcefile="${sources[$index]}"
url="${urls[$index]}"
if [ -z "${url}" ]; then
url="${sourcefile}"
fi
if [ -f "${sourcefile}" ]; then
echo "${sourcefile} exists, checking..."
_md5sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')"
if [ "${_md5sum}" = "${md5sums[$index]}" ]; then
echo "md5sum match, skip ${sourcefile}."
continue
fi
done
popd
echo "md5sum does not match, refetching..."
rm -f -- "${sourcefile}"
fi
case "${url}" in
http://*|https://*|ftp://*)
echo "Downloading ${sourcefile} from ${url}..."
wget -O "${sourcefile}" -- "${url}" || leaf_error "wget failed: ${url}"
;;
*)
local_src="${pkg_src_root}/${url}"
echo "Copying ${sourcefile} from local file ${local_src}..."
[ -f "${local_src}" ] || leaf_error "local source not found: ${local_src}"
cp -f -- "${local_src}" "${sourcefile}" || leaf_error "cp failed: ${local_src}"
;;
esac
_md5sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')"
if [ "${_md5sum}" != "${md5sums[$index]}" ]; then
leaf_error "md5sums of ${sourcefile}(${_md5sum}) does not match with ${md5sums[$index]}!"
fi
done
popd >/dev/null || true
echo "Sources ready."
src_prepare
}