예제 #1
0
  /**
   * Constructs an {@link ObjcCommon} instance based on the attributes of the given rule. The rule
   * should inherit from {@link ObjcLibraryRule}..
   */
  static ObjcCommon common(
      RuleContext ruleContext,
      Iterable<SdkFramework> extraSdkFrameworks,
      boolean alwayslink,
      ExtraImportLibraries extraImportLibraries,
      Iterable<ObjcProvider> extraDepObjcProviders) {
    CompilationArtifacts compilationArtifacts =
        CompilationSupport.compilationArtifacts(ruleContext);

    return new ObjcCommon.Builder(ruleContext)
        .setCompilationAttributes(new CompilationAttributes(ruleContext))
        .setResourceAttributes(new ResourceAttributes(ruleContext))
        .addExtraSdkFrameworks(extraSdkFrameworks)
        .addDefines(ruleContext.getTokenizedStringListAttr("defines"))
        .setCompilationArtifacts(compilationArtifacts)
        .addDepObjcProviders(ruleContext.getPrerequisites("deps", Mode.TARGET, ObjcProvider.class))
        .addDepObjcProviders(
            ruleContext.getPrerequisites("bundles", Mode.TARGET, ObjcProvider.class))
        .addNonPropagatedDepObjcProviders(
            ruleContext.getPrerequisites("non_propagated_deps", Mode.TARGET, ObjcProvider.class))
        .addDepCcHeaderProviders(
            ruleContext.getPrerequisites("deps", Mode.TARGET, CppCompilationContext.class))
        .addDepCcLinkProviders(
            ruleContext.getPrerequisites("deps", Mode.TARGET, CcLinkParamsProvider.class))
        .setIntermediateArtifacts(ObjcRuleClasses.intermediateArtifacts(ruleContext))
        .setAlwayslink(alwayslink)
        .addExtraImportLibraries(extraImportLibraries)
        .addDepObjcProviders(extraDepObjcProviders)
        .build();
  }
예제 #2
0
파일: IosTest.java 프로젝트: aehlig/bazel
  /** Constructs an {@link ObjcCommon} instance based on the attributes. */
  private ObjcCommon common(RuleContext ruleContext, Optional<ObjcProvider> protosObjcProvider) {
    CompilationArtifacts compilationArtifacts =
        CompilationSupport.compilationArtifacts(ruleContext);

    ObjcCommon.Builder builder =
        new ObjcCommon.Builder(ruleContext)
            .setCompilationAttributes(
                CompilationAttributes.Builder.fromRuleContext(ruleContext).build())
            .setCompilationArtifacts(compilationArtifacts)
            .setResourceAttributes(new ResourceAttributes(ruleContext))
            .addDefines(ruleContext.getTokenizedStringListAttr("defines"))
            .addDeps(ruleContext.getPrerequisites("deps", Mode.TARGET))
            .addRuntimeDeps(ruleContext.getPrerequisites("runtime_deps", Mode.TARGET))
            .addDeps(ruleContext.getPrerequisites("bundles", Mode.TARGET))
            .addDepObjcProviders(protosObjcProvider.asSet())
            .addNonPropagatedDepObjcProviders(
                ruleContext.getPrerequisites(
                    "non_propagated_deps", Mode.TARGET, ObjcProvider.class))
            .setIntermediateArtifacts(ObjcRuleClasses.intermediateArtifacts(ruleContext))
            .setHasModuleMap();

    if (isXcTest(ruleContext)) {
      builder
          .addExtraSdkFrameworks(AUTOMATIC_SDK_FRAMEWORKS_FOR_XCTEST)
          .addDepObjcProviders(ImmutableList.of(xcTestAppProvider(ruleContext).getObjcProvider()));
    }

    // Add the memleaks library if the --ios_memleaks flag is true.  The library pauses the test
    // after all tests have been executed so that leaks can be run.
    ObjcConfiguration config = ruleContext.getFragment(ObjcConfiguration.class);
    if (config.runMemleaks()) {
      builder.addDepObjcProviders(
          ruleContext.getPrerequisites(MEMLEAKS_DEP_ATTR, Mode.TARGET, ObjcProvider.class));
    }

    return builder.build();
  }
예제 #3
0
  /**
   * Packages up the manifest with resources, and generates the R.java.
   *
   * @deprecated in favor of {@link ApplicationManifest#packWithDataAndResources}.
   */
  @Deprecated
  public ResourceApk packWithResources(
      Artifact resourceApk,
      RuleContext ruleContext,
      NestedSet<ResourceContainer> resourceContainers,
      boolean createSource,
      Artifact proguardCfg) {

    TransitiveInfoCollection resourcesPrerequisite =
        ruleContext.getPrerequisite("resources", Mode.TARGET);
    ResourceContainer resourceContainer =
        Iterables.getOnlyElement(
            resourcesPrerequisite
                .getProvider(AndroidResourcesProvider.class)
                .getTransitiveAndroidResources());

    // Dealing with Android library projects
    if (Iterables.size(resourceContainers) > 1) {
      if (resourceContainer.getConstantsInlined()
          && !resourceContainer.getArtifacts(ResourceType.RESOURCES).isEmpty()) {
        ruleContext.ruleError(
            "This android_binary depends on an android_library, so the"
                + " resources '"
                + AndroidCommon.getAndroidResources(ruleContext).getLabel()
                + "' should have the attribute inline_constants set to 0");
        throw new RuleConfigurationException();
      }
    }

    // This binary depends on a library project, so we need to regenerate the
    // resources. The resulting sources and apk will combine all the resources
    // contained in the transitive closure of the binary.
    AndroidAaptActionHelper aaptActionHelper =
        new AndroidAaptActionHelper(
            ruleContext, getManifest(), Lists.newArrayList(resourceContainers));

    List<String> resourceConfigurationFilters =
        ruleContext.getTokenizedStringListAttr("resource_configuration_filters");
    List<String> uncompressedExtensions =
        ruleContext.getTokenizedStringListAttr("nocompress_extensions");

    ImmutableList.Builder<String> additionalAaptOpts = ImmutableList.<String>builder();

    for (String extension : uncompressedExtensions) {
      additionalAaptOpts.add("-0").add(extension);
    }
    if (!resourceConfigurationFilters.isEmpty()) {
      additionalAaptOpts.add("-c").add(Joiner.on(",").join(resourceConfigurationFilters));
    }

    Artifact javaSourcesJar = null;

    if (createSource) {
      javaSourcesJar =
          ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_JAVA_SOURCE_JAR);
      aaptActionHelper.createGenerateResourceSymbolsAction(
          javaSourcesJar, null, resourceContainer.getJavaPackage(), true);
    }

    List<String> densities = ruleContext.getTokenizedStringListAttr("densities");
    aaptActionHelper.createGenerateApkAction(
        resourceApk,
        resourceContainer.getRenameManifestPackage(),
        additionalAaptOpts.build(),
        densities);

    ResourceContainer updatedResources =
        new ResourceContainer(
            ruleContext.getLabel(),
            resourceContainer.getJavaPackage(),
            resourceContainer.getRenameManifestPackage(),
            resourceContainer.getConstantsInlined(),
            resourceApk,
            getManifest(),
            javaSourcesJar,
            resourceContainer.getArtifacts(ResourceType.ASSETS),
            resourceContainer.getArtifacts(ResourceType.RESOURCES),
            resourceContainer.getRoots(ResourceType.ASSETS),
            resourceContainer.getRoots(ResourceType.RESOURCES),
            resourceContainer.isManifestExported(),
            resourceContainer.getRTxt(),
            null);

    aaptActionHelper.createGenerateProguardAction(proguardCfg);

    return new ResourceApk(
        resourceApk,
        updatedResources.getJavaSourceJar(),
        resourceContainers,
        updatedResources,
        manifest,
        proguardCfg,
        true);
  }