diff --git a/docs/api/05-language-reference.md b/docs/api/05-language-reference.md index f3240ad485e..f280f6fa600 100644 --- a/docs/api/05-language-reference.md +++ b/docs/api/05-language-reference.md @@ -593,6 +593,7 @@ the following properties (given an example intrinsic `@x`): | `@assert()` | checks a condition and _throws_ if evaluated to false | | `@filename` | absolute path of the source file | | `@dirname` | absolute path of the source file's directory | +| `@target` | a string identifying the current target platform | | `@app` | the root of the construct tree | | `@unsafeCast()` | cast a value into a different type | | `@nodeof()` | obtain the [tree node](/docs/concepts/application-tree) of a preflight object | diff --git a/packages/@winglang/wingc/src/lsp/snapshots/completions/intrinsics.snap b/packages/@winglang/wingc/src/lsp/snapshots/completions/intrinsics.snap index df4afd74925..b79b34d2f83 100644 --- a/packages/@winglang/wingc/src/lsp/snapshots/completions/intrinsics.snap +++ b/packages/@winglang/wingc/src/lsp/snapshots/completions/intrinsics.snap @@ -22,4 +22,11 @@ source: packages/@winglang/wingc/src/lsp/completions.rs kind: markdown value: "Get the normalized absolute path of the current Wing source file.\n\nThe resolved path represents a path during preflight only and is not guaranteed to be valid while inflight." sortText: bb|@filename +- label: "@target" + kind: 6 + detail: str + documentation: + kind: markdown + value: "Returns a string identifying the current compilation platform.\n\nThis value is set by the CLI at compile time and can be used to conditionally compile code that is dependent on the target platform." + sortText: bb|@target diff --git a/packages/@winglang/wingc/src/lsp/snapshots/completions/intrinsics_partial.snap b/packages/@winglang/wingc/src/lsp/snapshots/completions/intrinsics_partial.snap index df4afd74925..b79b34d2f83 100644 --- a/packages/@winglang/wingc/src/lsp/snapshots/completions/intrinsics_partial.snap +++ b/packages/@winglang/wingc/src/lsp/snapshots/completions/intrinsics_partial.snap @@ -22,4 +22,11 @@ source: packages/@winglang/wingc/src/lsp/completions.rs kind: markdown value: "Get the normalized absolute path of the current Wing source file.\n\nThe resolved path represents a path during preflight only and is not guaranteed to be valid while inflight." sortText: bb|@filename +- label: "@target" + kind: 6 + detail: str + documentation: + kind: markdown + value: "Returns a string identifying the current compilation platform.\n\nThis value is set by the CLI at compile time and can be used to conditionally compile code that is dependent on the target platform." + sortText: bb|@target diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/resource/on-start.test.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/resource/on-start.test.w_test_sim.md index dd4557439b3..7a2968f04e6 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/resource/on-start.test.w_test_sim.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/resource/on-start.test.w_test_sim.md @@ -3,14 +3,14 @@ ## stdout.log ```log [ERROR] method calls fail if the resource fails to start | Error: unexpected error! - --> on-start.test.w:6:5 + --> on-start.test.w:5:5 | | inflight class OnStartThrowerBackend impl sim.IResource { | new() { -6 | throw "unexpected error!"; +5 | throw "unexpected error!"; | ^ -at $inflight_init /on-start.test.w:6:5 -at /on-start.test.w:17:18 +at $inflight_init /on-start.test.w:5:5 +at /on-start.test.w:16:18 [ERROR] method calls fail if the resource fails to start | Error: root/Default/OnStartThrower/Resource failed to start: Error: unexpected error! [ERROR] method calls fail if the resource fails to start | Error: Resource is not running (it may have crashed or stopped) pass ─ on-start.test.wsim » root/Default/test:method calls fail if the resource fails to start diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/resource/on-stop.test.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/resource/on-stop.test.w_test_sim.md index da5227a4fdf..5e6cb205fb8 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/resource/on-stop.test.w_test_sim.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/resource/on-stop.test.w_test_sim.md @@ -3,13 +3,13 @@ ## stdout.log ```log [ERROR] if a resource throws an error on stopping, it doesn't crash the simulation | Error: unexpected error! - --> on-stop.test.w:6:5 + --> on-stop.test.w:5:5 | | inflight class OnStopThrowerBackend impl sim.IResource { | pub onStop() { -6 | throw "unexpected error!"; +5 | throw "unexpected error!"; | ^ -at onStop /on-stop.test.w:6:5 +at onStop /on-stop.test.w:5:5 pass ─ on-stop.test.wsim » root/Default/test:if a resource throws an error on stopping, it doesn't crash the simulation Tests 1 passed (1) diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/schedule/init.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/schedule/init.test.w_compile_tf-aws.md new file mode 100644 index 00000000000..e93a393f163 --- /dev/null +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/schedule/init.test.w_compile_tf-aws.md @@ -0,0 +1,33 @@ +# [init.test.w](../../../../../../tests/sdk_tests/schedule/init.test.w) | compile | tf-aws + +## main.tf.json +```json +{ + "//": { + "metadata": { + "backend": "local", + "stackName": "root" + }, + "outputs": {} + }, + "provider": { + "aws": [ + {} + ] + }, + "resource": { + "aws_cloudwatch_event_rule": { + "s0_Schedule_7FE1E150": { + "//": { + "metadata": { + "path": "root/Default/Default/s0/Schedule", + "uniqueId": "s0_Schedule_7FE1E150" + } + }, + "schedule_expression": "rate(5 minutes)" + } + } + } +} +``` + diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/schedule/init.test.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/schedule/init.test.w_test_sim.md new file mode 100644 index 00000000000..9329ccefd9c --- /dev/null +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/schedule/init.test.w_test_sim.md @@ -0,0 +1,12 @@ +# [init.test.w](../../../../../../tests/sdk_tests/schedule/init.test.w) | test | sim + +## stdout.log +```log +pass ─ init.test.wsim (no tests) + +Tests 1 passed (1) +Snapshots 1 skipped +Test Files 1 passed (1) +Duration +``` + diff --git a/tools/hangar/__snapshots__/test_corpus/valid/casting.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/casting.test.w_compile_tf-aws.md index 47b9f5b4e68..86887482149 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/casting.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/casting.test.w_compile_tf-aws.md @@ -85,11 +85,10 @@ class $Root extends $stdlib.std.Resource { $helpers.nodeof(this).root.$preflightTypesMap = { }; let $preflightTypesMap = {}; const cloud = $stdlib.cloud; - const util = $stdlib.util; const aws = require("@cdktf/provider-aws"); $helpers.nodeof(this).root.$preflightTypesMap = $preflightTypesMap; const b = globalThis.$ClassFactory.new("@winglang/sdk.cloud.Bucket", cloud.Bucket, this, "Bucket"); - if ($helpers.eq((util.Util.env("WING_TARGET")), "tf-aws")) { + if ($helpers.eq(process.env.WING_TARGET, "tf-aws")) { const s3Bucket = ($helpers.nodeof(b).findChild("Default")); (s3Bucket.addOverride("bucket_prefix", "my-prefix-")); console.log($helpers.nodeof(s3Bucket).path); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md index 31d6ec7983f..385847fa764 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md @@ -51,7 +51,7 @@ module.exports = function({ $foo }) { "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); const $macros = require("@winglang/sdk/lib/macros"); -module.exports = function({ $expect_Util, $fn, $fn2, $sim }) { +module.exports = function({ $expect_Util, $fn, $fn2 }) { class $Closure3 { constructor($args) { const { } = $args; @@ -64,7 +64,7 @@ module.exports = function({ $expect_Util, $fn, $fn2, $sim }) { const y = (await $fn.invoke("")); const z = (await $fn2.invoke("")); (await $expect_Util.equal(x, "100")); - if ($sim) { + if ($helpers.eq(process.env.WING_TARGET, "sim")) { (await $expect_Util.equal(y, "101")); console.log("client has been reused"); } @@ -546,7 +546,6 @@ class $Root extends $stdlib.std.Resource { $expect_Util: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(globalThis.$ClassFactory.resolveType("@winglang/sdk.expect.Util") ?? expect.Util, "@winglang/sdk/expect", "Util"))}, $fn: ${$stdlib.core.liftObject(fn)}, $fn2: ${$stdlib.core.liftObject(fn2)}, - $sim: ${$stdlib.core.liftObject(sim)}, }) `; } @@ -556,13 +555,11 @@ class $Root extends $stdlib.std.Resource { [$stdlib.core.toLiftableModuleType(globalThis.$ClassFactory.resolveType("@winglang/sdk.expect.Util") ?? expect.Util, "@winglang/sdk/expect", "Util"), ["equal"]], [fn, ["invoke"]], [fn2, ["invoke"]], - [sim, []], ], "$inflight_init": [ [$stdlib.core.toLiftableModuleType(globalThis.$ClassFactory.resolveType("@winglang/sdk.expect.Util") ?? expect.Util, "@winglang/sdk/expect", "Util"), []], [fn, []], [fn2, []], - [sim, []], ], }); } @@ -630,7 +627,6 @@ class $Root extends $stdlib.std.Resource { const foo = new Foo(this, "Foo"); const fn = globalThis.$ClassFactory.new("@winglang/sdk.cloud.Function", cloud.Function, this, "Function", new $Closure1(this, "$Closure1")); const fn2 = globalThis.$ClassFactory.new("@winglang/sdk.cloud.Function", cloud.Function, this, "fn2", new $Closure2(this, "$Closure2")); - const sim = $helpers.eq((util.Util.env("WING_TARGET")), "sim"); globalThis.$ClassFactory.new("@winglang/sdk.std.Test", std.Test, this, "test:single instance of Foo", new $Closure3(this, "$Closure3")); const fn3 = globalThis.$ClassFactory.new("@winglang/sdk.cloud.Function", cloud.Function, this, "fn3", new $Closure4(this, "$Closure4")); globalThis.$ClassFactory.new("@winglang/sdk.std.Test", std.Test, this, "test:Foo state is not shared between function invocations", new $Closure5(this, "$Closure5")); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/intrinsics.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/intrinsics.test.w_compile_tf-aws.md index 98e4e785968..8c28992ceed 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/intrinsics.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/intrinsics.test.w_compile_tf-aws.md @@ -134,6 +134,7 @@ class $Root extends $stdlib.std.Resource { (expect.Util.equal($helpers.resolve(__dirname, "../../../intrinsics.test.w"), currentFile)); (expect.Util.equal((fs.Util.dirname(currentFile)), $helpers.resolve(__dirname, "../../.."))); (expect.Util.equal((bar.Bar.getSubfile(this)), (fs.Util.join($helpers.resolve(__dirname, "../../.."), "subdir", "bar.w")))); + (expect.Util.ok($macros.__Array_contains(false, ["sim", "tf-aws", "tf-azure", "tf-gcp", "awscdk"], process.env.WING_TARGET))); } } const $APP = $PlatformManager.createApp({ outdir: $outdir, name: "intrinsics.test", rootConstruct: $Root, isTestEnvironment: $wing_is_test, entrypointDir: process.env['WING_SOURCE_DIR'], rootId: process.env['WING_ROOT_ID'] });