forked from oracle/graal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make native-image equally usable for image building during development and release.
- Loading branch information
Showing
31 changed files
with
2,548 additions
and
1,816 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,4 @@ | |
**/src_gen/ | ||
**/test-output/ | ||
**/workingsets.xml | ||
**/native-image |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,7 @@ | ||
# This file contains support for building a set of junit tests into a native-image | ||
|
||
ImageName = svmjunit | ||
|
||
Args = -H:Features=com.oracle.svm.junit.JUnitFeature \ | ||
-H:Class=com.oracle.svm.junit.SVMJUnitRunner \ | ||
-H:TestFile=${*} \ |
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,5 @@ | ||
# This file contains support for building an image with NFI support | ||
|
||
Requires = Tool:truffle | ||
|
||
Args = -H:Features=com.oracle.svm.truffle.nfi.TruffleNFIFeature |
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 @@ | ||
Requires = Builtin:truffle |
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
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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
--debug-attach attach to debugger during image building | ||
-no-server do not use image-build server | ||
|
||
Raw image building options | ||
-server{-list[-details],-cleanup,-shutdown}[-all] where | ||
-list lists current image-build servers | ||
-cleanup remove stale image-build servers entries | ||
-shutdown cleanly shutdown running image-build servers | ||
|
||
-H:+PrintFlags list possible HostedOptions | ||
-R:+PrintFlags list possible RuntimeOptions | ||
Without using optional -all ending above actions are performed only | ||
for the current login-session. | ||
|
||
-server-session=<custom-session-name> | ||
Use custom session name instead of system provided | ||
session ID of the calling process | ||
|
||
-debug-attach attach to debugger during image building | ||
|
||
The non-standard options are subject to change without notice. |
166 changes: 166 additions & 0 deletions
166
substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java
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,166 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package com.oracle.svm.driver; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Queue; | ||
import java.util.jar.Attributes; | ||
import java.util.jar.Manifest; | ||
|
||
class DefaultOptionHandler extends NativeImage.OptionHandler<NativeImage> { | ||
|
||
DefaultOptionHandler(NativeImage nativeImage) { | ||
super(nativeImage); | ||
} | ||
|
||
@Override | ||
public boolean consume(Queue<String> args) { | ||
String headArg = args.peek(); | ||
switch (headArg) { | ||
case "-?": | ||
case "-help": | ||
args.poll(); | ||
nativeImage.showMessage(NativeImage.buildContext().helpText); | ||
System.exit(0); | ||
return true; | ||
case "-X": | ||
args.poll(); | ||
nativeImage.showMessage(NativeImage.buildContext().helpTextX); | ||
System.exit(0); | ||
return true; | ||
case "-cp": | ||
case "-classpath": | ||
args.poll(); | ||
String cpArgs = args.poll(); | ||
if (cpArgs == null) { | ||
NativeImage.showError("-cp requires class path specification"); | ||
} | ||
for (String cp : cpArgs.split(":")) { | ||
nativeImage.addCustomImageClasspath(Paths.get(cp)); | ||
} | ||
return true; | ||
case "-jar": | ||
args.poll(); | ||
String jarFilePathStr = args.poll(); | ||
if (jarFilePathStr == null) { | ||
NativeImage.showError("-jar requires jar file specification"); | ||
} | ||
handleJarFileArg(Paths.get(jarFilePathStr).toFile()); | ||
return true; | ||
case "-verbose": | ||
args.poll(); | ||
nativeImage.setVerbose(true); | ||
return true; | ||
case "-debug-attach": | ||
args.poll(); | ||
nativeImage.addImageBuilderJavaArgs("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=y"); | ||
return true; | ||
} | ||
|
||
if (headArg.startsWith(NativeImage.oH) || headArg.startsWith(NativeImage.oR)) { | ||
args.poll(); | ||
nativeImage.addCustomImageBuilderArgs(headArg); | ||
return true; | ||
} | ||
String javaArgsPrefix = "-D"; | ||
if (headArg.startsWith(javaArgsPrefix)) { | ||
args.poll(); | ||
nativeImage.addCustomJavaArgs(headArg); | ||
return true; | ||
} | ||
if (headArg.startsWith("-J")) { | ||
args.poll(); | ||
if (headArg.equals("-J")) { | ||
NativeImage.showError("The -J option should not be followed by a space"); | ||
} else { | ||
nativeImage.addCustomJavaArgs(headArg.substring(2)); | ||
} | ||
return true; | ||
} | ||
String debugOption = "-g"; | ||
if (headArg.equals(debugOption)) { | ||
args.poll(); | ||
nativeImage.addImageBuilderArg(NativeImage.oHDebug + 2); | ||
return true; | ||
} | ||
String optimizeOption = "-O"; | ||
if (headArg.startsWith(optimizeOption)) { | ||
args.poll(); | ||
if (headArg.equals(optimizeOption)) { | ||
NativeImage.showError("The " + optimizeOption + " option should not be followed by a space"); | ||
} else { | ||
nativeImage.addImageBuilderArg(NativeImage.oHOptimize + headArg.substring(2)); | ||
} | ||
return true; | ||
} | ||
String enableRuntimeAssertions = "-ea"; | ||
if (headArg.equals(enableRuntimeAssertions)) { | ||
args.poll(); | ||
nativeImage.addImageBuilderArg(NativeImage.oHRuntimeAssertions + true); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private void handleJarFileArg(File file) { | ||
try { | ||
Manifest manifest = null; | ||
for (FastJar.Entry entry : FastJar.list(file)) { | ||
if ("META-INF/MANIFEST.MF".equals(entry.name)) { | ||
manifest = new Manifest(FastJar.getInputStream(file, entry)); | ||
} | ||
} | ||
if (manifest == null) { | ||
return; | ||
} | ||
Attributes mainAttributes = manifest.getMainAttributes(); | ||
String mainClass = mainAttributes.getValue("Main-Class"); | ||
if (mainClass == null) { | ||
return; | ||
} | ||
nativeImage.addImageBuilderArg(NativeImage.oHClass + mainClass); | ||
String jarFileName = file.getName().toString(); | ||
String jarFileNameBase = jarFileName.substring(0, jarFileName.length() - 4); | ||
nativeImage.addImageBuilderArg(NativeImage.oHName + jarFileNameBase); | ||
Path filePath = file.toPath(); | ||
nativeImage.addImageClasspath(filePath); | ||
String classPath = mainAttributes.getValue("Class-Path"); | ||
/* Missing Class-Path Attribute is tolerable */ | ||
if (classPath != null) { | ||
for (String cp : classPath.split(" +")) { | ||
Path manifestClassPath = Paths.get(cp); | ||
if (!manifestClassPath.isAbsolute()) { | ||
/* Resolve relative manifestClassPath against directory containing jar */ | ||
manifestClassPath = filePath.getParent().resolve(manifestClassPath); | ||
} | ||
nativeImage.addImageClasspath(manifestClassPath); | ||
} | ||
} | ||
} catch (IOException e) { | ||
NativeImage.showError("Given file does not appear to be a jar-file: " + file, e); | ||
} | ||
} | ||
} |
Oops, something went wrong.