Search in sources :

Example 1 with Control

use of com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.Control in project bazel by bazelbuild.

the class XcodeGen method main.

public static void main(String[] args) throws IOException, OptionsParsingException {
    OptionsParser parser = OptionsParser.newOptionsParser(XcodeGenOptions.class);
    parser.parse(args);
    XcodeGenOptions options = parser.getOptions(XcodeGenOptions.class);
    if (options.control == null) {
        throw new IllegalArgumentException("--control must be specified\n" + Options.getUsage(XcodeGenOptions.class));
    }
    FileSystem fileSystem = FileSystems.getDefault();
    Control controlPb;
    try (InputStream in = Files.newInputStream(fileSystem.getPath(options.control))) {
        controlPb = Control.parseFrom(in);
    }
    Path pbxprojPath = fileSystem.getPath(controlPb.getPbxproj());
    Iterator<String> srcList = allSourceFilePaths(controlPb).iterator();
    Path workspaceRoot;
    // TODO(bazel-team): Remove this if-else clause once Bazel passes in the workspace root.
    if (controlPb.hasWorkspaceRoot()) {
        workspaceRoot = fileSystem.getPath(controlPb.getWorkspaceRoot());
    } else if (!srcList.hasNext()) {
        workspaceRoot = XcodeprojGeneration.relativeWorkspaceRoot(pbxprojPath);
    } else {
        // Get the absolute path to the workspace root.
        // TODO(bazel-team): Remove this hack, possibly by converting Xcodegen to be run with
        // "bazel run" and using RUNFILES to get the workspace root. For now, this is needed to work
        // around Xcode's handling of symlinks not playing nicely with how Bazel stores output
        // artifacts in /private/var/tmp. This means a relative path from .xcodeproj in bazel-out to
        // the workspace root in .xcodeproj will not work properly at certain times during
        // Xcode/xcodebuild execution. Walking up the path of a known source file prevents having
        // to reason about a file that might only be accessible through a symlink, like a tools jar.
        Path relSourceFilePath = fileSystem.getPath(srcList.next());
        Path absSourceFilePath = relSourceFilePath.toAbsolutePath();
        workspaceRoot = absSourceFilePath;
        for (int i = 0; i < relSourceFilePath.getNameCount(); i++) {
            workspaceRoot = workspaceRoot.getParent();
        }
    }
    try (OutputStream out = Files.newOutputStream(pbxprojPath)) {
        // This workspace root here is relative to the PWD, so that the .xccurrentversion
        // files can actually be read. The other workspaceRoot is relative to the .xcodeproj
        // root or is absolute.
        Path relativeWorkspaceRoot = fileSystem.getPath(".");
        PBXProject project = XcodeprojGeneration.xcodeproj(workspaceRoot, controlPb, ImmutableList.of(new CurrentVersionSetter(relativeWorkspaceRoot), new PbxReferencesGrouper(fileSystem)));
        XcodeprojGeneration.write(out, project);
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) OptionsParser(com.google.devtools.common.options.OptionsParser) Control(com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.Control) TargetControl(com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.TargetControl) FileSystem(java.nio.file.FileSystem) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject)

Aggregations

PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)1 Control (com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.Control)1 TargetControl (com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.TargetControl)1 OptionsParser (com.google.devtools.common.options.OptionsParser)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 FileSystem (java.nio.file.FileSystem)1 Path (java.nio.file.Path)1