Search in sources :

Example 1 with XcodeprojSerializer

use of com.facebook.buck.apple.xcode.XcodeprojSerializer in project bazel by bazelbuild.

the class XcodeprojGeneration method write.

/**
   * Writes a project to an {@code OutputStream} in the correct encoding.
   */
public static void write(OutputStream out, PBXProject project) throws IOException {
    XcodeprojSerializer ser = new XcodeprojSerializer(new GidGenerator(ImmutableSet.<String>of()), project);
    Writer outWriter = new OutputStreamWriter(out, StandardCharsets.UTF_8);
    // toXMLPropertyList includes an XML encoding specification (UTF-8), which we specify above.
    // Standard Xcodeproj files use the toASCIIPropertyList format, but Xcode will rewrite
    // XML-encoded project files automatically when first opening them. We use XML to prevent
    // encoding issues, since toASCIIPropertyList does not include the UTF-8 encoding comment, and
    // Xcode by default apparently uses MacRoman.
    // This encoding concern is probably why Buck also generates XML project files as well.
    outWriter.write(ser.toPlist().toXMLPropertyList());
    outWriter.flush();
}
Also used : XcodeprojSerializer(com.facebook.buck.apple.xcode.XcodeprojSerializer) OutputStreamWriter(java.io.OutputStreamWriter) NSString(com.dd.plist.NSString) GidGenerator(com.facebook.buck.apple.xcode.GidGenerator) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 2 with XcodeprojSerializer

use of com.facebook.buck.apple.xcode.XcodeprojSerializer in project buck by facebook.

the class ProjectGenerator method writeProjectFile.

/**
   * Create the project bundle structure and write {@code project.pbxproj}.
   */
private Path writeProjectFile(PBXProject project) throws IOException {
    XcodeprojSerializer serializer = new XcodeprojSerializer(new GidGenerator(ImmutableSet.copyOf(gidsToTargetNames.keySet())), project);
    NSDictionary rootObject = serializer.toPlist();
    Path xcodeprojDir = outputDirectory.resolve(projectName + ".xcodeproj");
    projectFilesystem.mkdirs(xcodeprojDir);
    Path serializedProject = xcodeprojDir.resolve("project.pbxproj");
    String contentsToWrite = rootObject.toXMLPropertyList();
    // Before we write any files, check if the file contents have changed.
    if (MoreProjectFilesystems.fileContentsDiffer(new ByteArrayInputStream(contentsToWrite.getBytes(Charsets.UTF_8)), serializedProject, projectFilesystem)) {
        LOG.debug("Regenerating project at %s", serializedProject);
        if (shouldGenerateReadOnlyFiles()) {
            projectFilesystem.writeContentsToPath(contentsToWrite, serializedProject, READ_ONLY_FILE_ATTRIBUTE);
        } else {
            projectFilesystem.writeContentsToPath(contentsToWrite, serializedProject);
        }
    } else {
        LOG.debug("Not regenerating project at %s (contents have not changed)", serializedProject);
    }
    return xcodeprojDir;
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) XcodeprojSerializer(com.facebook.buck.apple.xcode.XcodeprojSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) GidGenerator(com.facebook.buck.apple.xcode.GidGenerator)

Aggregations

NSString (com.dd.plist.NSString)2 GidGenerator (com.facebook.buck.apple.xcode.GidGenerator)2 XcodeprojSerializer (com.facebook.buck.apple.xcode.XcodeprojSerializer)2 NSDictionary (com.dd.plist.NSDictionary)1 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)1 BuildTargetSourcePath (com.facebook.buck.rules.BuildTargetSourcePath)1 PathSourcePath (com.facebook.buck.rules.PathSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Path (java.nio.file.Path)1