From 37d2b90806c4472dbcd0710952a0f4275cabcfed Mon Sep 17 00:00:00 2001 From: Bruno Bowden Date: Thu, 15 Oct 2015 00:44:42 -0700 Subject: [PATCH] vendored_libraries for podspec Moves the j2objc lib from spec.libraries to spec.vendored_libraries Fixes #460 --- .../j2objcgradle/tasks/PodspecTask.groovy | 40 ++++++++++++------- .../j2objcgradle/tasks/PodspecTaskTest.groovy | 36 +++++++++++------ 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/tasks/PodspecTask.groovy b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/tasks/PodspecTask.groovy index 4bc9b4a4..2bea48ea 100644 --- a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/tasks/PodspecTask.groovy +++ b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/tasks/PodspecTask.groovy @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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" + diff --git a/src/test/groovy/com/github/j2objccontrib/j2objcgradle/tasks/PodspecTaskTest.groovy b/src/test/groovy/com/github/j2objccontrib/j2objcgradle/tasks/PodspecTaskTest.groovy index 9302dabf..98d1f88d 100644 --- a/src/test/groovy/com/github/j2objccontrib/j2objcgradle/tasks/PodspecTaskTest.groovy +++ b/src/test/groovy/com/github/j2objccontrib/j2objcgradle/tasks/PodspecTaskTest.groovy @@ -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'", @@ -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 readPodspecRelease = podspecRelease.readLines() assert expectedPodspecRelease == readPodspecRelease @@ -131,7 +138,7 @@ class PodspecTaskTest { List 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') @@ -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'",