@invarn/cibuild 2.8.5 → 2.8.7
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 +11 -11
- package/dist/src/shared/detect-project.d.ts +3 -1
- package/dist/src/shared/detect-project.d.ts.map +1 -1
- package/dist/src/shared/detect-project.js +10 -7
- package/dist/src/shared/detect-project.test.js +37 -2
- package/dist/src/shared/gradle-settings.d.ts +17 -0
- package/dist/src/shared/gradle-settings.d.ts.map +1 -1
- package/dist/src/shared/gradle-settings.js +72 -0
- package/dist/src/shared/gradle-settings.test.d.ts +2 -0
- package/dist/src/shared/gradle-settings.test.d.ts.map +1 -0
- package/dist/src/shared/gradle-settings.test.js +65 -0
- package/dist/src/yaml/steps/android.d.ts +16 -0
- 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-memory.d.ts +53 -0
- package/dist/src/yaml/steps/gradle-memory.d.ts.map +1 -0
- package/dist/src/yaml/steps/gradle-memory.js +300 -0
- package/dist/src/yaml/steps/gradle-memory.test.d.ts +2 -0
- package/dist/src/yaml/steps/gradle-memory.test.d.ts.map +1 -0
- package/dist/src/yaml/steps/gradle-memory.test.js +275 -0
- package/package.json +1 -1
|
@@ -38,7 +38,9 @@ export declare function xcodeContainersIn(dir: string): string[];
|
|
|
38
38
|
*
|
|
39
39
|
* KMM is checked before Android because both have Gradle files, and it is
|
|
40
40
|
* decided by what the repository *is*: a module that applies the Kotlin
|
|
41
|
-
* Multiplatform plugin
|
|
41
|
+
* Multiplatform plugin or declares a Kotlin/Native Apple target in its own
|
|
42
|
+
* build file (garfiec/Librechat-Mobile applies the plugin only through a
|
|
43
|
+
* convention plugin), and an Apple consumer within one directory of the
|
|
42
44
|
* root. The three conventional directory names (`shared`, `composeApp`,
|
|
43
45
|
* `iosApp`) used to be the whole rule, and were wrong in both directions —
|
|
44
46
|
* `joreilly/PeopleInSpace` (`common` + `PeopleInSpaceSwiftUI/`) and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-project.d.ts","sourceRoot":"","sources":["../../../src/shared/detect-project.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,KAAK,GAAG,KAAK,CAAC;AAoB1D,iBAAS,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAM1C;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAYtD;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAYvD;
|
|
1
|
+
{"version":3,"file":"detect-project.d.ts","sourceRoot":"","sources":["../../../src/shared/detect-project.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,KAAK,GAAG,KAAK,CAAC;AAoB1D,iBAAS,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAM1C;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAYtD;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAYvD;AAwED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CA4B7E;AAED,oEAAoE;AACpE,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { declaresKotlinMultiplatform, parseSettingsModules, } from "./gradle-settings.js";
|
|
4
4
|
/** Directories that hold a copy of a project rather than the source of it. */
|
|
5
5
|
const NON_SOURCE_DIRS = new Set([
|
|
6
6
|
".git",
|
|
@@ -141,18 +141,19 @@ function hasAppleConsumerWithinOneLevel(root) {
|
|
|
141
141
|
}
|
|
142
142
|
return false;
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
/** The plugin, or a Kotlin/Native Apple target, in the module's own build file. */
|
|
145
|
+
function moduleIsMultiplatform(root, module) {
|
|
145
146
|
for (const name of ["build.gradle.kts", "build.gradle"]) {
|
|
146
147
|
const content = readOrNull(resolve(root, module, name));
|
|
147
|
-
if (content !== null &&
|
|
148
|
+
if (content !== null && declaresKotlinMultiplatform(content))
|
|
148
149
|
return true;
|
|
149
150
|
}
|
|
150
151
|
return false;
|
|
151
152
|
}
|
|
152
|
-
/** True when any module this build includes
|
|
153
|
+
/** True when any module this build includes is Kotlin Multiplatform. */
|
|
153
154
|
function hasMultiplatformModule(root) {
|
|
154
155
|
for (const module of CONVENTIONAL_MULTIPLATFORM_MODULES) {
|
|
155
|
-
if (
|
|
156
|
+
if (moduleIsMultiplatform(root, module))
|
|
156
157
|
return true;
|
|
157
158
|
}
|
|
158
159
|
for (const name of ["settings.gradle", "settings.gradle.kts"]) {
|
|
@@ -160,7 +161,7 @@ function hasMultiplatformModule(root) {
|
|
|
160
161
|
if (content === null)
|
|
161
162
|
continue;
|
|
162
163
|
for (const module of parseSettingsModules(content)) {
|
|
163
|
-
if (
|
|
164
|
+
if (moduleIsMultiplatform(root, module))
|
|
164
165
|
return true;
|
|
165
166
|
}
|
|
166
167
|
}
|
|
@@ -172,7 +173,9 @@ function hasMultiplatformModule(root) {
|
|
|
172
173
|
*
|
|
173
174
|
* KMM is checked before Android because both have Gradle files, and it is
|
|
174
175
|
* decided by what the repository *is*: a module that applies the Kotlin
|
|
175
|
-
* Multiplatform plugin
|
|
176
|
+
* Multiplatform plugin or declares a Kotlin/Native Apple target in its own
|
|
177
|
+
* build file (garfiec/Librechat-Mobile applies the plugin only through a
|
|
178
|
+
* convention plugin), and an Apple consumer within one directory of the
|
|
176
179
|
* root. The three conventional directory names (`shared`, `composeApp`,
|
|
177
180
|
* `iosApp`) used to be the whole rule, and were wrong in both directions —
|
|
178
181
|
* `joreilly/PeopleInSpace` (`common` + `PeopleInSpaceSwiftUI/`) and
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
* `shared` module was called KMM and handed a pipeline that builds an iOS app
|
|
11
11
|
* it does not have.
|
|
12
12
|
*/
|
|
13
|
-
import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from "node:fs";
|
|
14
|
-
import { join } from "node:path";
|
|
13
|
+
import { mkdtempSync, rmSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
15
|
import { tmpdir } from "node:os";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
16
17
|
import { detectMobileProjectRoot } from "./detect-project.js";
|
|
17
18
|
let root;
|
|
18
19
|
beforeEach(() => {
|
|
@@ -67,6 +68,27 @@ describe("detectMobileProjectRoot", () => {
|
|
|
67
68
|
xcodeProject("iosApp", "iosApp");
|
|
68
69
|
expect(detectMobileProjectRoot(root)).toBe("kmm");
|
|
69
70
|
});
|
|
71
|
+
// The build files of garfiec/Librechat-Mobile's `:shared` and
|
|
72
|
+
// openMF/mifos-mobile's `:cmp-shared` at their pins. Each applies Kotlin
|
|
73
|
+
// Multiplatform only through a convention plugin, and declares Apple
|
|
74
|
+
// targets in its own file.
|
|
75
|
+
const APPLE_TARGETS = join(dirname(fileURLToPath(import.meta.url)), "../../test/fixtures/kotlin-native-apple-targets");
|
|
76
|
+
const appleTargets = (name) => readFileSync(join(APPLE_TARGETS, name), "utf-8");
|
|
77
|
+
test("Kotlin/Native Apple targets behind a convention plugin are KMM (Librechat-Mobile)", () => {
|
|
78
|
+
settings("app", "core:common", "shared");
|
|
79
|
+
write("shared/build.gradle.kts", appleTargets("librechat-mobile.shared.build.gradle.kts"));
|
|
80
|
+
write("app/build.gradle.kts", ANDROID_APP);
|
|
81
|
+
write("core/common/build.gradle.kts", 'plugins { id("librechat.kmp.library") }\n');
|
|
82
|
+
xcodeProject("iosApp", "iosApp");
|
|
83
|
+
expect(detectMobileProjectRoot(root)).toBe("kmm");
|
|
84
|
+
});
|
|
85
|
+
test("Kotlin/Native Apple targets behind a convention plugin are KMM (mifos-mobile)", () => {
|
|
86
|
+
settings("cmp-android", "cmp-shared");
|
|
87
|
+
write("cmp-shared/build.gradle.kts", appleTargets("mifos-mobile.cmp-shared.build.gradle.kts"));
|
|
88
|
+
write("cmp-android/build.gradle.kts", ANDROID_APP);
|
|
89
|
+
xcodeProject("cmp-ios", "iosApp");
|
|
90
|
+
expect(detectMobileProjectRoot(root)).toBe("kmm");
|
|
91
|
+
});
|
|
70
92
|
test("a nested multiplatform module counts", () => {
|
|
71
93
|
settings("core:domain", "app");
|
|
72
94
|
write("core/domain/build.gradle.kts", KMP);
|
|
@@ -86,6 +108,19 @@ describe("detectMobileProjectRoot", () => {
|
|
|
86
108
|
expect(detectMobileProjectRoot(root)).toBe("android");
|
|
87
109
|
});
|
|
88
110
|
// The false positive the three directory names caused.
|
|
111
|
+
test("an iosApp folder beside modules with no Apple target and no KMP plugin is Android", () => {
|
|
112
|
+
settings("app", "shared");
|
|
113
|
+
write("app/build.gradle.kts", ANDROID_APP);
|
|
114
|
+
write("shared/build.gradle.kts", 'plugins { id("com.android.library") }\n// iosArm64() once lived here\nval note = "iosX64()"\n');
|
|
115
|
+
xcodeProject("iosApp", "iosApp");
|
|
116
|
+
expect(detectMobileProjectRoot(root)).toBe("android");
|
|
117
|
+
});
|
|
118
|
+
test("an Apple target with no Apple consumer is still Android", () => {
|
|
119
|
+
settings("shared", "app");
|
|
120
|
+
write("shared/build.gradle.kts", "kotlin { iosArm64() }\n");
|
|
121
|
+
write("app/build.gradle.kts", ANDROID_APP);
|
|
122
|
+
expect(detectMobileProjectRoot(root)).toBe("android");
|
|
123
|
+
});
|
|
89
124
|
test("a module merely named shared is not multiplatform", () => {
|
|
90
125
|
settings("shared", "app");
|
|
91
126
|
write("shared/build.gradle.kts", ANDROID_LIB);
|
|
@@ -23,6 +23,23 @@ export declare function parseSettingsModules(content: string): string[];
|
|
|
23
23
|
* convention plugin whose own id ends in `multiplatform`.
|
|
24
24
|
*/
|
|
25
25
|
export declare function declaresKotlinMultiplatformPlugin(content: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* True when a build file itself declares a Kotlin/Native Apple target.
|
|
28
|
+
*
|
|
29
|
+
* A convention plugin can hide the Kotlin Multiplatform plugin itself —
|
|
30
|
+
* garfiec/Librechat-Mobile's `:shared` applies `id("librechat.kmp.library")`
|
|
31
|
+
* and openMF/mifos-mobile's `:cmp-shared` a catalog alias — but the Apple
|
|
32
|
+
* targets are still declared in the module's own file. Only a call counts:
|
|
33
|
+
* the word in a comment or a string, or a source set named after a target
|
|
34
|
+
* (`iosArm64Main`), does not.
|
|
35
|
+
*/
|
|
36
|
+
export declare function declaresKotlinNativeAppleTarget(content: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* True when a build file makes its module Kotlin Multiplatform: it applies the
|
|
39
|
+
* plugin, or declares a Kotlin/Native Apple target. The KMM decision in
|
|
40
|
+
* `detect-project.ts` asks this, never the plugin test alone.
|
|
41
|
+
*/
|
|
42
|
+
export declare function declaresKotlinMultiplatform(content: string): boolean;
|
|
26
43
|
/**
|
|
27
44
|
* Every plugin identifier a build file declares: `id("x")`, `id 'x'`,
|
|
28
45
|
* `apply plugin: 'x'` / `apply(plugin = "x")`, and the version-catalog alias
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradle-settings.d.ts","sourceRoot":"","sources":["../../../src/shared/gradle-settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAY9D;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAO1E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAW3D"}
|
|
1
|
+
{"version":3,"file":"gradle-settings.d.ts","sourceRoot":"","sources":["../../../src/shared/gradle-settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAY9D;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAO1E;AAUD;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGxE;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEpE;AA4CD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAW3D"}
|
|
@@ -45,6 +45,78 @@ export function declaresKotlinMultiplatformPlugin(content) {
|
|
|
45
45
|
return true;
|
|
46
46
|
return declaredPluginIds(content).some((id) => /kotlin[._-]?multiplatform$/i.test(id));
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* The Kotlin/Native Apple target functions of the Kotlin Multiplatform DSL.
|
|
50
|
+
* A call to one (`iosArm64()`, `iosX64 { … }`, `listOf(iosArm64(), …)`) exists
|
|
51
|
+
* only inside a multiplatform module.
|
|
52
|
+
*/
|
|
53
|
+
const KOTLIN_NATIVE_APPLE_TARGET_CALL = /(?<![A-Za-z0-9_$])(?:ios(?:Arm32|Arm64|X64|SimulatorArm64)|macos(?:Arm64|X64)|watchos(?:Arm32|Arm64|X64|SimulatorArm64|DeviceArm64)|tvos(?:Arm64|X64|SimulatorArm64))\s*[({]/;
|
|
54
|
+
/**
|
|
55
|
+
* True when a build file itself declares a Kotlin/Native Apple target.
|
|
56
|
+
*
|
|
57
|
+
* A convention plugin can hide the Kotlin Multiplatform plugin itself —
|
|
58
|
+
* garfiec/Librechat-Mobile's `:shared` applies `id("librechat.kmp.library")`
|
|
59
|
+
* and openMF/mifos-mobile's `:cmp-shared` a catalog alias — but the Apple
|
|
60
|
+
* targets are still declared in the module's own file. Only a call counts:
|
|
61
|
+
* the word in a comment or a string, or a source set named after a target
|
|
62
|
+
* (`iosArm64Main`), does not.
|
|
63
|
+
*/
|
|
64
|
+
export function declaresKotlinNativeAppleTarget(content) {
|
|
65
|
+
if (!content || typeof content !== "string")
|
|
66
|
+
return false;
|
|
67
|
+
return KOTLIN_NATIVE_APPLE_TARGET_CALL.test(codeOnly(content));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* True when a build file makes its module Kotlin Multiplatform: it applies the
|
|
71
|
+
* plugin, or declares a Kotlin/Native Apple target. The KMM decision in
|
|
72
|
+
* `detect-project.ts` asks this, never the plugin test alone.
|
|
73
|
+
*/
|
|
74
|
+
export function declaresKotlinMultiplatform(content) {
|
|
75
|
+
return declaresKotlinMultiplatformPlugin(content) || declaresKotlinNativeAppleTarget(content);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A Kotlin or Groovy build file with its comments and string literals
|
|
79
|
+
* blanked, so what is left is code. Strings keep their quotes and lose their
|
|
80
|
+
* contents; a comment becomes a space.
|
|
81
|
+
*/
|
|
82
|
+
function codeOnly(content) {
|
|
83
|
+
let out = "";
|
|
84
|
+
let i = 0;
|
|
85
|
+
const n = content.length;
|
|
86
|
+
while (i < n) {
|
|
87
|
+
const c = content[i];
|
|
88
|
+
const next = content[i + 1];
|
|
89
|
+
if (c === "/" && next === "/") {
|
|
90
|
+
while (i < n && content[i] !== "\n")
|
|
91
|
+
i++;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (c === "/" && next === "*") {
|
|
95
|
+
const end = content.indexOf("*/", i + 2);
|
|
96
|
+
i = end === -1 ? n : end + 2;
|
|
97
|
+
out += " ";
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (content.startsWith('"""', i) || content.startsWith("'''", i)) {
|
|
101
|
+
const quote = content.slice(i, i + 3);
|
|
102
|
+
const end = content.indexOf(quote, i + 3);
|
|
103
|
+
i = end === -1 ? n : end + 3;
|
|
104
|
+
out += quote + quote;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (c === '"' || c === "'") {
|
|
108
|
+
let j = i + 1;
|
|
109
|
+
while (j < n && content[j] !== c && content[j] !== "\n")
|
|
110
|
+
j += content[j] === "\\" ? 2 : 1;
|
|
111
|
+
i = j + 1;
|
|
112
|
+
out += c + c;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
out += c;
|
|
116
|
+
i++;
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
48
120
|
/**
|
|
49
121
|
* Every plugin identifier a build file declares: `id("x")`, `id 'x'`,
|
|
50
122
|
* `apply plugin: 'x'` / `apply(plugin = "x")`, and the version-catalog alias
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gradle-settings.test.d.ts","sourceRoot":"","sources":["../../../src/shared/gradle-settings.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What in a module's own build file makes it Kotlin Multiplatform.
|
|
3
|
+
*
|
|
4
|
+
* The plugin is the first answer, but a convention plugin can hide it:
|
|
5
|
+
* garfiec/Librechat-Mobile's `:shared` applies `id("librechat.kmp.library")`
|
|
6
|
+
* and openMF/mifos-mobile's `:cmp-shared` applies
|
|
7
|
+
* `alias(libs.plugins.cmp.feature.convention)`. Both declare Kotlin/Native
|
|
8
|
+
* Apple targets in the module's own file, which only a multiplatform module
|
|
9
|
+
* can do, so that counts too. It has to be a call: the word in a comment or a
|
|
10
|
+
* string, or a source set named after a target, does not count.
|
|
11
|
+
*/
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
import { declaresKotlinMultiplatform, declaresKotlinMultiplatformPlugin, declaresKotlinNativeAppleTarget, } from "./gradle-settings.js";
|
|
16
|
+
const FIXTURES = join(dirname(fileURLToPath(import.meta.url)), "../../test/fixtures/kotlin-native-apple-targets");
|
|
17
|
+
const fixture = (name) => readFileSync(join(FIXTURES, name), "utf-8");
|
|
18
|
+
describe("declaresKotlinNativeAppleTarget", () => {
|
|
19
|
+
test("Librechat-Mobile: listOf(iosArm64(), iosSimulatorArm64()) behind a convention plugin", () => {
|
|
20
|
+
const content = fixture("librechat-mobile.shared.build.gradle.kts");
|
|
21
|
+
expect(declaresKotlinMultiplatformPlugin(content)).toBe(false);
|
|
22
|
+
expect(declaresKotlinNativeAppleTarget(content)).toBe(true);
|
|
23
|
+
expect(declaresKotlinMultiplatform(content)).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
test("mifos-mobile: iosX64(), iosArm64(), iosSimulatorArm64() behind a convention plugin", () => {
|
|
26
|
+
const content = fixture("mifos-mobile.cmp-shared.build.gradle.kts");
|
|
27
|
+
expect(declaresKotlinMultiplatformPlugin(content)).toBe(false);
|
|
28
|
+
expect(declaresKotlinNativeAppleTarget(content)).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
test.each([
|
|
31
|
+
"kotlin { iosArm64() }",
|
|
32
|
+
"kotlin {\n iosX64 {\n binaries.framework()\n }\n}",
|
|
33
|
+
'kotlin { iosSimulatorArm64("sim") }',
|
|
34
|
+
"kotlin { macosArm64() }",
|
|
35
|
+
"kotlin { macosX64() }",
|
|
36
|
+
"kotlin { watchosArm64(); watchosSimulatorArm64() }",
|
|
37
|
+
"kotlin { watchosDeviceArm64() }",
|
|
38
|
+
"kotlin { tvosArm64() }",
|
|
39
|
+
"kotlin { tvosSimulatorArm64 () }",
|
|
40
|
+
"kotlin {\n [iosArm64(), iosX64()].each { it.binaries.framework() }\n}",
|
|
41
|
+
])("a target call counts: %s", (content) => {
|
|
42
|
+
expect(declaresKotlinNativeAppleTarget(content)).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
test.each([
|
|
45
|
+
"// iosArm64()\nplugins { id(\"com.android.application\") }",
|
|
46
|
+
"/* kotlin { iosArm64() } */\nandroid { }",
|
|
47
|
+
"/*\n * iosX64()\n */",
|
|
48
|
+
'val note = "call iosArm64() for iOS"',
|
|
49
|
+
"def note = 'iosArm64()'",
|
|
50
|
+
'val s = """\n iosArm64()\n"""',
|
|
51
|
+
"val iosArm64Main by getting { }",
|
|
52
|
+
"sourceSets { iosArm64Main.dependencies { } }",
|
|
53
|
+
"sourceSets { iosMain.dependencies { } }",
|
|
54
|
+
"val iosArm64 = 1",
|
|
55
|
+
"myiosArm64()",
|
|
56
|
+
"linuxX64()\nandroidTarget()\njvm()",
|
|
57
|
+
"",
|
|
58
|
+
])("not a target call: %j", (content) => {
|
|
59
|
+
expect(declaresKotlinNativeAppleTarget(content)).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
test("a comment marker inside a string does not hide the call after it", () => {
|
|
62
|
+
expect(declaresKotlinNativeAppleTarget('val url = "https://example.com"\nkotlin { iosArm64() }')).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=gradle-settings.test.js.map
|
|
@@ -20,6 +20,10 @@ export interface GradleBuildInputs {
|
|
|
20
20
|
gradle_options?: string;
|
|
21
21
|
variant?: string;
|
|
22
22
|
module?: string;
|
|
23
|
+
/** JVM arguments to run the Gradle daemon with instead of the project's org.gradle.jvmargs; capped to the machine like the project's own. */
|
|
24
|
+
jvmargs?: string;
|
|
25
|
+
/** Gradle workers to run with (`--max-workers`), over any org.gradle.workers.max; a positive whole number. */
|
|
26
|
+
max_workers?: string | number;
|
|
23
27
|
}
|
|
24
28
|
/**
|
|
25
29
|
* Inputs for android-lint step
|
|
@@ -28,6 +32,10 @@ export interface AndroidLintInputs {
|
|
|
28
32
|
project_location?: string;
|
|
29
33
|
module?: string;
|
|
30
34
|
variant?: string;
|
|
35
|
+
/** JVM arguments to run the Gradle daemon with instead of the project's org.gradle.jvmargs; capped to the machine like the project's own. */
|
|
36
|
+
jvmargs?: string;
|
|
37
|
+
/** Gradle workers to run with (`--max-workers`), over any org.gradle.workers.max; a positive whole number. */
|
|
38
|
+
max_workers?: string | number;
|
|
31
39
|
}
|
|
32
40
|
/**
|
|
33
41
|
* Inputs for android-unit-test step
|
|
@@ -37,6 +45,10 @@ export interface AndroidUnitTestInputs {
|
|
|
37
45
|
module?: string;
|
|
38
46
|
variant?: string;
|
|
39
47
|
test_filter?: string;
|
|
48
|
+
/** JVM arguments to run the Gradle daemon with instead of the project's org.gradle.jvmargs; capped to the machine like the project's own. */
|
|
49
|
+
jvmargs?: string;
|
|
50
|
+
/** Gradle workers to run with (`--max-workers`), over any org.gradle.workers.max; a positive whole number. */
|
|
51
|
+
max_workers?: string | number;
|
|
40
52
|
}
|
|
41
53
|
/**
|
|
42
54
|
* Set Java version step executor
|
|
@@ -127,6 +139,10 @@ export interface AndroidBuildForUITestingInputs {
|
|
|
127
139
|
module?: string;
|
|
128
140
|
variant?: string;
|
|
129
141
|
arguments?: string;
|
|
142
|
+
/** JVM arguments to run the Gradle daemon with instead of the project's org.gradle.jvmargs; capped to the machine like the project's own. */
|
|
143
|
+
jvmargs?: string;
|
|
144
|
+
/** Gradle workers to run with (`--max-workers`), over any org.gradle.workers.max; a positive whole number. */
|
|
145
|
+
max_workers?: string | number;
|
|
130
146
|
}
|
|
131
147
|
/**
|
|
132
148
|
* Builds app APK and test APK for Android instrumented (UI) tests.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../../../src/yaml/steps/android.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,OAAO,EAAE,gBAAgB,EA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AW,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;CA2EzH"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { existsSync, readFileSync } from 'node:fs';
|
|
10
10
|
import { execSync } from 'node:child_process';
|
|
11
11
|
import { BaseStepExecutor, javaHomeVersionSpec } from './base.js';
|
|
12
|
+
import { gradleMemoryCommands } from './gradle-memory.js';
|
|
12
13
|
/**
|
|
13
14
|
* Set Java version step executor
|
|
14
15
|
* Sets the Java version to use for Android builds
|
|
@@ -459,6 +460,7 @@ export class GradleBuildStepExecutor extends BaseStepExecutor {
|
|
|
459
460
|
commands.push(' echo "Error: Neither ./gradlew nor gradle command found"');
|
|
460
461
|
commands.push(' exit 1');
|
|
461
462
|
commands.push('fi');
|
|
463
|
+
commands.push(...gradleMemoryCommands(this.getInput(inputs, 'jvmargs', ''), (v) => this.escapeBash(v), String(this.getInput(inputs, 'max_workers', '')).trim()));
|
|
462
464
|
// Build gradle command
|
|
463
465
|
commands.push('');
|
|
464
466
|
commands.push('# Timestamp marker — used to collect only artifacts from this build');
|
|
@@ -780,6 +782,7 @@ export class AndroidLintStepExecutor extends BaseStepExecutor {
|
|
|
780
782
|
commands.push(' echo "Error: Neither ./gradlew nor gradle command found"');
|
|
781
783
|
commands.push(' exit 1');
|
|
782
784
|
commands.push('fi');
|
|
785
|
+
commands.push(...gradleMemoryCommands(this.getInput(inputs, 'jvmargs', ''), (v) => this.escapeBash(v), String(this.getInput(inputs, 'max_workers', '')).trim()));
|
|
783
786
|
// Build lint task name
|
|
784
787
|
commands.push('');
|
|
785
788
|
commands.push('# Run lint');
|
|
@@ -969,6 +972,7 @@ export class AndroidUnitTestStepExecutor extends BaseStepExecutor {
|
|
|
969
972
|
commands.push(' echo "Error: Neither ./gradlew nor gradle command found"');
|
|
970
973
|
commands.push(' exit 1');
|
|
971
974
|
commands.push('fi');
|
|
975
|
+
commands.push(...gradleMemoryCommands(this.getInput(inputs, 'jvmargs', ''), (v) => this.escapeBash(v), String(this.getInput(inputs, 'max_workers', '')).trim()));
|
|
972
976
|
// Build test task name
|
|
973
977
|
commands.push('');
|
|
974
978
|
commands.push('# Run unit tests');
|
|
@@ -1036,6 +1040,7 @@ export class AndroidBuildForUITestingStepExecutor extends BaseStepExecutor {
|
|
|
1036
1040
|
commands.push('else');
|
|
1037
1041
|
commands.push(' GRADLE_CMD="gradle"');
|
|
1038
1042
|
commands.push('fi');
|
|
1043
|
+
commands.push(...gradleMemoryCommands(this.getInput(inputs, 'jvmargs', ''), (v) => this.escapeBash(v), String(this.getInput(inputs, 'max_workers', '')).trim()));
|
|
1039
1044
|
commands.push('');
|
|
1040
1045
|
// Build both app and test APKs
|
|
1041
1046
|
const appTask = gradleTaskPath(this.escapeBash(module), `assemble${variantCap}`);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gradle's daemon heaps, fitted to the machine the build runs on.
|
|
3
|
+
*
|
|
4
|
+
* A project's `gradle.properties` sizes its heaps for a developer laptop. On a
|
|
5
|
+
* 10 GiB build guest, `org.gradle.jvmargs=-Xmx8G` (which the Kotlin daemon
|
|
6
|
+
* inherits) or `-Xmx6g` beside `kotlin.daemon.jvmargs=-Xmx8g` asks for more
|
|
7
|
+
* than the machine has, and the kernel kills a daemon mid-build. All the log
|
|
8
|
+
* then says is "Gradle build daemon disappeared unexpectedly". IacobIonut01/ReFra
|
|
9
|
+
* and vitorpamplona/amethyst are the two measured cases; ReFra's own CI lowers
|
|
10
|
+
* its heap to 4g before building.
|
|
11
|
+
*
|
|
12
|
+
* Two things, both at run time, in the Gradle project directory:
|
|
13
|
+
*
|
|
14
|
+
* 1. **Cap.** Read the machine's memory and the declared `-Xmx` of the Gradle
|
|
15
|
+
* daemon and the Kotlin daemon. When their sum is past
|
|
16
|
+
* `GRADLE_HEAP_SHARE_PERCENT` of memory, scale both down to fit, and pass
|
|
17
|
+
* them on the command line (`-Dorg.gradle.jvmargs=`,
|
|
18
|
+
* `-Pkotlin.daemon.jvmargs=`). One line names the old values and the new.
|
|
19
|
+
* 2. **Say so.** When a Gradle run exits 137 or its output says the daemon
|
|
20
|
+
* disappeared, print the kernel's out-of-memory lines and one sentence
|
|
21
|
+
* with the machine's memory and what the build asked for.
|
|
22
|
+
* 3. **Workers.** A heap cap does not bound what runs beside the heaps:
|
|
23
|
+
* off-heap memory, and native compilers run in parallel. IacobIonut01/ReFra
|
|
24
|
+
* was killed again at a capped -Xmx3712m, one JVM holding ~5.1 GiB
|
|
25
|
+
* resident; its own CI also sets `org.gradle.workers.max=2`. A pipeline
|
|
26
|
+
* may ask for a worker count, passed as `--max-workers=<n>`.
|
|
27
|
+
*
|
|
28
|
+
* Precedence, measured with Gradle 8.14.3 and 9.5.0 (daemon and --no-daemon):
|
|
29
|
+
* `-Dorg.gradle.jvmargs` on the command line beats both the Gradle user
|
|
30
|
+
* home's and the project's `gradle.properties` for the daemon's heap, and
|
|
31
|
+
* `-P` beats `gradle.properties` for a Gradle property, which is how the
|
|
32
|
+
* Kotlin Gradle plugin reads `kotlin.daemon.jvmargs`. `--max-workers` beats
|
|
33
|
+
* `org.gradle.workers.max` in both files (`gradle.startParameter.maxWorkerCount`).
|
|
34
|
+
* `GRADLE_OPTS` is not used: it sizes the client JVM, not the daemon.
|
|
35
|
+
*
|
|
36
|
+
* Written as shell functions so what ships is what the tests run. Its lines
|
|
37
|
+
* start with "Gradle memory:", never with a step-progress marker.
|
|
38
|
+
*/
|
|
39
|
+
/** The share of the machine's memory the two daemon heaps may take together. */
|
|
40
|
+
export declare const GRADLE_HEAP_SHARE_PERCENT = 75;
|
|
41
|
+
export declare const GRADLE_MEMORY_FUNCTIONS = "# This machine's memory in MiB, or nothing when it cannot be read.\ncibuild_mem_mib() {\n if [ -r /proc/meminfo ]; then\n awk '/^MemTotal:/ { print int($2 / 1024); exit }' /proc/meminfo\n else\n local bytes\n bytes=$(sysctl -n hw.memsize 2>/dev/null || true)\n if [ -n \"$bytes\" ]; then echo $(( bytes / 1048576 )); fi\n fi\n}\n\n# $1 a .properties file, $2 a key. Prints \"<line number><TAB><value>\" for the\n# last assignment of the key, or nothing.\ncibuild_prop_line() {\n [ -f \"$1\" ] || return 0\n awk -v key=\"$2\" '\n { line = $0; sub(/^[ \\t]+/, \"\", line) }\n line ~ /^[#!]/ { next }\n {\n k = line; sub(/[ \\t]*[=:].*$/, \"\", k)\n if (k == key) { v = line; sub(/^[^=:]*[=:][ \\t]*/, \"\", v); sub(/[ \\t\\r]+$/, \"\", v); found = NR \"\\t\" v }\n }\n END { if (found != \"\") print found }\n ' \"$1\"\n}\n\n# The -Xmx of a JVM argument string in MiB (the last one wins, as in the JVM),\n# or nothing when it has none.\ncibuild_xmx_mib() {\n printf '%s\\n' \"$1\" | tr ' \\t' '\\n\\n' | awk '\n /^-Xmx[0-9]+[kKmMgGtT]?$/ {\n n = substr($0, 5); u = substr(n, length(n))\n if (u ~ /[0-9]/) { v = n / 1048576 }\n else {\n n = substr(n, 1, length(n) - 1)\n if (u ~ /[kK]/) v = n / 1024\n else if (u ~ /[mM]/) v = n\n else if (u ~ /[gG]/) v = n * 1024\n else v = n * 1048576\n }\n r = int(v)\n }\n END { if (r != \"\") print r }'\n}\n\n# $1 a JVM argument string, $2 a heap in MiB: the same arguments with every\n# -Xmx replaced by that one (added in front when there was none).\ncibuild_with_xmx() (\n set -f\n out=\"\"\n replaced=0\n for arg in $1; do\n case \"$arg\" in\n -Xmx*) if [ \"$replaced\" -eq 0 ]; then out=\"$out -Xmx${2}m\"; replaced=1; fi ;;\n *) out=\"$out $arg\" ;;\n esac\n done\n [ \"$replaced\" -eq 1 ] || out=\" -Xmx${2}m$out\"\n printf '%s' \"${out# }\"\n)\n\n# MiB as GiB with one decimal.\ncibuild_gib() {\n awk -v m=\"$1\" 'BEGIN { printf \"%.1f\", m / 1024 }'\n}\n\n# A heap scaled by budget/total, rounded down to 64 MiB, never below 512 MiB.\ncibuild_scaled_heap() {\n local v=$(( $1 * $2 / $3 / 64 * 64 ))\n [ \"$v\" -ge 512 ] || v=512\n echo \"$v\"\n}\n\n# The plan, from its inputs only, so a test can run it:\n# $1 this machine's memory in MiB (empty when unknown)\n# $2 the project's gradle.properties $3 the Gradle user home's\n# $4 JVM arguments the pipeline asks for instead (may be empty)\n# Sets CIBUILD_GRADLE_MEMORY_ARGS (extra Gradle arguments),\n# CIBUILD_GRADLE_MEMORY_LINE (what to print before Gradle runs; empty when\n# nothing changes) and CIBUILD_GRADLE_MEMORY_SENTENCE (what to print if a\n# daemon is killed).\n#\n# Precedence is Gradle's own: the command line beats GRADLE_USER_HOME's\n# gradle.properties, which beats the project's. A Kotlin daemon with no -Xmx of\n# its own inherits the Gradle daemon's, and in-process compilation has no\n# Kotlin daemon at all.\ncibuild_gradle_memory_plan() {\n local mem=\"$1\" project=\"$2\" user=\"$3\" preferred=\"$4\" l\n local jvm=\"\" jvm_at=\"\" kd=\"\" kd_at=\"\" strategy=\"\"\n CIBUILD_GRADLE_MEMORY_ARGS=()\n CIBUILD_GRADLE_MEMORY_LINE=\"\"\n CIBUILD_GRADLE_MEMORY_SENTENCE=\"\"\n\n if [ -n \"$preferred\" ]; then jvm=\"$preferred\"; jvm_at=\"the pipeline\"; fi\n for f in \"$user\" \"$project\"; do\n if [ -z \"$jvm_at\" ]; then\n l=$(cibuild_prop_line \"$f\" org.gradle.jvmargs)\n if [ -n \"$l\" ]; then jvm=\"${l#*\t}\"; jvm_at=\"$f:${l%%\t*}\"; fi\n fi\n if [ -z \"$kd_at\" ]; then\n l=$(cibuild_prop_line \"$f\" kotlin.daemon.jvmargs)\n if [ -n \"$l\" ]; then kd=\"${l#*\t}\"; kd_at=\"$f:${l%%\t*}\"; fi\n fi\n if [ -z \"$strategy\" ]; then\n l=$(cibuild_prop_line \"$f\" kotlin.compiler.execution.strategy)\n strategy=\"${l#*\t}\"\n fi\n done\n\n local g k kd_own=\"\"\n g=$(cibuild_xmx_mib \"$jvm\")\n [ -n \"$g\" ] || g=512\n if [ \"$strategy\" = \"in-process\" ]; then\n k=0\n else\n kd_own=$(cibuild_xmx_mib \"$kd\")\n k=\"${kd_own:-$g}\"\n fi\n local total=$(( g + k ))\n\n local asked\n if [ -n \"$jvm_at\" ]; then asked=\"org.gradle.jvmargs=$jvm at ${jvm_at}\"; else asked=\"Gradle's default -Xmx512m\"; fi\n if [ \"$k\" -eq 0 ]; then\n asked=\"$asked; Kotlin compiles in-process\"\n elif [ -n \"$kd_own\" ]; then\n asked=\"$asked, kotlin.daemon.jvmargs=$kd at ${kd_at}\"\n else\n asked=\"$asked; the Kotlin daemon inherits its -Xmx\"\n fi\n\n if [ -z \"$mem\" ]; then\n CIBUILD_GRADLE_MEMORY_SENTENCE=\"This build's Gradle and Kotlin daemons asked for $(cibuild_gib \"$total\") GiB ($asked); this machine's memory could not be read.\"\n if [ -n \"$preferred\" ]; then CIBUILD_GRADLE_MEMORY_ARGS=(\"-Dorg.gradle.jvmargs=$preferred\"); fi\n return 0\n fi\n\n local budget=$(( mem * 75 / 100 ))\n CIBUILD_GRADLE_MEMORY_SENTENCE=\"The build machine has $(cibuild_gib \"$mem\") GiB; this build's Gradle and Kotlin daemons asked for $(cibuild_gib \"$total\") GiB ($asked).\"\n\n if [ \"$total\" -le \"$budget\" ]; then\n if [ -n \"$preferred\" ]; then\n CIBUILD_GRADLE_MEMORY_ARGS=(\"-Dorg.gradle.jvmargs=$preferred\")\n CIBUILD_GRADLE_MEMORY_LINE=\"Gradle memory: org.gradle.jvmargs=$preferred, as the pipeline asks (-Dorg.gradle.jvmargs on the command line).\"\n fi\n return 0\n fi\n\n case \"$jvm\" in\n *\\\\)\n CIBUILD_GRADLE_MEMORY_LINE=\"Gradle memory: the declared heaps ask for $(cibuild_gib \"$total\") GiB of this machine's $(cibuild_gib \"$mem\") GiB, but org.gradle.jvmargs at ${jvm_at} continues onto another line, so it is left as it is.\"\n return 0\n ;;\n esac\n\n local ng nk new_jvm\n ng=$(cibuild_scaled_heap \"$g\" \"$budget\" \"$total\")\n new_jvm=$(cibuild_with_xmx \"$jvm\" \"$ng\")\n CIBUILD_GRADLE_MEMORY_ARGS=(\"-Dorg.gradle.jvmargs=$new_jvm\")\n local now=\"Gradle -Xmx${ng}m\"\n if [ \"$k\" -eq 0 ]; then\n :\n elif [ -n \"$kd_own\" ]; then\n nk=$(cibuild_scaled_heap \"$k\" \"$budget\" \"$total\")\n CIBUILD_GRADLE_MEMORY_ARGS+=(\"-Pkotlin.daemon.jvmargs=$(cibuild_with_xmx \"$kd\" \"$nk\")\")\n now=\"$now and the Kotlin daemon -Xmx${nk}m\"\n else\n now=\"$now, which the Kotlin daemon inherits\"\n fi\n CIBUILD_GRADLE_MEMORY_LINE=\"Gradle memory: this machine has $(cibuild_gib \"$mem\") GiB and the declared heaps ask for $(cibuild_gib \"$total\") GiB ($asked), past the $(cibuild_gib \"$budget\") GiB this build allows them. Running with $now, set on the command line.\"\n CIBUILD_GRADLE_MEMORY_SENTENCE=\"$CIBUILD_GRADLE_MEMORY_SENTENCE This build ran them capped: $now.\"\n}\n\n# $1 the number of Gradle workers the pipeline asks for (may be empty). Adds\n# --max-workers to the plan's arguments; run after cibuild_gradle_memory_plan.\n# Sets CIBUILD_GRADLE_WORKERS_LINE (what to print; empty when nothing asked).\ncibuild_gradle_workers_plan() {\n CIBUILD_GRADLE_WORKERS_LINE=\"\"\n [ -n \"$1\" ] || return 0\n case \"$1\" in\n *[!0-9]*|0*)\n CIBUILD_GRADLE_WORKERS_LINE=\"Gradle memory: max_workers=$1 is not a positive whole number, so it is not passed and Gradle picks its own worker count.\"\n return 0\n ;;\n esac\n CIBUILD_GRADLE_MEMORY_ARGS+=(\"--max-workers=$1\")\n CIBUILD_GRADLE_WORKERS_LINE=\"Gradle memory: running with --max-workers=$1, as the pipeline asks (set on the command line, over any org.gradle.workers.max).\"\n CIBUILD_GRADLE_MEMORY_SENTENCE=\"$CIBUILD_GRADLE_MEMORY_SENTENCE Gradle ran with --max-workers=$1.\"\n}\n\n# The kernel's out-of-memory lines, if this user may read the kernel log.\n# Linux guests restrict dmesg to root by default; their build user has\n# non-interactive sudo, so that is the second try.\ncibuild_kernel_oom_lines() {\n { dmesg 2>/dev/null || sudo -n dmesg 2>/dev/null || true; } |\n grep -i -E 'out of memory|oom-kill|oom_reaper|killed process' | tail -n 20 || true\n}\n\n# $1 Gradle's exit status, $2 a file holding its output. Says so when the\n# failure is a killed daemon rather than a failed build.\ncibuild_gradle_memory_report() {\n if [ \"$1\" -ne 137 ] && ! grep -q \"daemon disappeared unexpectedly\" \"$2\" 2>/dev/null; then\n return 0\n fi\n local oom\n oom=$(cibuild_kernel_oom_lines)\n echo \"\"\n echo \"Gradle memory: a Gradle daemon was killed rather than failing the build (exit $1).\"\n if [ -n \"$oom\" ]; then\n echo \"The kernel's out-of-memory lines:\"\n printf '%s\\n' \"$oom\" | sed 's/^/ /'\n else\n echo \"The kernel log shows no out-of-memory kill, or this machine does not let the build read it.\"\n fi\n if [ -n \"$CIBUILD_GRADLE_MEMORY_SENTENCE\" ]; then echo \"$CIBUILD_GRADLE_MEMORY_SENTENCE\"; fi\n}\n\n# Runs Gradle with the plan's arguments, and reports a killed daemon.\ncibuild_gradle() {\n local log rc\n log=$(mktemp)\n set +e\n \"$CIBUILD_GRADLE_BIN\" \"${CIBUILD_GRADLE_MEMORY_ARGS[@]}\" \"$@\" 2>&1 | tee \"$log\"\n rc=${PIPESTATUS[0]}\n set -e\n if [ \"$rc\" -ne 0 ]; then cibuild_gradle_memory_report \"$rc\" \"$log\" || true; fi\n rm -f \"$log\"\n return \"$rc\"\n}\n\n# $1 JVM arguments the pipeline asks for, $2 the Gradle workers it asks for\n# (either may be empty). Run in the Gradle project directory, after GRADLE_CMD\n# is chosen.\ncibuild_gradle_memory_cap() {\n cibuild_gradle_memory_plan \"$(cibuild_mem_mib || true)\" \"gradle.properties\" \\\n \"${GRADLE_USER_HOME:-$HOME/.gradle}/gradle.properties\" \"$1\"\n cibuild_gradle_workers_plan \"$2\"\n if [ -n \"$CIBUILD_GRADLE_MEMORY_LINE\" ]; then echo \"$CIBUILD_GRADLE_MEMORY_LINE\"; fi\n if [ -n \"$CIBUILD_GRADLE_WORKERS_LINE\" ]; then echo \"$CIBUILD_GRADLE_WORKERS_LINE\"; fi\n CIBUILD_GRADLE_BIN=\"$GRADLE_CMD\"\n GRADLE_CMD=cibuild_gradle\n}";
|
|
42
|
+
/**
|
|
43
|
+
* The commands a Gradle step runs once it has chosen `GRADLE_CMD` and is in
|
|
44
|
+
* the project directory. Afterwards `$GRADLE_CMD` runs Gradle with the plan's
|
|
45
|
+
* arguments and reports a killed daemon.
|
|
46
|
+
*
|
|
47
|
+
* `jvmargs` is what the pipeline asks for instead of the project's
|
|
48
|
+
* `org.gradle.jvmargs` (a value the repository's own CI sets, say); the cap
|
|
49
|
+
* still applies to it. `maxWorkers` is the worker count it asks for (the
|
|
50
|
+
* repository CI's `org.gradle.workers.max`), passed as `--max-workers`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function gradleMemoryCommands(jvmargs: string, escape: (value: string) => string, maxWorkers?: string): string[];
|
|
53
|
+
//# sourceMappingURL=gradle-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gradle-memory.d.ts","sourceRoot":"","sources":["../../../../src/yaml/steps/gradle-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,gFAAgF;AAChF,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,eAAO,MAAM,uBAAuB,4hTAgPlC,CAAC;AAEH;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EACjC,UAAU,SAAK,GACd,MAAM,EAAE,CAOV"}
|