Skip to content

Commit

Permalink
Fixed up a few log messages to mention "binaries" rather than "execut…
Browse files Browse the repository at this point in the history
…ables".

Better javadocs for Target. Made AbstractTarget more customizable by
subclasses. (#1060)
  • Loading branch information
ntherning committed Jul 16, 2015
1 parent de709ed commit acb642f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
6 changes: 5 additions & 1 deletion compiler/src/main/java/org/robovm/compiler/AppCompiler.java
Expand Up @@ -708,6 +708,10 @@ public static void main(String[] args) throws IOException {
if (createIpa) { if (createIpa) {
compiler.createIpa(ipaArchs); compiler.createIpa(ipaArchs);
} else { } else {
if (run && !compiler.config.getTarget().canLaunch()) {
throw new IllegalArgumentException("Cannot launch when building "
+ compiler.config.getTarget().getType() + " binaries");
}
compiler.compile(); compiler.compile();
if (run) { if (run) {
LaunchParameters launchParameters = compiler.config.getTarget().createLaunchParameters(); LaunchParameters launchParameters = compiler.config.getTarget().createLaunchParameters();
Expand Down Expand Up @@ -868,7 +872,7 @@ private static void printUsageAndExit(String errorMessage, List<Plugin> plugins)
+ " ${java.io.tmpdir}."); + " ${java.io.tmpdir}.");
System.err.println(" -jar <path> Use main class as specified by the manifest in this JAR \n" System.err.println(" -jar <path> Use main class as specified by the manifest in this JAR \n"
+ " archive."); + " archive.");
System.err.println(" -o <name> The name of the target executable"); System.err.println(" -o <name> The name of the target binary");
System.err.println(" -os <name> The name of the OS to build for. Allowed values are \n" System.err.println(" -os <name> The name of the OS to build for. Allowed values are \n"
+ " 'auto', 'linux', 'macosx' and 'ios'. Default is 'auto' which\n" + " 'auto', 'linux', 'macosx' and 'ios'. Default is 'auto' which\n"
+ " means use the LLVM deafult."); + " means use the LLVM deafult.");
Expand Down
Expand Up @@ -88,14 +88,29 @@ public boolean canLaunchInPlace() {
return true; return true;
} }


protected List<String> getTargetExportedSymbols() {
return Collections.emptyList();
}

protected List<String> getTargetCcArgs() {
return Collections.emptyList();
}

protected List<String> getTargetLibs() {
return Collections.emptyList();
}

public void build(List<File> objectFiles) throws IOException { public void build(List<File> objectFiles) throws IOException {
File outFile = new File(config.getTmpDir(), config.getExecutableName()); File outFile = new File(config.getTmpDir(), config.getExecutableName());


config.getLogger().debug("Building executable %s", outFile); config.getLogger().debug("Building %s binary %s", config.getTarget().getType(), outFile);


LinkedList<String> ccArgs = new LinkedList<String>(); LinkedList<String> ccArgs = new LinkedList<String>();
LinkedList<String> libs = new LinkedList<String>(); LinkedList<String> libs = new LinkedList<String>();


ccArgs.addAll(getTargetCcArgs());
libs.addAll(getTargetLibs());

String libSuffix = config.isUseDebugLibs() ? "-dbg" : ""; String libSuffix = config.isUseDebugLibs() ? "-dbg" : "";


libs.add("-lrobovm-bc" + libSuffix); libs.add("-lrobovm-bc" + libSuffix);
Expand Down Expand Up @@ -130,6 +145,7 @@ public void build(List<File> objectFiles) throws IOException {
ccArgs.add("-ObjC"); ccArgs.add("-ObjC");


List<String> exportedSymbols = new ArrayList<String>(); List<String> exportedSymbols = new ArrayList<String>();
exportedSymbols.addAll(getTargetExportedSymbols());
if (config.isSkipInstall()) { if (config.isSkipInstall()) {
exportedSymbols.add("catch_exception_raise"); exportedSymbols.add("catch_exception_raise");
} }
Expand Down Expand Up @@ -369,14 +385,14 @@ protected void copyFile(Resource resource, File file, File destDir) throws IOExc
} }


public void install() throws IOException { public void install() throws IOException {
config.getLogger().debug("Installing executable to %s", config.getInstallDir()); config.getLogger().debug("Installing %s binary to %s", config.getTarget().getType(), config.getInstallDir());
config.getInstallDir().mkdirs(); config.getInstallDir().mkdirs();
doInstall(config.getInstallDir(), config.getExecutableName()); doInstall(config.getInstallDir(), config.getExecutableName());
} }


protected void doInstall(File installDir, String executable) throws IOException { protected void doInstall(File installDir, String image) throws IOException {
if (!config.getTmpDir().equals(installDir) || !executable.equals(config.getExecutableName())) { if (!config.getTmpDir().equals(installDir) || !image.equals(config.getExecutableName())) {
File destFile = new File(installDir, executable); File destFile = new File(installDir, image);
FileUtils.copyFile(new File(config.getTmpDir(), config.getExecutableName()), destFile); FileUtils.copyFile(new File(config.getTmpDir(), config.getExecutableName()), destFile);
destFile.setExecutable(true, false); destFile.setExecutable(true, false);
} }
Expand Down
54 changes: 54 additions & 0 deletions compiler/src/main/java/org/robovm/compiler/target/Target.java
Expand Up @@ -25,27 +25,81 @@
import org.robovm.compiler.config.Config; import org.robovm.compiler.config.Config;
import org.robovm.compiler.config.OS; import org.robovm.compiler.config.OS;


/**
* Builds and launches (if supported) a particular type of binary (e.g. iOS
* apps, dynamic libraries, etc).
*/
public interface Target { public interface Target {


/**
* Returns a unique type id for this {@link Target}.
*/
String getType(); String getType();


/**
* Returns the {@link OS} this {@link Target} will build for. This is
* determined by {@link #init(Config)}. If an explicit {@link OS} has been
* set on the {@link Config} in the call to {@link #init(Config)} that
* {@link OS} will returned by this method. Otherwise {@link #init(Config)}
* will determine a default {@link OS} and this method returns that one.
*/
OS getOs(); OS getOs();


/**
* Returns the {@link Arch} this {@link Target} will build for. This is
* determined by {@link #init(Config)}. If an explicit {@link Arch} has been
* set on the {@link Config} in the call to {@link #init(Config)} that
* {@link Arch} will returned by this method. Otherwise
* {@link #init(Config)} will determine a default {@link Arch} and this
* method returns that one.
*/
Arch getArch(); Arch getArch();


String getInstallRelativeArchivePath(Path path); String getInstallRelativeArchivePath(Path path);


/**
* Returns {@code true} if binaries created by this {@link Target} can be
* launched, i.e. it produces executable binaries.
*/
boolean canLaunch(); boolean canLaunch();


/**
* Returns {@code true} if binaries created by this {@link Target} can be
* launched in place and doesn't have to be copied into some folder
* structure, e.g. an iOS app bundle.
*/
boolean canLaunchInPlace(); boolean canLaunchInPlace();


/**
* Builds a binary out of the specified object files.
*/
void build(List<File> objectFiles) throws IOException; void build(List<File> objectFiles) throws IOException;


/**
* Installs the built binary and any supporting files into the
* {@link Config#getInstallDir()} directory.
*/
void install() throws IOException; void install() throws IOException;


/**
* Launches the built binary if supported.
*
* @throws UnsupportedOperationException if binaries built by this
* {@link Target} cannot be launched.
*/
Process launch(LaunchParameters launchParameters) throws IOException; Process launch(LaunchParameters launchParameters) throws IOException;


/**
* Creates {@link LaunchParameters} for launching the binary built by this
* {@link Target}.
*
* @throws UnsupportedOperationException if binaries built by this
* {@link Target} cannot be launched.
*/
LaunchParameters createLaunchParameters(); LaunchParameters createLaunchParameters();


/**
* Initializes this {@link Target} from the specified {@link Config}.
*/
void init(Config config); void init(Config config);
} }

0 comments on commit acb642f

Please sign in to comment.