Search in sources :

Example 1 with XcodeTarget

use of org.gradle.ide.xcode.internal.XcodeTarget in project gradle by gradle.

the class GenerateSchemeFileTask method configureLaunchAction.

private void configureLaunchAction(XcodeSchemeFile.LaunchAction action) {
    action.setBuildConfiguration(xcodeProject.getTargets().iterator().next().getDefaultConfigurationName().get());
    for (XcodeTarget xcodeTarget : xcodeProject.getTargets()) {
        XcodeSchemeFile.BuildableReference buildableReference = toBuildableReference(xcodeTarget);
        if (xcodeTarget.isRunnable()) {
            action.setBuildableProductRunnable(buildableReference);
        }
        action.setBuildableReference(buildableReference);
        break;
    }
}
Also used : XcodeSchemeFile(org.gradle.ide.xcode.tasks.internal.XcodeSchemeFile) XcodeTarget(org.gradle.ide.xcode.internal.XcodeTarget)

Example 2 with XcodeTarget

use of org.gradle.ide.xcode.internal.XcodeTarget in project gradle by gradle.

the class XcodePlugin method newTarget.

private XcodeTarget newTarget(String name, String productName, String gradleCommand, String taskName, FileCollection sources) {
    String id = gidGenerator.generateGid("PBXLegacyTarget", name.hashCode());
    XcodeTarget target = objectFactory.newInstance(XcodeTarget.class, name, id);
    target.setTaskName(taskName);
    target.setGradleCommand(gradleCommand);
    target.setProductName(productName);
    target.getSources().setFrom(sources);
    return target;
}
Also used : XcodeTarget(org.gradle.ide.xcode.internal.XcodeTarget)

Example 3 with XcodeTarget

use of org.gradle.ide.xcode.internal.XcodeTarget in project gradle by gradle.

the class GenerateSchemeFileTask method configureTestAction.

private void configureTestAction(XcodeSchemeFile.TestAction action) {
    action.setBuildConfiguration(BUILD_DEBUG);
    for (final XcodeTarget xcodeTarget : xcodeProject.getTargets()) {
        if (xcodeTarget.isUnitTest()) {
            action.setBuildConfiguration(TEST_DEBUG);
            action.entry(new Action<XcodeSchemeFile.TestableEntry>() {

                @Override
                public void execute(XcodeSchemeFile.TestableEntry testableEntry) {
                    testableEntry.setSkipped(false);
                    XcodeSchemeFile.BuildableReference buildableReference = toBuildableReference(xcodeTarget);
                    testableEntry.setBuildableReference(buildableReference);
                }
            });
        }
    }
}
Also used : XcodeSchemeFile(org.gradle.ide.xcode.tasks.internal.XcodeSchemeFile) XcodeTarget(org.gradle.ide.xcode.internal.XcodeTarget)

Example 4 with XcodeTarget

use of org.gradle.ide.xcode.internal.XcodeTarget 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;
}
Also used : DefaultXcodeProject(org.gradle.ide.xcode.internal.DefaultXcodeProject) PBXProject(org.gradle.ide.xcode.internal.xcodeproj.PBXProject) PBXSourcesBuildPhase(org.gradle.ide.xcode.internal.xcodeproj.PBXSourcesBuildPhase) HashMap(java.util.HashMap) FileCollection(org.gradle.api.file.FileCollection) DisableCachingByDefault(org.gradle.work.DisableCachingByDefault) GidGenerator(org.gradle.ide.xcode.internal.xcodeproj.GidGenerator) ArrayList(java.util.ArrayList) PBXFileReference(org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference) Inject(javax.inject.Inject) TEST_DEBUG(org.gradle.ide.xcode.internal.DefaultXcodeProject.TEST_DEBUG) Provider(org.gradle.api.provider.Provider) Optional(com.google.common.base.Optional) Map(java.util.Map) XcodeBinary(org.gradle.ide.xcode.internal.XcodeBinary) NSString(com.dd.plist.NSString) XcodeProjectFile(org.gradle.ide.xcode.tasks.internal.XcodeProjectFile) XcodePropertyAdapter(org.gradle.ide.xcode.internal.XcodePropertyAdapter) PBXLegacyTarget(org.gradle.ide.xcode.internal.xcodeproj.PBXLegacyTarget) PBXShellScriptBuildPhase(org.gradle.ide.xcode.internal.xcodeproj.PBXShellScriptBuildPhase) Incubating(org.gradle.api.Incubating) Internal(org.gradle.api.tasks.Internal) PBXTarget(org.gradle.ide.xcode.internal.xcodeproj.PBXTarget) PropertyListGeneratorTask(org.gradle.plugins.ide.api.PropertyListGeneratorTask) NSDictionary(com.dd.plist.NSDictionary) Action(org.gradle.api.Action) SwiftVersion(org.gradle.language.swift.SwiftVersion) PBXNativeTarget(org.gradle.ide.xcode.internal.xcodeproj.PBXNativeTarget) XcodeUtils.toSpaceSeparatedList(org.gradle.ide.xcode.internal.XcodeUtils.toSpaceSeparatedList) Collection(java.util.Collection) PBXBuildFile(org.gradle.ide.xcode.internal.xcodeproj.PBXBuildFile) Cast(org.gradle.internal.Cast) Collectors(java.util.stream.Collectors) PBXGroup(org.gradle.ide.xcode.internal.xcodeproj.PBXGroup) File(java.io.File) Objects(java.util.Objects) Consumer(java.util.function.Consumer) XcodeprojSerializer(org.gradle.ide.xcode.internal.xcodeproj.XcodeprojSerializer) MachineArchitecture(org.gradle.nativeplatform.MachineArchitecture) XcodeProject(org.gradle.ide.xcode.XcodeProject) List(java.util.List) PBXReference(org.gradle.ide.xcode.internal.xcodeproj.PBXReference) Joiner(com.google.common.base.Joiner) XcodeTarget(org.gradle.ide.xcode.internal.XcodeTarget) PBXShellScriptBuildPhase(org.gradle.ide.xcode.internal.xcodeproj.PBXShellScriptBuildPhase) PBXNativeTarget(org.gradle.ide.xcode.internal.xcodeproj.PBXNativeTarget) NSDictionary(com.dd.plist.NSDictionary) 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)

Example 5 with XcodeTarget

use of org.gradle.ide.xcode.internal.XcodeTarget in project gradle by gradle.

the class GenerateXcodeProjectFileTask method configure.

@Override
protected void configure(XcodeProjectFile projectFile) {
    PBXProject project = new PBXProject(projectPath);
    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()) {
        if (xcodeTarget.isBuildable()) {
            project.getTargets().add(toGradlePbxTarget(xcodeTarget));
        } else {
            getLogger().warn("'" + xcodeTarget.getName() + "' component in project '" + projectPath + "' is not buildable.");
        }
        project.getTargets().add(toIndexPbxTarget(xcodeTarget));
        if (!xcodeTarget.isUnitTest() && xcodeTarget.getDebugOutputFile().isPresent()) {
            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);
        }
    }
    // Create build configuration at the project level from all target's build configuration
    project.getTargets().stream().flatMap(it -> it.getBuildConfigurationList().getBuildConfigurationsByName().asMap().keySet().stream()).forEach(project.getBuildConfigurationList().getBuildConfigurationsByName()::getUnchecked);
    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);
        }
    });
}
Also used : DefaultXcodeProject(org.gradle.ide.xcode.internal.DefaultXcodeProject) PBXProject(org.gradle.ide.xcode.internal.xcodeproj.PBXProject) PBXSourcesBuildPhase(org.gradle.ide.xcode.internal.xcodeproj.PBXSourcesBuildPhase) HashMap(java.util.HashMap) FileCollection(org.gradle.api.file.FileCollection) DisableCachingByDefault(org.gradle.work.DisableCachingByDefault) GidGenerator(org.gradle.ide.xcode.internal.xcodeproj.GidGenerator) ArrayList(java.util.ArrayList) PBXFileReference(org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference) Inject(javax.inject.Inject) TEST_DEBUG(org.gradle.ide.xcode.internal.DefaultXcodeProject.TEST_DEBUG) Provider(org.gradle.api.provider.Provider) Optional(com.google.common.base.Optional) Map(java.util.Map) XcodeBinary(org.gradle.ide.xcode.internal.XcodeBinary) NSString(com.dd.plist.NSString) XcodeProjectFile(org.gradle.ide.xcode.tasks.internal.XcodeProjectFile) XcodePropertyAdapter(org.gradle.ide.xcode.internal.XcodePropertyAdapter) PBXLegacyTarget(org.gradle.ide.xcode.internal.xcodeproj.PBXLegacyTarget) PBXShellScriptBuildPhase(org.gradle.ide.xcode.internal.xcodeproj.PBXShellScriptBuildPhase) Incubating(org.gradle.api.Incubating) Internal(org.gradle.api.tasks.Internal) PBXTarget(org.gradle.ide.xcode.internal.xcodeproj.PBXTarget) PropertyListGeneratorTask(org.gradle.plugins.ide.api.PropertyListGeneratorTask) NSDictionary(com.dd.plist.NSDictionary) Action(org.gradle.api.Action) SwiftVersion(org.gradle.language.swift.SwiftVersion) PBXNativeTarget(org.gradle.ide.xcode.internal.xcodeproj.PBXNativeTarget) XcodeUtils.toSpaceSeparatedList(org.gradle.ide.xcode.internal.XcodeUtils.toSpaceSeparatedList) Collection(java.util.Collection) PBXBuildFile(org.gradle.ide.xcode.internal.xcodeproj.PBXBuildFile) Cast(org.gradle.internal.Cast) Collectors(java.util.stream.Collectors) PBXGroup(org.gradle.ide.xcode.internal.xcodeproj.PBXGroup) File(java.io.File) Objects(java.util.Objects) Consumer(java.util.function.Consumer) XcodeprojSerializer(org.gradle.ide.xcode.internal.xcodeproj.XcodeprojSerializer) MachineArchitecture(org.gradle.nativeplatform.MachineArchitecture) XcodeProject(org.gradle.ide.xcode.XcodeProject) List(java.util.List) PBXReference(org.gradle.ide.xcode.internal.xcodeproj.PBXReference) Joiner(com.google.common.base.Joiner) XcodeTarget(org.gradle.ide.xcode.internal.XcodeTarget) XcodeprojSerializer(org.gradle.ide.xcode.internal.xcodeproj.XcodeprojSerializer) NSDictionary(com.dd.plist.NSDictionary) XcodeTarget(org.gradle.ide.xcode.internal.XcodeTarget) PBXProject(org.gradle.ide.xcode.internal.xcodeproj.PBXProject) 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)

Aggregations

XcodeTarget (org.gradle.ide.xcode.internal.XcodeTarget)5 NSDictionary (com.dd.plist.NSDictionary)2 NSString (com.dd.plist.NSString)2 Joiner (com.google.common.base.Joiner)2 Optional (com.google.common.base.Optional)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Action (org.gradle.api.Action)2 Incubating (org.gradle.api.Incubating)2 FileCollection (org.gradle.api.file.FileCollection)2 Provider (org.gradle.api.provider.Provider)2 Internal (org.gradle.api.tasks.Internal)2