org.robovm.compiler.util.ToolchainUtil Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2012 RoboVM AB
* Copyright (C) 2018 Daniel Thommes, NeverNull GmbH,
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.robovm.compiler.util;
import org.apache.commons.exec.ExecuteException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.robovm.compiler.config.Config;
import org.robovm.compiler.config.OS;
import org.robovm.compiler.config.tools.ActoolOptions;
import org.robovm.compiler.config.tools.TextureAtlas;
import org.robovm.compiler.log.ConsoleLogger;
import org.robovm.compiler.log.Logger;
import org.robovm.compiler.target.ios.IOSTarget;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author niklas
*
*/
public class ToolchainUtil {
private static String IOS_DEV_CLANG;
private static String IOS_SIM_CLANG;
private static String PNGCRUSH;
private static String PLUTIL;
private static String LIPO;
private static String BITCODE_STRIP;
private static String PACKAGE_APPLICATION;
private static String TEXTUREATLAS;
private static String ACTOOL;
private static String IBTOOL;
private static String NM;
private static String OTOOL;
private static String FILE;
private static String DSYMUTIL;
private static String SYMBOLS;
private static String getIOSDevClang() throws IOException {
if (IOS_DEV_CLANG == null) {
IOS_DEV_CLANG = findXcodeCommand("clang++", "iphoneos");
}
return IOS_DEV_CLANG;
}
private static String getIOSSimClang() throws IOException {
if (IOS_SIM_CLANG == null) {
IOS_SIM_CLANG = findXcodeCommand("clang++", "iphonesimulator");
}
return IOS_SIM_CLANG;
}
private static String getPngCrush() throws IOException {
if (PNGCRUSH == null) {
PNGCRUSH = findXcodeCommand("pngcrush", "iphoneos");
}
return PNGCRUSH;
}
private static String getTextureAtlas() throws IOException {
if (TEXTUREATLAS == null) {
TEXTUREATLAS = findXcodeCommand("TextureAtlas", "iphoneos");
}
return TEXTUREATLAS;
}
private static String getACTool() throws IOException {
if (ACTOOL == null) {
ACTOOL = findXcodeCommand("actool", "iphoneos");
}
return ACTOOL;
}
private static String getIBTool() throws IOException {
if (IBTOOL == null) {
IBTOOL = findXcodeCommand("ibtool", "iphoneos");
}
return IBTOOL;
}
private static String getPlutil() throws IOException {
if (PLUTIL == null) {
PLUTIL = findXcodeCommand("plutil", "iphoneos");
}
return PLUTIL;
}
private static String getLipo() throws IOException {
if (LIPO == null) {
LIPO = findXcodeCommand("lipo", "iphoneos");
}
return LIPO;
}
private static String getBitcodeStrip() throws IOException {
if (BITCODE_STRIP == null) {
BITCODE_STRIP = findXcodeCommand("bitcode_strip", "iphoneos");
}
return BITCODE_STRIP;
}
private static String getNm() throws IOException {
if (NM == null) {
NM = findXcodeCommand("nm", "iphoneos");
}
return NM;
}
private static String getOtool() throws IOException {
if(OTOOL == null) {
OTOOL = findXcodeCommand("otool", "iphoneos");
}
return OTOOL;
}
private static String getFile() throws IOException {
if (FILE == null) {
FILE = findXcodeCommand("file", "iphoneos");
}
return FILE;
}
private static String getPackageApplication() throws IOException {
if (PACKAGE_APPLICATION == null) {
PACKAGE_APPLICATION = findXcodeCommand("PackageApplication", "iphoneos");
}
return PACKAGE_APPLICATION;
}
private static String getDsymutil() throws IOException {
if (DSYMUTIL == null) {
DSYMUTIL = findXcodeCommand("dsymutil", "iphoneos");
}
return DSYMUTIL;
}
private static String getSymbols() throws IOException {
if (SYMBOLS == null) {
SYMBOLS = findXcodeCommand("symbols", "iphoneos");
}
return SYMBOLS;
}
private static void handleExecuteException(ExecuteException e) {
if (e.getExitValue() == 2) {
throw new IllegalArgumentException("No Xcode is selected. Is Xcode installed? "
+ "If yes, use 'sudo xcode-select -switch ' from a Terminal "
+ "to switch to the correct Xcode path.");
}
if (e.getExitValue() == 69) {
throw new IllegalArgumentException("You must agree to the Xcode/iOS license. "
+ "Please open Xcode once or run 'sudo xcrun clang' from a Terminal to agree to the terms.");
}
throw new IllegalArgumentException(e.getMessage());
}
public static String findXcodePath() throws IOException {
try {
String path = new Executor(Logger.NULL_LOGGER, "xcode-select").args("--print-path").execCapture();
File f = new File(path);
if (f.exists() && f.isDirectory()) {
if (new File(f, "Platforms").exists() && new File(f, "Toolchains").exists()) {
return path;
}
}
throw new IllegalArgumentException(String.format(
"The path '%s' does not appear to be a valid Xcode path. Use "
+ "'sudo xcode-select -switch ' from a Terminal "
+ "to switch to the correct Xcode path.", path));
} catch (ExecuteException e) {
handleExecuteException(e);
return null;
}
}
public static boolean isXcodeInstalled() {
try {
findXcodePath();
return true;
} catch(Exception e) {
return false;
}
}
public static String findXcodeCommand(String cmd, String sdk) throws IOException {
try {
return new Executor(Logger.NULL_LOGGER, "xcrun").args("-sdk", sdk, "-f", cmd).execCapture();
} catch (ExecuteException e) {
handleExecuteException(e);
return null;
}
}
public static void pngcrush(Config config, File inFile, File outFile) throws IOException {
new Executor(config.getLogger(), getPngCrush()).args("-q", "-iphone", "-f", "0", inFile, outFile).exec();
}
public static void textureatlas(Config config, File inDir, File outDir) throws IOException {
List opts = new ArrayList();
int outputFormat = 1;
int maxTextureDimension = 1;
if (config.getTools() != null && config.getTools().getTextureAtlas() != null) {
TextureAtlas atlasConfig = config.getTools().getTextureAtlas();
outputFormat = 1 + atlasConfig.getOutputFormat().ordinal();
maxTextureDimension = 1 + atlasConfig.getMaximumTextureDimension().ordinal();
if (atlasConfig.usePowerOfTwo()) {
opts.add("-p");
}
}
new Executor(config.getLogger(), getTextureAtlas()).args(opts, "-f", outputFormat, "-s", maxTextureDimension,
inDir, outDir).exec();
}
public static void actool(Config config, File partialInfoPlist, File outDir, File inDir) throws IOException {
actool(config, partialInfoPlist, outDir, Collections.singletonList(inDir));
}
public static void actool(Config config, File partialInfoPlist, File outDir, List inDirs) throws IOException {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy