Skip to content

Commit

Permalink
feat(cli): compile --output (#6359)
Browse files Browse the repository at this point in the history
## Checklist
fixes: #6340

- [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
tsuf239 authored May 2, 2024
1 parent e01948c commit 63683b5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 46 deletions.
4 changes: 4 additions & 0 deletions apps/wing/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ async function main() {
DEFAULT_PLATFORM
)
.option("-r, --rootId <rootId>", "App root id")
.option(
"-o, --output <output>",
'path to the output directory- default is "./target/<entrypoint>.<target>"'
)
.option("-v, --value <value>", "Platform-specific value in the form KEY=VALUE", addValue, [])
.option("--values <file>", "File with platform-specific values (TOML|YAML|JSON)")
.hook("preAction", progressHook)
Expand Down
5 changes: 5 additions & 0 deletions apps/wing/src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export interface CompileOptions {
* @default "./target"
*/
readonly targetDir?: string;
/**
* The overrides the location to save the compilation output
* @default "./target/<entrypoint>.<target>"
*/
readonly output?: string;
/**
* Whether to run the compiler in `wing test` mode. This may create multiple
* copies of the application resources in order to run tests in parallel.
Expand Down
102 changes: 57 additions & 45 deletions libs/wingcompiler/src/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,72 @@ export async function generateTmpDir() {
return mkdtemp(join(tmpdir(), "-wing-compile-test"));
}

describe(
"compile tests",
() => {
test("should produce stable artifacts for tf-aws", async () => {
const targetDir = `${await generateTmpDir()}/target`;
const artifactDir = await compile(exampleFilePath, {
platform: [BuiltinPlatform.TF_AWS],
targetDir,
});
describe("compile tests", () => {
test("should produce stable artifacts for tf-aws", async () => {
const targetDir = `${await generateTmpDir()}/target`;
const artifactDir = await compile(exampleFilePath, {
platform: [BuiltinPlatform.TF_AWS],
targetDir,
});

const stats = await stat(artifactDir);
expect(stats.isDirectory()).toBeTruthy();
expect(artifactDir).toContain(targetDir);
expect(basename(artifactDir)).toEqual("enums.test.tfaws");
});

const stats = await stat(artifactDir);
expect(stats.isDirectory()).toBeTruthy();
expect(artifactDir).toContain(targetDir);
expect(basename(artifactDir)).toEqual("enums.test.tfaws")
test("should produce temp artifacts for tf-aws testing", async () => {
const targetDir = `${await generateTmpDir()}/target`;
const artifactDir = await compile(exampleFilePath, {
platform: [BuiltinPlatform.TF_AWS],
targetDir,
testing: true,
});

test("should produce temp artifacts for tf-aws testing", async () => {
const targetDir = `${await generateTmpDir()}/target`;
const artifactDir = await compile(exampleFilePath, {
platform: [BuiltinPlatform.TF_AWS],
targetDir,
testing: true,
});
const stats = await stat(artifactDir);
expect(stats.isDirectory()).toBeTruthy();
expect(artifactDir).toContain(targetDir);
expect(basename(artifactDir).match(/enums\.test\.tfaws\.\d+$/)).toBeTruthy();
});

const stats = await stat(artifactDir);
expect(stats.isDirectory()).toBeTruthy();
expect(artifactDir).toContain(targetDir);
expect(basename(artifactDir).match(/enums\.test\.tfaws\.\d+$/)).toBeTruthy();
test("should produce stable artifacts for sim", async () => {
const targetDir = `${await generateTmpDir()}/target`;
const artifactDir = await compile(exampleFilePath, {
platform: [BuiltinPlatform.SIM],
targetDir,
});

test("should produce stable artifacts for sim", async () => {
const targetDir = `${await generateTmpDir()}/target`;
const artifactDir = await compile(exampleFilePath, {
platform: [BuiltinPlatform.SIM],
targetDir,
});
const stats = await stat(artifactDir);
expect(stats.isDirectory()).toBeTruthy();
expect(artifactDir).toContain(targetDir);
expect(basename(artifactDir)).toEqual("enums.test.wsim");
});

const stats = await stat(artifactDir);
expect(stats.isDirectory()).toBeTruthy();
expect(artifactDir).toContain(targetDir);
expect(basename(artifactDir)).toEqual("enums.test.wsim")
test("should produce stable artifacts for sim testing", async () => {
const targetDir = `${await generateTmpDir()}/target`;
const artifactDir = await compile(exampleFilePath, {
platform: [BuiltinPlatform.SIM],
targetDir,
testing: true,
});

test("should produce stable artifacts for sim testing", async () => {
const targetDir = `${await generateTmpDir()}/target`;
const artifactDir = await compile(exampleFilePath, {
platform: [BuiltinPlatform.SIM],
targetDir,
testing: true,
});
const stats = await stat(artifactDir);
expect(stats.isDirectory()).toBeTruthy();
expect(artifactDir).toContain(targetDir);
expect(basename(artifactDir)).toEqual("enums.test.wsim");
});

const stats = await stat(artifactDir);
expect(stats.isDirectory()).toBeTruthy();
expect(artifactDir).toContain(targetDir);
expect(basename(artifactDir)).toEqual("enums.test.wsim")
test("should be able to override the target directory", async () => {
const output = `${await generateTmpDir()}/a/b/dir.out`;
const artifactDir = await compile(exampleFilePath, {
platform: [BuiltinPlatform.SIM],
output,
testing: true,
});

const stats = await stat(artifactDir);
expect(stats.isDirectory()).toBeTruthy();
expect(artifactDir).toBe(output);
expect(basename(artifactDir)).toEqual("dir.out");
});
});
5 changes: 4 additions & 1 deletion libs/wingcompiler/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export interface CompileOptions {

// target directory for the output files
readonly targetDir?: string;

// overrides the target directory for the output files
readonly output?: string;
}

/**
Expand Down Expand Up @@ -139,7 +142,7 @@ export async function compile(entrypoint: string, options: CompileOptions): Prom
const testing = options.testing ?? false;
log?.("testing: %s", testing);
const target = determineTargetFromPlatforms(options.platform);
const synthDir = resolveSynthDir(targetdir, entrypointFile, target, testing);
const synthDir = options.output ?? resolveSynthDir(targetdir, entrypointFile, target, testing);
log?.("synth dir: %s", synthDir);
const workDir = resolve(synthDir, DOT_WING);
log?.("work dir: %s", workDir);
Expand Down

0 comments on commit 63683b5

Please sign in to comment.