@invarn/cibuild 2.9.1 → 2.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +88 -11
- package/dist/src/yaml/steps/android.d.ts.map +1 -1
- package/dist/src/yaml/steps/android.js +5 -0
- package/dist/src/yaml/steps/gradle-sdk-cmake.d.ts +28 -0
- package/dist/src/yaml/steps/gradle-sdk-cmake.d.ts.map +1 -0
- package/dist/src/yaml/steps/gradle-sdk-cmake.js +107 -0
- package/dist/src/yaml/steps/gradle-sdk-cmake.test.d.ts +2 -0
- package/dist/src/yaml/steps/gradle-sdk-cmake.test.d.ts.map +1 -0
- package/dist/src/yaml/steps/gradle-sdk-cmake.test.js +183 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../../../src/yaml/steps/android.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,OAAO,EAAE,gBAAgB,EAAuB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../../../src/yaml/steps/android.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,OAAO,EAAE,gBAAgB,EAAuB,MAAM,WAAW,CAAC;AAGlE,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,OA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CAAC,OAAO,CAAC;CAmM1G;AAED;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,gBAAgB;IAC/D,yBAAyB,CACvB,OAAO,EAAE,qBAAqB,EAC9B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3B,OAAO,EAAE,QAAQ,GAChB,qBAAqB,EAAE;IAiBpB,OAAO,CAAC,MAAM,EAAE,qBAAqB,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;CA8M9G;AAMD,MAAM,WAAW,8BAA8B;IAC7C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6IAA6I;IAC7I,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8GAA8G;IAC9G,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/B;AAED;;;GAGG;AACH,qBAAa,oCAAqC,SAAQ,gBAAgB;IACxE,yBAAyB,CACvB,OAAO,EAAE,8BAA8B,EACvC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3B,OAAO,EAAE,QAAQ,GAChB,qBAAqB,EAAE;IAM1B,UAAU,IAAI,UAAU,EAAE;IAOpB,OAAO,CAAC,MAAM,EAAE,8BAA8B,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;CA4EzH"}
|
|
@@ -10,6 +10,7 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
10
10
|
import { execSync } from 'node:child_process';
|
|
11
11
|
import { BaseStepExecutor, javaHomeVersionSpec } from './base.js';
|
|
12
12
|
import { gradleMemoryCommands } from './gradle-memory.js';
|
|
13
|
+
import { gradleSdkCmakeCommands } from './gradle-sdk-cmake.js';
|
|
13
14
|
/**
|
|
14
15
|
* Set Java version step executor
|
|
15
16
|
* Sets the Java version to use for Android builds
|
|
@@ -461,6 +462,7 @@ export class GradleBuildStepExecutor extends BaseStepExecutor {
|
|
|
461
462
|
commands.push(' exit 1');
|
|
462
463
|
commands.push('fi');
|
|
463
464
|
commands.push(...gradleMemoryCommands(this.getInput(inputs, 'jvmargs', ''), (v) => this.escapeBash(v), String(this.getInput(inputs, 'max_workers', '')).trim()));
|
|
465
|
+
commands.push(...gradleSdkCmakeCommands());
|
|
464
466
|
// Build gradle command
|
|
465
467
|
commands.push('');
|
|
466
468
|
commands.push('# Timestamp marker — used to collect only artifacts from this build');
|
|
@@ -783,6 +785,7 @@ export class AndroidLintStepExecutor extends BaseStepExecutor {
|
|
|
783
785
|
commands.push(' exit 1');
|
|
784
786
|
commands.push('fi');
|
|
785
787
|
commands.push(...gradleMemoryCommands(this.getInput(inputs, 'jvmargs', ''), (v) => this.escapeBash(v), String(this.getInput(inputs, 'max_workers', '')).trim()));
|
|
788
|
+
commands.push(...gradleSdkCmakeCommands());
|
|
786
789
|
// Build lint task name
|
|
787
790
|
commands.push('');
|
|
788
791
|
commands.push('# Run lint');
|
|
@@ -973,6 +976,7 @@ export class AndroidUnitTestStepExecutor extends BaseStepExecutor {
|
|
|
973
976
|
commands.push(' exit 1');
|
|
974
977
|
commands.push('fi');
|
|
975
978
|
commands.push(...gradleMemoryCommands(this.getInput(inputs, 'jvmargs', ''), (v) => this.escapeBash(v), String(this.getInput(inputs, 'max_workers', '')).trim()));
|
|
979
|
+
commands.push(...gradleSdkCmakeCommands());
|
|
976
980
|
// Build test task name
|
|
977
981
|
commands.push('');
|
|
978
982
|
commands.push('# Run unit tests');
|
|
@@ -1041,6 +1045,7 @@ export class AndroidBuildForUITestingStepExecutor extends BaseStepExecutor {
|
|
|
1041
1045
|
commands.push(' GRADLE_CMD="gradle"');
|
|
1042
1046
|
commands.push('fi');
|
|
1043
1047
|
commands.push(...gradleMemoryCommands(this.getInput(inputs, 'jvmargs', ''), (v) => this.escapeBash(v), String(this.getInput(inputs, 'max_workers', '')).trim()));
|
|
1048
|
+
commands.push(...gradleSdkCmakeCommands());
|
|
1044
1049
|
commands.push('');
|
|
1045
1050
|
// Build both app and test APKs
|
|
1046
1051
|
const appTask = gradleTaskPath(this.escapeBash(module), `assemble${variantCap}`);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDK CMake a build file pins, installed before Gradle runs.
|
|
3
|
+
*
|
|
4
|
+
* A module may pin its CMake (`android { externalNativeBuild { cmake {
|
|
5
|
+
* version = "3.31.6" } } }`). AGP downloads a pinned CMake it lacks, but only
|
|
6
|
+
* when it configures CMake, and a build's own Gradle task can need it first.
|
|
7
|
+
* IacobIonut01/ReFra's `buildHeifEncodeNative*` tasks run
|
|
8
|
+
* `scripts/native/build-heif-encode.sh`, which requires
|
|
9
|
+
* `$SDK/cmake/3.31.6/bin/cmake` and stops with "cmake 3.31.6 not found". The
|
|
10
|
+
* build images bake no SDK CMake, and a runner image cannot carry every
|
|
11
|
+
* version, so the version the project pins is installed with the SDK's own
|
|
12
|
+
* `sdkmanager` (its licences are accepted when the image is baked).
|
|
13
|
+
*
|
|
14
|
+
* Only literal versions inside a `cmake { }` block count. When there is no SDK
|
|
15
|
+
* or no sdkmanager, or the install fails, one line says so and the step goes
|
|
16
|
+
* on: AGP may still manage on its own.
|
|
17
|
+
*
|
|
18
|
+
* Written as shell functions so what ships is what the tests run. The shell
|
|
19
|
+
* is a raw string with no `${`, so every escape here is the one bash and awk
|
|
20
|
+
* read. Its lines start with "Android SDK:", never with a step-progress marker.
|
|
21
|
+
*/
|
|
22
|
+
export declare const GRADLE_SDK_CMAKE_FUNCTIONS: string;
|
|
23
|
+
/**
|
|
24
|
+
* The commands a Gradle step runs in the project directory before Gradle, so
|
|
25
|
+
* a CMake the project pins is in the SDK when its own tasks look for it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function gradleSdkCmakeCommands(): string[];
|
|
28
|
+
//# sourceMappingURL=gradle-sdk-cmake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gradle-sdk-cmake.d.ts","sourceRoot":"","sources":["../../../../src/yaml/steps/gradle-sdk-cmake.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,eAAO,MAAM,0BAA0B,QA6ErC,CAAC;AAEH;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAEjD"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDK CMake a build file pins, installed before Gradle runs.
|
|
3
|
+
*
|
|
4
|
+
* A module may pin its CMake (`android { externalNativeBuild { cmake {
|
|
5
|
+
* version = "3.31.6" } } }`). AGP downloads a pinned CMake it lacks, but only
|
|
6
|
+
* when it configures CMake, and a build's own Gradle task can need it first.
|
|
7
|
+
* IacobIonut01/ReFra's `buildHeifEncodeNative*` tasks run
|
|
8
|
+
* `scripts/native/build-heif-encode.sh`, which requires
|
|
9
|
+
* `$SDK/cmake/3.31.6/bin/cmake` and stops with "cmake 3.31.6 not found". The
|
|
10
|
+
* build images bake no SDK CMake, and a runner image cannot carry every
|
|
11
|
+
* version, so the version the project pins is installed with the SDK's own
|
|
12
|
+
* `sdkmanager` (its licences are accepted when the image is baked).
|
|
13
|
+
*
|
|
14
|
+
* Only literal versions inside a `cmake { }` block count. When there is no SDK
|
|
15
|
+
* or no sdkmanager, or the install fails, one line says so and the step goes
|
|
16
|
+
* on: AGP may still manage on its own.
|
|
17
|
+
*
|
|
18
|
+
* Written as shell functions so what ships is what the tests run. The shell
|
|
19
|
+
* is a raw string with no `${`, so every escape here is the one bash and awk
|
|
20
|
+
* read. Its lines start with "Android SDK:", never with a step-progress marker.
|
|
21
|
+
*/
|
|
22
|
+
export const GRADLE_SDK_CMAKE_FUNCTIONS = String.raw `# The CMake versions the project's build files pin, one per line as
|
|
23
|
+
# "<file>:<line><TAB><version>", first pin of each version only. Build
|
|
24
|
+
# outputs, .git and .gradle are not read.
|
|
25
|
+
cibuild_pinned_cmake_versions() {
|
|
26
|
+
find . \( -name build -o -name .git -o -name .gradle -o -name node_modules \) -prune -o \
|
|
27
|
+
-type f \( -name build.gradle -o -name build.gradle.kts \) -print 2>/dev/null | sort |
|
|
28
|
+
while IFS= read -r f; do
|
|
29
|
+
awk -v file="$f" '
|
|
30
|
+
FNR == 1 { inblk = 0; depth = 0 }
|
|
31
|
+
{
|
|
32
|
+
line = $0
|
|
33
|
+
sub(/\/\/.*$/, "", line)
|
|
34
|
+
if (!inblk && line ~ /(^|[^A-Za-z0-9_])cmake[ \t]*\{/) {
|
|
35
|
+
inblk = 1; depth = 0
|
|
36
|
+
sub(/.*(^|[^A-Za-z0-9_])cmake[ \t]*\{/, "{", line)
|
|
37
|
+
}
|
|
38
|
+
if (!inblk) next
|
|
39
|
+
if (match(line, /(^|[^A-Za-z0-9_.])version[ \t]*=?[ \t]*["\047][0-9]+\.[0-9]+(\.[0-9]+)?["\047]/)) {
|
|
40
|
+
v = substr(line, RSTART, RLENGTH); sub(/^.*version/, "", v); gsub(/[^0-9.]/, "", v)
|
|
41
|
+
print file ":" FNR "\t" v
|
|
42
|
+
}
|
|
43
|
+
depth += gsub(/\{/, "{", line) - gsub(/\}/, "}", line)
|
|
44
|
+
if (depth <= 0) inblk = 0
|
|
45
|
+
}
|
|
46
|
+
' "$f"
|
|
47
|
+
done | awk -F '\t' '!seen[$2]++'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
# The Android SDK: ANDROID_HOME, then ANDROID_SDK_ROOT, then local.properties'
|
|
51
|
+
# sdk.dir. Prints nothing when none names a directory.
|
|
52
|
+
cibuild_android_sdk_dir() {
|
|
53
|
+
local d
|
|
54
|
+
for d in "$ANDROID_HOME" "$ANDROID_SDK_ROOT"; do
|
|
55
|
+
if [ -n "$d" ] && [ -d "$d" ]; then echo "$d"; return 0; fi
|
|
56
|
+
done
|
|
57
|
+
if [ -f local.properties ]; then
|
|
58
|
+
d=$(sed -n 's/^[ \t]*sdk\.dir[ \t]*[=:][ \t]*//p' local.properties | tail -n 1 | sed 's/[ \t\r]*$//')
|
|
59
|
+
if [ -n "$d" ] && [ -d "$d" ]; then echo "$d"; return 0; fi
|
|
60
|
+
fi
|
|
61
|
+
return 0
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Installs every pinned CMake the SDK does not have. Never fails the step.
|
|
65
|
+
cibuild_install_pinned_cmake() {
|
|
66
|
+
local pins sdk sdkmanager at v out rc
|
|
67
|
+
pins=$(cibuild_pinned_cmake_versions)
|
|
68
|
+
[ -n "$pins" ] || return 0
|
|
69
|
+
sdk=$(cibuild_android_sdk_dir)
|
|
70
|
+
sdkmanager=""
|
|
71
|
+
if [ -n "$sdk" ] && [ -x "$sdk/cmdline-tools/latest/bin/sdkmanager" ]; then
|
|
72
|
+
sdkmanager="$sdk/cmdline-tools/latest/bin/sdkmanager"
|
|
73
|
+
elif [ -n "$sdk" ] && command -v sdkmanager >/dev/null 2>&1; then
|
|
74
|
+
sdkmanager=$(command -v sdkmanager)
|
|
75
|
+
fi
|
|
76
|
+
while IFS=' ' read -r at v; do
|
|
77
|
+
if [ -n "$sdk" ] && [ -x "$sdk/cmake/$v/bin/cmake" ]; then continue; fi
|
|
78
|
+
if [ -z "$sdk" ]; then
|
|
79
|
+
echo "Android SDK: $at pins cmake;$v, but no Android SDK was found (ANDROID_HOME, ANDROID_SDK_ROOT, local.properties sdk.dir), so it is not installed here."
|
|
80
|
+
continue
|
|
81
|
+
fi
|
|
82
|
+
if [ -z "$sdkmanager" ]; then
|
|
83
|
+
echo "Android SDK: $at pins cmake;$v, but $sdk has no sdkmanager, so it is not installed here."
|
|
84
|
+
continue
|
|
85
|
+
fi
|
|
86
|
+
echo "Android SDK: installing cmake;$v, which $at pins (externalNativeBuild cmake version) and this SDK does not have."
|
|
87
|
+
# Licences are answered from a process substitution, not a pipe, so
|
|
88
|
+
# neither set -e nor pipefail turns yes's SIGPIPE into a failure.
|
|
89
|
+
rc=0
|
|
90
|
+
out=$("$sdkmanager" "--sdk_root=$sdk" "cmake;$v" < <(yes 2>/dev/null) 2>&1) || rc=$?
|
|
91
|
+
if [ "$rc" -eq 0 ] && [ -x "$sdk/cmake/$v/bin/cmake" ]; then
|
|
92
|
+
echo "Android SDK: cmake;$v installed."
|
|
93
|
+
else
|
|
94
|
+
echo "Android SDK: installing cmake;$v failed (sdkmanager exit $rc); Gradle runs anyway:"
|
|
95
|
+
printf '%s\n' "$out" | tail -n 5 | sed 's/^/ /'
|
|
96
|
+
fi
|
|
97
|
+
done <<< "$pins"
|
|
98
|
+
return 0
|
|
99
|
+
}`;
|
|
100
|
+
/**
|
|
101
|
+
* The commands a Gradle step runs in the project directory before Gradle, so
|
|
102
|
+
* a CMake the project pins is in the SDK when its own tasks look for it.
|
|
103
|
+
*/
|
|
104
|
+
export function gradleSdkCmakeCommands() {
|
|
105
|
+
return ['', GRADLE_SDK_CMAKE_FUNCTIONS, '', 'cibuild_install_pinned_cmake'];
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=gradle-sdk-cmake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gradle-sdk-cmake.test.d.ts","sourceRoot":"","sources":["../../../../src/yaml/steps/gradle-sdk-cmake.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDK CMake a build file pins, installed before Gradle runs.
|
|
3
|
+
*
|
|
4
|
+
* IacobIonut01/ReFra pins `externalNativeBuild.cmake.version = "3.31.6"`, and
|
|
5
|
+
* its own native script (a Gradle task that runs before AGP configures CMake)
|
|
6
|
+
* requires `$SDK/cmake/3.31.6/bin/cmake`. AGP would download the pinned CMake,
|
|
7
|
+
* but only at its own configure step, which comes too late, and the build
|
|
8
|
+
* image bakes no SDK CMake. So the build failed with "cmake 3.31.6 not found".
|
|
9
|
+
*
|
|
10
|
+
* The shell under test is the one that ships: it is executed here, not
|
|
11
|
+
* re-implemented.
|
|
12
|
+
*/
|
|
13
|
+
import { execFileSync } from "node:child_process";
|
|
14
|
+
import { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { dirname, join } from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
import { AndroidBuildForUITestingStepExecutor, AndroidLintStepExecutor, AndroidUnitTestStepExecutor, GradleBuildStepExecutor, } from "./android.js";
|
|
19
|
+
import { GRADLE_SDK_CMAKE_FUNCTIONS } from "./gradle-sdk-cmake.js";
|
|
20
|
+
import { testConfig } from "./test-config.js";
|
|
21
|
+
const FIXTURES = join(dirname(fileURLToPath(import.meta.url)), "../../../test/fixtures/gradle-sdk-cmake");
|
|
22
|
+
let dir;
|
|
23
|
+
let sdk;
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
dir = mkdtempSync(join(tmpdir(), "cibuild-sdk-cmake-"));
|
|
26
|
+
sdk = join(dir, "sdk");
|
|
27
|
+
mkdirSync(join(dir, "project", "app"), { recursive: true });
|
|
28
|
+
mkdirSync(sdk);
|
|
29
|
+
});
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
rmSync(dir, { recursive: true, force: true });
|
|
32
|
+
});
|
|
33
|
+
/** A fake sdkmanager: records its arguments and installs what it is asked for. */
|
|
34
|
+
function fakeSdkmanager(exitCode = 0) {
|
|
35
|
+
const bin = join(sdk, "cmdline-tools", "latest", "bin");
|
|
36
|
+
mkdirSync(bin, { recursive: true });
|
|
37
|
+
const path = join(bin, "sdkmanager");
|
|
38
|
+
writeFileSync(path, `#!/bin/bash
|
|
39
|
+
echo "$*" >> "${dir}/sdkmanager-args"
|
|
40
|
+
[ ${exitCode} -eq 0 ] || { echo "Warning: Failed to find package"; exit ${exitCode}; }
|
|
41
|
+
for a in "$@"; do
|
|
42
|
+
case "$a" in
|
|
43
|
+
cmake\\;*) v="\${a#cmake;}"; mkdir -p "${sdk}/cmake/$v/bin"; printf '#!/bin/sh\\n' > "${sdk}/cmake/$v/bin/cmake"; chmod +x "${sdk}/cmake/$v/bin/cmake" ;;
|
|
44
|
+
esac
|
|
45
|
+
done
|
|
46
|
+
`);
|
|
47
|
+
chmodSync(path, 0o755);
|
|
48
|
+
return path;
|
|
49
|
+
}
|
|
50
|
+
/** Run the shipped install in the project directory, with the SDK in ANDROID_HOME. */
|
|
51
|
+
function install(env = { ANDROID_HOME: sdk }) {
|
|
52
|
+
const script = `${GRADLE_SDK_CMAKE_FUNCTIONS}
|
|
53
|
+
cibuild_install_pinned_cmake
|
|
54
|
+
echo "after: $?"`;
|
|
55
|
+
try {
|
|
56
|
+
const stdout = execFileSync("bash", ["-c", script], {
|
|
57
|
+
cwd: join(dir, "project"),
|
|
58
|
+
encoding: "utf-8",
|
|
59
|
+
env: { PATH: "/usr/bin:/bin", ...env },
|
|
60
|
+
});
|
|
61
|
+
return { status: 0, stdout };
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
const err = e;
|
|
65
|
+
return { status: err.status, stdout: err.stdout };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function sdkmanagerArgs() {
|
|
69
|
+
const file = join(dir, "sdkmanager-args");
|
|
70
|
+
return existsSync(file) ? readFileSync(file, "utf-8").trim().split("\n") : [];
|
|
71
|
+
}
|
|
72
|
+
describe("cibuild_install_pinned_cmake", () => {
|
|
73
|
+
test("ReFra: the pinned cmake;3.31.6 is installed, and one line says why", () => {
|
|
74
|
+
copyFileSync(join(FIXTURES, "refra.app.build.gradle.kts"), join(dir, "project", "app", "build.gradle.kts"));
|
|
75
|
+
fakeSdkmanager();
|
|
76
|
+
const run = install();
|
|
77
|
+
expect(sdkmanagerArgs()).toEqual([`--sdk_root=${sdk} cmake;3.31.6`]);
|
|
78
|
+
expect(existsSync(join(sdk, "cmake", "3.31.6", "bin", "cmake"))).toBe(true);
|
|
79
|
+
expect(run.stdout).toContain("Android SDK: installing cmake;3.31.6, which ./app/build.gradle.kts:47 pins (externalNativeBuild cmake version) and this SDK does not have.");
|
|
80
|
+
expect(run.stdout).toContain("Android SDK: cmake;3.31.6 installed.");
|
|
81
|
+
expect(run.stdout).toContain("after: 0");
|
|
82
|
+
});
|
|
83
|
+
test("a CMake the SDK already has is left alone, and nothing is printed", () => {
|
|
84
|
+
copyFileSync(join(FIXTURES, "refra.app.build.gradle.kts"), join(dir, "project", "app", "build.gradle.kts"));
|
|
85
|
+
fakeSdkmanager();
|
|
86
|
+
mkdirSync(join(sdk, "cmake", "3.31.6", "bin"), { recursive: true });
|
|
87
|
+
writeFileSync(join(sdk, "cmake", "3.31.6", "bin", "cmake"), "#!/bin/sh\n");
|
|
88
|
+
chmodSync(join(sdk, "cmake", "3.31.6", "bin", "cmake"), 0o755);
|
|
89
|
+
const run = install();
|
|
90
|
+
expect(sdkmanagerArgs()).toEqual([]);
|
|
91
|
+
expect(run.stdout).not.toContain("Android SDK:");
|
|
92
|
+
});
|
|
93
|
+
test("Groovy's `version \"x\"`, and only inside a cmake block, and never in a comment", () => {
|
|
94
|
+
writeFileSync(join(dir, "project", "app", "build.gradle"), [
|
|
95
|
+
"version = '9.9.9'",
|
|
96
|
+
"android {",
|
|
97
|
+
" defaultConfig {",
|
|
98
|
+
" versionName \"1.2.3\"",
|
|
99
|
+
" externalNativeBuild { cmake { cppFlags '-std=c++17' } }",
|
|
100
|
+
" }",
|
|
101
|
+
" externalNativeBuild {",
|
|
102
|
+
" cmake {",
|
|
103
|
+
" path 'src/main/cpp/CMakeLists.txt'",
|
|
104
|
+
" // version '3.10.2'",
|
|
105
|
+
" version '3.22.1'",
|
|
106
|
+
" }",
|
|
107
|
+
" }",
|
|
108
|
+
" ndkVersion '27.0.12077973'",
|
|
109
|
+
"}",
|
|
110
|
+
"",
|
|
111
|
+
].join("\n"));
|
|
112
|
+
fakeSdkmanager();
|
|
113
|
+
install();
|
|
114
|
+
expect(sdkmanagerArgs()).toEqual([`--sdk_root=${sdk} cmake;3.22.1`]);
|
|
115
|
+
});
|
|
116
|
+
test("a one-line cmake block, two modules pinning the same version, and build outputs skipped", () => {
|
|
117
|
+
writeFileSync(join(dir, "project", "app", "build.gradle.kts"), 'android { externalNativeBuild { cmake { version = "3.31.6" } } }\n');
|
|
118
|
+
mkdirSync(join(dir, "project", "lib"));
|
|
119
|
+
writeFileSync(join(dir, "project", "lib", "build.gradle.kts"), 'android {\n externalNativeBuild {\n cmake {\n version = "3.31.6"\n }\n }\n}\n');
|
|
120
|
+
mkdirSync(join(dir, "project", "app", "build", "tmp"), { recursive: true });
|
|
121
|
+
writeFileSync(join(dir, "project", "app", "build", "tmp", "build.gradle.kts"), 'cmake { version = "3.6.0" }\n');
|
|
122
|
+
fakeSdkmanager();
|
|
123
|
+
install();
|
|
124
|
+
expect(sdkmanagerArgs()).toEqual([`--sdk_root=${sdk} cmake;3.31.6`]);
|
|
125
|
+
});
|
|
126
|
+
test("a project that pins no CMake does nothing", () => {
|
|
127
|
+
writeFileSync(join(dir, "project", "app", "build.gradle.kts"), 'android { compileSdk = 36 }\n');
|
|
128
|
+
fakeSdkmanager();
|
|
129
|
+
const run = install();
|
|
130
|
+
expect(sdkmanagerArgs()).toEqual([]);
|
|
131
|
+
expect(run.stdout).toBe("after: 0\n");
|
|
132
|
+
});
|
|
133
|
+
test("the SDK from local.properties when ANDROID_HOME is unset", () => {
|
|
134
|
+
copyFileSync(join(FIXTURES, "refra.app.build.gradle.kts"), join(dir, "project", "app", "build.gradle.kts"));
|
|
135
|
+
writeFileSync(join(dir, "project", "local.properties"), `sdk.dir=${sdk}\n`);
|
|
136
|
+
fakeSdkmanager();
|
|
137
|
+
install({});
|
|
138
|
+
expect(sdkmanagerArgs()).toEqual([`--sdk_root=${sdk} cmake;3.31.6`]);
|
|
139
|
+
});
|
|
140
|
+
test("no SDK to install into: says so, and the step goes on", () => {
|
|
141
|
+
copyFileSync(join(FIXTURES, "refra.app.build.gradle.kts"), join(dir, "project", "app", "build.gradle.kts"));
|
|
142
|
+
const run = install({});
|
|
143
|
+
expect(run.stdout).toContain("Android SDK: ./app/build.gradle.kts:47 pins cmake;3.31.6, but no Android SDK was found (ANDROID_HOME, ANDROID_SDK_ROOT, local.properties sdk.dir), so it is not installed here.");
|
|
144
|
+
expect(run.stdout).toContain("after: 0");
|
|
145
|
+
});
|
|
146
|
+
test("an SDK without sdkmanager: says so, and the step goes on", () => {
|
|
147
|
+
copyFileSync(join(FIXTURES, "refra.app.build.gradle.kts"), join(dir, "project", "app", "build.gradle.kts"));
|
|
148
|
+
const run = install();
|
|
149
|
+
expect(run.stdout).toContain(`Android SDK: ./app/build.gradle.kts:47 pins cmake;3.31.6, but ${sdk} has no sdkmanager, so it is not installed here.`);
|
|
150
|
+
expect(run.stdout).toContain("after: 0");
|
|
151
|
+
});
|
|
152
|
+
test("a failed install says so, with sdkmanager's words, and the step goes on", () => {
|
|
153
|
+
copyFileSync(join(FIXTURES, "refra.app.build.gradle.kts"), join(dir, "project", "app", "build.gradle.kts"));
|
|
154
|
+
fakeSdkmanager(1);
|
|
155
|
+
const run = install();
|
|
156
|
+
expect(run.stdout).toContain("Android SDK: installing cmake;3.31.6 failed (sdkmanager exit 1); Gradle runs anyway:");
|
|
157
|
+
expect(run.stdout).toContain(" Warning: Failed to find package");
|
|
158
|
+
expect(run.stdout).toContain("after: 0");
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe("the Gradle steps", () => {
|
|
162
|
+
test("every Gradle step installs the pinned CMake before Gradle runs", async () => {
|
|
163
|
+
const steps = [
|
|
164
|
+
await new GradleBuildStepExecutor().execute({ gradle_task: "assembleDebug" }, {}, testConfig),
|
|
165
|
+
await new AndroidLintStepExecutor().execute({}, {}, testConfig),
|
|
166
|
+
await new AndroidUnitTestStepExecutor().execute({}, {}, testConfig),
|
|
167
|
+
await new AndroidBuildForUITestingStepExecutor().execute({}, {}, testConfig),
|
|
168
|
+
];
|
|
169
|
+
for (const step of steps) {
|
|
170
|
+
const script = step.script;
|
|
171
|
+
const at = script.indexOf("\ncibuild_install_pinned_cmake\n");
|
|
172
|
+
expect(at).toBeGreaterThan(-1);
|
|
173
|
+
expect(at).toBeLessThan(script.indexOf("$GRADLE_CMD "));
|
|
174
|
+
execFileSync("bash", ["-n", "-c", script]);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
test("no line the functions print can be taken for a step-progress marker", () => {
|
|
178
|
+
for (const line of GRADLE_SDK_CMAKE_FUNCTIONS.split("\n")) {
|
|
179
|
+
expect(line).not.toMatch(/INVARN_STEP|\[step_/);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
//# sourceMappingURL=gradle-sdk-cmake.test.js.map
|