Skip to content

Commit

Permalink
vendored_libraries for podspec
Browse files Browse the repository at this point in the history
Moves the j2objc lib from spec.libraries to spec.vendored_libraries

Fixes j2objc-contrib#460
  • Loading branch information
brunobowden committed Oct 15, 2015
1 parent 2a8201d commit 37d2b90
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting
import groovy.transform.CompileStatic
import org.gradle.api.DefaultTask
import org.gradle.api.InvalidUserDataException
import org.gradle.api.Project
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
Expand Down Expand Up @@ -79,8 +80,8 @@ class PodspecTask extends DefaultTask {

// Absolute path for header include, relative path for resource include
String headerIncludePath = getDestSrcMainObjDirFile().getAbsolutePath()
String resourceIncludePath = Utils.trimTrailingForwardSlash(
buildDir.relativize(getDestSrcMainResourcesDirFile().toURI()).toString())

String resourceIncludePath = relativizeToBuildDir(getDestSrcMainResourcesDirFile(), project)

// TODO: make this an explicit @Input
// Same for both debug and release builds
Expand All @@ -89,10 +90,10 @@ class PodspecTask extends DefaultTask {
// podspec creation
// TODO: allow custom list of libraries
// iOS packed libraries are shared with watchOS
String libDirIosDebug = new File(getDestLibDirFile(), '/iosDebug').absolutePath
String libDirIosRelease = new File(getDestLibDirFile(), '/iosRelease').absolutePath
String libDirOsxDebug = new File(getDestLibDirFile(), '/x86_64Debug').absolutePath
String libDirOsxRelease = new File(getDestLibDirFile(), '/x86_64Release').absolutePath
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)

Expand Down Expand Up @@ -120,6 +121,11 @@ class PodspecTask extends DefaultTask {
getPodspecRelease().write(podspecContentsRelease)
}

static private String relativizeToBuildDir(File path, Project proj) {
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
Expand All @@ -136,14 +142,15 @@ class PodspecTask extends DefaultTask {
String libDirIos, String libDirOsx, String libDirWatchos,
String minIos, String minOsx, String minWatchos) {

// Relative paths for content referenced by CocoaPods
validatePodspecPath(libDirIos, true)
validatePodspecPath(libDirOsx, true)
validatePodspecPath(libDirWatchos, true)
validatePodspecPath(resourceDir, true)

// Absolute paths for Xcode command line
validatePodspecPath(libDirIos, false)
validatePodspecPath(libDirOsx, false)
validatePodspecPath(j2objcHome, false)

// Relative paths for content referenced by CocoaPods
validatePodspecPath(publicHeadersDir, false)
validatePodspecPath(resourceDir, true)

// TODO: CocoaPods strongly recommends switching from 'resources' to 'resource_bundles'
// http://guides.cocoapods.org/syntax/podspec.html#resource_bundles
Expand All @@ -159,18 +166,21 @@ class PodspecTask extends DefaultTask {
" spec.resources = '$resourceDir/**/*'\n" +
" spec.requires_arc = true\n" +
" spec.libraries = " + // continuation of same line
"'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore', '$libName'\n" +
"'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore'\n" +
" spec.ios.vendored_libraries = '$libDirIos/lib$libName'\n" +
" spec.osx.vendored_libraries = '$libDirOsx/lib$libName'\n" +
" spec.watchos.vendored_libraries = '$libDirWatchos/lib$libName'\n" +
" spec.xcconfig = {\n" +
" 'HEADER_SEARCH_PATHS' => '$j2objcHome/include $publicHeadersDir'\n" +
" }\n" +
" spec.ios.xcconfig = {\n" +
" 'LIBRARY_SEARCH_PATHS' => '$j2objcHome/lib $libDirIos'\n" +
" 'LIBRARY_SEARCH_PATHS' => '$j2objcHome/lib'\n" +
" }\n" +
" spec.osx.xcconfig = {\n" +
" 'LIBRARY_SEARCH_PATHS' => '$j2objcHome/lib/macosx $libDirOsx'\n" +
" 'LIBRARY_SEARCH_PATHS' => '$j2objcHome/lib/macosx'\n" +
" }\n" +
" spec.watchos.xcconfig = {\n" +
" 'LIBRARY_SEARCH_PATHS' => '$j2objcHome/lib $libDirWatchos'\n" +
" 'LIBRARY_SEARCH_PATHS' => '$j2objcHome/lib'\n" +
" }\n" +
// http://guides.cocoapods.org/syntax/podspec.html#deployment_target
" spec.ios.deployment_target = '$minIos'\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,21 @@ class PodspecTaskTest {
" spec.summary = 'Generated by the J2ObjC Gradle Plugin.'",
" spec.resources = 'j2objcOutputs/src/main/resources/**/*'",
" spec.requires_arc = true",
" spec.libraries = 'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore', '$libName'",
" spec.libraries = 'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore'",
" spec.ios.vendored_libraries = 'j2objcOutputs/lib/iosDebug/lib$libName'",
" spec.osx.vendored_libraries = 'j2objcOutputs/lib/x86_64Debug/lib$libName'",
" spec.watchos.vendored_libraries = 'j2objcOutputs/lib/iosDebug/lib$libName'",
" spec.xcconfig = {",
" 'HEADER_SEARCH_PATHS' => '${j2objcHome}/include ${proj.file('build/j2objcOutputs/src/main/objc')}'",
" }",
" spec.ios.xcconfig = {",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib ${proj.file('build/j2objcOutputs/lib/iosDebug').absolutePath}'",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib'",
" }",
" spec.osx.xcconfig = {",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib/macosx ${proj.file('build/j2objcOutputs/lib/x86_64Debug').absolutePath}'",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib/macosx'",
" }",
" spec.watchos.xcconfig = {",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib ${proj.file('build/j2objcOutputs/lib/iosDebug').absolutePath}'",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib'",
" }",
" spec.ios.deployment_target = '8.3'",
" spec.osx.deployment_target = '10.8'",
Expand All @@ -103,24 +106,28 @@ class PodspecTaskTest {
" spec.summary = 'Generated by the J2ObjC Gradle Plugin.'",
" spec.resources = 'j2objcOutputs/src/main/resources/**/*'",
" spec.requires_arc = true",
" spec.libraries = 'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore', '$libName'",
" spec.libraries = 'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore'",
" spec.ios.vendored_libraries = 'j2objcOutputs/lib/iosRelease/lib$libName'",
" spec.osx.vendored_libraries = 'j2objcOutputs/lib/x86_64Release/lib$libName'",
" spec.watchos.vendored_libraries = 'j2objcOutputs/lib/iosRelease/lib$libName'",
" spec.xcconfig = {",
" 'HEADER_SEARCH_PATHS' => '${j2objcHome}/include ${proj.file('build/j2objcOutputs/src/main/objc')}'",
" }",
" spec.ios.xcconfig = {",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib ${proj.file('build/j2objcOutputs/lib/iosRelease').absolutePath}'",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib'",
" }",
" spec.osx.xcconfig = {",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib/macosx ${proj.file('build/j2objcOutputs/lib/x86_64Release').absolutePath}'",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib/macosx'",
" }",
" spec.watchos.xcconfig = {",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib ${proj.file('build/j2objcOutputs/lib/iosRelease').absolutePath}'",
" 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib'",
" }",
" spec.ios.deployment_target = '8.3'",
" spec.osx.deployment_target = '10.8'",
" spec.watchos.deployment_target = '2.0'",
" spec.osx.frameworks = 'ExceptionHandling'",
"end"]

File podspecRelease = proj.file("build/${podNameRelease}.podspec")
List<String> readPodspecRelease = podspecRelease.readLines()
assert expectedPodspecRelease == readPodspecRelease
Expand All @@ -131,7 +138,7 @@ class PodspecTaskTest {
List<String> podspecDebug = PodspecTask.genPodspec(
'POD-NAME', '/HEADER_INCLUDE', 'MAIN-RESOURCES',
'LIB-NAME', '/J2OBJC_HOME',
'/LIB-DIR-IOS', '/LIB-DIR-OSX', '/LIB-DIR-WATCHOS',
'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')

Expand All @@ -142,18 +149,21 @@ class PodspecTaskTest {
" spec.summary = 'Generated by the J2ObjC Gradle Plugin.'",
" spec.resources = 'MAIN-RESOURCES/**/*'",
" spec.requires_arc = true",
" spec.libraries = 'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore', 'LIB-NAME'",
" spec.libraries = 'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore'",
" spec.ios.vendored_libraries = 'LIB-DIR-IOS/libLIB-NAME'",
" spec.osx.vendored_libraries = 'LIB-DIR-OSX/libLIB-NAME'",
" spec.watchos.vendored_libraries = 'LIB-DIR-WATCHOS/libLIB-NAME'",
" spec.xcconfig = {",
" 'HEADER_SEARCH_PATHS' => '/J2OBJC_HOME/include /HEADER_INCLUDE'",
" }",
" spec.ios.xcconfig = {",
" 'LIBRARY_SEARCH_PATHS' => '/J2OBJC_HOME/lib /LIB-DIR-IOS'",
" 'LIBRARY_SEARCH_PATHS' => '/J2OBJC_HOME/lib'",
" }",
" spec.osx.xcconfig = {",
" 'LIBRARY_SEARCH_PATHS' => '/J2OBJC_HOME/lib/macosx /LIB-DIR-OSX'",
" 'LIBRARY_SEARCH_PATHS' => '/J2OBJC_HOME/lib/macosx'",
" }",
" spec.watchos.xcconfig = {",
" 'LIBRARY_SEARCH_PATHS' => '/J2OBJC_HOME/lib /LIB-DIR-WATCHOS'",
" 'LIBRARY_SEARCH_PATHS' => '/J2OBJC_HOME/lib'",
" }",
" spec.ios.deployment_target = '8.3.1'",
" spec.osx.deployment_target = '10.8.1'",
Expand Down

0 comments on commit 37d2b90

Please sign in to comment.