Skip to content

Commit d0d8d6d

Browse files
Rewrite repo-build and package-build in Python (toltec-dev#218)
(See toltec-dev#211.) The new build scripts are backward-compatible with existing recipes. Apart from some minor improvements on generated maintainer scripts, there are no changes in the final .ipk files. * Rewrite to Python 3.8 - Create `toltec` Python support library (in `scripts/toltec`) - Remove superseded `opkg` Python library (in `scripts/opkg`) - Add Python linting and formatting checks - Replace `scripts/repo-build` (Bash script) with `scripts/repo_build.py` - Replace `scripts/package-build` (Bash script) with `scripts/package_build.py` - Update Makefile and workflows to work with the new scripts * Package changes - Update koreader to not use the `$recipedir` variable (not documented, not supported by the new scripts, and should not be used anymore) - Update zoneinfo-utils to fix use of an undefined variable * Documentation changes - Add info on how required Python version and modules - Document custom fields and functions support * New features and improvements - Improve support for custom fields and functions in recipes - Remove unnecessary generated install scripts, reduce size of generated scripts - Parameterize the <https://toltec-dev.org> value in workflows, using a `REMOTE_HTTP` secret. - Rename the `REMOTE` secret to `REMOTE_SSH` for clarity * Additional checks - Check that all custom declarations start with `_` to guard against typos on optional standard declarations - Check that timestamp fields contain a valid ISO-8601 value - Check that pkgver fields contain a valid version number - Run all Bash scripts with `set -euo pipefail` flags enabled
1 parent 42d6fd6 commit d0d8d6d

29 files changed

+2004
-1497
lines changed

.github/actions/setup/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ runs:
66
shell: bash
77
run: |
88
sudo apt-get update -yq
9-
sudo apt-get install -yq bsdtar tree python3-docutils
9+
sudo apt-get install -yq bsdtar python3-docutils
1010
- name: Install shfmt and Shellcheck
1111
shell: bash
1212
run: |
@@ -35,3 +35,8 @@ runs:
3535
chmod a+x shellcheck
3636
sudo chown root:root shellcheck
3737
sudo mv shellcheck "$install_dir"
38+
- name: Install Python dependencies
39+
shell: bash
40+
run: |
41+
python -m pip install --upgrade pip
42+
pip install -r requirements.txt

.github/workflows/pr.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ jobs:
88
steps:
99
- name: Checkout the Git repository
1010
uses: actions/checkout@v2
11-
- name: Setup Toltec environment
11+
- name: Setup Python
12+
uses: actions/setup-python@v2
13+
with:
14+
python-version: '3.8'
15+
- name: Setup Toltec dependencies
1216
uses: ./.github/actions/setup
1317
- name: Check formatting
1418
run: make format
@@ -21,10 +25,14 @@ jobs:
2125
steps:
2226
- name: Checkout the Git repository
2327
uses: actions/checkout@v2
24-
- name: Setup Toltec environment
28+
- name: Setup Python
29+
uses: actions/setup-python@v2
30+
with:
31+
python-version: '3.8'
32+
- name: Setup Toltec dependencies
2533
uses: ./.github/actions/setup
2634
- name: Build packages
27-
run: remote_repo='https://toltec-dev.org/${{ github.base_ref }}' make repo-new
35+
run: make repo-new FLAGS='--remote-repo ${{ secrets.REMOTE_HTTP }}/${{ github.base_ref }}'
2836
- name: Save the build output
2937
uses: actions/upload-artifact@v2
3038
with:

.github/workflows/stable.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ jobs:
1010
steps:
1111
- name: Checkout the Git repository
1212
uses: actions/checkout@v2
13+
- name: Setup Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: '3.8'
1317
- name: Setup Toltec dependencies
1418
uses: ./.github/actions/setup
1519
- name: Build packages
16-
run: remote_repo="https://toltec-dev.org/stable" make repo
20+
run: |
21+
make repo FLAGS='--remote-repo ${{ secrets.REMOTE_HTTP }}/stable'
22+
./scripts/repo-build-web package build/repo
1723
- name: Sync packages with the remote repository
1824
uses: ./.github/actions/sync-repository
1925
with:
2026
local-path: build/repo/
2127
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
2228
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
23-
remote-path: ${{ secrets.REMOTE }}:/srv/toltec/stable
29+
remote-path: ${{ secrets.REMOTE_SSH }}:/srv/toltec/stable
2430
- name: Build website
2531
run: make web
2632
- name: Sync website with the remote repository
@@ -29,7 +35,7 @@ jobs:
2935
local-path: build/web/
3036
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
3137
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
32-
remote-path: ${{ secrets.REMOTE }}:/srv/toltec/web
38+
remote-path: ${{ secrets.REMOTE_SSH }}:/srv/toltec/web
3339
- name: Send notification to Discord
3440
continue-on-error: true
3541
uses: ./.github/actions/discord-send

.github/workflows/testing.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@ jobs:
1010
steps:
1111
- name: Checkout the Git repository
1212
uses: actions/checkout@v2
13+
- name: Setup Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: '3.8'
1317
- name: Setup Toltec dependencies
1418
uses: ./.github/actions/setup
1519
- name: Build packages
1620
run: |
17-
remote_repo="https://toltec-dev.org/testing" make repo
21+
make repo FLAGS='--remote-repo ${{ secrets.REMOTE_HTTP }}/testing'
22+
./scripts/repo-build-web package build/repo
1823
- name: Sync packages with the remote repository
1924
uses: ./.github/actions/sync-repository
2025
with:
2126
local-path: build/repo/
2227
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
2328
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
24-
remote-path: ${{ secrets.REMOTE }}:/srv/toltec/testing
29+
remote-path: ${{ secrets.REMOTE_SSH }}:/srv/toltec/testing
2530
- name: Send notification to Discord
2631
continue-on-error: true
2732
uses: ./.github/actions/discord-send

.mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mypy]
2+
[mypy-docker.*]
3+
ignore_missing_imports = True

.pylintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[SIMILARITIES]
2+
# Do not consider duplicate imports in several files as duplicated code
3+
ignore-imports=yes

Makefile

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,45 @@ web:
4747
./scripts/web-build web build/web
4848

4949
repo:
50-
./scripts/repo-build package build/package build/repo "$$remote_repo"
50+
./scripts/repo_build.py $(FLAGS)
5151

5252
repo-local:
53-
./scripts/repo-build -l package build/package build/repo "$$remote_repo"
53+
./scripts/repo_build.py --local $(FLAGS)
5454

5555
repo-new:
56-
./scripts/repo-build -n package build/package build/repo "$$remote_repo"
56+
./scripts/repo_build.py --no-fetch $(FLAGS)
5757

5858
repo-check:
5959
./scripts/repo-check build/repo
6060

6161
$(RECIPES): %:
62-
./scripts/package-build package/"${@}" build/package/"${@}"
62+
./scripts/package_build.py $(FLAGS) "$(@)"
6363

64-
$(RECIPES_PUSH): %:
65-
ssh root@"${HOST}" mkdir -p .cache/opkg
66-
scp build/package/"$(@:%-push=%)"/*/*.ipk root@"${HOST}":.cache/opkg
64+
push: %:
65+
rsync --rsync-path /opt/bin/rsync \
66+
--archive --verbose --compress --delete \
67+
build/repo/ \
68+
root@"$(HOST)":~/.cache/toltec/
6769

6870
format:
69-
@echo "==> Checking the formatting of shell scripts"
71+
@echo "==> Checking Bash formatting"
7072
shfmt -d .
73+
@echo "==> Checking Python formatting"
74+
black --line-length 80 --check --diff scripts
7175

7276
format-fix:
73-
@echo "==> Fixing the formatting of shell scripts"
77+
@echo "==> Fixing Bash formatting"
7478
shfmt -l -w .
79+
@echo "==> Fixing Python formatting"
80+
black --line-length 80 scripts
7581

7682
lint:
77-
@echo "==> Linting shell scripts"
83+
@echo "==> Linting Bash scripts"
7884
shellcheck $$(shfmt -f .)
85+
@echo "==> Typechecking Python files"
86+
MYPYPATH=scripts mypy --disallow-untyped-defs scripts
87+
@echo "==> Linting Python files"
88+
PYTHONPATH=: pylint scripts
7989
@echo "==> Verifying that the bootstrap checksum is correct"
8090
./scripts/bootstrap/checksum-check
8191

docs/building.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ Before running the build, make sure you have all the required dependencies:
1818

1919
* Docker
2020
* bsdtar
21-
* tree
21+
* Python ⩾ 3.8
22+
23+
You’ll also need all the Python modules listed in [requirements.txt](../requirements.txt) (install them by running `pip install --user -r requirements.txt` or using a [virtual environment](https://docs.python.org/3/tutorial/venv.html)).
2224

2325
To start the build, run `make repo-local`.
2426
This will be a long process, so you may want to grab a cup of coffee.

docs/contributing.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ Before proposing your package, make sure that it conforms to the rules on how to
5252

5353
### Style Guide
5454

55-
All contributions must follow the project’s [style guide](../.editorconfig).
56-
Shell scripts must also comply with [Shellcheck](https://github.com/koalaman/shellcheck).
5755
Sticking to a common set of conventions makes it easier for everyone to read the source code and reduces the time spent reviewing little formatting details.
5856

59-
The code style for shell scripts will automatically be checked when you submit your pull request.
60-
You may also check it manually by running `make format` (or `make format-fix` to automatically fix any issues) at the root of the repository (you need to have [shfmt](https://github.com/mvdan/sh) installed on your computer for this to work).
57+
All contributions must follow the project’s [style guide](../.editorconfig).
58+
The code style for shell scripts and Python code will automatically be checked for pull requests and can be checked locally using `make format`.
59+
Use `make format-fix` to automatically reformat your code to fit the style guide.
6160

62-
Compliance of shell scripts with Shellcheck will also automatically be checked.
63-
To check it manually, run `make lint` at the root of the repository (you need to have Shellcheck installed on your computer for this to work).
61+
Shell scripts must comply with [Shellcheck](https://github.com/koalaman/shellcheck).
62+
Python code must have valid type annotations (typechecked using [mypy](http://mypy-lang.org/)) and be free of [pylint](https://www.pylint.org/) errors.
63+
Compliance with those tools will automatically be checked for pull requests and can be checked locally using `make lint`.
6464

6565
### Code of Conduct
6666

docs/package.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Sourcing a recipe must have no side effects: the metadata section can only execu
2020

2121
At the top of the file is a block of fields that define metadata about the package.
2222
For consistency, declare those fields in the same order they are described below.
23+
You can also declare custom variables to reduce repetition, but make sure to prefix their name with `_`.
2324

2425
> **Note:** The field names and semantics are inspired both by the [Debian control file format](https://www.debian.org/doc/debian-policy/ch-controlfields.html) and the [Arch Linux PKGBUILD format](https://wiki.archlinux.org/index.php/PKGBUILD).
2526
@@ -246,6 +247,22 @@ Each entry can either be a local path relative to the recipe file or a full URL
246247
Archive files whose names end in `.zip`, `.tar.gz`, `.tar.xz`, or `.tar.bz` will be automatically extracted in place, with all container directories stripped.
247248
You can disable this behavior by adding the archive name to the `noextract` array.
248249

250+
#### `flags`
251+
252+
<table>
253+
<tr>
254+
<th>Required?</th>
255+
<td>No, defaults to <code>()</code></th>
256+
</tr>
257+
<tr>
258+
<th>Type</th>
259+
<td>Array of strings</td>
260+
</tr>
261+
</table>
262+
263+
Set of flags that affect the build process.
264+
Currently, the only available flag is `nostrip`, which disables the automatic removal of unneeded symbols from binaries.
265+
249266
#### `noextract`
250267

251268
<table>
@@ -284,6 +301,7 @@ This array must have exactly as many elements as the `source` array.
284301
### Prepare Section
285302

286303
The prepare section contains the `prepare()` function in which the source files may be prepared for the building step that follows.
304+
This function has access to all the metadata fields declared above.
287305
Common tasks include patching sources, extracting archives, and moving downloaded sources to the right location.
288306

289307
### Build Section
@@ -307,7 +325,7 @@ The `package()` function populates the `$pkgdir` directory with the files and di
307325
The install section can contain additional functions to customize the behavior of the package when it is installed, removed, or upgraded on the device.
308326
Those functions are `preinstall()`, `configure()`, `preremove()`, `postremove()`, `preupgrade()` and `postupgrade()`.
309327
Unlike the previous functions, all the install functions **run in the context of the target device.**
310-
They have access to all the metadata fields, but not to other functions.
328+
They have access to all the metadata fields and to custom functions whose name starts with `_`.
311329
They can also use functions from the [install library](../scripts/install-lib).
312330

313331
When installing a new package, the following happens:

package/koreader/package

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ source=(
1818
koreader.draft
1919
KOReader.oxide
2020
rm2-support.patch
21+
koreader
2122
)
2223
sha256sums=(
2324
38db8f3895472828d7c1d63fc54db426135a8dbf8425633e299a1a9abfdb69b2
2425
SKIP
2526
SKIP
2627
SKIP
28+
SKIP
2729
)
2830

2931
prepare() {
@@ -42,5 +44,5 @@ package() {
4244
install -D -m 644 -t "$pkgdir"/opt/etc/draft/ "$srcdir"/koreader.draft
4345
install -D -m 644 -t "$pkgdir"/opt/usr/share/applications/ "$srcdir"/KOReader.oxide
4446
install -D -m 644 -t "$pkgdir"/opt/etc/draft/icons/ "$srcdir"/resources/koreader.png
45-
install -D -m 755 -t "$pkgdir"/opt/bin/ "$recipedir"/koreader
47+
install -D -m 755 -t "$pkgdir"/opt/bin/ "$srcdir"/koreader
4648
}

package/zoneinfo-utils/package

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ build() {
4040

4141
shopt -s extglob
4242
cp -r ../* .
43-
make LFLAGS="${LDFLAGS}"
43+
make VERSION="$_tzver"
4444

4545
popd > /dev/null
4646

47-
make LFLAGS="${LDFLAGS}" CC=arm-linux-gnueabihf-cc
47+
make VERSION="$_tzver" CC=arm-linux-gnueabihf-cc
4848
}
4949

5050
package() {

requirements.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
appdirs==1.4.4
2+
astroid==2.4.2
3+
black==20.8b1
4+
certifi==2020.12.5
5+
chardet==4.0.0
6+
click==7.1.2
7+
docker==4.4.1
8+
idna==2.10
9+
isort==5.7.0
10+
lazy-object-proxy==1.4.3
11+
mccabe==0.6.1
12+
mypy==0.790
13+
mypy-extensions==0.4.3
14+
pathspec==0.8.1
15+
pylint==2.6.0
16+
python-dateutil==2.8.1
17+
regex==2020.11.13
18+
requests==2.25.1
19+
six==1.15.0
20+
toml==0.10.2
21+
typed-ast==1.4.2
22+
typing-extensions==3.7.4.3
23+
urllib3==1.26.2
24+
websocket-client==0.57.0
25+
wrapt==1.12.1

0 commit comments

Comments
 (0)