Ejemplo n.º 1
0
 @Nullable
 Artifact provisioningProfile() {
   Artifact explicitProvisioningProfile =
       ruleContext.getPrerequisiteArtifact("provisioning_profile", Mode.TARGET);
   if (explicitProvisioningProfile != null) {
     return explicitProvisioningProfile;
   }
   return ruleContext.getPrerequisiteArtifact(":default_provisioning_profile", Mode.TARGET);
 }
Ejemplo n.º 2
0
 /** Returns the SingleJar deploy jar Artifact. */
 private static Artifact getSingleJar(RuleContext ruleContext) {
   Artifact singleJar = JavaToolchainProvider.fromRuleContext(ruleContext).getSingleJar();
   if (singleJar != null) {
     return singleJar;
   }
   return ruleContext.getPrerequisiteArtifact("$singlejar", Mode.HOST);
 }
 private static void validateManifest(RuleContext ruleContext) throws RuleErrorException {
   if (ruleContext.getPrerequisiteArtifact("manifest", Mode.TARGET) == null) {
     ruleContext.attributeError(
         "manifest", "manifest is required when resource_files or assets are defined.");
     throw new RuleErrorException();
   }
 }
Ejemplo n.º 4
0
 /** Returns the options file, or null if it was not specified. */
 @Nullable
 Artifact getOptionsFile() {
   if (ruleContext.attributes().has(ObjcProtoLibraryRule.OPTIONS_FILE_ATTR, LABEL)) {
     return ruleContext.getPrerequisiteArtifact(
         ObjcProtoLibraryRule.OPTIONS_FILE_ATTR, Mode.HOST);
   }
   return null;
 }
Ejemplo n.º 5
0
 private CppModuleMap createCrosstoolModuleMap(RuleContext ruleContext) {
   if (ruleContext.getPrerequisite("module_map", Mode.HOST) == null) {
     return null;
   }
   Artifact moduleMapArtifact = ruleContext.getPrerequisiteArtifact("module_map", Mode.HOST);
   if (moduleMapArtifact == null) {
     return null;
   }
   return new CppModuleMap(moduleMapArtifact, "crosstool");
 }
  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));
  }
Ejemplo n.º 7
0
  private void registerTestScriptSubstitutionAction() throws InterruptedException {
    // testIpa is the app actually containing the tests
    Artifact testIpa = testIpa();

    String runMemleaks =
        ruleContext.getFragment(ObjcConfiguration.class).runMemleaks() ? "true" : "false";

    Map<String, String> testEnv = ruleContext.getConfiguration().getTestEnv();

    // The substitutions below are common for simulator and lab device.
    ImmutableList.Builder<Substitution> substitutions =
        new ImmutableList.Builder<Substitution>()
            .add(Substitution.of("%(memleaks)s", runMemleaks))
            .add(Substitution.of("%(test_app_ipa)s", testIpa.getRootRelativePathString()))
            .add(Substitution.of("%(test_app_name)s", baseNameWithoutIpa(testIpa)))
            .add(
                Substitution.of("%(plugin_jars)s", Artifact.joinRootRelativePaths(":", plugins())));

    substitutions.add(Substitution.ofSpaceSeparatedMap("%(test_env)s", testEnv));

    // xctestIpa is the app bundle being tested
    Optional<Artifact> xctestIpa = xctestIpa();
    if (xctestIpa.isPresent()) {
      substitutions
          .add(Substitution.of("%(xctest_app_ipa)s", xctestIpa.get().getRootRelativePathString()))
          .add(Substitution.of("%(xctest_app_name)s", baseNameWithoutIpa(xctestIpa.get())));
    } else {
      substitutions
          .add(Substitution.of("%(xctest_app_ipa)s", ""))
          .add(Substitution.of("%(xctest_app_name)s", ""));
    }

    Artifact template;
    if (!runWithLabDevice()) {
      substitutions.addAll(substitutionsForSimulator());
      template = ruleContext.getPrerequisiteArtifact("$test_template", Mode.TARGET);
    } else {
      substitutions.addAll(substitutionsForLabDevice());
      template = testTemplateForLabDevice();
    }

    ruleContext.registerAction(
        new TemplateExpansionAction(
            ruleContext.getActionOwner(),
            template,
            generatedTestScript(),
            substitutions.build(),
            /*executable=*/ true));
  }
Ejemplo n.º 8
0
  public static AndroidIdeInfoProvider createAndroidIdeInfoProvider(
      RuleContext ruleContext,
      AndroidSemantics semantics,
      AndroidIdlHelper idlHelper,
      OutputJar resourceJar,
      ResourceApk resourceApk,
      Artifact zipAlignedApk,
      Iterable<Artifact> apksUnderTest) {
    AndroidIdeInfoProvider.Builder ideInfoProviderBuilder =
        new AndroidIdeInfoProvider.Builder()
            .setIdlClassJar(idlHelper.getIdlClassJar())
            .setIdlSourceJar(idlHelper.getIdlSourceJar())
            .setResourceJar(resourceJar)
            .addIdlParcelables(idlHelper.getIdlParcelables())
            .addIdlSrcs(idlHelper.getIdlSources())
            .addIdlGeneratedJavaFiles(idlHelper.getIdlGeneratedJavaSources())
            .addAllApksUnderTest(apksUnderTest);

    if (zipAlignedApk != null) {
      ideInfoProviderBuilder.setApk(zipAlignedApk);
    }

    // If the rule defines resources, put those in the IDE info. Otherwise, proxy the data coming
    // from the android_resources rule in its direct dependencies, if such a thing exists.
    if (LocalResourceContainer.definesAndroidResources(ruleContext.attributes())) {
      ideInfoProviderBuilder
          .setDefinesAndroidResources(true)
          .addResourceSources(resourceApk.getPrimaryResource().getArtifacts(ResourceType.RESOURCES))
          .addAssetSources(
              resourceApk.getPrimaryResource().getArtifacts(ResourceType.ASSETS),
              getAssetDir(ruleContext))
          // Sets the possibly merged manifest and the raw manifest.
          .setGeneratedManifest(resourceApk.getPrimaryResource().getManifest())
          .setManifest(ruleContext.getPrerequisiteArtifact("manifest", Mode.TARGET))
          .setJavaPackage(getJavaPackage(ruleContext));
    } else {
      semantics.addNonLocalResources(ruleContext, resourceApk, ideInfoProviderBuilder);
    }

    return ideInfoProviderBuilder.build();
  }
Ejemplo n.º 9
0
 /** Returns the proto compiler to be used. */
 Artifact getProtoCompiler() {
   return ruleContext.getPrerequisiteArtifact(ObjcRuleClasses.PROTO_COMPILER_ATTR, Mode.HOST);
 }
Ejemplo n.º 10
0
 @Nullable
 Artifact entitlements() {
   return ruleContext.getPrerequisiteArtifact("entitlements", Mode.TARGET);
 }
Ejemplo n.º 11
0
 Artifact iossim() {
   return checkNotNull(ruleContext.getPrerequisiteArtifact("$iossim", Mode.HOST));
 }
Ejemplo n.º 12
0
 Artifact stdRedirectDylib() {
   return checkNotNull(ruleContext.getPrerequisiteArtifact("$std_redirect_dylib", Mode.HOST));
 }
Ejemplo n.º 13
0
 /** Gets the binary of the testrunner attribute, if there is one. */
 private Optional<Artifact> testRunner() {
   return Optional.fromNullable(ruleContext.getPrerequisiteArtifact("$test_runner", Mode.TARGET));
 }
Ejemplo n.º 14
0
 private Artifact stdRedirectDylib() {
   return ruleContext.getPrerequisiteArtifact("$std_redirect_dylib", Mode.HOST);
 }
Ejemplo n.º 15
0
 private Artifact iossim() {
   return ruleContext.getPrerequisiteArtifact("$iossim", Mode.HOST);
 }
Ejemplo n.º 16
0
 Artifact runnerScriptTemplate() {
   return checkNotNull(
       ruleContext.getPrerequisiteArtifact("$runner_script_template", Mode.HOST));
 }
Ejemplo n.º 17
0
 /**
  * Adds a dummy source file to the Xcode target. This is needed if the target does not have any
  * source files but Xcode requires one.
  *
  * @return this xcode support
  */
 XcodeSupport addDummySource(XcodeProvider.Builder xcodeProviderBuilder) {
   xcodeProviderBuilder.addAdditionalSources(
       ruleContext.getPrerequisiteArtifact("$dummy_source", Mode.TARGET));
   return this;
 }
Ejemplo n.º 18
0
 public static ApplicationManifest fromRule(RuleContext ruleContext) {
   return new ApplicationManifest(ruleContext.getPrerequisiteArtifact("manifest", Mode.TARGET));
 }
Ejemplo n.º 19
0
  @Override
  public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException {
    ImmutableList<Artifact> srcJars = ImmutableList.of();
    ImmutableList<Artifact> jars = collectJars(ruleContext);
    Artifact srcJar = ruleContext.getPrerequisiteArtifact("srcjar", Mode.TARGET);

    if (ruleContext.hasErrors()) {
      return null;
    }

    ImmutableList<TransitiveInfoCollection> targets =
        ImmutableList.<TransitiveInfoCollection>builder()
            .addAll(ruleContext.getPrerequisites("deps", Mode.TARGET))
            .addAll(ruleContext.getPrerequisites("exports", Mode.TARGET))
            .build();
    final JavaCommon common = new JavaCommon(ruleContext, semantics, targets, targets, targets);
    semantics.checkRule(ruleContext, common);

    // No need for javac options - no compilation happening here.
    JavaCompilationHelper helper =
        new JavaCompilationHelper(
            ruleContext,
            semantics,
            ImmutableList.<String>of(),
            new JavaTargetAttributes.Builder(semantics));
    ImmutableMap.Builder<Artifact, Artifact> compilationToRuntimeJarMap = ImmutableMap.builder();
    ImmutableList<Artifact> interfaceJars =
        processWithIjar(jars, helper, compilationToRuntimeJarMap);

    common.setJavaCompilationArtifacts(collectJavaArtifacts(jars, interfaceJars));

    CppCompilationContext transitiveCppDeps = common.collectTransitiveCppDeps();
    NestedSet<LinkerInput> transitiveJavaNativeLibraries =
        common.collectTransitiveJavaNativeLibraries();
    boolean neverLink = JavaCommon.isNeverLink(ruleContext);
    JavaCompilationArgs javaCompilationArgs =
        common.collectJavaCompilationArgs(false, neverLink, compilationArgsFromSources());
    JavaCompilationArgs recursiveJavaCompilationArgs =
        common.collectJavaCompilationArgs(true, neverLink, compilationArgsFromSources());
    NestedSet<Artifact> transitiveJavaSourceJars =
        collectTransitiveJavaSourceJars(ruleContext, srcJar);
    if (srcJar != null) {
      srcJars = ImmutableList.of(srcJar);
    }

    // The "neverlink" attribute is transitive, so if it is enabled, we don't add any
    // runfiles from this target or its dependencies.
    Runfiles runfiles =
        neverLink
            ? Runfiles.EMPTY
            : new Runfiles.Builder(ruleContext.getWorkspaceName())
                // add the jars to the runfiles
                .addArtifacts(common.getJavaCompilationArtifacts().getRuntimeJars())
                .addTargets(targets, RunfilesProvider.DEFAULT_RUNFILES)
                .addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES)
                .addTargets(targets, JavaRunfilesProvider.TO_RUNFILES)
                .add(ruleContext, JavaRunfilesProvider.TO_RUNFILES)
                .build();

    CcLinkParamsStore ccLinkParamsStore =
        new CcLinkParamsStore() {
          @Override
          protected void collect(
              CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
            builder.addTransitiveTargets(
                common.targetsTreatedAsDeps(ClasspathType.BOTH),
                JavaCcLinkParamsProvider.TO_LINK_PARAMS,
                CcLinkParamsProvider.TO_LINK_PARAMS);
          }
        };
    RuleConfiguredTargetBuilder ruleBuilder = new RuleConfiguredTargetBuilder(ruleContext);
    NestedSetBuilder<Artifact> filesBuilder = NestedSetBuilder.stableOrder();
    filesBuilder.addAll(jars);

    semantics.addProviders(
        ruleContext,
        common,
        ImmutableList.<String>of(),
        null /* classJar */,
        srcJar /* srcJar */,
        null /* genJar */,
        null /* gensrcJar */,
        compilationToRuntimeJarMap.build(),
        helper,
        filesBuilder,
        ruleBuilder);

    NestedSet<Artifact> filesToBuild = filesBuilder.build();

    JavaSourceInfoProvider javaSourceInfoProvider =
        new JavaSourceInfoProvider.Builder()
            .setJarFiles(jars)
            .setSourceJarsForJarFiles(srcJars)
            .build();

    NestedSet<Artifact> proguardSpecs = new ProguardLibrary(ruleContext).collectProguardSpecs();

    common.addTransitiveInfoProviders(ruleBuilder, filesToBuild, null);
    return ruleBuilder
        .setFilesToBuild(filesToBuild)
        .add(
            JavaRuntimeJarProvider.class,
            new JavaRuntimeJarProvider(common.getJavaCompilationArtifacts().getRuntimeJars()))
        .addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, new JavaSkylarkApiProvider())
        .add(JavaNeverlinkInfoProvider.class, new JavaNeverlinkInfoProvider(neverLink))
        .add(RunfilesProvider.class, RunfilesProvider.simple(runfiles))
        .add(CcLinkParamsProvider.class, new CcLinkParamsProvider(ccLinkParamsStore))
        .add(
            JavaCompilationArgsProvider.class,
            new JavaCompilationArgsProvider(javaCompilationArgs, recursiveJavaCompilationArgs))
        .add(
            JavaNativeLibraryProvider.class,
            new JavaNativeLibraryProvider(transitiveJavaNativeLibraries))
        .add(CppCompilationContext.class, transitiveCppDeps)
        .add(JavaSourceInfoProvider.class, javaSourceInfoProvider)
        .add(
            JavaSourceJarsProvider.class,
            new JavaSourceJarsProvider(transitiveJavaSourceJars, srcJars))
        .add(ProguardSpecProvider.class, new ProguardSpecProvider(proguardSpecs))
        .addOutputGroup(JavaSemantics.SOURCE_JARS_OUTPUT_GROUP, transitiveJavaSourceJars)
        .addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL, proguardSpecs)
        .build();
  }
Ejemplo n.º 20
0
 /** Returns the location of the environment_plist.sh. */
 public Artifact environmentPlistScript() {
   return checkNotNull(ruleContext.getPrerequisiteArtifact("$environment_plist_sh", Mode.HOST));
 }
Ejemplo n.º 21
0
 /**
  * Returns the location of the realpath tool. TODO(dmaclach): Should not be required once
  * https://github.com/google/bazel/issues/285 is fixed.
  */
 Artifact realpath() {
   return ruleContext.getPrerequisiteArtifact("$realpath", Mode.HOST);
 }
Ejemplo n.º 22
0
 /**
  * A dummy .c file to be included in xcode projects. This is needed if the target does not have
  * any source files but Xcode requires one.
  */
 public Artifact dummySource() {
   return scopedArtifact(
       ruleContext.getPrerequisiteArtifact("$dummy_source", Mode.TARGET).getRootRelativePath());
 }
Ejemplo n.º 23
0
 @Nullable
 Artifact launchStoryboard() {
   return ruleContext.getPrerequisiteArtifact("launch_storyboard", Mode.TARGET);
 }