Skip to content

Commit

Permalink
Merge branch 'master' into fix/java18-jdk-8272564-workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Ski authored Jul 17, 2022
2 parents 59e7e43 + 8903a0c commit de4aa8f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public enum TreeShakerMode {
@ElementList(required = false, entry = "path")
private ArrayList<QualifiedFile> appExtensionPaths;
@Element(required = false)
private SwiftSupport swiftSupport = null;
private SwiftSupport swiftSupport = new SwiftSupport();
@ElementList(required = false, entry = "resource")
private ArrayList<Resource> resources;
@ElementList(required = false, entry = "classpathentry")
Expand Down Expand Up @@ -478,15 +478,15 @@ public List<File> getAppExtensionPaths() {
}

public SwiftSupport getSwiftSupport() {
return swiftSupport;
return swiftSupport.isEnabled() ? swiftSupport : null;
}

public boolean hasSwiftSupport() {
return swiftSupport != null;
return swiftSupport.isEnabled();
}

public List<File> getSwiftLibPaths() {
return swiftSupport == null ? Collections.emptyList()
return !swiftSupport.isEnabled() ? Collections.emptyList()
: swiftSupport.getSwiftLibPaths().stream()
.filter(this::isQualified)
.map(f -> f.entry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
* Configuration entry for Swift language related configurations
*/
public class SwiftSupport {
/**
* specifies if swift support is enabled, allows to disable it if required
*/
@Element(required = false)
private boolean enable = true;

/**
* path where swift library to be looked at
* also these libraries will be added to linker library search path
Expand All @@ -23,15 +29,19 @@ public class SwiftSupport {
* specifies if swift runtime libraries to be copied
*/
@Element(required = false)
private Boolean copySwiftLibs = true;
private boolean copySwiftLibs = true;


public boolean isEnabled() {
return enable;
}

public List<Config.QualifiedFile> getSwiftLibPaths() {
return swiftLibPaths == null ? Collections.emptyList()
: Collections.unmodifiableList(swiftLibPaths);
}

public boolean shouldCopySwiftLibs() {
return copySwiftLibs != null ? copySwiftLibs : true;
return copySwiftLibs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public void processFile(Resource resource, File file, File destDir) throws IOExc

if (isDynamicLibrary(file)) {
// remove simulator and deprecated archs, also strip bitcode if not used
if (config.getOs() == OS.ios && config.getArch().isArm()) {
if (config.getOs() == OS.ios && config.getArch().getEnv() != Environment.Simulator) {
File libFile = new File(destDir, file.getName());
stripExtraArches(libFile);
if (!config.isEnableBitcode())
Expand Down Expand Up @@ -440,7 +440,7 @@ public boolean processDir(Resource resource, File dir, File destDir) throws IOEx
public void processFile(Resource resource, File file, File destDir) throws IOException {
copyFile(resource, file, destDir);

if (config.getOs() == OS.ios && config.getArch().isArm()) {
if (config.getOs() == OS.ios && config.getArch().getEnv() != Environment.Simulator) {
// remove simulator and deprecated archs, also strip bitcode if not used
if (isAppExtension(file)) {
File libFile = new File(destDir, file.getName());
Expand Down Expand Up @@ -670,7 +670,7 @@ protected void copySwiftLibs(Collection<String> swiftLibraries, File targetDir,
// don't strip if libraries goes to SwiftSupport folder
if (strip) {
// remove simulator and deprecated archs, also strip bitcode if not used
if (config.getOs() == OS.ios && config.getArch().isArm()) {
if (config.getOs() == OS.ios && config.getArch().getEnv() != Environment.Simulator) {
File libFile = new File(targetDir, swiftLibrary.getName());
stripExtraArches(libFile);
if (!config.isEnableBitcode())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public static void lipoRemoveArchs(Config config, File inFile, File outFile, Str
}
args.add("-output");
args.add(outFile);
new Executor(Logger.NULL_LOGGER, getLipo()).args(args).exec();
new Executor(config.getLogger(), getLipo()).args(args).exec();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.io.*;
import java.util.Arrays;
import java.util.Collections;

Expand Down Expand Up @@ -418,4 +415,34 @@ public void testGetFileName() throws Exception {
assertEquals("com/example/AB9ca44297c0e0d22df654119dce73ee52d3d51c71.class.o",
Config.getFileName("com/example/ABCDEFGIHJABCDEFGIHJABCDEFGIHJABCDEFGIHJABCDEFGIHJ", "class.o", 50));
}

@Test
public void testSwiftSupportEnabledByDefault() throws Exception {
String configText = "<config>\n" +
" <target>ios</target>\n" +
"</config>";
Config.Builder builder = new Config.Builder();

builder.read(new StringReader(configText), wd);
Config config = builder.config;

assertTrue(config.hasSwiftSupport());
assertNotNull(config.getSwiftSupport());
assertTrue(config.getSwiftSupport().isEnabled());
assertTrue(config.getSwiftSupport().shouldCopySwiftLibs());
}

@Test
public void testSwiftSupportCanBeDisabled() throws Exception {
String configText = "<config>\n" +
" <swiftSupport>\n" +
" <enable>false</enable>\n" +
" </swiftSupport>\n" +
"</config>";
Config.Builder builder = new Config.Builder();
builder.read(new StringReader(configText), wd);
Config config = builder.config;
assertFalse(config.hasSwiftSupport());
assertNull(config.getSwiftSupport());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<framework>Foundation</framework>
<framework>AppKit</framework>
</frameworks>
<swiftSupport>
<enable>true</enable>
<copySwiftLibs>true</copySwiftLibs>
</swiftSupport>
<resources>
<resource>resources</resource>
<resource>/usr/share/resources</resource>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<config>
<swiftSupport>
<enable>true</enable>
<copySwiftLibs>true</copySwiftLibs>
</swiftSupport>
<target>ios</target>
<iosSdkVersion>6.1</iosSdkVersion>
<iosInfoPList>Info.plist</iosInfoPList>
Expand Down

0 comments on commit de4aa8f

Please sign in to comment.