diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2025-05-07 12:10:55 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2025-05-07 16:39:59 +0200 |
commit | b909c514866f1f0713edd831d183e4fa1e5c91f5 (patch) | |
tree | 3654f3655cb10a002c499106bfb01ee62afe9e62 | |
parent | eff965fdd8f03668f99d9c90ea9a3f81dabc3b66 (diff) | |
download | rules-cc-b909c514866f1f0713edd831d183e4fa1e5c91f5.tar.gz |
Do not assume out_dirs exist
-rw-r--r-- | CC/foreign/cmake/EXPRESSIONS | 2 | ||||
-rw-r--r-- | CC/foreign/make/EXPRESSIONS | 2 | ||||
-rwxr-xr-x | CC/include_scan | 2 | ||||
-rw-r--r-- | CC/include_scan.c | 17 | ||||
-rwxr-xr-x | CC/include_scan.py | 1 |
5 files changed, 20 insertions, 4 deletions
diff --git a/CC/foreign/cmake/EXPRESSIONS b/CC/foreign/cmake/EXPRESSIONS index e0ceab2..e8217dd 100644 --- a/CC/foreign/cmake/EXPRESSIONS +++ b/CC/foreign/cmake/EXPRESSIONS @@ -302,7 +302,7 @@ { "type": "++" , "$1": [ [ "set -eu" - , "mkdir scratch" + , "mkdir -p scratch install" , "readonly ROOT=\"$(pwd)\"" , "export TMPDIR=\"$(pwd)/scratch\"" , "export TOOLCHAIN=\"$(pwd)/toolchain\"" diff --git a/CC/foreign/make/EXPRESSIONS b/CC/foreign/make/EXPRESSIONS index 57b0a94..55d9fa8 100644 --- a/CC/foreign/make/EXPRESSIONS +++ b/CC/foreign/make/EXPRESSIONS @@ -277,7 +277,7 @@ { "type": "++" , "$1": [ [ "set -eu" - , "mkdir scratch" + , "mkdir -p scratch install" , "readonly ROOT=\"$(pwd)\"" , "export TMPDIR=\"$(pwd)/scratch\"" , "export DESTDIR=\"$(pwd)/install\"" diff --git a/CC/include_scan b/CC/include_scan index b7c1590..aaaa77c 100755 --- a/CC/include_scan +++ b/CC/include_scan @@ -30,6 +30,8 @@ set -eu readonly OUT_DIR="$1" shift +mkdir -p "${OUT_DIR}/include" + STDOUT="$("$@")" || exit $? for FILE in $(echo "$STDOUT" | tr ' ' '\n' | sort | uniq); do FILE="$(realpath -s -m --relative-to=. "${FILE}")" diff --git a/CC/include_scan.c b/CC/include_scan.c index ea013ad..8652fc0 100644 --- a/CC/include_scan.c +++ b/CC/include_scan.c @@ -94,11 +94,13 @@ int main(int argc, const char *argv[]) { int retval = 0; char *path = NULL; char *prefix; + char *outdir; size_t prefix_len = 0; + size_t outdir_len = 0; struct IncludeList incl; if (argc < 3) { - fprintf(stderr, "usage: %s PREFIX FILE ARGV...\n", argv[0]); + fprintf(stderr, "usage: %s OUT_DIR ARGV...\n", argv[0]); fprintf(stderr, "Missing arguments\n"); exit(EXIT_FAILURE); } @@ -130,9 +132,20 @@ int main(int argc, const char *argv[]) { strcat(prefix + prefix_len, "/"); prefix_len += 1; parse_paths(&incl, fd[0], "include/", prefix); - free(prefix); close(fd[0]); + /* create output directory "<prefix>/include" */ + outdir_len = prefix_len + 8 /* strlen("include/") */; + outdir = (char *)calloc(outdir_len + 1, sizeof(char)); + strcat(outdir, prefix); + strcat(outdir + prefix_len, "include/"); + if (helper_mkdir_p(outdir, 0755) != 0) { + fprintf(stderr, "Failed to create output directory\n"); + return 1; + } + free(prefix); + free(outdir); + /* wait for child to finish */ while (1) { if (waitpid(pid, &status, 0) == -1) { diff --git a/CC/include_scan.py b/CC/include_scan.py index e169ec5..d99392b 100755 --- a/CC/include_scan.py +++ b/CC/include_scan.py @@ -41,6 +41,7 @@ def include_scan(out_dir: str, cmd: list[str]): paths = {os.path.normpath(i) for i in items.split(' ')} includes = {p for p in paths if p.startswith('include/')} + os.makedirs(os.path.join(out_dir, 'include'), exist_ok=True) for path in includes: out_path = os.path.join(out_dir, path) try: |