private static Collection<Artifact> getTargetListAttribute(
     RuleContext ruleContext, String attributeName) {
   return (ruleContext.attributes().has(attributeName, BuildType.LABEL_LIST)
           && ruleContext.getAttributeMode(attributeName) == Mode.TARGET)
       ? ruleContext.getPrerequisiteArtifacts(attributeName, Mode.TARGET).list()
       : ImmutableList.<Artifact>of();
 }
예제 #2
0
 /**
  * Returns the list of proto files that were added directly into the deps attributes. This way
  * of specifying the protos is deprecated, and displays a warning when the target does so.
  */
 private ImmutableList<Artifact> getProtoDepsFiles() {
   PrerequisiteArtifacts prerequisiteArtifacts =
       ruleContext.getPrerequisiteArtifacts("deps", Mode.TARGET);
   ImmutableList<Artifact> protos = prerequisiteArtifacts.filter(FileType.of(".proto")).list();
   if (!protos.isEmpty()) {
     ruleContext.attributeWarning("deps", FILES_DEPRECATED_WARNING);
   }
   return protos;
 }
예제 #3
0
 /** Returns the list of portable proto filters. */
 ImmutableList<Artifact> getPortableProtoFilters() {
   if (ruleContext
       .attributes()
       .has(ObjcProtoLibraryRule.PORTABLE_PROTO_FILTERS_ATTR, LABEL_LIST)) {
     return ruleContext
         .getPrerequisiteArtifacts(ObjcProtoLibraryRule.PORTABLE_PROTO_FILTERS_ATTR, Mode.HOST)
         .list();
   }
   return ImmutableList.of();
 }
  protected void createActions(
      ConfiguredTarget base,
      RuleContext ruleContext,
      Iterable<Artifact> protoSources,
      NestedSet<Artifact> transitiveProtoSources,
      Iterable<Artifact> headerMappingFiles,
      Iterable<Artifact> classMappingFiles,
      J2ObjcSource j2ObjcSource) {
    String genDir = ruleContext.getConfiguration().getGenfilesDirectory().getExecPathString();
    Artifact compiler = ruleContext.getPrerequisiteArtifact("$protoc_darwin", Mode.HOST);
    Artifact j2objcPlugin = ruleContext.getPrerequisiteArtifact("$j2objc_plugin", Mode.HOST);

    ruleContext.registerAction(
        new SpawnAction.Builder()
            .setMnemonic("TranslatingJ2ObjcProtos")
            .addInput(compiler)
            .addInput(j2objcPlugin)
            .addInputs(
                ruleContext.getPrerequisiteArtifacts("$protoc_support_darwin", Mode.HOST).list())
            .addInputs(protoSources)
            .addTransitiveInputs(transitiveProtoSources)
            .addOutputs(j2ObjcSource.getObjcSrcs())
            .addOutputs(j2ObjcSource.getObjcHdrs())
            .addOutputs(headerMappingFiles)
            .addOutputs(classMappingFiles)
            .setExecutable(new PathFragment("/usr/bin/python"))
            .setCommandLine(
                new CustomCommandLine.Builder()
                    .add(compiler.getPath().toString())
                    .add("-w")
                    .add(compiler.getRoot().getPath().toString())
                    .add("--generate-j2objc")
                    .add("--generator-param=file_dir_mapping")
                    .add("--generator-param=generate_class_mappings")
                    .add("--j2objc-plugin=" + j2objcPlugin.getExecPathString())
                    .add("--output-dir=" + genDir)
                    .addExecPaths(protoSources)
                    .build())
            .setExecutionInfo(ImmutableMap.of(ExecutionRequirements.REQUIRES_DARWIN, ""))
            .build(ruleContext));
  }
예제 #5
0
 /** Returns the list of files needed by the proto compiler. */
 ImmutableList<Artifact> getProtoCompilerSupport() {
   return ruleContext
       .getPrerequisiteArtifacts(ObjcRuleClasses.PROTO_COMPILER_SUPPORT_ATTR, Mode.HOST)
       .list();
 }
예제 #6
0
 /** Returns the list of well known type protos. */
 ImmutableList<Artifact> getWellKnownTypeProtos() {
   return ruleContext
       .getPrerequisiteArtifacts(ObjcRuleClasses.PROTOBUF_WELL_KNOWN_TYPES, Mode.HOST)
       .list();
 }