Search in sources :

Example 1 with PBXShellScriptBuildPhase

use of org.gradle.ide.xcode.internal.xcodeproj.PBXShellScriptBuildPhase in project gradle by gradle.

the class GenerateXcodeProjectFileTask method toXCTestPbxTarget.

private PBXTarget toXCTestPbxTarget(XcodeTarget xcodeTarget) {
    PBXShellScriptBuildPhase hackBuildPhase = new PBXShellScriptBuildPhase();
    hackBuildPhase.setShellPath("/bin/sh");
    hackBuildPhase.setShellScript("# Script to generate specific Swift files Xcode expects when running tests.\n" + "set -eu\n" + "ARCH_ARRAY=($ARCHS)\n" + "SUFFIXES=(swiftdoc swiftmodule h)\n" + "for ARCH in \"${ARCH_ARRAY[@]}\"\n" + "do\n" + "  for SUFFIX in \"${SUFFIXES[@]}\"\n" + "  do\n" + "    touch \"$OBJECT_FILE_DIR_normal/$ARCH/$PRODUCT_NAME.$SUFFIX\"\n" + "  done\n" + "done");
    PBXSourcesBuildPhase sourcesBuildPhase = new PBXSourcesBuildPhase();
    for (File file : xcodeTarget.getSources()) {
        PBXFileReference fileReference = pathToFileReference.get(file.getAbsolutePath());
        sourcesBuildPhase.getFiles().add(new PBXBuildFile(fileReference));
    }
    PBXShellScriptBuildPhase gradleBuildPhase = new PBXShellScriptBuildPhase();
    gradleBuildPhase.setShellPath("/bin/sh");
    gradleBuildPhase.setShellScript("exec \"" + xcodeTarget.getGradleCommand() + "\" " + buildGradleArgs(xcodeTarget) + " < /dev/null");
    PBXNativeTarget target = new PBXNativeTarget(xcodeTarget.getName(), xcodeTarget.getProductType());
    target.setProductName(xcodeTarget.getProductName());
    target.setGlobalID(xcodeTarget.getId());
    // Note the order in which the build phase are added is important
    target.getBuildPhases().add(hackBuildPhase);
    target.getBuildPhases().add(sourcesBuildPhase);
    target.getBuildPhases().add(gradleBuildPhase);
    File outputFile = xcodeTarget.getDebugOutputFile().get().getAsFile();
    target.setProductReference(new PBXFileReference(outputFile.getName(), outputFile.getAbsolutePath(), PBXReference.SourceTree.ABSOLUTE));
    NSDictionary debugSettings = target.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(BUILD_DEBUG).getBuildSettings();
    NSDictionary releaseSettings = target.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(BUILD_RELEASE).getBuildSettings();
    NSDictionary testRunnerSettings = target.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(TEST_DEBUG).getBuildSettings();
    if (!xcodeTarget.getCompileModules().isEmpty()) {
        debugSettings.put("SWIFT_INCLUDE_PATHS", toSpaceSeparatedList(parentDirs(xcodeTarget.getCompileModules())));
        releaseSettings.put("SWIFT_INCLUDE_PATHS", toSpaceSeparatedList(parentDirs(xcodeTarget.getCompileModules())));
        testRunnerSettings.put("SWIFT_INCLUDE_PATHS", toSpaceSeparatedList(parentDirs(xcodeTarget.getCompileModules())));
    }
    testRunnerSettings.put("SWIFT_VERSION", toXcodeSwiftVersion(xcodeTarget.getSwiftSourceCompatibility()));
    testRunnerSettings.put("PRODUCT_NAME", target.getProductName());
    testRunnerSettings.put("OTHER_LDFLAGS", "-help");
    testRunnerSettings.put("OTHER_CFLAGS", "-help");
    testRunnerSettings.put("OTHER_SWIFT_FLAGS", "-help");
    testRunnerSettings.put("SWIFT_INSTALL_OBJC_HEADER", "NO");
    testRunnerSettings.put("SWIFT_OBJC_INTERFACE_HEADER_NAME", "$(PRODUCT_NAME).h");
    debugSettings.put("PRODUCT_NAME", target.getProductName());
    debugSettings.put("SWIFT_VERSION", toXcodeSwiftVersion(xcodeTarget.getSwiftSourceCompatibility()));
    releaseSettings.put("PRODUCT_NAME", target.getProductName());
    releaseSettings.put("SWIFT_VERSION", toXcodeSwiftVersion(xcodeTarget.getSwiftSourceCompatibility()));
    return target;
}
Also used : PBXShellScriptBuildPhase(org.gradle.ide.xcode.internal.xcodeproj.PBXShellScriptBuildPhase) PBXNativeTarget(org.gradle.ide.xcode.internal.xcodeproj.PBXNativeTarget) NSDictionary(com.dd.plist.NSDictionary) PBXBuildFile(org.gradle.ide.xcode.internal.xcodeproj.PBXBuildFile) XcodeProjectFile(org.gradle.ide.xcode.tasks.internal.XcodeProjectFile) PBXBuildFile(org.gradle.ide.xcode.internal.xcodeproj.PBXBuildFile) File(java.io.File) PBXFileReference(org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference) PBXSourcesBuildPhase(org.gradle.ide.xcode.internal.xcodeproj.PBXSourcesBuildPhase)

Aggregations

NSDictionary (com.dd.plist.NSDictionary)1 File (java.io.File)1 PBXBuildFile (org.gradle.ide.xcode.internal.xcodeproj.PBXBuildFile)1 PBXFileReference (org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference)1 PBXNativeTarget (org.gradle.ide.xcode.internal.xcodeproj.PBXNativeTarget)1 PBXShellScriptBuildPhase (org.gradle.ide.xcode.internal.xcodeproj.PBXShellScriptBuildPhase)1 PBXSourcesBuildPhase (org.gradle.ide.xcode.internal.xcodeproj.PBXSourcesBuildPhase)1 XcodeProjectFile (org.gradle.ide.xcode.tasks.internal.XcodeProjectFile)1