use of org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference in project gradle by gradle.
the class GenerateXcodeProjectFileTask method toIndexPbxTarget.
private PBXTarget toIndexPbxTarget(XcodeTarget xcodeTarget) {
PBXSourcesBuildPhase buildPhase = new PBXSourcesBuildPhase();
for (File file : xcodeTarget.getSources()) {
PBXFileReference fileReference = pathToFileReference.get(file.getAbsolutePath());
buildPhase.getFiles().add(new PBXBuildFile(fileReference));
}
PBXNativeTarget target = new PBXNativeTarget("[INDEXING ONLY] " + xcodeTarget.getName(), xcodeTarget.getProductType());
target.setProductName(xcodeTarget.getProductName());
NSDictionary buildSettings = new NSDictionary();
buildSettings.put("SWIFT_VERSION", toXcodeSwiftVersion(xcodeTarget.getSwiftSourceCompatibility()));
// Mandatory
buildSettings.put("PRODUCT_NAME", xcodeTarget.getProductName());
if (!xcodeTarget.getHeaderSearchPaths().isEmpty()) {
buildSettings.put("HEADER_SEARCH_PATHS", toSpaceSeparatedList(xcodeTarget.getHeaderSearchPaths()));
}
if (!xcodeTarget.getCompileModules().isEmpty()) {
buildSettings.put("SWIFT_INCLUDE_PATHS", toSpaceSeparatedList(parentDirs(xcodeTarget.getCompileModules())));
}
target.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(BUILD_DEBUG).setBuildSettings(buildSettings);
target.getBuildPhases().add(buildPhase);
return target;
}
use of org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference in project gradle by gradle.
the class GenerateXcodeProjectFileTask method toToolAndLibraryPbxTarget.
private PBXTarget toToolAndLibraryPbxTarget(XcodeTarget xcodeTarget) {
PBXLegacyTarget target = new PBXLegacyTarget(xcodeTarget.getName(), xcodeTarget.getProductType());
target.setProductName(xcodeTarget.getProductName());
NSDictionary debugSettings = target.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(BUILD_DEBUG).getBuildSettings();
NSDictionary releaseSettings = target.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(BUILD_RELEASE).getBuildSettings();
target.setBuildToolPath(xcodeTarget.getGradleCommand());
target.setBuildArgumentsString(buildGradleArgs(xcodeTarget));
target.setGlobalID(xcodeTarget.getId());
File outputFile = xcodeTarget.getDebugOutputFile().get().getAsFile();
target.setProductReference(new PBXFileReference(outputFile.getName(), outputFile.getAbsolutePath(), PBXReference.SourceTree.ABSOLUTE));
File debugOutputFile = xcodeTarget.getDebugOutputFile().get().getAsFile();
debugSettings.put("CONFIGURATION_BUILD_DIR", new NSString(debugOutputFile.getParentFile().getAbsolutePath()));
debugSettings.put("PRODUCT_NAME", target.getProductName());
debugSettings.put("SWIFT_VERSION", toXcodeSwiftVersion(xcodeTarget.getSwiftSourceCompatibility()));
File releaseOutputFile = xcodeTarget.getReleaseOutputFile().get().getAsFile();
releaseSettings.put("CONFIGURATION_BUILD_DIR", new NSString(releaseOutputFile.getParentFile().getAbsolutePath()));
releaseSettings.put("PRODUCT_NAME", target.getProductName());
releaseSettings.put("SWIFT_VERSION", toXcodeSwiftVersion(xcodeTarget.getSwiftSourceCompatibility()));
return target;
}
use of org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference 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;
}
use of org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference in project gradle by gradle.
the class GenerateXcodeProjectFileTask method addToGroup.
private void addToGroup(PBXGroup group, FileCollection sources) {
for (File source : sources.getAsFileTree()) {
PBXFileReference fileReference = toFileReference(source);
pathToFileReference.put(source.getAbsolutePath(), fileReference);
group.getChildren().add(fileReference);
}
}
use of org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference in project gradle by gradle.
the class GenerateXcodeProjectFileTask method configure.
@Override
protected void configure(XcodeProjectFile projectFile) {
PBXProject project = new PBXProject(getProject().getPath());
project.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(BUILD_DEBUG);
project.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(BUILD_RELEASE);
addToGroup(project.getMainGroup(), xcodeProject.getGroups().getSources(), "Sources");
addToGroup(project.getMainGroup(), xcodeProject.getGroups().getHeaders(), "Headers");
addToGroup(project.getMainGroup(), xcodeProject.getGroups().getTests(), "Tests");
addToGroup(project.getMainGroup(), xcodeProject.getGroups().getRoot());
for (XcodeTarget xcodeTarget : xcodeProject.getTargets()) {
project.getTargets().add(toGradlePbxTarget(xcodeTarget));
project.getTargets().add(toIndexPbxTarget(xcodeTarget));
if (xcodeTarget.isUnitTest()) {
// Creates XCTest configuration only if XCTest are present.
project.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(TEST_DEBUG);
} else {
File debugOutputFile = xcodeTarget.getDebugOutputFile().get().getAsFile();
PBXFileReference fileReference = new PBXFileReference(debugOutputFile.getName(), debugOutputFile.getAbsolutePath(), PBXReference.SourceTree.ABSOLUTE);
fileReference.setExplicitFileType(Optional.of(xcodeTarget.getOutputFileType()));
project.getMainGroup().getOrCreateChildGroupByName(PRODUCTS_GROUP_NAME).getChildren().add(fileReference);
}
}
XcodeprojSerializer serializer = new XcodeprojSerializer(gidGenerator, project);
final NSDictionary rootObject = serializer.toPlist();
projectFile.transformAction(new Action<NSDictionary>() {
@Override
public void execute(NSDictionary dict) {
dict.clear();
dict.putAll(rootObject);
}
});
}
Aggregations