forked from Mirror/pmbootstrap
...instead of running apk every time to get the list of installed packages and their versions. The internal package database from apk has the same format, as the extracted APKINDEX file (except that it has more key-value pairs, which we ignore/do not need right now). So the APKINDEX code has been extended to parse both tar-packed APKINDEX files and regular text files in the APKINDEX format. This is required for #108, for a better detection of outdated packages (because the internal package database saves the package's timestamp, too). A nice benefit is, that this is faster than calling apk every time and it doesn't fill up the log as much. I've also used this improved function for determining the apk version (for the outdated version check), and I've deleted pmb.parse.other.package_split(), as it is not needed anymore.
78 lines
3 KiB
Python
78 lines
3 KiB
Python
"""
|
|
Copyright 2017 Oliver Smith
|
|
|
|
This file is part of pmbootstrap.
|
|
|
|
pmbootstrap is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
pmbootstrap is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
import logging
|
|
import json
|
|
import os
|
|
import pmb.build
|
|
import pmb.parse.apkbuild
|
|
import pmb.helpers.repo
|
|
import pmb.challenge
|
|
|
|
|
|
def build(args, apk_path):
|
|
# Parse buildinfo
|
|
buildinfo_path = apk_path + ".buildinfo.json"
|
|
if not os.path.exists(buildinfo_path):
|
|
logging.info("NOTE: To create a .buildinfo.json file, use the"
|
|
" --buildinfo command while building: 'pmbootstrap build"
|
|
" --buildinfo <pkgname>'")
|
|
raise RuntimeError("Missing file: " + buildinfo_path)
|
|
with open(buildinfo_path) as handle:
|
|
buildinfo = json.load(handle)
|
|
|
|
# Install all listed packages
|
|
pmb.chroot.apk.install(args, buildinfo["versions"].keys())
|
|
|
|
# Verify the installed versions
|
|
installed = pmb.chroot.apk.installed(args)
|
|
for pkgname, version in buildinfo["versions"].items():
|
|
version_installed = installed[pkgname]["version"]
|
|
if version_installed != version:
|
|
raise RuntimeError("Dependency " + pkgname + " version is different"
|
|
" (installed: " + version_installed + ","
|
|
" buildinfo: " + version + ")!")
|
|
# Build the package
|
|
repo_before = pmb.helpers.repo.files(args)
|
|
pmb.build.package(args, buildinfo["pkgname"], buildinfo["arch"],
|
|
force=True, buildinfo=True)
|
|
repo_diff = pmb.helpers.repo.diff(args, repo_before)
|
|
|
|
# Diff the apk contents
|
|
staging_path = os.path.abspath(os.path.dirname(apk_path) + "/../")
|
|
for file in repo_diff:
|
|
file_staging = staging_path + "/" + file
|
|
file_work = args.work + "/packages/" + file
|
|
|
|
if file.endswith(".apk"):
|
|
logging.info("Verify " + file)
|
|
pmb.challenge.apk(args, file_staging, file_work)
|
|
elif (file.endswith("/APKINDEX.tar.gz") or
|
|
file.endswith(".apk.buildinfo.json")):
|
|
# We only verify the apk file (see above). The APKINDEX can
|
|
# be verified separately.
|
|
continue
|
|
else:
|
|
raise RuntimeError("Unknown file type changed in the"
|
|
" package repository folder: " + file)
|
|
|
|
# Output the changed files from the repository
|
|
if args.output_repo_changes:
|
|
with open(args.output_repo_changes, "w") as handler:
|
|
for file in repo_diff:
|
|
handler.write(file + "\n")
|