Skip to content

Commit

Permalink
Merge pull request #358 from madvay/enabledArchs
Browse files Browse the repository at this point in the history
Enabled architectures, fixes #357
  • Loading branch information
advayDev1 committed Aug 20, 2015
2 parents 60fb749 + 2ae4450 commit 7ef3450
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,35 @@ class J2objcConfig {
// Public to allow assignment of array of targets as shown in example
List<String> supportedArchs = NativeCompilation.ALL_SUPPORTED_ARCHS.clone() as List<String>

/**
* An architecture is active if it is both supported ({@link #supportedArchs})
* and enabled in the current environment via the comma-separated j2objc.enabledArchs
* value in local.properties.
* <p/>
* If no j2objc.enabledArchs value is specified in local.properties, all supported
* architectures are also active, otherwise the intersection of supportedArchs
* and j2objc.enabledArchs is used.
*/
List<String> getActiveArchs() {
// null is the default value, since an explicit empty string means no architectures
// are enabled.
String archsCsv = Utils.getLocalProperty(project, 'enabledArchs', null)
if (archsCsv == null) {
return supportedArchs
}
List<String> enabledArchs = archsCsv.split(',').toList()
// Given `j2objc.enabledArchs=` we will have one architecture of empty string,
// instead we want no architectures at all in this case.
enabledArchs.remove('')
List<String> invalidArchs = enabledArchs.minus(
NativeCompilation.ALL_SUPPORTED_ARCHS.clone() as List<String>).toList()
if (!invalidArchs.isEmpty()) {
throw new InvalidUserDataException("Invalid 'enabledArchs' entry: " + invalidArchs.join(', '))
}
// Keep the return value sorted to prevent changes in intersection ordering
// from forcing a rebuild.
return supportedArchs.intersect(enabledArchs).toList().sort()
}

// TEST
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class NativeCompilation {
}
}
}
j2objcConfig.supportedArchs.each { String arch ->
j2objcConfig.activeArchs.each { String arch ->
if (!(arch in ALL_SUPPORTED_ARCHS)) {
throw new InvalidUserDataException(
"Requested architecture $arch must be one of $ALL_SUPPORTED_ARCHS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PackLibrariesTask extends DefaultTask {
@InputFiles
ConfigurableFileCollection getLibrariesFiles() {
String staticLibraryPath = "${project.buildDir}/binaries/${project.name}-j2objcStaticLibrary"
return project.files(getSupportedArchs().collect { String arch ->
return project.files(getActiveArchs().collect { String arch ->
"$staticLibraryPath/$arch$buildType/lib${project.name}-j2objc.a"
})
}
Expand All @@ -47,7 +47,7 @@ class PackLibrariesTask extends DefaultTask {
String buildType

@Input
List<String> getSupportedArchs() { return J2objcConfig.from(project).supportedArchs }
List<String> getActiveArchs() { return J2objcConfig.from(project).activeArchs }


@OutputDirectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Utils {
private static final List<String> PROPERTIES_VALID_KEYS =
Collections.unmodifiableList(Arrays.asList(
'debug.enabled',
'enabledArchs',
'home',
'release.enabled',
'translateOnlyMode'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.github.j2objccontrib.j2objcgradle

import com.github.j2objccontrib.j2objcgradle.tasks.TestingUtils
import groovy.transform.CompileStatic
import groovy.transform.TypeCheckingMode
import org.gradle.api.InvalidUserDataException
Expand All @@ -26,6 +27,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.testng.Assert

/**
* J2objcConfig tests.
Expand Down Expand Up @@ -62,8 +64,10 @@ class J2objcConfigTest {
assert pDir + '/build/j2objcOutputs/lib' == ext.getDestLibDirFile().absolutePath
assert pDir + '/build/j2objcOutputs/src/main/objc' == ext.getDestSrcDirFile('main', 'objc').absolutePath
assert pDir + '/build/j2objcOutputs/src/test/objc' == ext.getDestSrcDirFile('test', 'objc').absolutePath
assert pDir + '/build/j2objcOutputs/src/main/resources' == ext.getDestSrcDirFile('main', 'resources').absolutePath
assert pDir + '/build/j2objcOutputs/src/test/resources' == ext.getDestSrcDirFile('test', 'resources').absolutePath
assert pDir + '/build/j2objcOutputs/src/main/resources' == ext.getDestSrcDirFile('main', 'resources')
.absolutePath
assert pDir + '/build/j2objcOutputs/src/test/resources' == ext.getDestSrcDirFile('test', 'resources')
.absolutePath
}

@Test
Expand Down Expand Up @@ -152,4 +156,44 @@ class J2objcConfigTest {
String[] expected = ['-arg1', '-arg2', '-arg3']
assert Arrays.equals(expected, j2objcConfig.extraLinkerArgs)
}

@Test
void testSupportedAndEnabledArchs_NoLocalProperties() {
// there is no local.properties file in this case
J2objcConfig j2objcConfig = new J2objcConfig(proj)
Assert.assertEqualsNoOrder(j2objcConfig.activeArchs.toArray(),
j2objcConfig.supportedArchs.toArray())
}

@Test
void testSupportedAndEnabledArchs_SubsetEnabledArchsSpecified() {
J2objcConfig j2objcConfig = TestingUtils.setupProjectJ2objcConfig(
new TestingUtils.ProjectConfig(createJ2objcConfig: true,
extraLocalProperties: ['j2objc.enabledArchs=ios_armv7,ios_armv7s']))
assert j2objcConfig.activeArchs == ['ios_armv7', 'ios_armv7s']
}

@Test(expected = InvalidUserDataException.class)
void testSupportedAndEnabledArchs_SubsetAndBogusEnabledArchsSpecified() {
J2objcConfig j2objcConfig = TestingUtils.setupProjectJ2objcConfig(
new TestingUtils.ProjectConfig(createJ2objcConfig: true,
extraLocalProperties: ['j2objc.enabledArchs=ios_armv7,bogus,ios_armv7s']))
j2objcConfig.getActiveArchs()
}

@Test
void testSupportedAndEnabledArchs_EmptyEnabledArchSpecified() {
J2objcConfig j2objcConfig = TestingUtils.setupProjectJ2objcConfig(
new TestingUtils.ProjectConfig(createJ2objcConfig: true,
extraLocalProperties: ['j2objc.enabledArchs=']))
assert j2objcConfig.activeArchs.empty
}

@Test
void testSupportedAndEnabledArchs_NoEnabledArchsSpecified() {
J2objcConfig j2objcConfig = TestingUtils.setupProjectJ2objcConfig(
new TestingUtils.ProjectConfig(createJ2objcConfig: true))
Assert.assertEqualsNoOrder(j2objcConfig.activeArchs.toArray(),
j2objcConfig.supportedArchs.toArray())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class TestingUtils {
boolean createReportsDir = false
/** the parent project for this project, if any */
Project rootProject = null
/** lines to add to the local.properties file (in addition to j2objc.home) */
List<String> extraLocalProperties = []
}

/**
Expand Down Expand Up @@ -78,7 +80,9 @@ class TestingUtils {
// To satisfy Utils.J2objcHome()
String j2objcHome = File.createTempDir('J2OBJC_HOME', '').path
File localProperties = proj.file('local.properties')
localProperties.write("j2objc.home=$j2objcHome\n")
List<String> localPropertiesLines = ["j2objc.home=$j2objcHome"]
localPropertiesLines.addAll(config.extraLocalProperties)
localProperties.write(localPropertiesLines.join('\n'))

J2objcConfig j2objcConfig = null
if (config.applyJ2objcPlugin) {
Expand All @@ -98,6 +102,10 @@ class TestingUtils {
return [proj, j2objcHome, j2objcConfig]
}

static J2objcConfig setupProjectJ2objcConfig(ProjectConfig config) {
return setupProject(config)[2] as J2objcConfig
}

static Set<? extends Task> getTaskDependencies(Project proj, String name) {
// Strange API requires passing the task as a parameter to getDependencies.
Task task = proj.tasks.getByName(name)
Expand Down

0 comments on commit 7ef3450

Please sign in to comment.