Search in sources :

Example 1 with NSDictionary

use of com.dd.plist.NSDictionary in project buck by facebook.

the class AppleSdkDiscovery method buildSdkFromPath.

private static boolean buildSdkFromPath(Path sdkDir, AppleSdk.Builder sdkBuilder, ImmutableMap<String, AppleToolchain> xcodeToolchains, Optional<AppleToolchain> defaultToolchain, AppleConfig appleConfig) throws IOException {
    try (InputStream sdkSettingsPlist = Files.newInputStream(sdkDir.resolve("SDKSettings.plist"));
        BufferedInputStream bufferedSdkSettingsPlist = new BufferedInputStream(sdkSettingsPlist)) {
        NSDictionary sdkSettings;
        try {
            sdkSettings = (NSDictionary) PropertyListParser.parse(bufferedSdkSettingsPlist);
        } catch (PropertyListFormatException | ParseException | SAXException e) {
            LOG.error(e, "Malformatted SDKSettings.plist. Skipping SDK path %s.", sdkDir);
            return false;
        } catch (ParserConfigurationException e) {
            throw new IOException(e);
        }
        String name = sdkSettings.objectForKey("CanonicalName").toString();
        String version = sdkSettings.objectForKey("Version").toString();
        NSDictionary defaultProperties = (NSDictionary) sdkSettings.objectForKey("DefaultProperties");
        Optional<ImmutableList<String>> toolchains = appleConfig.getToolchainsOverrideForSDKName(name);
        boolean foundToolchain = false;
        if (!toolchains.isPresent()) {
            NSArray settingsToolchains = (NSArray) sdkSettings.objectForKey("Toolchains");
            if (settingsToolchains != null) {
                toolchains = Optional.of(Arrays.stream(settingsToolchains.getArray()).map(Object::toString).collect(MoreCollectors.toImmutableList()));
            }
        }
        if (toolchains.isPresent()) {
            for (String toolchainId : toolchains.get()) {
                AppleToolchain toolchain = xcodeToolchains.get(toolchainId);
                if (toolchain != null) {
                    foundToolchain = true;
                    sdkBuilder.addToolchains(toolchain);
                } else {
                    LOG.debug("Specified toolchain %s not found for SDK path %s", toolchainId, sdkDir);
                }
            }
        }
        if (!foundToolchain && defaultToolchain.isPresent()) {
            foundToolchain = true;
            sdkBuilder.addToolchains(defaultToolchain.get());
        }
        if (!foundToolchain) {
            LOG.warn("No toolchains found and no default toolchain. Skipping SDK path %s.", sdkDir);
            return false;
        } else {
            NSString platformName = (NSString) defaultProperties.objectForKey("PLATFORM_NAME");
            ApplePlatform applePlatform = ApplePlatform.of(platformName.toString());
            sdkBuilder.setName(name).setVersion(version).setApplePlatform(applePlatform);
            ImmutableList<String> architectures = validArchitecturesForPlatform(applePlatform, sdkDir);
            sdkBuilder.addAllArchitectures(architectures);
            return true;
        }
    } catch (NoSuchFileException e) {
        LOG.warn(e, "Skipping SDK at path %s, no SDKSettings.plist found", sdkDir);
        return false;
    }
}
Also used : NSArray(com.dd.plist.NSArray) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) ImmutableList(com.google.common.collect.ImmutableList) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) SAXException(org.xml.sax.SAXException) PropertyListFormatException(com.dd.plist.PropertyListFormatException) BufferedInputStream(java.io.BufferedInputStream) ParseException(java.text.ParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with NSDictionary

use of com.dd.plist.NSDictionary in project buck by facebook.

the class AppleToolchainDiscovery method toolchainFromPlist.

private static Optional<AppleToolchain> toolchainFromPlist(Path toolchainDir, String plistName) throws IOException {
    Path toolchainInfoPlistPath = toolchainDir.resolve(plistName);
    InputStream toolchainInfoPlist = Files.newInputStream(toolchainInfoPlistPath);
    BufferedInputStream bufferedToolchainInfoPlist = new BufferedInputStream(toolchainInfoPlist);
    NSDictionary parsedToolchainInfoPlist;
    try {
        parsedToolchainInfoPlist = (NSDictionary) PropertyListParser.parse(bufferedToolchainInfoPlist);
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        LOG.error(e, "Failed to parse %s: %s, ignoring", plistName, toolchainInfoPlistPath);
        return Optional.empty();
    }
    NSObject identifierObject = parsedToolchainInfoPlist.objectForKey("Identifier");
    if (identifierObject == null) {
        LOG.error("Identifier not found for toolchain path %s, ignoring", toolchainDir);
        return Optional.empty();
    }
    String identifier = identifierObject.toString();
    NSObject versionObject = parsedToolchainInfoPlist.objectForKey("DTSDKBuild");
    Optional<String> version = versionObject == null ? Optional.empty() : Optional.of(versionObject.toString());
    LOG.debug("Mapped SDK identifier %s to path %s", identifier, toolchainDir);
    AppleToolchain.Builder toolchainBuilder = AppleToolchain.builder();
    toolchainBuilder.setIdentifier(identifier);
    toolchainBuilder.setVersion(version);
    toolchainBuilder.setPath(toolchainDir);
    return Optional.of(toolchainBuilder.build());
}
Also used : Path(java.nio.file.Path) NSObject(com.dd.plist.NSObject) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) SAXException(org.xml.sax.SAXException) PropertyListFormatException(com.dd.plist.PropertyListFormatException) BufferedInputStream(java.io.BufferedInputStream) ParseException(java.text.ParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 3 with NSDictionary

use of com.dd.plist.NSDictionary in project buck by facebook.

the class NewNativeTargetProjectMutator method addSourcePathToHeadersBuildPhase.

private void addSourcePathToHeadersBuildPhase(SourcePath headerPath, PBXGroup headersGroup, HeaderVisibility visibility) {
    PBXFileReference fileReference = headersGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputPathToSourcePath(headerPath), Optional.empty()));
    PBXBuildFile buildFile = new PBXBuildFile(fileReference);
    if (visibility != HeaderVisibility.PRIVATE) {
        NSDictionary settings = new NSDictionary();
        settings.put("ATTRIBUTES", new NSArray(new NSString(AppleHeaderVisibilities.toXcodeAttribute(visibility))));
        buildFile.setSettings(Optional.of(settings));
    } else {
        buildFile.setSettings(Optional.empty());
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) NSString(com.dd.plist.NSString) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 4 with NSDictionary

use of com.dd.plist.NSDictionary in project buck by facebook.

the class ProvisioningProfileCopyStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
    final String bundleID;
    try {
        bundleID = AppleInfoPlistParsing.getBundleIdFromPlistStream(filesystem.getInputStreamForRelativePath(infoPlist)).get();
    } catch (IOException e) {
        throw new HumanReadableException("Unable to get bundle ID from info.plist: " + infoPlist);
    }
    final Optional<ImmutableMap<String, NSObject>> entitlements;
    final String prefix;
    if (entitlementsPlist.isPresent()) {
        try {
            NSDictionary entitlementsPlistDict = (NSDictionary) PropertyListParser.parse(entitlementsPlist.get().toFile());
            entitlements = Optional.of(ImmutableMap.copyOf(entitlementsPlistDict.getHashMap()));
            prefix = ProvisioningProfileMetadata.prefixFromEntitlements(entitlements.get()).orElse("*");
        } catch (IOException e) {
            throw new HumanReadableException("Unable to find entitlement .plist: " + entitlementsPlist.get());
        } catch (Exception e) {
            throw new HumanReadableException("Malformed entitlement .plist: " + entitlementsPlist.get());
        }
    } else {
        entitlements = ProvisioningProfileStore.MATCH_ANY_ENTITLEMENT;
        prefix = "*";
    }
    final Optional<ImmutableList<CodeSignIdentity>> identities;
    if (!codeSignIdentityStore.getIdentities().isEmpty()) {
        identities = Optional.of(codeSignIdentityStore.getIdentities());
    } else {
        identities = ProvisioningProfileStore.MATCH_ANY_IDENTITY;
    }
    Optional<ProvisioningProfileMetadata> bestProfile = provisioningProfileUUID.isPresent() ? provisioningProfileStore.getProvisioningProfileByUUID(provisioningProfileUUID.get()) : provisioningProfileStore.getBestProvisioningProfile(bundleID, platform, entitlements, identities);
    if (dryRunResultsPath.isPresent()) {
        try {
            NSDictionary dryRunResult = new NSDictionary();
            dryRunResult.put(BUNDLE_ID, bundleID);
            dryRunResult.put(ENTITLEMENTS, entitlements.orElse(ImmutableMap.of()));
            if (bestProfile.isPresent()) {
                dryRunResult.put(PROFILE_UUID, bestProfile.get().getUUID());
                dryRunResult.put(PROFILE_FILENAME, bestProfile.get().getProfilePath().getFileName().toString());
                dryRunResult.put(TEAM_IDENTIFIER, bestProfile.get().getEntitlements().get("com.apple.developer.team-identifier"));
            }
            filesystem.writeContentsToPath(dryRunResult.toXMLPropertyList(), dryRunResultsPath.get());
        } catch (IOException e) {
            context.logError(e, "Failed when trying to write dry run results: %s", getDescription(context));
            return StepExecutionResult.ERROR;
        }
    }
    selectedProvisioningProfileFuture.set(bestProfile);
    if (!bestProfile.isPresent()) {
        String message = "No valid non-expired provisioning profiles match for " + prefix + "." + bundleID;
        if (dryRunResultsPath.isPresent()) {
            LOG.warn(message);
            return StepExecutionResult.SUCCESS;
        } else {
            throw new HumanReadableException(message);
        }
    }
    Path provisioningProfileSource = bestProfile.get().getProfilePath();
    // Copy the actual .mobileprovision.
    try {
        filesystem.copy(provisioningProfileSource, provisioningProfileDestination, CopySourceMode.FILE);
    } catch (IOException e) {
        context.logError(e, "Failed when trying to copy: %s", getDescription(context));
        return StepExecutionResult.ERROR;
    }
    // Merge the entitlements with the profile, and write out.
    if (entitlementsPlist.isPresent()) {
        return (new PlistProcessStep(filesystem, entitlementsPlist.get(), Optional.empty(), signingEntitlementsTempPath, bestProfile.get().getMergeableEntitlements(), ImmutableMap.of(), PlistProcessStep.OutputFormat.XML)).execute(context);
    } else {
        // No entitlements.plist explicitly specified; write out the minimal entitlements needed.
        String appID = bestProfile.get().getAppID().getFirst() + "." + bundleID;
        NSDictionary entitlementsPlist = new NSDictionary();
        entitlementsPlist.putAll(bestProfile.get().getMergeableEntitlements());
        entitlementsPlist.put(APPLICATION_IDENTIFIER, appID);
        entitlementsPlist.put(KEYCHAIN_ACCESS_GROUPS, new String[] { appID });
        return (new WriteFileStep(filesystem, entitlementsPlist.toXMLPropertyList(), signingEntitlementsTempPath, /* executable */
        false)).execute(context);
    }
}
Also used : Path(java.nio.file.Path) NSDictionary(com.dd.plist.NSDictionary) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) HumanReadableException(com.facebook.buck.util.HumanReadableException) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Example 5 with NSDictionary

use of com.dd.plist.NSDictionary in project buck by facebook.

the class ProjectGenerator method generateBuildWithBuckTarget.

private void generateBuildWithBuckTarget(TargetNode<?, ?> targetNode) {
    final BuildTarget buildTarget = targetNode.getBuildTarget();
    String buckTargetProductName = getXcodeTargetName(buildTarget) + BUILD_WITH_BUCK_POSTFIX;
    PBXAggregateTarget buildWithBuckTarget = new PBXAggregateTarget(buckTargetProductName);
    buildWithBuckTarget.setProductName(buckTargetProductName);
    PBXShellScriptBuildPhase buildShellScriptBuildPhase = new PBXShellScriptBuildPhase();
    buildShellScriptBuildPhase.setShellScript(getBuildWithBuckShellScript(targetNode));
    buildWithBuckTarget.getBuildPhases().add(buildShellScriptBuildPhase);
    // Only add a shell script for fixing UUIDs if it is an AppleBundle
    if (targetNode.getDescription() instanceof AppleBundleDescription) {
        PBXShellScriptBuildPhase codesignPhase = new PBXShellScriptBuildPhase();
        codesignPhase.setShellScript(getCodesignShellScript(targetNode));
        buildWithBuckTarget.getBuildPhases().add(codesignPhase);
    }
    TargetNode<CxxLibraryDescription.Arg, ?> node = getAppleNativeNode(targetGraph, targetNode).get();
    ImmutableMap<String, ImmutableMap<String, String>> configs = getXcodeBuildConfigurationsForTargetNode(node, ImmutableMap.of()).get();
    XCConfigurationList configurationList = new XCConfigurationList();
    PBXGroup group = project.getMainGroup().getOrCreateDescendantGroupByPath(StreamSupport.stream(buildTarget.getBasePath().spliterator(), false).map(Object::toString).collect(MoreCollectors.toImmutableList())).getOrCreateChildGroupByName(getXcodeTargetName(buildTarget));
    for (String configurationName : configs.keySet()) {
        XCBuildConfiguration configuration = configurationList.getBuildConfigurationsByName().getUnchecked(configurationName);
        configuration.setBaseConfigurationReference(getConfigurationFileReference(group, getConfigurationNameToXcconfigPath(buildTarget).apply(configurationName)));
        NSDictionary inlineSettings = new NSDictionary();
        inlineSettings.put("HEADER_SEARCH_PATHS", "");
        inlineSettings.put("LIBRARY_SEARCH_PATHS", "");
        inlineSettings.put("FRAMEWORK_SEARCH_PATHS", "");
        configuration.setBuildSettings(inlineSettings);
    }
    buildWithBuckTarget.setBuildConfigurationList(configurationList);
    project.getTargets().add(buildWithBuckTarget);
    targetNodeToGeneratedProjectTargetBuilder.put(targetNode, buildWithBuckTarget);
}
Also used : XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) XCConfigurationList(com.facebook.buck.apple.xcode.xcodeproj.XCConfigurationList) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) PBXAggregateTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXAggregateTarget) ImmutableMap(com.google.common.collect.ImmutableMap) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) AppleNativeTargetDescriptionArg(com.facebook.buck.apple.AppleNativeTargetDescriptionArg) StringWithMacrosArg(com.facebook.buck.rules.args.StringWithMacrosArg) AppleWrapperResourceArg(com.facebook.buck.apple.AppleWrapperResourceArg) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription)

Aggregations

NSDictionary (com.dd.plist.NSDictionary)70 NSString (com.dd.plist.NSString)33 NSObject (com.dd.plist.NSObject)22 IOException (java.io.IOException)16 Test (org.junit.Test)15 File (java.io.File)13 NSArray (com.dd.plist.NSArray)12 Path (java.nio.file.Path)11 InputStream (java.io.InputStream)8 NSNumber (com.dd.plist.NSNumber)7 PBXBuildFile (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile)6 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 BufferedInputStream (java.io.BufferedInputStream)6 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)4 NoSuchFileException (java.nio.file.NoSuchFileException)4 PropertyListFormatException (com.dd.plist.PropertyListFormatException)3 ExecutionContext (com.facebook.buck.step.ExecutionContext)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)3