2023-01-22 18:11:10 +00:00
|
|
|
# Copyright 2023 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2018-01-15 22:00:11 +00:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import pmb.chroot.user
|
|
|
|
import pmb.helpers.cli
|
2018-02-24 21:49:10 +00:00
|
|
|
import pmb.parse
|
2018-01-15 22:00:11 +00:00
|
|
|
|
|
|
|
|
pmbootstrap newapkbuild: Properly parse arguments (#1320)
* pmbootstrap newapkbuild: Properly parse arguments
The `pmbootstrap newapkbuild` action wraps Alpine's `newapkbuild`. We
used to directly pass all arguments to `newapkbuild` without verifying
in Python whether they make sense or not. However, as `newpakbuild`
doesn't do strict sanity checks on the arguments, it is easy to end up
with unexpected behavior when using the command for the first time.
For example, `newapkbuild` allows either specifying a PKGNAME or SRCURL
as last parameter, and also allows setting a PKGNAME with the `-n`
parameter. It only makes sense to use that option when passing a
SRCURL.
With this commit, we duplicate the optins that should be passed through
to `newapkbuild` and use argparse to fully sanitize the options and
display a help page (`pmbootstrap newapkbuild -h`) that is consistent
with the other help pages.
Details:
* The `-f` (force) flag does not get passed through anymore. Instead we
use it in Python to skip asking if an existing aport should be
overwritten (the aports are outside of the chroot, so `newapkbuild`
can't handle it in a way that makes sense for pmbootstrap).
* Output of `newapkbuild` gets redirected to the log file now, as we
don't need it to display a help page.
* Don't verify the pkgver while creating the new APKBUILD. When passing
a SRCURL, the pkgver gets extracted from the end of the URL and may
not have a valid format yet (but we want the APKBUILD anyway).
* Stored options passed through in `pmb/config/__init__.py` and use it
in both `pmb/parse/arguments.py` and `pmb/helpers/frontend.py`.
* Only allow `-n` with SRCURL
* The postmarketOS aports folder gets specified with `--folder` now.
That way the generated help page is much closer to the original one
from `newapkbuild`. The default is `main`.
* Made the package type flags (CMake, autotools, ...) exclusive so only
one of them can be specified
2018-03-15 21:42:34 +00:00
|
|
|
def newapkbuild(args, folder, args_passed, force=False):
|
2018-01-15 22:00:11 +00:00
|
|
|
# Initialize build environment and build folder
|
|
|
|
pmb.build.init(args)
|
|
|
|
build = "/home/pmos/build"
|
|
|
|
build_outside = args.work + "/chroot_native" + build
|
|
|
|
if os.path.exists(build_outside):
|
|
|
|
pmb.chroot.root(args, ["rm", "-r", build])
|
|
|
|
pmb.chroot.user(args, ["mkdir", "-p", build])
|
|
|
|
|
|
|
|
# Run newapkbuild
|
pmbootstrap newapkbuild: Properly parse arguments (#1320)
* pmbootstrap newapkbuild: Properly parse arguments
The `pmbootstrap newapkbuild` action wraps Alpine's `newapkbuild`. We
used to directly pass all arguments to `newapkbuild` without verifying
in Python whether they make sense or not. However, as `newpakbuild`
doesn't do strict sanity checks on the arguments, it is easy to end up
with unexpected behavior when using the command for the first time.
For example, `newapkbuild` allows either specifying a PKGNAME or SRCURL
as last parameter, and also allows setting a PKGNAME with the `-n`
parameter. It only makes sense to use that option when passing a
SRCURL.
With this commit, we duplicate the optins that should be passed through
to `newapkbuild` and use argparse to fully sanitize the options and
display a help page (`pmbootstrap newapkbuild -h`) that is consistent
with the other help pages.
Details:
* The `-f` (force) flag does not get passed through anymore. Instead we
use it in Python to skip asking if an existing aport should be
overwritten (the aports are outside of the chroot, so `newapkbuild`
can't handle it in a way that makes sense for pmbootstrap).
* Output of `newapkbuild` gets redirected to the log file now, as we
don't need it to display a help page.
* Don't verify the pkgver while creating the new APKBUILD. When passing
a SRCURL, the pkgver gets extracted from the end of the URL and may
not have a valid format yet (but we want the APKBUILD anyway).
* Stored options passed through in `pmb/config/__init__.py` and use it
in both `pmb/parse/arguments.py` and `pmb/helpers/frontend.py`.
* Only allow `-n` with SRCURL
* The postmarketOS aports folder gets specified with `--folder` now.
That way the generated help page is much closer to the original one
from `newapkbuild`. The default is `main`.
* Made the package type flags (CMake, autotools, ...) exclusive so only
one of them can be specified
2018-03-15 21:42:34 +00:00
|
|
|
pmb.chroot.user(args, ["newapkbuild"] + args_passed, working_dir=build)
|
2018-01-15 22:00:11 +00:00
|
|
|
glob_result = glob.glob(build_outside + "/*/APKBUILD")
|
|
|
|
if not len(glob_result):
|
|
|
|
return
|
|
|
|
|
|
|
|
# Paths for copying
|
|
|
|
source_apkbuild = glob_result[0]
|
2021-11-09 11:52:10 +00:00
|
|
|
pkgname = pmb.parse.apkbuild(source_apkbuild, False)["pkgname"]
|
2018-01-15 22:00:11 +00:00
|
|
|
target = args.aports + "/" + folder + "/" + pkgname
|
|
|
|
|
|
|
|
# Move /home/pmos/build/$pkgname/* to /home/pmos/build/*
|
|
|
|
for path in glob.glob(build_outside + "/*/*"):
|
|
|
|
path_inside = build + "/" + pkgname + "/" + os.path.basename(path)
|
|
|
|
pmb.chroot.user(args, ["mv", path_inside, build])
|
|
|
|
pmb.chroot.user(args, ["rmdir", build + "/" + pkgname])
|
|
|
|
|
|
|
|
# Overwrite confirmation
|
|
|
|
if os.path.exists(target):
|
|
|
|
logging.warning("WARNING: Folder already exists: " + target)
|
pmbootstrap newapkbuild: Properly parse arguments (#1320)
* pmbootstrap newapkbuild: Properly parse arguments
The `pmbootstrap newapkbuild` action wraps Alpine's `newapkbuild`. We
used to directly pass all arguments to `newapkbuild` without verifying
in Python whether they make sense or not. However, as `newpakbuild`
doesn't do strict sanity checks on the arguments, it is easy to end up
with unexpected behavior when using the command for the first time.
For example, `newapkbuild` allows either specifying a PKGNAME or SRCURL
as last parameter, and also allows setting a PKGNAME with the `-n`
parameter. It only makes sense to use that option when passing a
SRCURL.
With this commit, we duplicate the optins that should be passed through
to `newapkbuild` and use argparse to fully sanitize the options and
display a help page (`pmbootstrap newapkbuild -h`) that is consistent
with the other help pages.
Details:
* The `-f` (force) flag does not get passed through anymore. Instead we
use it in Python to skip asking if an existing aport should be
overwritten (the aports are outside of the chroot, so `newapkbuild`
can't handle it in a way that makes sense for pmbootstrap).
* Output of `newapkbuild` gets redirected to the log file now, as we
don't need it to display a help page.
* Don't verify the pkgver while creating the new APKBUILD. When passing
a SRCURL, the pkgver gets extracted from the end of the URL and may
not have a valid format yet (but we want the APKBUILD anyway).
* Stored options passed through in `pmb/config/__init__.py` and use it
in both `pmb/parse/arguments.py` and `pmb/helpers/frontend.py`.
* Only allow `-n` with SRCURL
* The postmarketOS aports folder gets specified with `--folder` now.
That way the generated help page is much closer to the original one
from `newapkbuild`. The default is `main`.
* Made the package type flags (CMake, autotools, ...) exclusive so only
one of them can be specified
2018-03-15 21:42:34 +00:00
|
|
|
question = "Continue and delete its contents?"
|
|
|
|
if not force and not pmb.helpers.cli.confirm(args, question):
|
2018-01-15 22:00:11 +00:00
|
|
|
raise RuntimeError("Aborted.")
|
|
|
|
pmb.helpers.run.user(args, ["rm", "-r", target])
|
|
|
|
|
|
|
|
# Copy the aport (without the extracted src folder)
|
|
|
|
logging.info("Create " + target)
|
|
|
|
pmb.helpers.run.user(args, ["mkdir", "-p", target])
|
|
|
|
for path in glob.glob(build_outside + "/*"):
|
|
|
|
if not os.path.isdir(path):
|
|
|
|
pmb.helpers.run.user(args, ["cp", path, target])
|