diff --git a/.changeset/fresh-frogs-enter.md b/.changeset/fresh-frogs-enter.md new file mode 100644 index 00000000..76c39869 --- /dev/null +++ b/.changeset/fresh-frogs-enter.md @@ -0,0 +1,5 @@ +--- +"cmake-rn": patch +--- + +Fix expansion of options in --build and --out diff --git a/packages/cmake-rn/src/cli.ts b/packages/cmake-rn/src/cli.ts index a7d56530..10bf9f63 100644 --- a/packages/cmake-rn/src/cli.ts +++ b/packages/cmake-rn/src/cli.ts @@ -74,7 +74,7 @@ const tripletOption = new Option( const buildPathOption = new Option( "--build ", "Specify the build directory to store the configured CMake project", -); +).default("{source}/build"); const cleanOption = new Option( "--clean", @@ -84,7 +84,7 @@ const cleanOption = new Option( const outPathOption = new Option( "--out ", "Specify the output directory to store the final build artifacts", -).default(false, "./{build}/{configuration}"); +).default("{build}/{configuration}"); const defineOption = new Option( "-D,--define ", @@ -151,8 +151,27 @@ for (const platform of platforms) { program = platform.amendCommand(program); } +function expandTemplate( + input: string, + values: Record, +): string { + return input.replaceAll(/{([^}]+)}/g, (_, key: string) => + typeof values[key] === "string" ? values[key] : "", + ); +} + program = program.action( wrapAction(async ({ triplet: requestedTriplets, ...baseOptions }) => { + baseOptions.build = path.resolve( + process.cwd(), + expandTemplate(baseOptions.build, baseOptions), + ); + baseOptions.out = path.resolve( + process.cwd(), + expandTemplate(baseOptions.out, baseOptions), + ); + const { out, build: buildPath } = baseOptions; + assertFixable( fs.existsSync(path.join(baseOptions.source, "CMakeLists.txt")), `No CMakeLists.txt found in source directory: ${chalk.dim(baseOptions.source)}`, @@ -161,7 +180,6 @@ program = program.action( }, ); - const buildPath = getBuildPath(baseOptions); if (baseOptions.clean) { await fs.promises.rm(buildPath, { recursive: true, force: true }); } @@ -197,10 +215,6 @@ program = program.action( } } - if (!baseOptions.out) { - baseOptions.out = path.join(buildPath, baseOptions.configuration); - } - const tripletContexts = [...triplets].map((triplet) => { const platform = findPlatformForTriplet(triplet); const tripletBuildPath = getTripletBuildPath(buildPath, triplet); @@ -262,7 +276,7 @@ program = program.action( } await platform.postBuild( { - outputPath: baseOptions.out || baseOptions.source, + outputPath: out, triplets: relevantTriplets, }, baseOptions, @@ -288,11 +302,6 @@ function getTripletsSummary( .join(" / "); } -function getBuildPath({ build, source }: BaseOpts) { - // TODO: Add configuration (debug vs release) - return path.resolve(process.cwd(), build || path.join(source, "build")); -} - /** * Namespaces the output path with a triplet name */