Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add manage_containers.py #27

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
42470be
Dockerfile refactor
Willenst Oct 2, 2024
5bf8957
Add python script to manage containers
Willenst Sep 13, 2024
5a158d2
adding tests
Willenst Oct 16, 2024
52d8f5a
Add old clangs for make_linux.py
Willenst Sep 13, 2024
391cc4c
Update README.md
Willenst Sep 13, 2024
c93a0be
Fix the "dockerman" bug
a13xp0p0v Oct 26, 2024
bfe78cb
Get rid of Docker in naming -- we will add Podman support later
a13xp0p0v Oct 26, 2024
1f10600
Style fixes (no functional changes)
a13xp0p0v Oct 26, 2024
4c62705
Reword some comments and don't mention docker (we will add podman later)
a13xp0p0v Oct 26, 2024
6cfb977
Drop an empty line in the output
a13xp0p0v Oct 26, 2024
7f542bf
Rename the testing script
a13xp0p0v Oct 26, 2024
61dbfc5
Call `coverage` as `python3 -m coverage` to make it work on older mac…
a13xp0p0v Oct 26, 2024
07bc928
Clear the state before beginning the test
a13xp0p0v Oct 26, 2024
801aa27
Fix some compiler names in make_linux.py
a13xp0p0v Oct 26, 2024
f9eace9
Fix the "dockerman" bug in other scripts
Willenst Oct 28, 2024
24b0812
Make `Container.check()` more more reliable
Willenst Nov 1, 2024
b4aad39
Improve output
Willenst Nov 1, 2024
3b6934e
Prioritize clang over gcc
Willenst Nov 1, 2024
eebd810
Improve the `make_linux.py` help message
a13xp0p0v Nov 9, 2024
6a760b6
Drop the "all compilers" mode in `make_linux.py`
a13xp0p0v Nov 9, 2024
3eb8292
Rename `make_linux.py` to `build_linux.py`
a13xp0p0v Nov 9, 2024
559972b
Reorder clang and gcc
Willenst Nov 11, 2024
733653a
Reorder gcc and clang in `build_linux.py`
Willenst Nov 11, 2024
e522037
Update `README.md`
Willenst Nov 11, 2024
187a50f
Remove the obsolete shell scripts
Willenst Nov 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ RUN set -ex; \
update-alternatives --install /usr/bin/arm-linux-gnueabi-g++ arm-linux-gnueabi-g++ /usr/bin/arm-linux-gnueabi-g++-${GCC_VERSION} 100; \
fi; \
if [ "$CLANG_VERSION" ]; then \
apt-get install -y -q clang-${CLANG_VERSION} lld-${CLANG_VERSION} clang-tools-${CLANG_VERSION}; \
if [ "$CLANG_VERSION" = "5" ] || [ "$CLANG_VERSION" = "6" ]; then \
CLANG_VERSION="${CLANG_VERSION}.0"; \
apt-get install -y -q clang-${CLANG_VERSION} lld-${CLANG_VERSION} clang-tools-6.0; \
else \
apt-get install -y -q clang-${CLANG_VERSION} lld-${CLANG_VERSION} clang-tools-${CLANG_VERSION}; \
fi; \
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 100; \
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION} 100; \
update-alternatives --install /usr/bin/lld lld /usr/bin/lld-${CLANG_VERSION} 100; \
Expand Down
228 changes: 179 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ __Supported gcc versions:__
- gcc-14

__Supported clang versions:__
- clang-5
- clang-6
- clang-7
- clang-8
- clang-9
- clang-10
- clang-11
- clang-12
- clang-13
- clang-14
Expand All @@ -46,38 +53,106 @@ __Supported clang versions:__

## Usage

### Building all containers
### Building containers:

__Get help:__

```console
$ python3 manage_containers.py -h
usage: manage_containers.py [-h] [-l] [-a compiler] [-r] [-q]

Manage the kernel-build-containers

options:
-h, --help show this help message and exit
-l, --list show the kernel build containers
-a compiler, --add compiler
build a container with clang-5 / clang-6 / clang-7 / clang-8 / clang-9 / clang-10 / clang-11 / clang-12 / clang-13 / clang-14 / clang-15 /
clang-16 / clang-17 / gcc-4.9 / gcc-5 / gcc-6 / gcc-7 / gcc-8 / gcc-9 / gcc-10 / gcc-11 / gcc-12 / gcc-13 / gcc-14 / all (use "all" for
building all containers)
-r, --remove remove all created containers
-q, --quiet suppress container build output
```

__Building all containers:__

```console
$ bash build_containers.sh
$ python3 manage_containers.py -a all
```

Created containers:
__Created containers:__

```console
$ sudo docker image list | grep kernel-build-container
kernel-build-container clang-17 c24d2754f36d About a minute ago 6.01GB
kernel-build-container clang-16 9b3f7dce5f5b 12 minutes ago 6.01GB
kernel-build-container clang-15 9f62c82c4826 24 minutes ago 3.83GB
kernel-build-container clang-14 83523b7c7241 41 minutes ago 2.21GB
kernel-build-container clang-13 8c0f0e68075a 46 minutes ago 2.27GB
kernel-build-container clang-12 ac2cea3e0e97 51 minutes ago 2.21GB
kernel-build-container gcc-14 ff56932d9a3e 7 hours ago 4.36GB
kernel-build-container gcc-13 b05623469193 7 hours ago 3.14GB
kernel-build-container gcc-12 63562d1fbb5e 7 hours ago 1.55GB
kernel-build-container gcc-11 c4b2e14874f2 7 hours ago 1.03GB
kernel-build-container gcc-10 bcbfb78c4a6c 7 hours ago 1.27GB
kernel-build-container gcc-9 76f580f18759 7 hours ago 833MB
kernel-build-container gcc-8 e22bee633dff 8 hours ago 1.12GB
kernel-build-container gcc-7 e79708f81b84 8 hours ago 740MB
kernel-build-container gcc-6 61f40d3e3e58 8 hours ago 992MB
kernel-build-container gcc-5 ed6270a767c6 8 hours ago 720MB
kernel-build-container gcc-4.9 408db89527ec 8 hours ago 913MB
REPOSITORY TAG IMAGE ID CREATED SIZE
kernel-build-container clang-17 f82a39f4f536 10 seconds ago 4.87GB
kernel-build-container gcc-14 f82a39f4f536 10 seconds ago 4.87GB
kernel-build-container clang-16 debeffa0b306 2 minutes ago 4.89GB
kernel-build-container clang-15 282ee1c70ef4 5 minutes ago 3.49GB
kernel-build-container gcc-13 282ee1c70ef4 5 minutes ago 3.49GB
kernel-build-container clang-14 65e5a9bfec0f 7 minutes ago 1.88GB
kernel-build-container gcc-12 65e5a9bfec0f 7 minutes ago 1.88GB
kernel-build-container clang-13 57e0584fe0d3 12 minutes ago 1.96GB
kernel-build-container clang-12 fbb06aca13c9 13 minutes ago 1.71GB
kernel-build-container gcc-11 fbb06aca13c9 13 minutes ago 1.71GB
kernel-build-container clang-11 b3a75c3fd9ad 14 minutes ago 1.62GB
kernel-build-container gcc-10 b3a75c3fd9ad 14 minutes ago 1.62GB
kernel-build-container clang-10 6401372cf5aa 15 minutes ago 1.39GB
kernel-build-container gcc-9 6401372cf5aa 15 minutes ago 1.39GB
kernel-build-container clang-9 6668ffd11788 17 minutes ago 1.55GB
kernel-build-container gcc-8 6668ffd11788 17 minutes ago 1.55GB
kernel-build-container clang-8 23935b3308af 18 minutes ago 1.4GB
kernel-build-container gcc-7 23935b3308af 18 minutes ago 1.4GB
kernel-build-container clang-7 a9cc66b33f3e 19 minutes ago 1.5GB
kernel-build-container gcc-6 a9cc66b33f3e 19 minutes ago 1.5GB
kernel-build-container clang-6 8485509afe41 21 minutes ago 1.33GB
kernel-build-container gcc-5 8485509afe41 21 minutes ago 1.33GB
kernel-build-container clang-5 939c94215f80 22 minutes ago 1.87GB
kernel-build-container gcc-4.9 939c94215f80 22 minutes ago 1.87GB
```

__Building all containers quietly:__

```console
$ python3 manage_containers.py -a all -q
```

__Expected output:__

```console
----------------------------------
Ubuntu | Clang | GCC | Status
----------------------------------
16.04 | 5 | 4.9 | [+]
16.04 | 6 | 5 | [+]
18.04 | 7 | 6 | [+]
18.04 | 8 | 7 | [+]
20.04 | 9 | 8 | [+]
20.04 | 10 | 9 | [+]
20.04 | 11 | 10 | [+]
22.04 | 12 | 11 | [+]
22.04 | 13 | 12 | [+]
22.04 | 14 | 12 | [+]
23.04 | 15 | 13 | [+]
24.04 | 16 | 14 | [+]
24.04 | 17 | 14 | [+]
```

__Building the specified container:__

```console
$ python3 manage_containers.py -a clang-10
```

__Building the specified container quietly:__

```console
$ python3 manage_containers.py -a clang-10 -q
```

### Running a container

Get help:
__Get help:__

```console
$ bash start_container.sh
Expand All @@ -91,7 +166,7 @@ usage: start_container.sh compiler src_dir out_dir [-n] [-e VAR] [-h] [-v] [-- c
If cmd is empty, we will start an interactive bash in the container.
```

Run interactive bash in the container:
__Run interactive bash in the container:__

```console
$ bash start_container.sh gcc-12 ~/linux-stable/linux-stable/ ~/linux-stable/build_out/
Expand All @@ -108,7 +183,7 @@ See "man sudo_root" for details.
a13x@38f63939b504:~/src$
```

Execute a command in the container:
__Execute a command in the container:__

```console
$ bash start_container.sh clang-15 ~/linux-stable/linux-stable/ ~/linux-stable/build_out/ -- make defconfig
Expand All @@ -125,38 +200,35 @@ Gonna run command "make defconfig"

### Building the Linux kernel

Get help:
__Get help:__

```console
$ python3 make_linux.py --help
usage: make_linux.py [-h] -c {gcc-4.9,gcc-5,gcc-6,gcc-7,gcc-8,gcc-9,gcc-10,gcc-11,gcc-12,gcc-13,gcc-14,
clang-12,clang-13,clang-14,clang-15,clang-16,clang-17,all} -a {x86_64,i386,arm64,arm}
-s src -o out [-k kconfig] [-q] [-t]
...
$ python3 build_linux.py --help
usage: build_linux.py [-h] -c COMPILER -a ARCH -s SRC -o OUT [-k KCONFIG] [-q] [-t] ...

Build the Linux kernel using kernel-build-containers
Build Linux kernel using kernel-build-containers

positional arguments:
... additional arguments for 'make', can be separated by -- delimiter

options:
-h, --help show this help message and exit
-c {gcc-4.9,gcc-5,gcc-6,gcc-7,gcc-8,gcc-9,gcc-10,gcc-11,gcc-12,gcc-13,gcc-14,
clang-12,clang-13,clang-14,clang-15,clang-16,clang-17,all}
building compiler ('all' to build with each of them)
-a {x86_64,i386,arm64,arm}
build target architecture
-s src Linux kernel sources directory
-o out build output directory
-k kconfig path to kernel kconfig file
-q for running `make` in quiet mode
-t for running `make` in single-threaded mode (multi-threaded by default)
-c COMPILER, --compiler COMPILER
compiler for building (clang-5 / clang-6 / clang-7 / clang-8 / clang-9 / clang-10 / clang-11 / clang-12 / clang-13 / clang-14 / clang-15 /
clang-16 / clang-17gcc-4.9 / gcc-5 / gcc-6 / gcc-7 / gcc-8 / gcc-9 / gcc-10 / gcc-11 / gcc-12 / gcc-13 / gcc-14)
-a ARCH, --arch ARCH build target architecture (x86_64 / i386 / arm64 / arm)
-s SRC, --src SRC Linux kernel sources directory
-o OUT, --out OUT build output directory
-k KCONFIG, --kconfig KCONFIG
path to kernel kconfig file
-q, --quiet for running `make` in quiet mode
-t, --single-thread for running `make` in single-threaded mode (multi-threaded by default)
```

Configure the Linux kernel with `menuconfig` in the needed container:
__Configure the Linux kernel with `menuconfig` in the needed container:__

```console
$ python3 make_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13 -- menuconfig
$ python3 build_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13 -- menuconfig
[+] Going to build the Linux kernel for arm64
[+] Using "/home/a13x/linux-stable/experiment.config" as kernel config
[+] Using "/home/a13x/linux-stable/linux-stable" as Linux kernel sources directory
Expand Down Expand Up @@ -199,10 +271,10 @@ The finish_container.sh script returned 2
[+] Done, see the results
```

Build the Linux kernel in the needed container:
__Build the Linux kernel in the needed container:__

```console
$ python3 make_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13
$ python3 build_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13
[+] Going to build the Linux kernel for arm64
[+] Using "/home/a13x/linux-stable/experiment.config" as kernel config
[+] Using "/home/a13x/linux-stable/linux-stable" as Linux kernel sources directory
Expand Down Expand Up @@ -244,7 +316,7 @@ See the build log: /home/a13x/linux-stable/build_out/experiment__arm64__gcc-13/b
The tool returns an error if the kconfig file specified with `-k` differs from the `.config` in the build output directory:

```console
$ python3 make_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13
$ python3 build_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13
[+] Going to build the Linux kernel for arm64
[+] Using "/home/a13x/linux-stable/experiment.config" as kernel config
[+] Using "/home/a13x/linux-stable/linux-stable" as Linux kernel sources directory
Expand All @@ -269,14 +341,14 @@ $ diff ~/linux-stable/experiment.config ~/linux-stable/build_out/experiment__arm
---
> # CONFIG_NFC_S3FWRN5_I2C is not set
$ cp ~/linux-stable/build_out/experiment__arm64__gcc-13/.config ~/linux-stable/experiment.config
$ python3 make_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13
$ python3 build_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13
```

### Finishing with the container

That tool is used by `make_linux.py` for fast stopping the kernel build.
That tool is used by `build_linux.py` for fast stopping the kernel build.

Get help:
__Get help:__

```console
$ bash finish_container.sh
Expand All @@ -288,6 +360,64 @@ usage: finish_container.sh kill/nokill out_dir

### Removing created Docker images

__Remove all created images:__

```console
$ python3 manage_containers.py -r
```

__Expected output without running containers:__

```console
$ bash rm_containers.sh
$ python3 manage_containers.py -r
We need to use sudo to run the Docker

Ubuntu | GCC | Clang | Status
----------------------------------
16.04 | 4.9 | 5 | [-]
16.04 | 5 | 6 | [-]
18.04 | 6 | 7 | [-]
18.04 | 7 | 8 | [-]
20.04 | 8 | 9 | [-]
20.04 | 9 | 10 | [-]
20.04 | 10 | 11 | [-]
22.04 | 11 | 12 | [-]
22.04 | 12 | 13 | [-]
22.04 | 12 | 14 | [-]
23.04 | 13 | 15 | [-]
24.04 | 14 | 16 | [-]
24.04 | 14 | 17 | [-]
```

__Running container variation:__

__Expected output with running clang-12 container:__

You still have running containers, that can't be removed:
148254296e5d kernel-build-container:clang-12 "/bin/bash" 14 seconds ago Up 14 seconds determined_grothendieck


Ubuntu | GCC | Clang | Status
----------------------------------
16.04 | 4.9 | 5 | [-]
16.04 | 5 | 6 | [-]
18.04 | 6 | 7 | [-]
18.04 | 7 | 8 | [-]
20.04 | 8 | 9 | [-]
20.04 | 9 | 10 | [-]
20.04 | 10 | 11 | [-]
22.04 | 11 | 12 | [+]
22.04 | 12 | 13 | [-]
22.04 | 12 | 14 | [-]
23.04 | 13 | 15 | [-]
24.04 | 14 | 16 | [-]
24.04 | 14 | 17 | [-]
```

### Running tests for manage_containers.py (for developers):

```console
$ test_containers.sh
```

Results will be stored in htmlcov/index.html
Loading