Skip to content

Commit

Permalink
Remove yarn_install & npm_install dependency on Windows powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Apr 23, 2019
1 parent 7d9ba37 commit 6f16ba4
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions internal/copy_repository/_copy.bat
Original file line number Diff line number Diff line change
@@ -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
30 changes: 0 additions & 30 deletions internal/copy_repository/_copy.ps1

This file was deleted.

15 changes: 1 addition & 14 deletions internal/copy_repository/_copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions internal/copy_repository/copy_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions scripts/test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tools/npm_packages/test_workspace/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
1 change: 1 addition & 0 deletions tools/npm_packages/test_workspace/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello world');
9 changes: 9 additions & 0 deletions tools/npm_packages/test_workspace/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "test_workspace",
"version": "0.0.1",
"bazelWorkspaces": {
"test_workspace": {
"rootPath": "."
}
}
}
9 changes: 9 additions & 0 deletions tools/npm_packages/test_workspace/subdir/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
1 change: 1 addition & 0 deletions tools/npm_packages/test_workspace/subdir/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello world from subdir');
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6f16ba4

Please sign in to comment.