Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/toolchain/BuildFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ export class BuildFlags {
}
}

/**
* Extract scratch-path or build-path value from an array of arguments
* @param args Array of command-line arguments to search
* @returns The path value if found, otherwise undefined
*/
private static extractScratchPath(args: string[]): string | undefined {
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if ((arg === "--scratch-path" || arg === "--build-path") && i + 1 < args.length) {
return args[i + 1];
}
if (arg.startsWith("--scratch-path=")) {
return arg.substring("--scratch-path=".length);
}
if (arg.startsWith("--build-path=")) {
return arg.substring("--build-path=".length);
}
}
return undefined;
}

/**
* Get build path from configuration if exists or return a fallback .build directory in given workspace
* @param filesystem path to workspace that will be used as a fallback loacation with .build directory
Expand All @@ -139,7 +160,20 @@ export class BuildFlags {
): string {
const nodePath =
platform === "posix" ? path.posix : platform === "win32" ? path.win32 : path;
const buildPath = configuration.buildPath.length > 0 ? configuration.buildPath : ".build";

// First check if user has --scratch-path or --build-path in their build arguments
let buildPath = BuildFlags.extractScratchPath(configuration.buildArguments);

// If not in buildArguments, check packageArguments
if (!buildPath) {
buildPath = BuildFlags.extractScratchPath(configuration.packageArguments);
}

// If not in either arguments list, check the buildPath configuration
if (!buildPath) {
buildPath = configuration.buildPath.length > 0 ? configuration.buildPath : ".build";
}

if (!nodePath.isAbsolute(buildPath) && absolute) {
return nodePath.join(workspacePath, buildPath);
} else {
Expand Down
109 changes: 109 additions & 0 deletions test/unit-tests/toolchain/BuildFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ suite("BuildFlags Test Suite", () => {

suite("buildDirectoryFromWorkspacePath", () => {
const buildPathConfig = mockGlobalValue(configuration, "buildPath");
const buildArgsConfig = mockGlobalValue(configuration, "buildArguments");
const packageArgsConfig = mockGlobalValue(configuration, "packageArguments");

beforeEach(() => {
buildPathConfig.setValue("");
buildArgsConfig.setValue([]);
packageArgsConfig.setValue([]);
});

test("no configuration provided", () => {
buildPathConfig.setValue("");
Expand Down Expand Up @@ -239,6 +247,107 @@ suite("BuildFlags Test Suite", () => {
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", true)
).to.equalPath("/some/full/workspace/test/path/some/relative/test/path");
});

test("--scratch-path in buildArguments with separate value", () => {
buildArgsConfig.setValue(["--scratch-path", "/custom/scratch/path"]);

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
).to.equalPath("/custom/scratch/path");

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", true)
).to.equalPath("/custom/scratch/path");
});

test("--scratch-path in buildArguments with equals format", () => {
buildArgsConfig.setValue(["--scratch-path=/custom/scratch/path"]);

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
).to.equalPath("/custom/scratch/path");

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", true)
).to.equalPath("/custom/scratch/path");
});

test("--scratch-path with relative path in buildArguments", () => {
buildArgsConfig.setValue(["--scratch-path", "custom/build"]);

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
).to.equalPath("custom/build");

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", true)
).to.equalPath("/some/full/workspace/test/path/custom/build");
});

test("--build-path in buildArguments (legacy support)", () => {
buildArgsConfig.setValue(["--build-path", "/legacy/build/path"]);

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
).to.equalPath("/legacy/build/path");

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", true)
).to.equalPath("/legacy/build/path");
});

test("--scratch-path in packageArguments", () => {
packageArgsConfig.setValue(["--scratch-path", "/package/scratch/path"]);

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
).to.equalPath("/package/scratch/path");

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", true)
).to.equalPath("/package/scratch/path");
});

test("buildArguments takes precedence over packageArguments", () => {
buildArgsConfig.setValue(["--scratch-path", "/build/args/path"]);
packageArgsConfig.setValue(["--scratch-path", "/package/args/path"]);

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
).to.equalPath("/build/args/path");
});

test("buildArguments takes precedence over buildPath config", () => {
buildPathConfig.setValue("/config/path");
buildArgsConfig.setValue(["--scratch-path", "/build/args/path"]);

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
).to.equalPath("/build/args/path");
});

test("packageArguments takes precedence over buildPath config", () => {
buildPathConfig.setValue("/config/path");
packageArgsConfig.setValue(["--scratch-path", "/package/args/path"]);

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
).to.equalPath("/package/args/path");
});

test("--scratch-path among other arguments", () => {
buildArgsConfig.setValue([
"--verbose",
"--scratch-path",
"/custom/path",
"--configuration",
"release",
]);

expect(
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
).to.equalPath("/custom/path");
});
});

suite("withAdditionalFlags", () => {
Expand Down