Skip to content

Commit

Permalink
Merge pull request #670 from dkimitsa/fix/669-enable-swiftsuport-byde…
Browse files Browse the repository at this point in the history
…fault

* fixed #669: this enables swift support by default with option to disable it
  • Loading branch information
Tom-Ski authored Jul 17, 2022
2 parents 4ae4bc1 + 83eff48 commit 8903a0c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 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 @@ -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 8903a0c

Please sign in to comment.