コード例 #1
0
ファイル: ProtoSupport.java プロジェクト: dslomov/bazel
  private ImmutableList<Artifact> generatedOutputArtifacts(FileType newFileType) {
    ImmutableList.Builder<Artifact> builder = new ImmutableList.Builder<>();
    for (Artifact protoFile : getFilteredProtoSources()) {
      String protoFileName = FileSystemUtils.removeExtension(protoFile.getFilename());
      String generatedOutputName;
      if (attributes.outputsCpp()) {
        generatedOutputName = protoFileName;
      } else if (usesProtobufLibrary()) {
        // The protobuf library generates filenames with some slight modifications.
        generatedOutputName = generateProtobufFilename(protoFileName);
      } else {
        String lowerUnderscoreBaseName = protoFileName.replace('-', '_').toLowerCase();
        generatedOutputName = LOWER_UNDERSCORE.to(UPPER_CAMEL, lowerUnderscoreBaseName);
      }

      PathFragment generatedFilePath =
          new PathFragment(
              protoFile.getRootRelativePath().getParentDirectory(),
              new PathFragment(generatedOutputName));

      PathFragment outputFile =
          FileSystemUtils.appendExtension(generatedFilePath, newFileType.getExtensions().get(0));

      if (outputFile != null) {
        builder.add(
            ruleContext.getUniqueDirectoryArtifact(
                UNIQUE_DIRECTORY_NAME, outputFile, ruleContext.getBinOrGenfilesDirectory()));
      }
    }
    return builder.build();
  }
コード例 #2
0
ファイル: ProtoSupport.java プロジェクト: dslomov/bazel
 private ImmutableList<Artifact> getGeneratedSources() {
   return generatedOutputArtifacts(
       FileType.of(
           ".pb"
               + (usesProtobufLibrary() ? "objc" : "")
               + (attributes.outputsCpp() ? ".cc" : ".m")));
 }
コード例 #3
0
ファイル: ProtoSupport.java プロジェクト: dslomov/bazel
  private CustomCommandLine getPb2CommandLine() {
    CustomCommandLine.Builder commandLineBuilder =
        new CustomCommandLine.Builder()
            .add(attributes.getProtoCompiler().getExecPathString())
            .add("--input-file-list")
            .add(getProtoInputListFile().getExecPathString())
            .add("--output-dir")
            .add(getWorkspaceRelativeOutputDir().getSafePathString())
            .add("--working-dir")
            .add(".");

    if (attributes.getOptionsFile() != null) {
      commandLineBuilder
          .add("--compiler-options-path")
          .add(attributes.getOptionsFile().getExecPathString());
    }

    if (attributes.outputsCpp()) {
      commandLineBuilder.add("--generate-cpp");
    }

    if (attributes.usesObjcHeaderNames()) {
      commandLineBuilder.add("--use-objc-header-names");
    }
    return commandLineBuilder.build();
  }
コード例 #4
0
ファイル: ProtoSupport.java プロジェクト: dslomov/bazel
  /**
   * Validates proto support.
   *
   * <ul>
   *   <li>Validates that there are protos specified to be compiled.
   *   <li>Validates that, when enabling the open source protobuf library, the options for the PB2
   *       are not specified also.
   *   <li>Validates that, when enabling the open source protobuf library, the rule specifies at
   *       least one portable proto filter file.
   * </ul>
   *
   * @return this proto support
   */
  public ProtoSupport validate() {
    if (attributes.getProtoFiles().isEmpty()) {
      ruleContext.ruleError(NO_PROTOS_ERROR);
    }

    if (usesProtobufLibrary()) {
      if (attributes.getPortableProtoFilters().isEmpty()) {
        ruleContext.ruleError(PORTABLE_PROTO_FILTERS_EMPTY_ERROR);
      }

      if (attributes.outputsCpp()
          || attributes.usesObjcHeaderNames()
          || attributes.needsPerProtoIncludes()
          || attributes.getOptionsFile() != null) {
        ruleContext.ruleError(PORTABLE_PROTO_FILTERS_NOT_EXCLUSIVE_ERROR);
      }
    }
    return this;
  }