Skip to content

Commit

Permalink
min OS versions switch to older defaults
Browse files Browse the repository at this point in the history
- minIosVersion = ‘6.0’
- minOsxVersion = ’10.4’
- minWatchosVersion = ‘1.0’
  • Loading branch information
brunobowden committed Oct 16, 2015
1 parent a086623 commit f40c543
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,23 +611,23 @@ class J2objcConfig {
* <p/>
* See https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html#//apple_ref/doc/uid/10000163i-CH1-SW2
*/
String minIosVersion = '8.3'
String minIosVersion = '6.0'

/**
* The minimum OS X version to build against. You cannot use APIs that are not supported
* in this version.
* <p/>
* See https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html#//apple_ref/doc/uid/10000163i-CH1-SW2
*/
String minOsxVersion = '10.8'
String minOsxVersion = '10.4'

/**
* The minimum Watch OS version to build against. You cannot use APIs that are not supported
* in this version.
* <p/>
* See https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html#//apple_ref/doc/uid/10000163i-CH1-SW2
*/
String minWatchosVersion = '2.0'
String minWatchosVersion = '1.0'

// XCODE
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ class PodspecTask extends DefaultTask {
@Input
File getDestLibDirFile() { return J2objcConfig.from(project).getDestLibDirFile() }

@Input
String getLibName() { return "${project.name}-j2objc" }

@Input
String getPodNameDebug() { "j2objc-${project.name}-debug" }
@Input
String getPodNameRelease() { "j2objc-${project.name}-release" }

@Input
String getMinIosVersion() { return J2objcConfig.from(project).getMinIosVersion() }
@Input
String getMinOsxVersion() { return J2objcConfig.from(project).getMinOsxVersion() }
@Input
String getMinWatchosVersion() { return J2objcConfig.from(project).getMinWatchosVersion() }


// CocoaPods podspec files that are referenced by the Podfile
@OutputFile
Expand All @@ -74,46 +84,33 @@ class PodspecTask extends DefaultTask {

@TaskAction
void podspecWrite() {
// podspec paths must be relative to podspec file, which is in buildDir
// NOTE: toURI() adds trailing slash in production but not in unit tests
URI buildDir = project.buildDir.toURI()

// Absolute path for header include, relative path for resource include
String headerIncludePath = getDestSrcMainObjDirFile().getAbsolutePath()

String resourceIncludePath = relativizeToBuildDir(getDestSrcMainResourcesDirFile(), project)

// TODO: make this an explicit @Input
// Same for both debug and release builds
String libName = "${project.name}-j2objc"

// podspec creation
// TODO: allow custom list of libraries
// podspec paths must be relative to podspec file, which is in buildDir
String resourceIncludePath = relativizeToBuildDir(getDestSrcMainResourcesDirFile(), project)
// iOS packed libraries are shared with watchOS
String libDirIosDebug = relativizeToBuildDir(new File(getDestLibDirFile(), 'iosDebug'), project)
String libDirIosRelease = relativizeToBuildDir(new File(getDestLibDirFile(), 'iosRelease'), project)
String libDirOsxDebug = relativizeToBuildDir(new File(getDestLibDirFile(), 'x86_64Debug'), project)
String libDirOsxRelease = relativizeToBuildDir(new File(getDestLibDirFile(), 'x86_64Release'), project)

J2objcConfig j2objcConfig = J2objcConfig.from(project)

String minIos = j2objcConfig.minIosVersion
String minOsx = j2objcConfig.minOsxVersion
String minWatchos = j2objcConfig.minWatchosVersion
validateNumericVersion(minIos, 'minIosVersion')
validateNumericVersion(minOsx, 'minOsxVersion')
validateNumericVersion(minWatchos, 'minWatchosVersion')
validateNumericVersion(getMinIosVersion(), 'minIosVersion')
validateNumericVersion(getMinOsxVersion(), 'minOsxVersion')
validateNumericVersion(getMinWatchosVersion(), 'minWatchosVersion')

String podspecContentsDebug =
genPodspec(getPodNameDebug(), headerIncludePath, resourceIncludePath,
libName, getJ2objcHome(),
libDirIosDebug, libDirOsxDebug, libDirIosDebug,
minIos, minOsx, minWatchos)
getMinIosVersion(), getMinOsxVersion(), getMinWatchosVersion(),
getLibName(), getJ2objcHome())
String podspecContentsRelease =
genPodspec(getPodNameRelease(), headerIncludePath, resourceIncludePath,
libName, getJ2objcHome(),
libDirIosRelease, libDirOsxRelease, libDirIosRelease,
minIos, minOsx, minWatchos)
getMinIosVersion(), getMinOsxVersion(), getMinWatchosVersion(),
getLibName(), getJ2objcHome())

logger.debug("Writing debug podspec... ${getPodspecDebug()}")
getPodspecDebug().write(podspecContentsDebug)
Expand All @@ -122,25 +119,17 @@ class PodspecTask extends DefaultTask {
}

static private String relativizeToBuildDir(File path, Project proj) {
// NOTE: toURI() adds trailing slash in production but not in unit tests
return Utils.trimTrailingForwardSlash(
proj.getBuildDir().toURI().relativize(path.toURI()).toString())
}

@VisibleForTesting
void validateNumericVersion(String version, String type) {
// Requires at least a major and minor version number
Matcher versionMatcher = (version =~ /^[0-9]*(\.[0-9]+)+$/)
if (!versionMatcher.find()) {
logger.warn("Non-numeric version for $type: $version")
}
}

// Podspec references are relative to project.buildDir
@VisibleForTesting
static String genPodspec(String podname, String publicHeadersDir, String resourceDir,
String libName, String j2objcHome,
String libDirIos, String libDirOsx, String libDirWatchos,
String minIos, String minOsx, String minWatchos) {
String minIosVersion, String minOsxVersion, String minWatchosVersion,
String libName, String j2objcHome) {

// Relative paths for content referenced by CocoaPods
validatePodspecPath(libDirIos, true)
Expand Down Expand Up @@ -183,13 +172,22 @@ class PodspecTask extends DefaultTask {
" 'LIBRARY_SEARCH_PATHS' => '$j2objcHome/lib'\n" +
" }\n" +
// http://guides.cocoapods.org/syntax/podspec.html#deployment_target
" spec.ios.deployment_target = '$minIos'\n" +
" spec.osx.deployment_target = '$minOsx'\n" +
" spec.watchos.deployment_target = '$minWatchos'\n" +
" spec.ios.deployment_target = '$minIosVersion'\n" +
" spec.osx.deployment_target = '$minOsxVersion'\n" +
" spec.watchos.deployment_target = '$minWatchosVersion'\n" +
" spec.osx.frameworks = 'ExceptionHandling'\n" +
"end\n"
}

@VisibleForTesting
void validateNumericVersion(String version, String type) {
// Requires at least a major and minor version number
Matcher versionMatcher = (version =~ /^[0-9]*(\.[0-9]+)+$/)
if (!versionMatcher.find()) {
logger.warn("Non-numeric version for $type: $version")
}
}

@VisibleForTesting
static void validatePodspecPath(String path, boolean relativeRequired) {
if (path.contains('//')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package com.github.j2objccontrib.j2objcgradle.tasks
import com.github.j2objccontrib.j2objcgradle.J2objcConfig
import org.gradle.api.InvalidUserDataException
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException;
Expand Down Expand Up @@ -137,10 +135,10 @@ class PodspecTaskTest {
void testGenPodspec() {
List<String> podspecDebug = PodspecTask.genPodspec(
'POD-NAME', '/HEADER_INCLUDE', 'MAIN-RESOURCES',
'LIB-NAME', '/J2OBJC_HOME',
'LIB-DIR-IOS', 'LIB-DIR-OSX', 'LIB-DIR-WATCHOS',
// Using non-existent OS version numbers to ensure that no defaults are being used
'8.3.1', '10.8.1', '2.0.1').split('\n')
'8.3.1', '10.8.1', '2.0.1',
'LIB-NAME', '/J2OBJC_HOME').split('\n')

List<String> expectedPodspecDebug = [
"Pod::Spec.new do |spec|",
Expand Down

0 comments on commit f40c543

Please sign in to comment.