From 6f16ba43ce980f0c3e020f95ec4c69d1676921e3 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 22 Apr 2019 16:32:40 -0700 Subject: [PATCH] Remove yarn_install & npm_install dependency on Windows powershell Fixes https://github.com/angular/angular/issues/29760 --- .circleci/config.yml | 2 ++ WORKSPACE | 5 ++++ internal/copy_repository/_copy.bat | 19 ++++++++++++ internal/copy_repository/_copy.ps1 | 30 ------------------- internal/copy_repository/_copy.sh | 15 +--------- internal/copy_repository/copy_repository.bzl | 12 ++++---- package.json | 1 + scripts/test_all.sh | 7 +++++ tools/npm_packages/test_workspace/BUILD.bazel | 9 ++++++ tools/npm_packages/test_workspace/index.js | 1 + .../npm_packages/test_workspace/package.json | 9 ++++++ .../test_workspace/subdir/BUILD.bazel | 9 ++++++ .../test_workspace/subdir/index.js | 1 + yarn.lock | 3 ++ 14 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 internal/copy_repository/_copy.bat delete mode 100644 internal/copy_repository/_copy.ps1 create mode 100644 tools/npm_packages/test_workspace/BUILD.bazel create mode 100644 tools/npm_packages/test_workspace/index.js create mode 100644 tools/npm_packages/test_workspace/package.json create mode 100644 tools/npm_packages/test_workspace/subdir/BUILD.bazel create mode 100644 tools/npm_packages/test_workspace/subdir/index.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 41703af6a1..248c7c0486 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -162,6 +162,8 @@ jobs: - run: bazel run //internal/node/test:has_deps_hybrid - run: bazel run //internal/e2e/fine_grained_no_bin:index - run: bazel run @fine_grained_deps_yarn//typescript/bin:tsc + - run: bazel run @test_workspace//:bin + - run: bazel run @test_workspace//subdir:bin test_legacy_runfiles: <<: *job_defaults diff --git a/WORKSPACE b/WORKSPACE index dafd35b273..2f37c4f6f3 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -81,6 +81,11 @@ yarn_install( "@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_nested_main/nested/main.js", "@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_nested_main/nested/package.json", "@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_nested_main/package.json", + "@build_bazel_rules_nodejs//:tools/npm_packages/test_workspace/BUILD.bazel", + "@build_bazel_rules_nodejs//:tools/npm_packages/test_workspace/index.js", + "@build_bazel_rules_nodejs//:tools/npm_packages/test_workspace/package.json", + "@build_bazel_rules_nodejs//:tools/npm_packages/test_workspace/subdir/BUILD.bazel", + "@build_bazel_rules_nodejs//:tools/npm_packages/test_workspace/subdir/index.js", ], package_json = "//:package.json", yarn_lock = "//:yarn.lock", diff --git a/internal/copy_repository/_copy.bat b/internal/copy_repository/_copy.bat new file mode 100644 index 0000000000..bb7017bcf3 --- /dev/null +++ b/internal/copy_repository/_copy.bat @@ -0,0 +1,19 @@ +REM Copyright 2018 The Bazel Authors. All rights reserved. +REM +REM Licensed under the Apache License, Version 2.0 (the "License"); +REM you may not use this file except in compliance with the License. +REM You may obtain a copy of the License at +REM +REM http://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. + +REM This file name starts with an underscore as it is copied +REM to the yarn_install/npm_install external repository before it is run. +REM This makes it less likely to conflict with user data files. + +xcopy /E %1 %2 diff --git a/internal/copy_repository/_copy.ps1 b/internal/copy_repository/_copy.ps1 deleted file mode 100644 index e1dc416b26..0000000000 --- a/internal/copy_repository/_copy.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2018 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. - -# This file name starts with an underscore as it is copied -# to the yarn_install/npm_install external repository before it is run. -# This makes it less likely to conflict with user data files. - -$markerFile = $args[0] -$outDir = $args[1] -$srcDir = Split-Path $markerFile - -$srcFiles = Get-ChildItem -Path $srcDir -Recurse -File -Name -foreach ($srcFile in $srcFiles) { - $srcPath = Join-Path -Path $srcDir -ChildPath $srcFile - $destPath = Join-Path -Path $outDir -ChildPath $srcFile - $destDir = Split-Path $destPath - New-Item -Path $destDir -ItemType directory -Force - Copy-Item -Path $srcPath -Destination $destPath -} diff --git a/internal/copy_repository/_copy.sh b/internal/copy_repository/_copy.sh index beb46fea06..93aa61df07 100644 --- a/internal/copy_repository/_copy.sh +++ b/internal/copy_repository/_copy.sh @@ -17,21 +17,8 @@ # to the yarn_install/npm_install external repository before it is run. # This makes it less likely to conflict with user data files. -wrap() { - out=$("$@" 2>&1) - ret="$?" - if [[ "$ret" -ne 0 ]]; then - >&2 printf "$out" - >&2 printf "\n" - exit "$ret" - fi -} - -MARKER_FILE=$1 +SRC_DIR=$1 OUT_DIR=$2 mkdir -p "${OUT_DIR}" - -SRC_DIR=$(dirname "${MARKER_FILE}") - cp -a $SRC_DIR/. $OUT_DIR diff --git a/internal/copy_repository/copy_repository.bzl b/internal/copy_repository/copy_repository.bzl index 61ccb476fb..0e76cf3ff1 100644 --- a/internal/copy_repository/copy_repository.bzl +++ b/internal/copy_repository/copy_repository.bzl @@ -18,17 +18,17 @@ load("@build_bazel_rules_nodejs//internal/common:os_name.bzl", "os_name") def _copy_file(rctx, src): - src_path = rctx.path(src) - rctx.template(src_path.basename, src_path) + rctx.template(src.basename, src) def _copy_repository_impl(rctx): + src_path = "/".join(str(rctx.path(rctx.attr.marker_file)).split("/")[:-1]) is_windows = os_name(rctx).find("windows") != -1 if is_windows: - _copy_file(rctx, Label("@build_bazel_rules_nodejs//internal/copy_repository:_copy.ps1")) - result = rctx.execute(["powershell", "-file", "_copy.ps1", rctx.path(rctx.attr.marker_file), "."]) + _copy_file(rctx, rctx.path(Label("@build_bazel_rules_nodejs//internal/copy_repository:_copy.bat"))) + result = rctx.execute(["cmd.exe", "/C", "_copy.bat", src_path.replace("/", "\\"), "."]) else: - _copy_file(rctx, Label("@build_bazel_rules_nodejs//internal/copy_repository:_copy.sh")) - result = rctx.execute(["./_copy.sh", rctx.path(rctx.attr.marker_file), "."]) + _copy_file(rctx, rctx.path(Label("@build_bazel_rules_nodejs//internal/copy_repository:_copy.sh"))) + result = rctx.execute(["./_copy.sh", src_path, "."]) if result.return_code: fail("copy_repository failed: \nSTDOUT:\n%s\nSTDERR:\n%s" % (result.stdout, result.stderr)) diff --git a/package.json b/package.json index 10aae99c79..f9ac20e205 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "rollup-plugin-node-resolve": "~4.2.0", "rollup-plugin-sourcemaps": "^0.4.2", "shelljs": "0.8.3", + "test_workspaces": "file:./tools/npm_packages/test_workspace", "typescript": "^3.3.1", "unidiff": "1.0.1", "zone.js": "0.8.29" diff --git a/scripts/test_all.sh b/scripts/test_all.sh index 5fe817a322..09bd5b9e78 100755 --- a/scripts/test_all.sh +++ b/scripts/test_all.sh @@ -47,8 +47,15 @@ echo_and_run bazel run //internal/node/test:has_deps_hybrid echo_and_run bazel run //internal/e2e/fine_grained_no_bin:index echo_and_run bazel run @fine_grained_deps_yarn//typescript/bin:tsc +# TODO: Once https://github.com/bazelbuild/bazel/pull/8090 lands targets +# can be changed to test targets and we can run them with `bazel test` +echo_and_run bazel run @test_workspace//:bin +echo_and_run bazel run @test_workspace//subdir:bin + # bazel test @examples_program//... # DOES NOT WORK WITH --nolegacy_external_runfiles # bazel test @internal_e2e_packages//... # DOES NOT WORK WITH --nolegacy_external_runfiles +# TODO: re-enable when after https://github.com/bazelbuild/bazel/pull/8090 makes it into a Bazel release +# Related issue https://github.com/bazelbuild/bazel/issues/8088 on Windows echo_and_run ./scripts/build_release.sh echo_and_run ./scripts/build_packages_all.sh diff --git a/tools/npm_packages/test_workspace/BUILD.bazel b/tools/npm_packages/test_workspace/BUILD.bazel new file mode 100644 index 0000000000..c286620f33 --- /dev/null +++ b/tools/npm_packages/test_workspace/BUILD.bazel @@ -0,0 +1,9 @@ +load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") + +nodejs_binary( + name = "bin", + data = [ + ":index.js", + ], + entry_point = "test_workspace/index.js", +) diff --git a/tools/npm_packages/test_workspace/index.js b/tools/npm_packages/test_workspace/index.js new file mode 100644 index 0000000000..5a68eb5f11 --- /dev/null +++ b/tools/npm_packages/test_workspace/index.js @@ -0,0 +1 @@ +console.log('Hello world'); \ No newline at end of file diff --git a/tools/npm_packages/test_workspace/package.json b/tools/npm_packages/test_workspace/package.json new file mode 100644 index 0000000000..03028f82db --- /dev/null +++ b/tools/npm_packages/test_workspace/package.json @@ -0,0 +1,9 @@ +{ + "name": "test_workspace", + "version": "0.0.1", + "bazelWorkspaces": { + "test_workspace": { + "rootPath": "." + } + } +} diff --git a/tools/npm_packages/test_workspace/subdir/BUILD.bazel b/tools/npm_packages/test_workspace/subdir/BUILD.bazel new file mode 100644 index 0000000000..1d531b019b --- /dev/null +++ b/tools/npm_packages/test_workspace/subdir/BUILD.bazel @@ -0,0 +1,9 @@ +load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") + +nodejs_binary( + name = "bin", + data = [ + ":index.js", + ], + entry_point = "test_workspace/subdir/index.js", +) diff --git a/tools/npm_packages/test_workspace/subdir/index.js b/tools/npm_packages/test_workspace/subdir/index.js new file mode 100644 index 0000000000..1e288822c9 --- /dev/null +++ b/tools/npm_packages/test_workspace/subdir/index.js @@ -0,0 +1 @@ +console.log('Hello world from subdir'); \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 302dd8e6da..2843e8b044 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1455,6 +1455,9 @@ strip-eof@^1.0.0: resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8= +"test_workspaces@file:./tools/npm_packages/test_workspace": + version "0.0.1" + to-ast@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/to-ast/-/to-ast-1.0.0.tgz#0c4a31c8c98edfde9aaf0192c794b4c8b11ee287"