Skip to content

Commit 06b14c0

Browse files
authored
Merge pull request #8486 from martinkunkel2/devcontainer
Add devcontainer setup and small related fixes
2 parents 6cee2cb + e41c140 commit 06b14c0

File tree

9 files changed

+141
-6
lines changed

9 files changed

+141
-6
lines changed

.devcontainer/Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM mcr.microsoft.com/devcontainers/base:ubuntu-24.04
2+
3+
# install gnu coreutils test dependencies
4+
RUN apt-get update \
5+
&& apt-get install -y --no-install-recommends \
6+
attr \
7+
autoconf \
8+
automake \
9+
autopoint \
10+
bison \
11+
g++ \
12+
gcc \
13+
gdb \
14+
gperf \
15+
jq \
16+
libacl1-dev \
17+
libattr1-dev \
18+
libcap-dev \
19+
libexpect-perl \
20+
libselinux1-dev \
21+
python3-pyinotify \
22+
quilt \
23+
texinfo \
24+
valgrind \
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
# install dependencies for uutils
28+
RUN apt-get update \
29+
&& apt-get install -y --no-install-recommends \
30+
clang \
31+
gdb \
32+
python3-pip \
33+
&& rm -rf /var/lib/apt/lists/*
34+
35+
# pre-commit
36+
RUN pip3 install --break-system-packages pre-commit

.devcontainer/devcontainer.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "uutils-devcontainer",
3+
"build": {
4+
"dockerfile": "Dockerfile"
5+
},
6+
"features": {
7+
"ghcr.io/devcontainers/features/rust:1":
8+
{
9+
"version": "latest",
10+
"profile": "default",
11+
"components": "llvm-tools-preview"
12+
}
13+
},
14+
"onCreateCommand": {
15+
"install pre-commit hooks": "pre-commit install",
16+
"update permissions for gnu coreutils volume": "sudo chown vscode:vscode ${containerWorkspaceFolder}/../gnu"
17+
},
18+
"mounts": [
19+
{
20+
"source": "devcontainer-gnu-coreutils-${devcontainerId}",
21+
"target": "${containerWorkspaceFolder}/../gnu",
22+
"type": "volume"
23+
}
24+
],
25+
"customizations": {
26+
"vscode": {
27+
"extensions": [
28+
"streetsidesoftware.code-spell-checker",
29+
"foxundermoon.shell-format",
30+
"ms-vscode.cpptools"
31+
],
32+
"settings": {
33+
"rust-analyzer.check.command": "clippy",
34+
"rust-analyzer.debug.engine": "ms-vscode.cpptools",
35+
"rust-analyzer.debug.engineSettings": {
36+
"cppdbg": {
37+
"miDebuggerPath": "rust-gdb",
38+
"setupCommands": [
39+
{
40+
"description": "Enable pretty-printing for gdb",
41+
"text": "-enable-pretty-printing",
42+
"ignoreFailures": false
43+
}
44+
]
45+
}
46+
}
47+
}
48+
}
49+
}
50+
}

.github/workflows/devcontainer.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Devcontainer
2+
3+
# spell-checker:ignore devcontainers nextest
4+
5+
on:
6+
pull_request:
7+
push:
8+
branches:
9+
- '*'
10+
11+
permissions:
12+
contents: read # to fetch code (actions/checkout)
13+
14+
# End the current execution if there is a new changeset in the PR.
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
18+
19+
jobs:
20+
test:
21+
name: Verify devcontainer
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 45
24+
steps:
25+
- uses: actions/checkout@v5
26+
with:
27+
persist-credentials: false
28+
- name: Run test in devcontainer
29+
uses: devcontainers/ci@v0.3
30+
with:
31+
push: never
32+
runCmd: |
33+
curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
34+
cargo nextest run --hide-progress-bar --profile ci

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ repos:
77
- id: check-added-large-files
88
- id: check-executables-have-shebangs
99
- id: check-json
10+
exclude: '.vscode/cSpell\.json' # cSpell.json uses comments
1011
- id: check-shebang-scripts-are-executable
1112
exclude: '.+\.rs' # would be triggered by #![some_attribute]
1213
- id: check-symlinks

.vscode/cSpell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"vendor/**",
2929
"**/*.svg",
3030
"src/uu/*/locales/*.ftl",
31-
"src/uucore/locales/*.ftl"
31+
"src/uucore/locales/*.ftl",
32+
".devcontainer/**"
3233
],
3334

3435
"enableGlobDot": true,

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{ "cSpell.import": [".vscode/cspell.json"] }
1+
{
2+
"cSpell.import": [
3+
"./.vscode/cSpell.json"
4+
]
5+
}

DEVELOPMENT.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ This section will explain how to install and configure these tools.
2525
We also have an extensive CI that uses these tools and will check your code before it can be merged.
2626
The next section [Testing](#testing) will explain how to run those checks locally to avoid waiting for the CI.
2727

28+
As an alternative to host installation of the tools, you can open the project with the provided development container configuration.
29+
For more information about development containers, see the [Visual Studio Code Dev Containers documentation](https://code.visualstudio.com/docs/devcontainers/containers).
30+
2831
### Rust toolchain
2932

3033
[Install Rust](https://www.rust-lang.org/tools/install)

tests/by-util/test_dd.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,9 @@ fn test_skip_past_dev() {
15591559
// NOTE: This test intends to trigger code which can only be reached with root permissions.
15601560
let ts = TestScenario::new(util_name!());
15611561

1562-
if let Ok(result) = run_ucmd_as_root_with_stdin_stdout(
1562+
if !ts.fixtures.file_exists("/dev/sda1") {
1563+
print!("Test skipped; no /dev/sda1 device found");
1564+
} else if let Ok(result) = run_ucmd_as_root_with_stdin_stdout(
15631565
&ts,
15641566
&["bs=1", "skip=10000000000000000", "count=0", "status=noxfer"],
15651567
Some("/dev/sda1"),
@@ -1581,7 +1583,9 @@ fn test_seek_past_dev() {
15811583
// NOTE: This test intends to trigger code which can only be reached with root permissions.
15821584
let ts = TestScenario::new(util_name!());
15831585

1584-
if let Ok(result) = run_ucmd_as_root_with_stdin_stdout(
1586+
if !ts.fixtures.file_exists("/dev/sda1") {
1587+
print!("Test skipped; no /dev/sda1 device found");
1588+
} else if let Ok(result) = run_ucmd_as_root_with_stdin_stdout(
15851589
&ts,
15861590
&["bs=1", "seek=10000000000000000", "count=0", "status=noxfer"],
15871591
None,

util/build-gnu.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ fi
7171

7272
release_tag_GNU="v9.7"
7373

74-
if test ! -d "${path_GNU}"; then
74+
# check if the GNU coreutils has been cloned, if not print instructions
75+
# note: the ${path_GNU} might already exist, so we check for the .git directory
76+
if test ! -d "${path_GNU}/.git"; then
7577
echo "Could not find GNU coreutils (expected at '${path_GNU}')"
7678
echo "Run the following to download into the expected path:"
7779
echo "git clone --recurse-submodules https://github.com/coreutils/coreutils.git \"${path_GNU}\""
@@ -136,7 +138,7 @@ cd -
136138
touch g
137139
echo "stat with selinux support"
138140
./target/debug/stat -c%C g || true
139-
141+
rm g
140142

141143
cp "${UU_BUILD_DIR}/install" "${UU_BUILD_DIR}/ginstall" # The GNU tests rename this script before running, to avoid confusion with the make target
142144
# Create *sum binaries

0 commit comments

Comments
 (0)