Skip to content

Commit

Permalink
Code cleanup and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Oct 24, 2023
1 parent 421377f commit 2da4b3b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/src/main/java/com/defold/extender/Extender.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ private void emitSwiftHeaders(PodSpec pod, Map<String, Object> manifestContext,
context.put("ext", ImmutableMap.of("includes", includes, "frameworks", frameworks, "frameworkPaths", frameworkPaths));
context.put("moduleName", pod.moduleName);
context.put("swiftSourceFiles", pod.swiftSourceFilePaths);
context.put("swiftHeaderPath", new File(pod.generatedDir, pod.moduleName + "-Swift.h"));
context.put("swiftHeaderPath", pod.swiftModuleHeader);
context.put("swiftTarget", getSwiftTargetFromPlatform(platform));
context.put("swiftVersion", "5");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ public class PodSpec {
public String osxversion = "";
public String iosModuleMap = null;
public String osxModuleMap = null;
public Boolean isFramework = false;
// Set to true if this Pod contains at least on .xcframework
public Boolean containsFramework = false;
// The Swift source file header (ModuleName-Swift.h)
// This file is referenced from the modulemap and generated in
// Extender.java as part of the process when building .swift files
public File swiftModuleHeader = null;
public Set<String> swiftSourceFilePaths = new LinkedHashSet<>();
public Set<File> swiftSourceFiles = new LinkedHashSet<>();
public Set<File> sourceFiles = new LinkedHashSet<>();
Expand All @@ -250,8 +255,9 @@ public class PodSpec {
public PlatformSet libraries = new PlatformSet();
public PlatformSet publicHeaders = new PlatformSet();
public File dir;
public boolean installed;
public File generatedDir;
// true if this podspec was installed by Cocoapods
public boolean installed;

public PodSpec getSubspec(String name) {
for (PodSpec spec : subspecs) {
Expand All @@ -267,9 +273,12 @@ public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(name + ":" + version + "\n");
sb.append(" dir: " + dir + "\n");
sb.append(" moduleName: " + moduleName + "\n");
sb.append(" generated dir: " + generatedDir + "\n");
sb.append(" installed: " + installed + "\n");
sb.append(" src: " + sourceFiles + "\n");
sb.append(" swift src: " + swiftSourceFiles + "\n");
sb.append(" swift module header: " + swiftModuleHeader + "\n");
sb.append(" includes: " + includePaths + "\n");
sb.append(" defines: " + defines + "\n");
sb.append(" flags: " + flags + "\n");
Expand Down Expand Up @@ -749,7 +758,7 @@ private List<File> listFilesGlob(File dir, String pattern) {

// https://clang.llvm.org/docs/Modules.html#module-declaration
private void createModuleMap(PodSpec pod, Set<String> headerPatterns, File moduleMapFile, File jobDir) throws ExtenderException {
LOGGER.info("createModuleMap() " + pod.moduleName + " header patterns: " + headerPatterns);
LOGGER.info("createModuleMap() " + pod.moduleName + " from header patterns: " + headerPatterns + " " + moduleMapFile);

List<String> headers = new ArrayList<>();
List<String> umbrellaHeaders = new ArrayList<>();
Expand All @@ -759,6 +768,7 @@ private void createModuleMap(PodSpec pod, Set<String> headerPatterns, File modul
// generated by the swift compiler if -emit-objc-header flag is set
if (!pod.swiftSourceFiles.isEmpty()) {
File swiftModuleHeader = new File(pod.generatedDir, pod.moduleName + "-Swift.h");
pod.swiftModuleHeader = swiftModuleHeader;
headers.add(swiftModuleHeader.getAbsolutePath());
}

Expand Down Expand Up @@ -791,23 +801,20 @@ private void createModuleMap(PodSpec pod, Set<String> headerPatterns, File modul

// generate final modulemap
HashMap<String, Object> envContext = new HashMap<>();
envContext.put("FRAMEWORKOPT", pod.isFramework ? "framework" : "");
envContext.put("FRAMEWORKOPT", pod.containsFramework ? "framework" : "");
envContext.put("MODULE_ID", fullModuleName);
envContext.put("HEADERS", headers);
envContext.put("UMBRELLA_HEADERS", umbrellaHeaders);
envContext.put("UMBRELLA_DIRECTORIES", umbrellaDirectories);
envContext.put("SUBMODULE", pod.isFramework ? "module * { export * }" : "");
envContext.put("SUBMODULE", pod.containsFramework ? "module * { export * }" : "");

String moduleMap = templateExecutor.execute(modulemapTemplateContents, envContext);
LOGGER.info("Created modulemap:\n{}", moduleMap);

try {
Files.writeString(moduleMapFile.toPath(), moduleMap);
}
catch (IOException e) {
throw new ExtenderException(e, "Unable to create modulemap for " + pod.moduleName);
}
LOGGER.info("createModuleMap() DONE " + pod.moduleName);
}

private File createModuleMapFile(PodSpec pod, String platform) {
Expand Down Expand Up @@ -1014,7 +1021,7 @@ private PodSpec createPodSpec(JSONObject specJson, PodSpec parent, File podsDir,
addPodIncludePaths(spec, path);
}
else {
spec.isFramework = true;
spec.containsFramework = true;
}
}
}
Expand Down

0 comments on commit 2da4b3b

Please sign in to comment.