Skip to content

Commit 1aa7541

Browse files
committed
Use CMAKE_RN_TARGETS as default targets
1 parent 4924f66 commit 1aa7541

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

packages/cmake-rn/src/cli.ts

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,23 @@ const configurationOption = new Option("--configuration <configuration>")
4141
// TODO: Derive default targets
4242
// This is especially important when driving the build from within a React Native app package.
4343

44-
const targetOption = new Option(
45-
"--target <target...>",
46-
"Targets to build for"
47-
).choices(allTargets);
44+
const { CMAKE_RN_TARGETS } = process.env;
45+
46+
const defaultTargets = CMAKE_RN_TARGETS ? CMAKE_RN_TARGETS.split(",") : [];
47+
48+
for (const target of defaultTargets) {
49+
assert(
50+
(allTargets as string[]).includes(target),
51+
`Unexpected target in CMAKE_RN_TARGETS: ${target}`
52+
);
53+
}
54+
55+
const targetOption = new Option("--target <target...>", "Targets to build for")
56+
.choices(allTargets)
57+
.default(
58+
defaultTargets,
59+
"CMAKE_RN_TARGETS environment variable split by ','"
60+
);
4861

4962
const buildPathOption = new Option(
5063
"--build <path>",
@@ -148,16 +161,19 @@ program = program.action(
148161
});
149162

150163
// Configure every triplet project
164+
const targetsSummary = chalk.dim(
165+
`(${getTargetsSummary(targetContexts)})`
166+
);
151167
await oraPromise(
152168
Promise.all(
153169
targetContexts.map(({ platform, ...context }) =>
154170
configureProject(platform, context, baseOptions)
155171
)
156172
),
157173
{
158-
text: "Configuring projects",
174+
text: `Configuring projects ${targetsSummary}`,
159175
isSilent: baseOptions.verbose,
160-
successText: "Configured projects",
176+
successText: `Configured projects ${targetsSummary}`,
161177
failText: ({ message }) => `Failed to configure projects: ${message}`,
162178
}
163179
);
@@ -208,6 +224,23 @@ program = program.action(
208224
}
209225
);
210226

227+
function getTargetsSummary(
228+
targetContexts: { target: string; platform: Platform }[]
229+
) {
230+
const targetsPerPlatform: Record<string, string[]> = {};
231+
for (const { target, platform } of targetContexts) {
232+
if (!targetsPerPlatform[platform.id]) {
233+
targetsPerPlatform[platform.id] = [];
234+
}
235+
targetsPerPlatform[platform.id].push(target);
236+
}
237+
return Object.entries(targetsPerPlatform)
238+
.map(([platformId, targets]) => {
239+
return `${platformId}: ${targets.join(", ")}`;
240+
})
241+
.join(" / ");
242+
}
243+
211244
function getBuildPath({ build, source }: BaseOpts) {
212245
// TODO: Add configuration (debug vs release)
213246
return path.resolve(process.cwd(), build || path.join(source, "build"));

0 commit comments

Comments
 (0)