-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
windows_utils.bzl: Escaping \ and " before passing args to bash scrip… #1685
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0838596
windows_utils.bzl: Escaping \ and " before passing args to bash scrip…
meteorcloudy 9efad5f
Escape \ twice
meteorcloudy 5a19625
Fix binary_with_no_arguments test
meteorcloudy 878a7ac
Add test for passing cmd args
meteorcloudy 0c0e4fb
Some fixes
meteorcloudy 4e279a5
Address reviewer comments
meteorcloudy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @license | ||
* 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. | ||
*/ | ||
|
||
const process = require('process') | ||
|
||
|
||
for (var i=2; i < process.argv.length; i += 1) { | ||
console.log("arg" + i + "=(" + process.argv[i] + ")"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2019 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. | ||
|
||
# --- begin runfiles.bash initialization v2 --- | ||
# Copy-pasted from the Bazel Bash runfiles library v2. | ||
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash | ||
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$0.runfiles/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e | ||
# --- end runfiles.bash initialization v2 --- | ||
|
||
source "$(rlocation build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel-skylib/tests/unittest.bash)" \ | ||
|| { echo "Could not source build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel-skylib/tests/unittest.bash" >&2; exit 1; } | ||
|
||
case "$(uname -s | tr [:upper:] [:lower:])" in | ||
msys*|mingw*|cygwin*) | ||
declare -r is_windows=true | ||
;; | ||
*) | ||
declare -r is_windows=false | ||
;; | ||
esac | ||
|
||
if "$is_windows"; then | ||
export MSYS_NO_PATHCONV=1 | ||
export MSYS2_ARG_CONV_EXCL="*" | ||
fi | ||
|
||
function test_pass_cmd_args() { | ||
if "$is_windows"; then | ||
script=build_bazel_rules_nodejs/internal/common/test/print_cmd_args.bat | ||
else | ||
script=build_bazel_rules_nodejs/internal/common/test/print_cmd_args.sh | ||
fi | ||
|
||
"$(rlocation ${script})" '/foo bar' "\\foo \\bar" "/foo bar/" \foo\bar /foo/bar \\foo\\bar "\foo\bar" "\\foo\\bar" '\foo\bar' '\\foo\\bar' >"$TEST_log" | ||
|
||
expect_log 'arg2=(/foo bar)' | ||
expect_log 'arg3=(\\foo \\bar)' | ||
expect_log 'arg4=(/foo bar/)' | ||
expect_log 'arg5=(foobar)' | ||
expect_log 'arg6=(/foo/bar)' | ||
expect_log 'arg7=(\\foo\\bar)' | ||
expect_log 'arg8=(\\foo\\bar)' | ||
expect_log 'arg9=(\\foo\\bar)' | ||
expect_log 'arg10=(\\foo\\bar)' | ||
expect_log 'arg11=(\\\\foo\\\\bar)' | ||
} | ||
|
||
run_suite "test_pass_cmd_args test suite" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,12 @@ set RUNFILES_MANIFEST_ONLY=1 | |
call :rlocation "{sh_script}" run_script | ||
for %%a in ("{bash_bin}") do set "bash_bin_dir=%%~dpa" | ||
set PATH=%bash_bin_dir%;%PATH% | ||
"{bash_bin}" -c "!run_script! %*" | ||
set args=%* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice to have some comments here to explain that this is escaping the arguments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, comments added. |
||
if defined args ( | ||
set args=!args:\=\\\\! | ||
set args=!args:"=\"! | ||
) | ||
"{bash_bin}" -c "!run_script! !args!" | ||
""".format( | ||
bash_bin = ctx.toolchains["@bazel_tools//tools/sh:toolchain_type"].path, | ||
sh_script = _to_manifest_path(ctx, shell_script), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the
process
global variable is defined in a nodejs context without needing a require statementThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done