2017-07-18 19:01:11 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
"""
|
|
|
|
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/>.
|
|
|
|
"""
|
|
|
|
|
2017-09-18 21:36:54 +00:00
|
|
|
import glob
|
2017-07-18 19:01:11 +00:00
|
|
|
import json
|
2017-09-18 21:36:54 +00:00
|
|
|
import logging
|
|
|
|
import os
|
2017-08-14 14:25:28 +00:00
|
|
|
import sys
|
|
|
|
|
2017-07-18 19:01:11 +00:00
|
|
|
import pmb.aportgen
|
|
|
|
import pmb.build
|
|
|
|
import pmb.config
|
|
|
|
import pmb.challenge
|
|
|
|
import pmb.chroot
|
|
|
|
import pmb.chroot.initfs
|
|
|
|
import pmb.chroot.other
|
|
|
|
import pmb.flasher
|
|
|
|
import pmb.helpers.logging
|
|
|
|
import pmb.helpers.other
|
|
|
|
import pmb.helpers.run
|
|
|
|
import pmb.install
|
|
|
|
import pmb.parse
|
2017-08-09 20:26:40 +00:00
|
|
|
import pmb.qemu
|
2017-07-18 19:01:11 +00:00
|
|
|
|
|
|
|
|
2017-09-02 03:53:58 +00:00
|
|
|
def _parse_flavor(args):
|
|
|
|
"""
|
|
|
|
Verify the flavor argument if specified, or return a default value.
|
|
|
|
"""
|
|
|
|
# Make sure, that at least one kernel is installed
|
|
|
|
suffix = "rootfs_" + args.device
|
|
|
|
pmb.chroot.apk.install(args, ["device-" + args.device], suffix)
|
|
|
|
|
|
|
|
# Parse and verify the flavor argument
|
|
|
|
flavor = args.flavor
|
|
|
|
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix)
|
|
|
|
if flavor:
|
|
|
|
if flavor not in flavors:
|
|
|
|
raise RuntimeError("No kernel installed with flavor " + flavor + "!" +
|
|
|
|
" Run 'pmbootstrap flasher list_flavors' to get a list.")
|
|
|
|
return flavor
|
|
|
|
if not len(flavors):
|
|
|
|
raise RuntimeError(
|
|
|
|
"No kernel flavors installed in chroot " + suffix + "! Please let"
|
|
|
|
" your device package depend on a package starting with 'linux-'.")
|
|
|
|
return flavors[0]
|
|
|
|
|
|
|
|
|
2017-07-26 18:59:11 +00:00
|
|
|
def _parse_suffix(args):
|
|
|
|
if args.rootfs:
|
|
|
|
return "rootfs_" + args.device
|
|
|
|
elif args.buildroot:
|
|
|
|
return "buildroot_" + args.deviceinfo["arch"]
|
|
|
|
elif args.suffix:
|
|
|
|
return args.suffix
|
|
|
|
else:
|
|
|
|
return "native"
|
|
|
|
|
|
|
|
|
2017-07-18 19:01:11 +00:00
|
|
|
def aportgen(args):
|
2017-07-26 18:59:11 +00:00
|
|
|
for package in args.packages:
|
|
|
|
pmb.aportgen.generate(args, package)
|
2017-07-18 19:01:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def build(args):
|
2017-09-08 23:50:59 +00:00
|
|
|
if args.strict:
|
|
|
|
pmb.chroot.zap(args, False)
|
2017-07-26 18:59:11 +00:00
|
|
|
for package in args.packages:
|
|
|
|
pmb.build.package(args, package, args.arch, args.force,
|
2017-09-08 23:50:59 +00:00
|
|
|
args.buildinfo, args.strict)
|
2017-07-18 19:01:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def build_init(args):
|
2017-07-26 18:59:11 +00:00
|
|
|
suffix = _parse_suffix(args)
|
|
|
|
pmb.build.init(args, suffix)
|
2017-07-18 19:01:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def challenge(args):
|
|
|
|
pmb.challenge.frontend(args)
|
|
|
|
|
|
|
|
|
|
|
|
def checksum(args):
|
2017-07-26 18:59:11 +00:00
|
|
|
for package in args.packages:
|
|
|
|
pmb.build.checksum(args, package)
|
2017-07-18 19:01:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def chroot(args):
|
2017-07-26 18:59:11 +00:00
|
|
|
suffix = _parse_suffix(args)
|
|
|
|
pmb.chroot.apk.check_min_version(args, suffix)
|
|
|
|
logging.info("(" + suffix + ") % " + " ".join(args.command))
|
|
|
|
pmb.chroot.root(args, args.command, suffix, log=False)
|
2017-07-18 19:01:11 +00:00
|
|
|
|
|
|
|
|
2017-08-14 14:25:28 +00:00
|
|
|
def config(args):
|
|
|
|
pmb.helpers.logging.disable()
|
|
|
|
if args.name and args.name not in pmb.config.defaults:
|
|
|
|
valid_keys = ", ".join(sorted(pmb.config.defaults.keys()))
|
|
|
|
print("The variable name you have specified is invalid.")
|
|
|
|
print("The following are supported: " + valid_keys)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
cfg = pmb.config.load(args)
|
|
|
|
if args.value:
|
|
|
|
cfg["pmbootstrap"][args.name] = args.value
|
|
|
|
pmb.config.save(args, cfg)
|
|
|
|
elif args.name:
|
|
|
|
value = cfg["pmbootstrap"].get(args.name, "")
|
|
|
|
print(value)
|
|
|
|
else:
|
|
|
|
cfg.write(sys.stdout)
|
|
|
|
|
|
|
|
|
2017-07-18 19:01:11 +00:00
|
|
|
def index(args):
|
2017-10-11 15:11:25 +00:00
|
|
|
pmb.build.index_repo(args, args.arch_native)
|
|
|
|
pmb.build.symlink_noarch_packages(args)
|
2017-07-18 19:01:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def initfs(args):
|
|
|
|
pmb.chroot.initfs.frontend(args)
|
|
|
|
|
|
|
|
|
|
|
|
def install(args):
|
|
|
|
pmb.install.install(args)
|
|
|
|
|
|
|
|
|
|
|
|
def flasher(args):
|
|
|
|
pmb.flasher.frontend(args)
|
|
|
|
|
|
|
|
|
2017-09-06 20:14:03 +00:00
|
|
|
def export(args):
|
|
|
|
pmb.export.frontend(args)
|
|
|
|
|
|
|
|
|
2017-07-18 19:01:11 +00:00
|
|
|
def menuconfig(args):
|
|
|
|
pmb.build.menuconfig(args, args.package, args.deviceinfo["arch"])
|
|
|
|
|
|
|
|
|
2017-09-18 21:36:54 +00:00
|
|
|
def kconfig_check(args):
|
|
|
|
# Default to all kernel packages
|
|
|
|
packages = args.packages
|
|
|
|
if not packages:
|
|
|
|
for aport in glob.glob(args.aports + "/*/linux-*"):
|
|
|
|
packages.append(os.path.basename(aport).split("linux-")[1])
|
|
|
|
|
|
|
|
# Iterate over all kernels
|
|
|
|
error = False
|
|
|
|
packages.sort()
|
|
|
|
for package in packages:
|
|
|
|
if not pmb.parse.kconfig.check(args, package, details=True):
|
|
|
|
error = True
|
|
|
|
|
|
|
|
# At least one failure
|
|
|
|
if error:
|
|
|
|
raise RuntimeError("kconfig_check failed!")
|
|
|
|
|
|
|
|
|
2017-07-18 19:01:11 +00:00
|
|
|
def parse_apkbuild(args):
|
2017-07-28 22:34:40 +00:00
|
|
|
aport = pmb.build.other.find_aport(args, args.package)
|
|
|
|
path = aport + "/APKBUILD"
|
|
|
|
print(json.dumps(pmb.parse.apkbuild(args, path), indent=4))
|
2017-07-18 19:01:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def parse_apkindex(args):
|
|
|
|
result = pmb.parse.apkindex.parse(args, args.apkindex_path)
|
2017-07-22 09:54:49 +00:00
|
|
|
if args.package:
|
|
|
|
if args.package not in result:
|
|
|
|
raise RuntimeError("Package not found in the APKINDEX: " +
|
|
|
|
args.package)
|
|
|
|
result = result[args.package]
|
2017-07-18 19:01:11 +00:00
|
|
|
print(json.dumps(result, indent=4))
|
|
|
|
|
|
|
|
|
2017-08-09 20:26:40 +00:00
|
|
|
def qemu(args):
|
|
|
|
pmb.qemu.run(args)
|
|
|
|
|
|
|
|
|
2017-07-18 19:01:11 +00:00
|
|
|
def shutdown(args):
|
|
|
|
pmb.chroot.shutdown(args)
|
|
|
|
|
|
|
|
|
|
|
|
def stats(args):
|
|
|
|
pmb.build.ccache_stats(args, args.arch)
|
|
|
|
|
|
|
|
|
|
|
|
def log(args):
|
2017-08-07 18:56:35 +00:00
|
|
|
if args.clear_log:
|
2017-09-06 20:14:03 +00:00
|
|
|
pmb.helpers.run.user(args, ["truncate", "-s", "0", args.log],
|
|
|
|
log=False)
|
2017-07-18 19:01:11 +00:00
|
|
|
pmb.helpers.run.user(args, ["tail", "-f", args.log, "-n", args.lines],
|
|
|
|
log=False)
|
|
|
|
|
|
|
|
|
|
|
|
def log_distccd(args):
|
|
|
|
logpath = "/home/user/distccd.log"
|
2017-08-07 18:56:35 +00:00
|
|
|
if args.clear_log:
|
|
|
|
pmb.chroot.user(args, ["truncate", "-s", "0", logpath], log=False)
|
2017-07-18 19:01:11 +00:00
|
|
|
pmb.chroot.user(args, ["tail", "-f", logpath, "-n", args.lines], log=False)
|
|
|
|
|
|
|
|
|
|
|
|
def zap(args):
|
2017-09-06 20:14:03 +00:00
|
|
|
pmb.chroot.zap(args, packages=args.packages, http=args.http,
|
2017-09-14 18:28:10 +00:00
|
|
|
mismatch_bins=args.mismatch_bins, distfiles=args.distfiles)
|