use of org.robovm.compiler.config.Resource in project robovm by robovm.
the class AppCompiler method main.
public static void main(String[] args) throws IOException {
AppCompiler compiler = null;
Config.Builder builder = null;
boolean verbose = false;
boolean run = false;
boolean archive = false;
List<Arch> archs = new ArrayList<>();
String dumpConfigFile = null;
List<String> runArgs = new ArrayList<String>();
try {
builder = new Config.Builder();
Map<String, PluginArgument> pluginArguments = builder.fetchPluginArguments();
int i = 0;
while (i < args.length) {
if ("-cp".equals(args[i]) || "-classpath".equals(args[i])) {
for (String p : args[++i].split(File.pathSeparator)) {
builder.addClasspathEntry(new File(p));
}
} else if ("-bcp".equals(args[i]) || "-bootcp".equals(args[i]) || "-bootclasspath".equals(args[i])) {
for (String p : args[++i].split(File.pathSeparator)) {
builder.addBootClasspathEntry(new File(p));
}
} else if ("-jar".equals(args[i])) {
builder.mainJar(new File(args[++i]));
} else if ("-o".equals(args[i])) {
builder.executableName(args[++i]);
} else if ("-d".equals(args[i])) {
builder.installDir(new File(args[++i]));
} else if ("-cache".equals(args[i])) {
builder.cacheDir(new File(args[++i]));
} else if ("-home".equals(args[i])) {
builder.home(new Config.Home(new File(args[++i])));
} else if ("-tmp".equals(args[i])) {
builder.tmpDir(new File(args[++i]));
} else if ("-threads".equals(args[i])) {
String s = args[++i];
try {
int n = Integer.parseInt(s);
// Make sure n > 0 and cap at 128 threads.
n = Math.max(n, 1);
n = Math.min(n, 128);
builder.threads(n);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Unparsable thread count: " + s);
}
} else if ("-run".equals(args[i])) {
run = true;
} else if ("-verbose".equals(args[i])) {
verbose = true;
} else if ("-config".equals(args[i])) {
builder.read(new File(args[++i]));
} else if ("-dumpconfig".equals(args[i])) {
dumpConfigFile = args[++i];
} else if ("-properties".equals(args[i])) {
builder.addProperties(new File(args[++i]));
} else if (args[i].startsWith("-P")) {
int index = args[i].indexOf('=');
if (index <= 0) {
throw new IllegalArgumentException("Malformed property: " + args[i]);
}
String name = args[i].substring(2, index);
String value = args[i].substring(index + 1);
builder.addProperty(name, value);
} else if ("-debug".equals(args[i])) {
builder.debug(true);
} else if ("-use-debug-libs".equals(args[i])) {
builder.useDebugLibs(true);
} else if ("-dump-intermediates".equals(args[i])) {
builder.dumpIntermediates(true);
} else if ("-dynamic-jni".equals(args[i])) {
// TODO: Old option not used any longer. We still accept it
// for now. Delete it in a future release.
} else if ("-skiprt".equals(args[i])) {
builder.skipRuntimeLib(true);
} else if ("-skipsign".equals(args[i])) {
builder.iosSkipSigning(true);
} else if ("-clean".equals(args[i])) {
builder.clean(true);
} else if ("-help".equals(args[i]) || "-?".equals(args[i])) {
printUsageAndExit(null, builder.getPlugins());
} else if ("-version".equals(args[i])) {
printVersionAndExit();
} else if ("-cc".equals(args[i])) {
builder.ccBinPath(new File(args[++i]));
} else if ("-os".equals(args[i])) {
String s = args[++i];
builder.os("auto".equals(s) ? null : OS.valueOf(s));
} else if ("-arch".equals(args[i])) {
String s = args[++i];
if (!"auto".equals(s)) {
archs.add(Arch.valueOf(s));
}
} else if ("-archs".equals(args[i])) {
for (String s : args[++i].split(":")) {
if (!"auto".equals(s)) {
archs.add(Arch.valueOf(s));
}
}
// } else if ("-cpu".equals(args[i])) {
// builder.cpu(args[++i]);
} else if ("-target".equals(args[i])) {
String s = args[++i];
builder.targetType("auto".equals(s) ? null : s);
} else if ("-treeshaker".equals(args[i])) {
String s = args[++i];
builder.treeShakerMode(TreeShakerMode.valueOf(s));
} else if ("-forcelinkclasses".equals(args[i])) {
for (String p : args[++i].split(":")) {
p = p.replace('#', '*');
builder.addForceLinkClass(p);
}
} else if ("-libs".equals(args[i])) {
for (String p : args[++i].split(":")) {
builder.addLib(new Config.Lib(p, true));
}
} else if ("-exportedsymbols".equals(args[i])) {
for (String p : args[++i].split(":")) {
builder.addExportedSymbol(p);
}
} else if ("-unhidesymbols".equals(args[i])) {
for (String p : args[++i].split(":")) {
builder.addUnhideSymbol(p);
}
} else if ("-frameworks".equals(args[i])) {
for (String p : args[++i].split(":")) {
builder.addFramework(p);
}
} else if ("-weakframeworks".equals(args[i])) {
for (String p : args[++i].split(":")) {
builder.addWeakFramework(p);
}
} else if ("-resources".equals(args[i])) {
for (String p : args[++i].split(":")) {
if (AntPathMatcher.isPattern(p)) {
File dir = new File(AntPathMatcher.rtrimWildcardTokens(p));
String pattern = AntPathMatcher.extractPattern(p);
builder.addResource(new Resource(dir, null).include(pattern));
} else {
builder.addResource(new Resource(new File(p)));
}
}
} else if ("-cacerts".equals(args[i])) {
String name = args[++i];
Config.Cacerts cacerts = null;
if (!"none".equals(name)) {
try {
cacerts = Config.Cacerts.valueOf(name);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Illegal -cacerts value: " + name);
}
}
builder.cacerts(cacerts);
} else if ("-plist".equals(args[i])) {
builder.infoPList(new File(args[++i]));
} else if ("-entitlements".equals(args[i])) {
builder.iosEntitlementsPList(new File(args[++i]));
} else if ("-signidentity".equals(args[i])) {
builder.iosSignIdentity(SigningIdentity.find(SigningIdentity.list(), args[++i]));
} else if ("-provisioningprofile".equals(args[i])) {
builder.iosProvisioningProfile(ProvisioningProfile.find(ProvisioningProfile.list(), args[++i]));
} else if ("-sdk".equals(args[i])) {
builder.iosSdkVersion(args[++i]);
} else if ("-printdevicetypes".equals(args[i])) {
printDeviceTypesAndExit();
} else if ("-devicetype".equals(args[i])) {
builder.iosDeviceType(args[++i]);
} else if ("-archive".equals(args[i])) {
archive = true;
} else if ("-createipa".equals(args[i])) {
archive = true;
} else if ("-ipaarchs".equals(args[i])) {
for (String s : args[++i].split(":")) {
if (!"auto".equals(s)) {
archs.add(Arch.valueOf(s));
}
}
} else if (args[i].startsWith("-D")) {
} else if (args[i].startsWith("-X")) {
} else if (args[i].startsWith("-rvm:")) {
runArgs.add(args[i]);
} else if (args[i].startsWith("-")) {
String argName = args[i].substring(1, args[i].length());
if (argName.contains("=")) {
argName = argName.substring(0, argName.indexOf('='));
}
PluginArgument arg = pluginArguments.get(argName);
if (arg != null) {
builder.addPluginArgument(args[i].substring(1));
} else {
throw new IllegalArgumentException("Unrecognized option: " + args[i]);
}
} else {
builder.mainClass(args[i++]);
break;
}
i++;
}
builder.archs(archs.toArray(new Arch[archs.size()]));
while (i < args.length) {
runArgs.add(args[i++]);
}
if (archive && run) {
throw new IllegalArgumentException("Specify either -run or -createipa/-archive, not both");
}
builder.logger(new ConsoleLogger(verbose));
builder.skipInstall(run);
if (dumpConfigFile != null) {
if (dumpConfigFile.equals("-")) {
builder.write(new OutputStreamWriter(System.out), new File("."));
} else {
File file = new File(dumpConfigFile);
if (file.exists()) {
throw new IllegalArgumentException("Cannot dump config to " + file.getAbsolutePath() + ". The file already exists.");
}
builder.write(file);
}
return;
}
compiler = new AppCompiler(builder.build());
} catch (Throwable t) {
String message = t.getMessage();
if (t instanceof ArrayIndexOutOfBoundsException) {
message = "Missing argument";
}
if (t instanceof IndexOutOfBoundsException) {
message = "Missing argument";
}
if (verbose && !(t instanceof StringIndexOutOfBoundsException) && !(t instanceof IllegalArgumentException)) {
t.printStackTrace();
}
printUsageAndExit(message, builder != null ? builder.getPlugins() : null);
}
try {
if (archive) {
compiler.build();
compiler.archive();
} else {
if (run && !compiler.config.getTarget().canLaunch()) {
throw new IllegalArgumentException("Cannot launch when building " + compiler.config.getTarget().getType() + " binaries");
}
if (run) {
// Just compile the first slice if multiple archs have been specified
compiler.compile();
LaunchParameters launchParameters = compiler.config.getTarget().createLaunchParameters();
if (launchParameters instanceof IOSSimulatorLaunchParameters) {
IOSSimulatorLaunchParameters simParams = (IOSSimulatorLaunchParameters) launchParameters;
String deviceName = null;
String sdkVersion = null;
if (compiler.config.getIosDeviceType() != null) {
String[] parts = compiler.config.getIosDeviceType().split("[:;, ]+");
deviceName = parts[0].trim();
sdkVersion = parts.length > 1 ? parts[1].trim() : null;
}
DeviceType type = DeviceType.getBestDeviceType(compiler.config.getArch(), null, deviceName, sdkVersion);
simParams.setDeviceType(type);
}
launchParameters.setArguments(runArgs);
compiler.launch(launchParameters);
} else {
compiler.build();
compiler.config.getTarget().install();
}
}
} catch (Throwable t) {
String message = t.getMessage();
if (verbose && !(t instanceof ExecuteException)) {
t.printStackTrace();
}
printUsageAndExit(message, builder.getPlugins());
}
}
use of org.robovm.compiler.config.Resource in project robovm by robovm.
the class AbstractTarget method copyDynamicFrameworks.
protected void copyDynamicFrameworks(File destDir) throws IOException {
final Set<String> swiftLibraries = new HashSet<>();
File frameworksDir = new File(destDir, "Frameworks");
for (String framework : config.getFrameworks()) {
boolean isCustomFramework = false;
File frameworkDir = null;
for (File path : config.getFrameworkPaths()) {
frameworkDir = new File(path, framework + ".framework");
if (frameworkDir.exists() && frameworkDir.isDirectory()) {
isCustomFramework = true;
break;
}
}
if (isCustomFramework) {
// check if this is a dynamic framework by finding
// at least ony dylib in the root folder
boolean isDynamicFramework = false;
for (File file : frameworkDir.listFiles()) {
if (file.isFile() && isDynamicLibrary(file)) {
isDynamicFramework = true;
break;
}
}
if (isDynamicFramework) {
config.getLogger().info("Copying framework %s from %s to %s", framework, frameworkDir, destDir);
new Resource(frameworkDir).walk(new Walker() {
@Override
public boolean processDir(Resource resource, File dir, File destDir) throws IOException {
return !(dir.getName().equals("Headers") || dir.getName().equals("PrivateHeaders") || dir.getName().equals("Modules") || dir.getName().equals("Versions") || dir.getName().equals("Documentation"));
}
@Override
public void processFile(Resource resource, File file, File destDir) throws IOException {
if (!isStaticLibrary(file)) {
copyFile(resource, file, destDir);
if (isDynamicLibrary(file)) {
// remove simulator archs for device builds
if (config.getOs() == OS.ios && config.getArch().isArm()) {
String archs = ToolchainUtil.lipoInfo(config, file);
File inFile = new File(destDir, file.getName());
File tmpFile = new File(destDir, file.getName() + ".tmp");
FileUtils.copyFile(inFile, tmpFile);
if (archs.contains(Arch.x86.getClangName())) {
ToolchainUtil.lipoRemoveArchs(config, inFile, tmpFile, Arch.x86);
}
if (archs.contains(Arch.x86_64.getClangName())) {
ToolchainUtil.lipoRemoveArchs(config, inFile, tmpFile, Arch.x86_64);
}
FileUtils.copyFile(tmpFile, inFile);
tmpFile.delete();
}
// check if this dylib depends on Swift
// and register those libraries to be copied
// to bundle.app/Frameworks
String dependencies = ToolchainUtil.otool(file);
Pattern swiftLibraryPattern = Pattern.compile("libswift.+\\.dylib");
Matcher matcher = swiftLibraryPattern.matcher(dependencies);
while (matcher.find()) {
String library = dependencies.substring(matcher.start(), matcher.end());
swiftLibraries.add(library);
}
}
}
}
}, frameworksDir);
}
}
}
// copy Swift libraries if required
if (!swiftLibraries.isEmpty()) {
copySwiftLibs(swiftLibraries, frameworksDir);
}
}
Aggregations