2022-01-02 21:38:21 +00:00
|
|
|
# Copyright 2022 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-05-26 20:35:21 +00:00
|
|
|
import glob
|
Properly escape commands in pmb.chroot.user() (#1316)
## Introduction
In #1302 we noticed that `pmb.chroot.user()` does not escape commands
properly: When passing one string with spaces, it would pass them as
two strings to the chroot. The use case is passing a description with
a space inside to `newapkbuild` with `pmboostrap newapkbuild`.
This is not a security issue, as we don't pass strings from untrusted
input to this function.
## Functions for running commands in pmbootstrap
To put the rest of the description in context: We have four high level
functions that run commands:
* `pmb.helpers.run.user()`
* `pmb.helpers.run.root()`
* `pmb.chroot.root()`
* `pmb.chroot.user()`
In addition, one low level function that the others invoke:
* `pmb.helpers.run.core()`
## Flawed test case
The issue described above did not get detected for so long, because we
have a test case in place since day one, which verifies that all of the
functions above escape everything properly:
* `test/test_shell_escape.py`
So the test case ran a given command through all these functions, and
compared the result each time. However, `pmb.chroot.root()`
modified the command variable (passed by reference) and did the
escaping already, which means `pmb.chroot.user()` running directly
afterwards only returns the right output when *not* doing any escaping.
Without questioning the accuracy of the test case, I've escaped
commands and environment variables with `shlex.quote()` *before*
passing them to `pmb.chroot.user()`. In retrospective this does not
make sense at all and is reverted with this commit.
## Environment variables
By coincidence, we have only passed custom environment variables to
`pmb.chroot.user()`, never to the other high level functions. This only
worked, because we did not do any escaping and the passed line gets
executed as shell command:
```
$ MYENV=test echo test2
test 2
```
If it was properly escaped as one shell command:
```
$ 'MYENV=test echo test2'
sh: MYENV=test echo test2: not found
```
So doing that clearly doesn't work anymore. I have added a new `env`
parameter to `pmb.chroot.user()` (and to all other high level functions
for consistency), where environment variables can be passed as a
dictionary. Then the function knows what to do and we end up with
properly escaped commands and environment variables.
## Details
* Add new `env` parameter to all high level command execution functions
* New `pmb.helpers.run.flat_cmd()` function, that takes a command as
list and environment variables as dict, and creates a properly escaped
flat string from the input.
* Use that function for proper escaping in all high level exec funcs
* Don't escape commands *before* passing them to `pmb.chroot.user()`
* Describe parameters of the command execution functions
* `pmbootstrap -v` writes the exact command to the log that was
executed (in addition to the simplified form we always write down for
readability)
* `test_shell_escape.py`: verify that the command passed by reference
has not been modified, add a new test for strings with spaces, add
tests for new function `pmb.helpers.run.flat_cmd()`
* Remove obsolete commend in `pmb.chroot.distccd` about environment
variables, because we don't use any there anymore
* Add `TERM=xterm` to default environment variables in the chroot,
so running ncurses applications like `menuconfig` and `nano` works out of
the box
2018-03-10 22:58:39 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import shlex
|
2019-10-06 12:38:19 +00:00
|
|
|
import datetime
|
2017-05-26 20:35:21 +00:00
|
|
|
|
|
|
|
import pmb.chroot
|
2017-06-19 18:33:56 +00:00
|
|
|
import pmb.helpers.file
|
2017-09-25 22:05:29 +00:00
|
|
|
import pmb.helpers.git
|
2018-11-15 07:30:49 +00:00
|
|
|
import pmb.helpers.pmaports
|
2017-09-25 22:05:29 +00:00
|
|
|
import pmb.helpers.run
|
2017-05-26 20:35:21 +00:00
|
|
|
import pmb.parse.apkindex
|
2017-08-12 14:03:40 +00:00
|
|
|
import pmb.parse.version
|
2017-05-26 20:35:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def copy_to_buildpath(args, package, suffix="native"):
|
|
|
|
# Sanity check
|
2018-11-15 07:30:49 +00:00
|
|
|
aport = pmb.helpers.pmaports.find(args, package)
|
2017-05-26 20:35:21 +00:00
|
|
|
if not os.path.exists(aport + "/APKBUILD"):
|
|
|
|
raise ValueError("Path does not contain an APKBUILD file:" +
|
|
|
|
aport)
|
|
|
|
|
|
|
|
# Clean up folder
|
2017-10-12 20:08:10 +00:00
|
|
|
build = args.work + "/chroot_" + suffix + "/home/pmos/build"
|
2017-05-26 20:35:21 +00:00
|
|
|
if os.path.exists(build):
|
2018-07-14 01:13:28 +00:00
|
|
|
pmb.chroot.root(args, ["rm", "-rf", "/home/pmos/build"], suffix)
|
2017-05-26 20:35:21 +00:00
|
|
|
|
2018-10-05 07:05:31 +00:00
|
|
|
# Copy aport contents with resolved symlinks
|
|
|
|
pmb.helpers.run.root(args, ["cp", "-rL", aport + "/", build])
|
2017-10-12 20:08:10 +00:00
|
|
|
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos",
|
2018-07-14 01:13:28 +00:00
|
|
|
"/home/pmos/build"], suffix)
|
2017-05-26 20:35:21 +00:00
|
|
|
|
|
|
|
|
2018-02-20 19:52:28 +00:00
|
|
|
def is_necessary(args, arch, apkbuild, indexes=None):
|
2017-05-26 20:35:21 +00:00
|
|
|
"""
|
2017-06-19 18:33:56 +00:00
|
|
|
Check if the package has already been built. Compared to abuild's check,
|
2018-11-06 06:56:11 +00:00
|
|
|
this check also works for different architectures.
|
2017-05-26 20:35:21 +00:00
|
|
|
|
2017-06-11 12:45:00 +00:00
|
|
|
:param arch: package target architecture
|
|
|
|
:param apkbuild: from pmb.parse.apkbuild()
|
2018-02-20 19:52:28 +00:00
|
|
|
:param indexes: list of APKINDEX.tar.gz paths
|
2017-06-11 12:45:00 +00:00
|
|
|
:returns: boolean
|
2017-05-26 20:35:21 +00:00
|
|
|
"""
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
# Get package name, version, define start of debug message
|
2017-05-26 20:35:21 +00:00
|
|
|
package = apkbuild["pkgname"]
|
|
|
|
version_new = apkbuild["pkgver"] + "-r" + apkbuild["pkgrel"]
|
2017-07-19 18:05:34 +00:00
|
|
|
msg = "Build is necessary for package '" + package + "': "
|
2017-05-26 20:35:21 +00:00
|
|
|
|
|
|
|
# Get old version from APKINDEX
|
2018-02-20 19:52:28 +00:00
|
|
|
index_data = pmb.parse.apkindex.package(args, package, arch, False,
|
|
|
|
indexes)
|
2017-06-20 18:13:05 +00:00
|
|
|
if not index_data:
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
logging.debug(msg + "No binary package available")
|
2017-06-20 18:13:05 +00:00
|
|
|
return True
|
2017-05-26 20:35:21 +00:00
|
|
|
|
2020-04-04 10:45:22 +00:00
|
|
|
# Can't build pmaport for arch: use Alpine's package (#1897)
|
|
|
|
if arch and not pmb.helpers.pmaports.check_arches(apkbuild["arch"], arch):
|
|
|
|
logging.verbose(f"{package}: build is not necessary, because pmaport"
|
|
|
|
" can't be built for {arch}. Using Alpine's binary"
|
|
|
|
" package.")
|
|
|
|
return False
|
|
|
|
|
2017-06-20 18:13:05 +00:00
|
|
|
# a) Binary repo has a newer version
|
|
|
|
version_old = index_data["version"]
|
2017-08-12 14:03:40 +00:00
|
|
|
if pmb.parse.version.compare(version_old, version_new) == 1:
|
2018-11-06 06:58:05 +00:00
|
|
|
logging.warning("WARNING: package {}: aport version {} is lower than"
|
|
|
|
" {} from the binary repository. {} will be used when"
|
|
|
|
" installing {}. See also:"
|
|
|
|
" <https://postmarketos.org/warning-repo2>"
|
|
|
|
"".format(package, version_new, version_old,
|
|
|
|
version_old, package))
|
2017-06-20 18:13:05 +00:00
|
|
|
return False
|
2017-06-19 18:33:56 +00:00
|
|
|
|
2017-06-20 18:13:05 +00:00
|
|
|
# b) Aports folder has a newer version
|
2017-06-19 18:33:56 +00:00
|
|
|
if version_new != version_old:
|
2021-04-27 02:56:42 +00:00
|
|
|
logging.debug(f"{msg}Binary package out of date (binary: "
|
|
|
|
f"{version_old}, aport: {version_new})")
|
2017-06-19 18:33:56 +00:00
|
|
|
return True
|
|
|
|
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
# Aports and binary repo have the same version.
|
2018-01-28 23:27:33 +00:00
|
|
|
return False
|
2017-05-26 20:35:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def index_repo(args, arch=None):
|
2017-06-08 16:19:17 +00:00
|
|
|
"""
|
2017-08-19 12:52:11 +00:00
|
|
|
Recreate the APKINDEX.tar.gz for a specific repo, and clear the parsing
|
|
|
|
cache for that file for the current pmbootstrap session (to prevent
|
|
|
|
rebuilding packages twice, in case the rebuild takes less than a second).
|
|
|
|
|
2017-06-08 16:19:17 +00:00
|
|
|
:param arch: when not defined, re-index all repos
|
|
|
|
"""
|
|
|
|
pmb.build.init(args)
|
|
|
|
|
2020-04-10 13:21:23 +00:00
|
|
|
channel = pmb.config.pmaports.read_config(args)["channel"]
|
2017-05-26 20:35:21 +00:00
|
|
|
if arch:
|
2020-04-10 13:21:23 +00:00
|
|
|
paths = [f"{args.work}/packages/{channel}/{arch}"]
|
2017-05-26 20:35:21 +00:00
|
|
|
else:
|
2020-04-10 13:21:23 +00:00
|
|
|
paths = glob.glob(f"{args.work}/packages/{channel}/*")
|
2017-05-26 20:35:21 +00:00
|
|
|
|
|
|
|
for path in paths:
|
2018-01-04 16:26:03 +00:00
|
|
|
if os.path.isdir(path):
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
path_arch = os.path.basename(path)
|
|
|
|
path_repo_chroot = "/home/pmos/packages/pmos/" + path_arch
|
|
|
|
logging.debug("(native) index " + path_arch + " repository")
|
2019-10-06 12:38:19 +00:00
|
|
|
description = str(datetime.datetime.now())
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
commands = [
|
Properly escape commands in pmb.chroot.user() (#1316)
## Introduction
In #1302 we noticed that `pmb.chroot.user()` does not escape commands
properly: When passing one string with spaces, it would pass them as
two strings to the chroot. The use case is passing a description with
a space inside to `newapkbuild` with `pmboostrap newapkbuild`.
This is not a security issue, as we don't pass strings from untrusted
input to this function.
## Functions for running commands in pmbootstrap
To put the rest of the description in context: We have four high level
functions that run commands:
* `pmb.helpers.run.user()`
* `pmb.helpers.run.root()`
* `pmb.chroot.root()`
* `pmb.chroot.user()`
In addition, one low level function that the others invoke:
* `pmb.helpers.run.core()`
## Flawed test case
The issue described above did not get detected for so long, because we
have a test case in place since day one, which verifies that all of the
functions above escape everything properly:
* `test/test_shell_escape.py`
So the test case ran a given command through all these functions, and
compared the result each time. However, `pmb.chroot.root()`
modified the command variable (passed by reference) and did the
escaping already, which means `pmb.chroot.user()` running directly
afterwards only returns the right output when *not* doing any escaping.
Without questioning the accuracy of the test case, I've escaped
commands and environment variables with `shlex.quote()` *before*
passing them to `pmb.chroot.user()`. In retrospective this does not
make sense at all and is reverted with this commit.
## Environment variables
By coincidence, we have only passed custom environment variables to
`pmb.chroot.user()`, never to the other high level functions. This only
worked, because we did not do any escaping and the passed line gets
executed as shell command:
```
$ MYENV=test echo test2
test 2
```
If it was properly escaped as one shell command:
```
$ 'MYENV=test echo test2'
sh: MYENV=test echo test2: not found
```
So doing that clearly doesn't work anymore. I have added a new `env`
parameter to `pmb.chroot.user()` (and to all other high level functions
for consistency), where environment variables can be passed as a
dictionary. Then the function knows what to do and we end up with
properly escaped commands and environment variables.
## Details
* Add new `env` parameter to all high level command execution functions
* New `pmb.helpers.run.flat_cmd()` function, that takes a command as
list and environment variables as dict, and creates a properly escaped
flat string from the input.
* Use that function for proper escaping in all high level exec funcs
* Don't escape commands *before* passing them to `pmb.chroot.user()`
* Describe parameters of the command execution functions
* `pmbootstrap -v` writes the exact command to the log that was
executed (in addition to the simplified form we always write down for
readability)
* `test_shell_escape.py`: verify that the command passed by reference
has not been modified, add a new test for strings with spaces, add
tests for new function `pmb.helpers.run.flat_cmd()`
* Remove obsolete commend in `pmb.chroot.distccd` about environment
variables, because we don't use any there anymore
* Add `TERM=xterm` to default environment variables in the chroot,
so running ncurses applications like `menuconfig` and `nano` works out of
the box
2018-03-10 22:58:39 +00:00
|
|
|
# Wrap the index command with sh so we can use '*.apk'
|
|
|
|
["sh", "-c", "apk -q index --output APKINDEX.tar.gz_"
|
2019-10-06 12:38:19 +00:00
|
|
|
" --description " + shlex.quote(description) + ""
|
Properly escape commands in pmb.chroot.user() (#1316)
## Introduction
In #1302 we noticed that `pmb.chroot.user()` does not escape commands
properly: When passing one string with spaces, it would pass them as
two strings to the chroot. The use case is passing a description with
a space inside to `newapkbuild` with `pmboostrap newapkbuild`.
This is not a security issue, as we don't pass strings from untrusted
input to this function.
## Functions for running commands in pmbootstrap
To put the rest of the description in context: We have four high level
functions that run commands:
* `pmb.helpers.run.user()`
* `pmb.helpers.run.root()`
* `pmb.chroot.root()`
* `pmb.chroot.user()`
In addition, one low level function that the others invoke:
* `pmb.helpers.run.core()`
## Flawed test case
The issue described above did not get detected for so long, because we
have a test case in place since day one, which verifies that all of the
functions above escape everything properly:
* `test/test_shell_escape.py`
So the test case ran a given command through all these functions, and
compared the result each time. However, `pmb.chroot.root()`
modified the command variable (passed by reference) and did the
escaping already, which means `pmb.chroot.user()` running directly
afterwards only returns the right output when *not* doing any escaping.
Without questioning the accuracy of the test case, I've escaped
commands and environment variables with `shlex.quote()` *before*
passing them to `pmb.chroot.user()`. In retrospective this does not
make sense at all and is reverted with this commit.
## Environment variables
By coincidence, we have only passed custom environment variables to
`pmb.chroot.user()`, never to the other high level functions. This only
worked, because we did not do any escaping and the passed line gets
executed as shell command:
```
$ MYENV=test echo test2
test 2
```
If it was properly escaped as one shell command:
```
$ 'MYENV=test echo test2'
sh: MYENV=test echo test2: not found
```
So doing that clearly doesn't work anymore. I have added a new `env`
parameter to `pmb.chroot.user()` (and to all other high level functions
for consistency), where environment variables can be passed as a
dictionary. Then the function knows what to do and we end up with
properly escaped commands and environment variables.
## Details
* Add new `env` parameter to all high level command execution functions
* New `pmb.helpers.run.flat_cmd()` function, that takes a command as
list and environment variables as dict, and creates a properly escaped
flat string from the input.
* Use that function for proper escaping in all high level exec funcs
* Don't escape commands *before* passing them to `pmb.chroot.user()`
* Describe parameters of the command execution functions
* `pmbootstrap -v` writes the exact command to the log that was
executed (in addition to the simplified form we always write down for
readability)
* `test_shell_escape.py`: verify that the command passed by reference
has not been modified, add a new test for strings with spaces, add
tests for new function `pmb.helpers.run.flat_cmd()`
* Remove obsolete commend in `pmb.chroot.distccd` about environment
variables, because we don't use any there anymore
* Add `TERM=xterm` to default environment variables in the chroot,
so running ncurses applications like `menuconfig` and `nano` works out of
the box
2018-03-10 22:58:39 +00:00
|
|
|
" --rewrite-arch " + shlex.quote(path_arch) + " *.apk"],
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
["abuild-sign", "APKINDEX.tar.gz_"],
|
|
|
|
["mv", "APKINDEX.tar.gz_", "APKINDEX.tar.gz"]
|
|
|
|
]
|
|
|
|
for command in commands:
|
|
|
|
pmb.chroot.user(args, command, working_dir=path_repo_chroot)
|
|
|
|
else:
|
2018-01-04 16:26:03 +00:00
|
|
|
logging.debug("NOTE: Can't build index for: " + path)
|
2021-11-09 11:54:07 +00:00
|
|
|
pmb.parse.apkindex.clear_cache(f"{path}/APKINDEX.tar.gz")
|
2017-05-26 20:35:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def configure_abuild(args, suffix, verify=False):
|
2017-12-21 16:42:29 +00:00
|
|
|
"""
|
|
|
|
Set the correct JOBS count in abuild.conf
|
|
|
|
|
|
|
|
:param verify: internally used to test if changing the config has worked.
|
|
|
|
"""
|
2017-05-26 20:35:21 +00:00
|
|
|
path = args.work + "/chroot_" + suffix + "/etc/abuild.conf"
|
|
|
|
prefix = "export JOBS="
|
|
|
|
with open(path, encoding="utf-8") as handle:
|
|
|
|
for line in handle:
|
|
|
|
if not line.startswith(prefix):
|
|
|
|
continue
|
|
|
|
if line != (prefix + args.jobs + "\n"):
|
|
|
|
if verify:
|
2021-04-27 02:56:42 +00:00
|
|
|
raise RuntimeError(f"Failed to configure abuild: {path}"
|
|
|
|
"\nTry to delete the file"
|
|
|
|
"(or zap the chroot).")
|
2017-05-26 20:35:21 +00:00
|
|
|
pmb.chroot.root(args, ["sed", "-i", "-e",
|
2021-04-27 02:56:42 +00:00
|
|
|
f"s/^{prefix}.*/{prefix}{args.jobs}/",
|
|
|
|
"/etc/abuild.conf"],
|
|
|
|
suffix)
|
2017-05-26 20:35:21 +00:00
|
|
|
configure_abuild(args, suffix, True)
|
|
|
|
return
|
|
|
|
raise RuntimeError("Could not find " + prefix + " line in " + path)
|
2017-12-21 16:42:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def configure_ccache(args, suffix="native", verify=False):
|
|
|
|
"""
|
|
|
|
Set the maximum ccache size
|
|
|
|
|
|
|
|
:param verify: internally used to test if changing the config has worked.
|
|
|
|
"""
|
|
|
|
# Check if the settings have been set already
|
|
|
|
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
|
|
|
|
path = args.work + "/cache_ccache_" + arch + "/ccache.conf"
|
|
|
|
if os.path.exists(path):
|
|
|
|
with open(path, encoding="utf-8") as handle:
|
|
|
|
for line in handle:
|
|
|
|
if line == ("max_size = " + args.ccache_size + "\n"):
|
|
|
|
return
|
|
|
|
if verify:
|
|
|
|
raise RuntimeError("Failed to configure ccache: " + path + "\nTry to"
|
|
|
|
" delete the file (or zap the chroot).")
|
|
|
|
|
|
|
|
# Set the size and verify
|
|
|
|
pmb.chroot.user(args, ["ccache", "--max-size", args.ccache_size],
|
|
|
|
suffix)
|
|
|
|
configure_ccache(args, suffix, True)
|