From a16cbc66b2c59cb5e0c1256a3de42a0837da4924 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 1 Oct 2018 13:01:22 -0700 Subject: [PATCH 1/2] Only apply tsetse checks to internal repository --- internal/common/tsconfig.bzl | 1 + internal/tsc_wrapped/tsc_wrapped.ts | 6 +++++- internal/tsc_wrapped/tsconfig.ts | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/common/tsconfig.bzl b/internal/common/tsconfig.bzl index fc9467fd..fa6daa25 100644 --- a/internal/common/tsconfig.bzl +++ b/internal/common/tsconfig.bzl @@ -140,6 +140,7 @@ def create_tsconfig( "workspaceName": ctx.workspace_name, "target": str(ctx.label), "package": ctx.label.package, + "externalTarget": ctx.label.workspace_root.startswith("external/"), "tsickleGenerateExterns": getattr(ctx.attr, "generate_externs", True), "tsickleExternsPath": tsickle_externs.path if tsickle_externs else "", "untyped": not getattr(ctx.attr, "tsickle_typed", False), diff --git a/internal/tsc_wrapped/tsc_wrapped.ts b/internal/tsc_wrapped/tsc_wrapped.ts index 2e99ccb2..f539e8cf 100644 --- a/internal/tsc_wrapped/tsc_wrapped.ts +++ b/internal/tsc_wrapped/tsc_wrapped.ts @@ -109,7 +109,11 @@ function runOneBuild( ignoredFilesPrefixes, }); } - program = tsetsePlugin.wrap(program, disabledTsetseRules); + + // Only apply tsetse checks to the internal repository + if (!bazelOpts.externalTarget) { + program = tsetsePlugin.wrap(program, disabledTsetseRules); + } // These checks mirror ts.getPreEmitDiagnostics, with the important // exception that if you call program.getDeclarationDiagnostics() it somehow diff --git a/internal/tsc_wrapped/tsconfig.ts b/internal/tsc_wrapped/tsconfig.ts index 076439c0..7feba21d 100644 --- a/internal/tsc_wrapped/tsconfig.ts +++ b/internal/tsc_wrapped/tsconfig.ts @@ -33,6 +33,9 @@ export interface BazelOptions { /** The bazel package, eg my/pkg */ package: string; + /** True if the target being built is from an external workspace. */ + externalTarget: boolean; + /** If true, convert require()s into goog.module(). */ googmodule: boolean; From ad1af0fb29d66e4b0190574c98d7563e2562cd33 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 1 Oct 2018 13:26:04 -0700 Subject: [PATCH 2/2] Verify that tsetse is not run on external targets --- .bazelci/presubmit.yml | 4 ++++ .circleci/config.yml | 2 ++ WORKSPACE | 5 ++++ .../disable_tsetse_for_external/BUILD.bazel | 23 +++++++++++++++++++ .../e2e/disable_tsetse_for_external/WORKSPACE | 15 ++++++++++++ .../e2e/disable_tsetse_for_external/main.ts | 19 +++++++++++++++ .../disable_tsetse_for_external/tsconfig.json | 0 7 files changed, 68 insertions(+) create mode 100644 internal/e2e/disable_tsetse_for_external/BUILD.bazel create mode 100644 internal/e2e/disable_tsetse_for_external/WORKSPACE create mode 100644 internal/e2e/disable_tsetse_for_external/main.ts create mode 100644 internal/e2e/disable_tsetse_for_external/tsconfig.json diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index e7db89ff..855be682 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -6,6 +6,7 @@ platforms: - "@nodejs//:yarn" build_targets: - "..." + - "@disable_tsetse_for_external_test//..." test_flags: # TODO(gregmagolan): shared libs needed by chrome & firefox not available on ubuntu1404 - "--test_tag_filters=-browser:chromium-local,-browser:firefox-local" @@ -17,6 +18,7 @@ platforms: - "@nodejs//:yarn" build_targets: - "..." + - "@disable_tsetse_for_external_test//..." test_flags: # TODO(gregmagolan): shared libs needed by chrome & firefox not available on ubuntu1604 - "--test_tag_filters=-browser:chromium-local,-browser:firefox-local" @@ -28,6 +30,7 @@ platforms: - "@nodejs//:yarn" build_targets: - "..." + - "@disable_tsetse_for_external_test//..." test_flags: # TODO(gregmagolan): chrome & firefox unknown breakage on macos target here; does work locally on mac - "--test_tag_filters=-browser:chromium-local,-browser:firefox-local" @@ -39,5 +42,6 @@ platforms: - "@nodejs//:yarn" build_targets: - "..." + - "@disable_tsetse_for_external_test//..." test_targets: - "..." diff --git a/.circleci/config.yml b/.circleci/config.yml index 91dfabfc..2f506954 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -56,6 +56,7 @@ jobs: - run: bazel info release - run: bazel build ... - run: bazel test ... + - run: bazel build @disable_tsetse_for_external_test//... # This job tests the same stuff, but without the .bazelrc file. # It disables worker mode, for example. @@ -77,6 +78,7 @@ jobs: # is required to keep Bazel from exhausting the memory. - run: bazel --bazelrc=/dev/null --host_jvm_args=-Xmx3g build ... --local_resources=2560,1.0,1.0 - run: bazel --bazelrc=/dev/null --host_jvm_args=-Xmx3g test ... --local_resources=2560,1.0,1.0 + - run: bazel --bazelrc=/dev/null --host_jvm_args=-Xmx3g build @disable_tsetse_for_external_test//... --local_resources=2560,1.0,1.0 - save_cache: key: *cache_key diff --git a/WORKSPACE b/WORKSPACE index e80d8904..265eee5b 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -205,3 +205,8 @@ local_repository( name = "package_typescript_karma_e2e", path = "internal/e2e/package_typescript_karma", ) + +local_repository( + name = "disable_tsetse_for_external_test", + path = "internal/e2e/disable_tsetse_for_external", +) diff --git a/internal/e2e/disable_tsetse_for_external/BUILD.bazel b/internal/e2e/disable_tsetse_for_external/BUILD.bazel new file mode 100644 index 00000000..87c84610 --- /dev/null +++ b/internal/e2e/disable_tsetse_for_external/BUILD.bazel @@ -0,0 +1,23 @@ +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package(default_visibility = ["//visibility:public"]) + +load("@build_bazel_rules_typescript//internal:defaults.bzl", "ts_library") + +ts_library( + name = "main", + srcs = glob(["*.ts"]), + deps = ["@npm//:@types"], +) diff --git a/internal/e2e/disable_tsetse_for_external/WORKSPACE b/internal/e2e/disable_tsetse_for_external/WORKSPACE new file mode 100644 index 00000000..96c1bacf --- /dev/null +++ b/internal/e2e/disable_tsetse_for_external/WORKSPACE @@ -0,0 +1,15 @@ +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +workspace(name = "disable_tsetse_for_external_test") diff --git a/internal/e2e/disable_tsetse_for_external/main.ts b/internal/e2e/disable_tsetse_for_external/main.ts new file mode 100644 index 00000000..691f11af --- /dev/null +++ b/internal/e2e/disable_tsetse_for_external/main.ts @@ -0,0 +1,19 @@ +export {}; + +// string.trim() result is unused +let stringUnused; +stringUnused = 'hello'; +stringUnused.trim(); +const stringLiteralUnused = 'hello'; +stringLiteralUnused.trim(); + +// Array.concat() result is unused. +const arrayOfStringsUnused = ['hello']; +arrayOfStringsUnused.concat(arrayOfStringsUnused); + +// Object.create() result is unused +const objectUnused = {}; +Object.create(objectUnused); + +// string.replace() with a substring +stringUnused.replace('o', 'O'); diff --git a/internal/e2e/disable_tsetse_for_external/tsconfig.json b/internal/e2e/disable_tsetse_for_external/tsconfig.json new file mode 100644 index 00000000..e69de29b