diff --git a/package.json b/package.json index 2505770091..76fb8c7110 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "start": "node scripts/hosted_mode/start_chrome_and_server.js", "test": "node scripts/npm_test.js", "test-local": "node scripts/npm_test.js --layout-tests-directory=test/webtests/", - "unittest": "NO_TEXT_COVERAGE=1 python scripts/test/run_unittests.py" + "unittest": "NO_TEXT_COVERAGE=1 python scripts/test/run_unittests.py", + "ts_library-test": "./third_party/typescript/tests/verify_ts_libary.sh" } } \ No newline at end of file diff --git a/third_party/typescript/tests/.gitignore b/third_party/typescript/tests/.gitignore index 466e24805a..5a7096bc0d 100644 --- a/third_party/typescript/tests/.gitignore +++ b/third_party/typescript/tests/.gitignore @@ -1 +1,2 @@ -out/ \ No newline at end of file +out/ +build_output.txt \ No newline at end of file diff --git a/third_party/typescript/tests/README.md b/third_party/typescript/tests/README.md index 296645c7f0..b4b2f40bc7 100644 --- a/third_party/typescript/tests/README.md +++ b/third_party/typescript/tests/README.md @@ -7,5 +7,4 @@ All tests are fixtures in the [fixtures/](fixtures/) directory, which are compil Each test fixture contains the following: - A `.gn` file which specifies this is a GN root, to run `gn gen` on the correct directory. - A `BUILDCONFIG.gn` which includes the minimal Chromium configuration to work with `autoninja`. - -All fixtures specify the (otherwise unused) toolchain defined in `toolchain/BUILD.gn`, as it is required by Ninja to succesfully run a build. +- A `toolchain/BUILD.gn` which specifies an (otherwise unused) toolchain, as it is required by Ninja to succesfully run a build. diff --git a/third_party/typescript/tests/fixtures/compilation_failure_front_end/.gn b/third_party/typescript/tests/fixtures/compilation_failure_front_end/.gn new file mode 100644 index 0000000000..f6bbde0267 --- /dev/null +++ b/third_party/typescript/tests/fixtures/compilation_failure_front_end/.gn @@ -0,0 +1,5 @@ +# Copyright 2020 the V8 project authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +buildconfig = "//BUILDCONFIG.gn" diff --git a/third_party/typescript/tests/fixtures/compilation_failure_front_end/BUILD.gn b/third_party/typescript/tests/fixtures/compilation_failure_front_end/BUILD.gn new file mode 100644 index 0000000000..6b4340eca9 --- /dev/null +++ b/third_party/typescript/tests/fixtures/compilation_failure_front_end/BUILD.gn @@ -0,0 +1,7 @@ +# Copyright 2020 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +group("compilation_failure_front_end") { + deps = [ "front_end/module" ] +} diff --git a/third_party/typescript/tests/fixtures/compilation_failure_front_end/BUILDCONFIG.gn b/third_party/typescript/tests/fixtures/compilation_failure_front_end/BUILDCONFIG.gn new file mode 100644 index 0000000000..532299ad86 --- /dev/null +++ b/third_party/typescript/tests/fixtures/compilation_failure_front_end/BUILDCONFIG.gn @@ -0,0 +1,9 @@ +# Copyright (c) 2019 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +declare_args() { + devtools_location = "../../../../../" +} + +set_default_toolchain("//toolchain:default") diff --git a/third_party/typescript/tests/fixtures/compilation_failure_front_end/build_output.txt.expected b/third_party/typescript/tests/fixtures/compilation_failure_front_end/build_output.txt.expected new file mode 100644 index 0000000000..062d447615 --- /dev/null +++ b/third_party/typescript/tests/fixtures/compilation_failure_front_end/build_output.txt.expected @@ -0,0 +1,14 @@ +ninja: Entering directory `./third_party/typescript/tests/out/fixtures/compilation_failure_front_end' +[1/5] ACTION //front_end/module:dep(//toolchain:default) +[2/5] STAMP obj/front_end/module/dep.stamp +[3/5] ACTION //front_end/module:module(//toolchain:default) +FAILED: gen/front_end/module/module-tsconfig.json gen/front_end/module/module-tsconfig.json.tsbuildinfo gen/front_end/module/index.js gen/front_end/module/index.js.map resources/inspector/module/index.js gen/front_end/module/index.d.ts +python ts_library.py --tsconfig_output_location gen/front_end/module/module-tsconfig.json --deps ./dep-tsconfig.json --front_end_directory ../../../fixtures/compilation_failure_front_end/front_end/module --sources ../../../fixtures/compilation_failure_front_end/front_end/module/index.ts + +TypeScript compilation failed. Used tsconfig gen/front_end/module/module-tsconfig.json + +../../../fixtures/compilation_failure_front_end/front_end/module/index.ts(3,1): error TS2349: This expression is not callable. + Type 'Number' has no call signatures. + + +ninja: build stopped: subcommand failed. diff --git a/third_party/typescript/tests/fixtures/compilation_failure_front_end/front_end/module/BUILD.gn b/third_party/typescript/tests/fixtures/compilation_failure_front_end/front_end/module/BUILD.gn new file mode 100644 index 0000000000..bfeecbf4c4 --- /dev/null +++ b/third_party/typescript/tests/fixtures/compilation_failure_front_end/front_end/module/BUILD.gn @@ -0,0 +1,14 @@ +# Copyright 2020 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +import("../../../../../typescript.gni") + +ts_library("module") { + sources = [ "index.ts" ] + + deps = [ ":dep" ] +} + +ts_library("dep") { + sources = [ "exporting.ts" ] +} diff --git a/third_party/typescript/tests/fixtures/compilation_failure_front_end/front_end/module/exporting.ts b/third_party/typescript/tests/fixtures/compilation_failure_front_end/front_end/module/exporting.ts new file mode 100644 index 0000000000..98e78b18cc --- /dev/null +++ b/third_party/typescript/tests/fixtures/compilation_failure_front_end/front_end/module/exporting.ts @@ -0,0 +1 @@ +export const foo = 42; \ No newline at end of file diff --git a/third_party/typescript/tests/fixtures/compilation_failure_front_end/front_end/module/index.ts b/third_party/typescript/tests/fixtures/compilation_failure_front_end/front_end/module/index.ts new file mode 100644 index 0000000000..2036c3cb04 --- /dev/null +++ b/third_party/typescript/tests/fixtures/compilation_failure_front_end/front_end/module/index.ts @@ -0,0 +1,3 @@ +import {foo} from './exporting.js'; + +foo(); \ No newline at end of file diff --git a/third_party/typescript/tests/toolchain/BUILD.gn b/third_party/typescript/tests/fixtures/compilation_failure_front_end/toolchain/BUILD.gn similarity index 81% rename from third_party/typescript/tests/toolchain/BUILD.gn rename to third_party/typescript/tests/fixtures/compilation_failure_front_end/toolchain/BUILD.gn index 29c2a84dd1..35e817644d 100644 --- a/third_party/typescript/tests/toolchain/BUILD.gn +++ b/third_party/typescript/tests/fixtures/compilation_failure_front_end/toolchain/BUILD.gn @@ -2,10 +2,6 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -pool("action_pool") { - depth = 1 -} - toolchain("default") { # These two are really entirely generic, but have to be repeated in # each toolchain because GN doesn't allow a template to be used here. @@ -14,7 +10,4 @@ toolchain("default") { command = "touch {{output}}" description = "STAMP {{output}}" } - tool("action") { - pool = ":action_pool($default_toolchain)" - } } diff --git a/third_party/typescript/tests/fixtures/simple_dep/BUILDCONFIG.gn b/third_party/typescript/tests/fixtures/simple_dep/BUILDCONFIG.gn index 849e9e411d..532299ad86 100644 --- a/third_party/typescript/tests/fixtures/simple_dep/BUILDCONFIG.gn +++ b/third_party/typescript/tests/fixtures/simple_dep/BUILDCONFIG.gn @@ -6,4 +6,4 @@ declare_args() { devtools_location = "../../../../../" } -set_default_toolchain("../../toolchain:default") +set_default_toolchain("//toolchain:default") diff --git a/third_party/typescript/tests/fixtures/simple_dep/build_output.txt.expected b/third_party/typescript/tests/fixtures/simple_dep/build_output.txt.expected new file mode 100644 index 0000000000..a94418a1cc --- /dev/null +++ b/third_party/typescript/tests/fixtures/simple_dep/build_output.txt.expected @@ -0,0 +1,6 @@ +ninja: Entering directory `./third_party/typescript/tests/out/fixtures/simple_dep' +[1/5] ACTION //front_end/module:dep(//toolchain:default) +[2/5] STAMP obj/front_end/module/dep.stamp +[3/5] ACTION //front_end/module:module(//toolchain:default) +[4/5] STAMP obj/front_end/module/module.stamp +[5/5] STAMP obj/simple_dep.stamp diff --git a/third_party/typescript/tests/fixtures/simple_dep/toolchain/BUILD.gn b/third_party/typescript/tests/fixtures/simple_dep/toolchain/BUILD.gn new file mode 100644 index 0000000000..35e817644d --- /dev/null +++ b/third_party/typescript/tests/fixtures/simple_dep/toolchain/BUILD.gn @@ -0,0 +1,13 @@ +# Copyright 2020 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +toolchain("default") { + # These two are really entirely generic, but have to be repeated in + # each toolchain because GN doesn't allow a template to be used here. + # See //build/toolchain/toolchain.gni for details. + tool("stamp") { + command = "touch {{output}}" + description = "STAMP {{output}}" + } +} diff --git a/third_party/typescript/tests/fixtures/test_dep/BUILDCONFIG.gn b/third_party/typescript/tests/fixtures/test_dep/BUILDCONFIG.gn index 849e9e411d..532299ad86 100644 --- a/third_party/typescript/tests/fixtures/test_dep/BUILDCONFIG.gn +++ b/third_party/typescript/tests/fixtures/test_dep/BUILDCONFIG.gn @@ -6,4 +6,4 @@ declare_args() { devtools_location = "../../../../../" } -set_default_toolchain("../../toolchain:default") +set_default_toolchain("//toolchain:default") diff --git a/third_party/typescript/tests/fixtures/test_dep/build_output.txt.expected b/third_party/typescript/tests/fixtures/test_dep/build_output.txt.expected new file mode 100644 index 0000000000..20d6ea65f9 --- /dev/null +++ b/third_party/typescript/tests/fixtures/test_dep/build_output.txt.expected @@ -0,0 +1,8 @@ +ninja: Entering directory `./third_party/typescript/tests/out/fixtures/test_dep' +[1/7] ACTION //front_end/module:dep(//toolchain:default) +[2/7] STAMP obj/front_end/module/dep.stamp +[3/7] ACTION //front_end/module:module(//toolchain:default) +[4/7] STAMP obj/front_end/module/module.stamp +[5/7] ACTION //test/module:module(//toolchain:default) +[6/7] STAMP obj/test/module/module.stamp +[7/7] STAMP obj/test_dep.stamp diff --git a/third_party/typescript/tests/fixtures/test_dep/toolchain/BUILD.gn b/third_party/typescript/tests/fixtures/test_dep/toolchain/BUILD.gn new file mode 100644 index 0000000000..35e817644d --- /dev/null +++ b/third_party/typescript/tests/fixtures/test_dep/toolchain/BUILD.gn @@ -0,0 +1,13 @@ +# Copyright 2020 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +toolchain("default") { + # These two are really entirely generic, but have to be repeated in + # each toolchain because GN doesn't allow a template to be used here. + # See //build/toolchain/toolchain.gni for details. + tool("stamp") { + command = "touch {{output}}" + description = "STAMP {{output}}" + } +} diff --git a/third_party/typescript/tests/verify_ts_libary.sh b/third_party/typescript/tests/verify_ts_libary.sh index dfffdde25c..16d0385924 100755 --- a/third_party/typescript/tests/verify_ts_libary.sh +++ b/third_party/typescript/tests/verify_ts_libary.sh @@ -3,12 +3,35 @@ # found in the LICENSE file. ROOT_DIRECTORY=$(dirname "$0") +TS_LIBRARY_PATH=$(realpath $ROOT_DIRECTORY/../ts_library.py | sed 's/\//\\\//g') rm -rf $ROOT_DIRECTORY/out/fixtures +failed=0 -gn gen --root=$ROOT_DIRECTORY/fixtures/simple_dep $ROOT_DIRECTORY/out/fixtures/simple_dep -autoninja -C $ROOT_DIRECTORY/out/fixtures/simple_dep simple_dep +run_fixture() { + local fixture_name="$1" + local build_output_file="$ROOT_DIRECTORY/fixtures/$fixture_name/build_output.txt" + echo "Generating Ninja build files for $fixture_name" + gn gen --root=$ROOT_DIRECTORY/fixtures/$fixture_name $ROOT_DIRECTORY/out/fixtures/$fixture_name -gn gen --root=$ROOT_DIRECTORY/fixtures/test_dep $ROOT_DIRECTORY/out/fixtures/test_dep -autoninja -C $ROOT_DIRECTORY/out/fixtures/test_dep test_dep \ No newline at end of file + echo "Compiling with Ninja for $fixture_name" + autoninja -C $ROOT_DIRECTORY/out/fixtures/$fixture_name $fixture_name > "$build_output_file" + + # Replace the absolute python library path to make sure we can diff on different machines + sed -i "" "s/$TS_LIBRARY_PATH/ts_library.py/g" $build_output_file + + diff_output=$(diff "$build_output_file.expected" "$build_output_file") + + if [[ "$diff_output" != "" ]]; then + echo "Diff output for $fixture_name:" + echo "$diff_output" + failed=1 + fi +} + +run_fixture "simple_dep" +run_fixture "test_dep" +run_fixture "compilation_failure_front_end" + +exit $failed \ No newline at end of file diff --git a/third_party/typescript/ts_library.py b/third_party/typescript/ts_library.py index b24fe9266d..9902127237 100644 --- a/third_party/typescript/ts_library.py +++ b/third_party/typescript/ts_library.py @@ -96,7 +96,7 @@ def main(): found_errors, stderr = runTsc(tsconfig_location=tsconfig_output_location) if found_errors: print('') - print('TypeScript compilation failed. Used tsconfig %s' % tsconfig_output_location) + print('TypeScript compilation failed. Used tsconfig %s' % opts.tsconfig_output_location) print('') print(stderr) print('')