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;
}
}
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());
}
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());
}
}
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);
}
}
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);
}
Aggregations