Skip to content

Commit

Permalink
Merge pull request #47 from defold/build-dir-fix
Browse files Browse the repository at this point in the history
Make sure that build dir is removed.
  • Loading branch information
king-lothman authored Jun 19, 2017
2 parents 02e9ed5 + 3c46b3c commit 9941890
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions server/src/main/java/com/defold/extender/Extender.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class Extender {
private List<File> extDirs = new ArrayList<>();
private List<File> manifests = new ArrayList<>();

public static final String FRAMEWORK_RE = "(.+)\\.framework";
public static final String JAR_RE = "(.+\\.jar)";
public static final String JS_RE = "(.+\\.js)";
static final String FRAMEWORK_RE = "(.+)\\.framework";
static final String JAR_RE = "(.+\\.jar)";
static final String JS_RE = "(.+\\.js)";

private static final String ANDROID_NDK_PATH = System.getenv("ANDROID_NDK_PATH");
private static final String ANDROID_NDK_INCLUDE_PATH = System.getenv("ANDROID_NDK_INCLUDE");
Expand Down Expand Up @@ -71,23 +71,29 @@ class Extender {

this.platform = platform;
this.sdk = sdk;
this.platformConfig = config.platforms.get(platform);
this.platformConfig = getPlatformConfig();

Path buildPath = Paths.get(buildDirectory);
Files.createDirectories(buildPath);
this.build = Files.createTempDirectory(buildPath, "build").toFile();

if (this.platformConfig == null) {
throw new ExtenderException(String.format("Unsupported platform %s", platform));
}

this.manifestValidator = new ExtensionManifestValidator(new WhitelistConfig(), this.platformConfig.allowedFlags, this.platformConfig.allowedLibs);

// Collect extension directories (used by both buildEngine and buildClassesDex)
this.manifests = allFiles.stream().filter(f -> f.getName().equals("ext.manifest")).collect(Collectors.toList());
this.extDirs = this.manifests.stream().map(File::getParentFile).collect(Collectors.toList());
}

private PlatformConfig getPlatformConfig() throws ExtenderException {
PlatformConfig platformConfig = config.platforms.get(platform);

if (platformConfig == null) {
throw new ExtenderException(String.format("Unsupported platform %s", platform));
}

return platformConfig;
}

// Does a regexp match on the filename for each file found in a directory
static List<String> collectFilesByName(File dir, String re) {
List<String> libs = new ArrayList<>();
Expand Down Expand Up @@ -148,7 +154,7 @@ static <T> T loadYaml(File root, File manifest, Class<T> type) throws IOExceptio
try {
return new Yaml().loadAs(yaml, type);
} catch(YAMLException e) {
throw new ExtenderException(String.format("Error in file '%s': %s", ExtenderUtil.getRelativePath(root, manifest).toString(), e.toString()));
throw new ExtenderException(String.format("Error in file '%s': %s", ExtenderUtil.getRelativePath(root, manifest), e.toString()));
}
}

Expand Down Expand Up @@ -299,7 +305,7 @@ private File compileMain(File maincpp, Map<String, Object> manifestContext) thro
return o;
}

private File buildExtension(File manifest, Map<String, Object> manifestContext) throws IOException, InterruptedException, ExtenderException {
private void buildExtension(File manifest, Map<String, Object> manifestContext) throws IOException, InterruptedException, ExtenderException {
File extDir = manifest.getParentFile();
File srcDir = new File(extDir, "src");
Collection<File> srcFiles = new ArrayList<>();
Expand Down Expand Up @@ -329,7 +335,6 @@ private File buildExtension(File manifest, Map<String, Object> manifestContext)
context.put("objs", objs);
String command = templateExecutor.execute(platformConfig.libCmd, context);
processExecutor.execute(command);
return lib;
}

static List<String> getAppManifestItems(AppManifestConfiguration manifest, String platform, String name) throws ExtenderException {
Expand Down Expand Up @@ -432,7 +437,7 @@ private File linkEngine(List<String> symbols, Map<String, Object> manifestContex
return exe;
}

public File buildRJar() throws ExtenderException {
private File buildRJar() throws ExtenderException {
try {
File rJavaDir = new File(extensionSource, "_app/rjava/");
if (rJavaDir.exists() && rJavaDir.isDirectory()) {
Expand Down Expand Up @@ -492,7 +497,7 @@ public File buildRJar() throws ExtenderException {
return null;
}

public File buildJavaExtension(File manifest, Map<String, Object> manifestContext, File rJar) throws ExtenderException {
private File buildJavaExtension(File manifest, Map<String, Object> manifestContext, File rJar) throws ExtenderException {

if (platformConfig.javaSourceRe == null || platformConfig.javacCmd == null || platformConfig.jarCmd == null) {
return null;
Expand Down Expand Up @@ -571,7 +576,7 @@ public File buildJavaExtension(File manifest, Map<String, Object> manifestContex
}
}

public List<File> buildJava(File rJar) throws ExtenderException {
private List<File> buildJava(File rJar) throws ExtenderException {
List<File> builtJars = new ArrayList<>();
if (rJar != null) {
builtJars.add(rJar);
Expand Down Expand Up @@ -621,7 +626,7 @@ private Map<String, Object> getManifestContext(ManifestConfiguration manifestCon
return new HashMap<>();
}

public File buildClassesDex(List<File> extraJars) throws ExtenderException {
private File buildClassesDex(List<File> extraJars) throws ExtenderException {
LOGGER.info("Building classes.dex with extension source {}", extensionSource);

// To support older versions of build.yml where dxCmd is not defined:
Expand Down Expand Up @@ -655,7 +660,7 @@ public File buildClassesDex(List<File> extraJars) throws ExtenderException {
return classesDex;
}

File buildEngine() throws ExtenderException {
private File buildEngine() throws ExtenderException {
LOGGER.info("Building engine for platform {} with extension source {}", platform, extensionSource);

try {
Expand Down

0 comments on commit 9941890

Please sign in to comment.