Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/da/win'
Browse files Browse the repository at this point in the history
  • Loading branch information
olpaw committed Oct 31, 2019
2 parents d871231 + 961c5a7 commit 75b55c6
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 20 deletions.
5 changes: 3 additions & 2 deletions sdk/mx.sdk/mx_sdk_vm_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ def _add_link(_dest, _target, _component=None):
_add(layout, '<jre_base>/lib/graalvm/', ['dependency:' + d for d in graalvm_dists], _component, with_sources=True)

for _provided_executable in _component.provided_executables:
_provided_executable = mx_subst.results_substitutions.substitute(_provided_executable)
if _component.short_name == 'vvm':
_add(layout, _jdk_jre_bin, 'extracted-dependency:tools:VISUALVM_PLATFORM_SPECIFIC/./' + _provided_executable, _component)
else:
Expand Down Expand Up @@ -1526,7 +1527,7 @@ def _template_file(self):
ext = 'cmd' if mx.get_os() == 'windows' else 'sh'
_custom_launcher = self.subject.native_image_config.custom_bash_launcher
if _custom_launcher:
return join(self.subject.suite.dir, _custom_launcher + "." + ext)
return join(self.subject.component.suite.dir, _custom_launcher + "." + ext)
return join(_suite.mxDir, 'vm', 'launcher_template.' + ext)

def native_image_needs_build(self, out_file):
Expand Down Expand Up @@ -1558,7 +1559,7 @@ def _get_main_class():
return self.subject.native_image_config.main_class

def _get_extra_jvm_args():
return ' '.join(self.subject.native_image_config.extra_jvm_args)
return mx.list_to_cmd_line(self.subject.native_image_config.extra_jvm_args)

_template_subst = mx_subst.SubstitutionEngine(mx_subst.string_substitutions)
_template_subst.register_no_arg('classpath', _get_classpath)
Expand Down
2 changes: 1 addition & 1 deletion sdk/mx.sdk/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# SOFTWARE.
#
suite = {
"mxversion" : "5.231.0",
"mxversion" : "5.243.0",
"name" : "sdk",
"version" : "20.0.0",
"release" : False,
Expand Down
75 changes: 66 additions & 9 deletions sdk/mx.sdk/vm/launcher_template.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,76 @@
::
:: ----------------------------------------------------------------------------------------------------
@echo off

setlocal enabledelayedexpansion

echo %* | findstr = >nul && (
echo Warning: the '=' character in program arguments is not fully supported.
echo Make sure that command line arguments using it are wrapped in double quotes.
echo Example:
echo "--vm.Dfoo=bar"
echo.
)

set location=%~dp0

set relcp=<classpath>
set realcp=
set delim=
set "relcp=<classpath>"
set "realcp="
set "cp_delim="

:nextcp
for /f "delims=;" %%i in ("%relcp%") do (
set realcp=%realcp%%delim%%location%%%i
set delim=;
for /f "tokens=1* delims=;" %%i in ("%relcp%") do (
set "realcp=%realcp%%cp_delim%%location%%%i"
set "cp_delim=;"
set "relcp_next=%relcp:*;=%"
)
if not "%relcp_next%"=="%relcp%" set "relcp=%relcp_next%" & goto :nextcp

set "jvm_args=-Dorg.graalvm.launcher.shell=true"
set "launcher_args="
set "args_delim="

for %%a in (%*) do (
rem Unquote the argument (`u_arg=%%~a`) before checking its prefix.
rem Pass program arguments to the main class as they are quoted by the user (`arg=%%a`)
set "arg=%%a"
set "u_arg=%%~a"

set "jvm_arg="
set "wrong_cp="

rem Unfortunately, parsing of `--jvm.*` and `--vm.*` arguments has to be done blind:
rem Maybe some of those arguments where not really intended for the launcher but were application arguments
if "!u_arg:~0,5!"=="--vm." (
set "jvm_arg=-!u_arg:~5!"
) else if "!u_arg:~0,6!"=="--jvm." (
set "jvm_arg=-!u_arg:~6!"
)

if not "!jvm_arg!"=="" (
if "!jvm_arg!"=="-cp" (
set "wrong_cp=true"
) else if "!jvm_arg!"=="-classpath" (
set "wrong_cp=true"
)

if "!wrong_cp!"=="true" (
echo "!arg!" argument must be of the form "!arg!=<classpath>", not two separate arguments
exit /b 1
) else if "!jvm_arg:~0,4!"=="-cp=" (
set "realcp=%realcp%;!jvm_arg:~4!"
) else if "!jvm_arg:~0,11!"=="-classpath=" (
set "realcp=%realcp%;!jvm_arg:~11!"
) else (
rem Quote all VM arguments
set "jvm_args=!jvm_args! "!jvm_arg!""
)
) else (
set "launcher_args=!launcher_args!!args_delim!!arg!"
set "args_delim= "
)
)
set relcp_next=%relcp:*;=%
if not "%relcp_next%"=="%relcp%" set relcp=%relcp_next% & goto :nextcp

if "%VERBOSE_GRAALVM_LAUNCHERS%"=="true" echo on

"%location%<jre_bin>\java" -Dorg.graalvm.launcher.shell=true -cp "%realcp%" <main_class> %*
"%location%<jre_bin>\java" %jvm_args% <extra_jvm_args> -cp "%realcp%" <main_class> %launcher_args%
2 changes: 1 addition & 1 deletion sdk/mx.sdk/vm/launcher_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ done
jvm_args=("-Dorg.graalvm.launcher.shell=true")
launcher_args=()

# Unfortunately, parsing of `--jvm.*` arguments has to be done blind:
# Unfortunately, parsing of `--jvm.*` and `--vm.*` arguments has to be done blind:
# Maybe some of those arguments where not really intended for the launcher but were application arguments

for o in "$@"; do
Expand Down
2 changes: 1 addition & 1 deletion substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ def _native_image_launcher_extra_jvm_args():
],
),
],
provided_executables=['bin/rebuild-images'] if not mx.is_windows() else [],
provided_executables=['bin/<cmd:rebuild-images>'],
installable=True,
))

Expand Down
171 changes: 171 additions & 0 deletions substratevm/mx.substratevm/rebuild-images.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
@echo off

rem Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
rem DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
rem
rem This code is free software; you can redistribute it and/or modify it
rem under the terms of the GNU General Public License version 2 only, as
rem published by the Free Software Foundation. Oracle designates this
rem particular file as subject to the "Classpath" exception as provided
rem by Oracle in the LICENSE file that accompanied this code.
rem
rem This code is distributed in the hope that it will be useful, but WITHOUT
rem ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
rem FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
rem version 2 for more details (a copy is included in the LICENSE file that
rem accompanied this code).
rem
rem You should have received a copy of the GNU General Public License version
rem 2 along with this work; if not, write to the Free Software Foundation,
rem Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
rem
rem Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
rem or visit www.oracle.com if you need additional information or have any
rem questions.

setlocal enabledelayedexpansion

echo %* | findstr = >nul && (
echo Warning: the '=' character in program arguments is not fully supported.
echo Make sure that command line arguments using it are wrapped in double quotes.
echo Example:
echo "-Dfoo=bar"
echo.
)

set "rebuild_images=%~dpnx0"
call :dirname "%rebuild_images%" bin_dir
rem We assume we are in `lib\svm\bin`
set "graalvm_home=%bin_dir%\..\..\.."

set "to_build="
set "custom_args="

for %%a in (%*) do (
rem Unquote the argument (`u_arg=%%~a`) before checking its prefix.
rem Pass the argument to the native-image executable as it was quoted by the user (`arg=%%a`)
set "arg=%%a"
set "u_arg=%%~a"

set "_tb="
set "_h="

if "!u_arg!"=="polyglot" (
set "_tb=!u_arg!"
) else if "!u_arg!"=="libpolyglot" (
set "_tb=!u_arg!"
) else if "!u_arg!"=="js" (
set "_tb=!u_arg!"
) else if "!u_arg!"=="llvm" (
set "_tb=!u_arg!"
) else if "!u_arg!"=="python" (
set "_tb=!u_arg!"
) else if "!u_arg!"=="ruby" (
set "_tb=!u_arg!"
) else if "!u_arg!"=="--help" (
set "_h=true"
) else if "!u_arg!"=="-h" (
set "_h=true"
)

if defined _tb (
if defined to_build (
set "to_build=!to_build! !_tb!
) else (
set "to_build=!_tb!
)
) else if defined _h (
echo Rebuilds native images in place
call :usage
exit /b 0
) else if "!u_arg!"=="--verbose" (
set "verbose=true"
) else if "!u_arg!"=="-v" (
set "verbose=true"
) else if defined custom_args (
set "custom_args=!custom_args! !arg!"
) else (
set "custom_args=!arg!"
)
)

if not defined to_build (
echo Nothing to build
call :usage
exit /b 0
)

rem The list of components to be built does not contain special characters
for %%f in (%to_build%) do (
set "cmd_line="%graalvm_home%\bin\native-image""

if "%%f"=="polyglot" (
call :launcher polyglot cmd_line
) else if "%%f"=="libpolyglot" (
call :libpolyglot cmd_line
) else if "%%f"=="js" (
call :launcher js cmd_line
) else if "%%f"=="llvm" (
call :launcher lli cmd_line
) else if "%%f"=="python" (
call :launcher graalpython cmd_line
) else if "%%f"=="ruby" (
call :launcher truffleruby cmd_line
) else (
echo Should not reach here
exit /b 1
)
echo Building %%f...
if defined verbose echo !cmd_line!
!cmd_line!
)

goto :eof

:dirname file output
setlocal
set "dir=%~dp1"
set "dir=%dir:~0,-1%"
endlocal & set "%2=%dir%"
exit /b 0

:usage
echo Usage: "%~nx0 [-v|--verbose] polyglot|libpolyglot|js|llvm|python|ruby... [custom native-image args]..."
exit /b 0

:common cmd_line
setlocal
if defined custom_args (
set "cmd_line=%cmd_line% %custom_args%"
)
for /f "tokens=* usebackq" %%l in (`"%graalvm_home%\bin\native-image" --help-extra`) do (
set "line=%%l"
if not "!line:--no-server=!"=="!line!" (
set "cmd_line=%cmd_line% --no-server"
)
)
if exist "%graalvm_home%\lib\svm\builder\svm-enterprise.jar" (
set "cmd_line=%cmd_line% -g"
)
endlocal & set "%1=%cmd_line%"
exit /b 0

:polyglot_common cmd_line
set "%1=%cmd_line% --language:all"
exit /b 0

:libpolyglot cmd_line
call :common cmd_line
call :polyglot_common cmd_line
set "%1=%cmd_line% --macro:polyglot-library"
exit /b 0

:launcher cmd cmd_line
call :common cmd_line
setlocal
set "cmd_line=%cmd_line% --macro:%1-launcher"
if "%1"=="polyglot" (
call :polyglot_common cmd_line
)
endlocal & set "%2=%cmd_line%"
exit /b 0
6 changes: 3 additions & 3 deletions substratevm/mx.substratevm/rebuild-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ while [[ -h "$source" ]] ; do
done
location="$( cd -P "$( dirname "$source" )" && pwd )"

# we assume we are in `jre/lib/svm/bin`
graalvm_home="${location}/../../../.."
# we assume we are in `lib/svm/bin`
graalvm_home="${location}/../../.."

function usage_and_exit() {
echo "Usage: $0 [--verbose] polyglot|libpolyglot|js|llvm|python|ruby... [custom native-image args]..."
Expand Down Expand Up @@ -83,7 +83,7 @@ function common() {
cmd_line+=("--no-server")
fi

if [[ -f "${graalvm_home}/jre/lib/svm/builder/svm-enterprise.jar" ]]; then
if [[ -f "${graalvm_home}/lib/svm/builder/svm-enterprise.jar" ]]; then
cmd_line+=("-g")
fi
}
Expand Down
17 changes: 15 additions & 2 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,8 +995,21 @@
"native" : True,
"platformDependent" : True,
"description" : "Native Image support distribution for the GraalVM",
"layout" : {
"bin/rebuild-images" : "file:mx.substratevm/rebuild-images.sh",
"os_arch" : {
"windows": {
"<others>" : {
"layout" : {
"bin/" : "file:mx.substratevm/rebuild-images.cmd",
},
},
},
"<others>": {
"<others>": {
"layout" : {
"bin/rebuild-images" : "file:mx.substratevm/rebuild-images.sh",
},
},
},
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ public int execute() throws IOException {
}

public static Path findNativeImagePath(CommandInput input, Feedback feedback) {
Path p = input.getGraalHomePath().resolve(SystemUtils.fromCommonString(feedback.l10n("REBUILD_ToolRelativePath")));
String toolRelativePath = feedback.l10n("REBUILD_ToolRelativePath");
if (SystemUtils.isWindows()) {
toolRelativePath += ".cmd";
}
Path p = input.getGraalHomePath().resolve(SystemUtils.fromCommonString(toolRelativePath));
return (Files.isReadable(p) || Files.isExecutable(p)) ? p : null;
}
}

0 comments on commit 75b55c6

Please sign in to comment.