diff options
author | Renaud Paquay <rpaquay@google.com> | 2017-01-26 13:57:04 +0000 |
---|---|---|
committer | Laszlo Csomor <laszlocsomor@google.com> | 2017-01-26 14:53:56 +0000 |
commit | bbfa9fa5ad1dd66ecedcb136a4ff3d0f8d397b9b (patch) | |
tree | 6fefeda8d3f9492fa03eb52f67add9af6704d86b /src/main/java | |
parent | 015edb05335fa26a2021827502d368dbc154e9ae (diff) |
Java template windows performance
Address issue #2426
Closes #2427.
--
Reviewed-on: https://github.com/bazelbuild/bazel/pull/2427
PiperOrigin-RevId: 145664779
MOS_MIGRATED_REVID=145664779
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt | 55 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template_windows.txt | 3 |
2 files changed, 51 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt index 36575d52ab..8c9ee0db57 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt @@ -74,16 +74,50 @@ die() { } # Windows -PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" +PLATFORM="$OSTYPE" function is_windows() { # On windows, the shell test actually running on msys - if [[ "${PLATFORM}" =~ msys_nt* ]]; then + if [[ "${PLATFORM}" =~ msys* ]]; then true else false fi } +if is_windows; then + function to_win_path() { + # Replace all "/" with "\" + result="${1////\\}" + + # Replace "\x\" with "X:\" + prefix="${result:0:3}" + prefix="${prefix,,}" + for letter in {a..z} ; do + if [[ "$prefix" == "\\$letter\\" ]]; then + result="${letter^^}:${result:2}" + break + fi + done + echo "$result" + } + + function to_unix_path() { + # Replace all "\" with "/" + result="${1//\\//}" + + # Replace "C:/" or "c:/" with "/c/" + prefix="${result:0:3}" + prefix="${prefix,,}" + for letter in {a..z} ; do + if [[ "$prefix" == "$letter:/" ]]; then + result="/${letter}${result:2}" + break + fi + done + echo "$result" + } +fi + # Parse arguments sequentially until the first unrecognized arg is encountered. # Scan the remaining args for --wrapper_script_flag=X options and process them. ARGS=() @@ -119,7 +153,7 @@ done # If we are running on Windows, convert the windows style path # to unix style for detecting runfiles path. if is_windows; then - self=$(cygpath --unix "$0") + self="$(to_unix_path $0)" else self="$0" fi @@ -162,7 +196,7 @@ fi # If we are running on Windows, we need a windows style runfiles path for constructing CLASSPATH if is_windows; then - JAVA_RUNFILES=$(cygpath --windows "$JAVA_RUNFILES") + JAVA_RUNFILES="$(to_win_path $JAVA_RUNFILES)" fi RUNFILES_MANIFEST_FILE="${JAVA_RUNFILES}/MANIFEST" @@ -177,11 +211,22 @@ if [ -z "$RUNFILES_MANIFEST_ONLY" ]; then fi } else + # Read file into my_array + mapfile -t my_array < $RUNFILES_MANIFEST_FILE + + # Process each runfile line into a [key,value] entry in runfiles_array + declare -A runfiles_array + for line in "${my_array[@]}" + do + line_split=($line) + runfiles_array[${line_split[0]}]=${line_split[1]} + done + function rlocation() { if [[ "$1" = /* ]]; then echo $1 else - echo $(grep "^$1 " $RUNFILES_MANIFEST_FILE | awk '{ print $2 }') + echo ${runfiles_array[$1]} fi } fi diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template_windows.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template_windows.txt index 179d55cdee..b367f86dd7 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template_windows.txt +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template_windows.txt @@ -20,13 +20,12 @@ @SETLOCAL ENABLEEXTENSIONS @set bash_path=%bash_exe_path% -@set cygpath_path=%cygpath_exe_path% @rem launcher=${$0%.cmd} @set launcher=%~dp0%~n0 @rem sh_path=$($cygpath_path -m $launcher) -@for /f %%i in ('%cygpath_path% -m %launcher%') do @set sh_path=%%i +@set sh_path=%launcher:\=/% @rem replaces $ with \$ in $*, then puts it on the command line @rem Cribbed from here: http://ss64.com/nt/syntax-replace.html |