use of org.gradle.ide.xcode.internal.xcodeproj.PBXTarget 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");
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(newSourceBuildPhase(xcodeTarget.getSources()));
target.getBuildPhases().add(gradleBuildPhase);
File outputFile = xcodeTarget.getDebugOutputFile().get().getAsFile();
target.setProductReference(new PBXFileReference(outputFile.getName(), outputFile.getAbsolutePath(), PBXReference.SourceTree.ABSOLUTE));
getAllBinaries().stream().filter(it -> !Objects.equals(it.getBuildConfigurationName(), TEST_DEBUG)).forEach(configureBuildSettings(xcodeTarget, target));
NSDictionary testRunnerSettings = target.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(TEST_DEBUG).getBuildSettings();
if (!xcodeTarget.getCompileModules().isEmpty()) {
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");
return target;
}
Aggregations