Search in sources :

Example 36 with RuleConfiguredTargetBuilder

use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.

the class IosTest method create.

/**
   * {@inheritDoc}
   *
   * Creates a target, including registering actions, just as {@link #create(RuleContext)} does.
   * The difference between {@link #create(RuleContext)} and this method is that this method does
   * only what is needed to support tests on the environment besides generate the Xcodeproj file
   * and build the app and test {@code .ipa}s. The {@link #create(RuleContext)} method delegates
   * to this method.
   */
@Override
public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    ProtobufSupport protoSupport = new ProtobufSupport(ruleContext).registerGenerationActions().registerCompilationActions();
    Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider();
    Optional<XcodeProvider> protosXcodeProvider = protoSupport.getXcodeProvider();
    ObjcCommon common = common(ruleContext, protosObjcProvider);
    if (!common.getCompilationArtifacts().get().getArchive().isPresent()) {
        ruleContext.ruleError(REQUIRES_SOURCE_ERROR);
    }
    if (!ruleContext.getFragment(AppleConfiguration.class).getIosMultiCpus().isEmpty()) {
        ruleContext.ruleError(NO_MULTI_CPUS_ERROR);
    }
    XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder().addPropagatedDependencies(protosXcodeProvider.asSet());
    NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
    addResourceFilesToBuild(ruleContext, common.getObjcProvider(), filesToBuild);
    XcodeProductType productType = getProductType(ruleContext);
    ExtraLinkArgs extraLinkArgs;
    Iterable<Artifact> extraLinkInputs;
    String bundleFormat;
    if (!isXcTest(ruleContext)) {
        extraLinkArgs = new ExtraLinkArgs();
        extraLinkInputs = ImmutableList.of();
        bundleFormat = ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT;
    } else {
        xcodeProviderBuilder.setProductType(productType);
        XcodeProvider appIpaXcodeProvider = ruleContext.getPrerequisite(XCTEST_APP_ATTR, Mode.TARGET, XcodeProvider.class);
        if (appIpaXcodeProvider != null) {
            xcodeProviderBuilder.setTestHost(appIpaXcodeProvider);
        }
        XcTestAppProvider testApp = xcTestAppProvider(ruleContext);
        Artifact bundleLoader = testApp.getBundleLoader();
        // -bundle causes this binary to be linked as a bundle and not require an entry point
        // (i.e. main())
        // -bundle_loader causes the code in this test to have access to the symbols in the test rig,
        // or more specifically, the flag causes ld to consider the given binary when checking for
        // missing symbols.
        // -rpath @loader_path/Frameworks allows test bundles to load dylibs from the app's
        // Frameworks directory.
        extraLinkArgs = new ExtraLinkArgs("-bundle", "-bundle_loader", bundleLoader.getExecPathString(), "-Xlinker", "-rpath", "-Xlinker", "@loader_path/Frameworks");
        extraLinkInputs = ImmutableList.of(bundleLoader);
        bundleFormat = ReleaseBundlingSupport.XCTEST_BUNDLE_DIR_FORMAT;
        filesToBuild.add(testApp.getIpa());
    }
    J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider.union(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcMappingFileProvider.class));
    J2ObjcEntryClassProvider j2ObjcEntryClassProvider = new J2ObjcEntryClassProvider.Builder().addTransitive(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcEntryClassProvider.class)).build();
    CompilationSupport.create(ruleContext).registerLinkActions(common.getObjcProvider(), j2ObjcMappingFileProvider, j2ObjcEntryClassProvider, extraLinkArgs, extraLinkInputs, DsymOutputType.TEST).registerCompileAndArchiveActions(common).registerFullyLinkAction(common.getObjcProvider(), ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB)).addXcodeSettings(xcodeProviderBuilder, common).validateAttributes();
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    new ReleaseBundlingSupport(ruleContext, common.getObjcProvider(), LinkedBinary.LOCAL_AND_DEPENDENCIES, bundleFormat, appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS), appleConfiguration.getMultiArchPlatform(PlatformType.IOS)).registerActions(DsymOutputType.TEST).addXcodeSettings(xcodeProviderBuilder).addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.TEST)).validateResources().validateAttributes();
    new ResourceSupport(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder);
    new XcodeSupport(ruleContext).addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), productType).addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)).addDependencies(xcodeProviderBuilder, new Attribute("deps", Mode.TARGET)).addNonPropagatedDependencies(xcodeProviderBuilder, new Attribute("non_propagated_deps", Mode.TARGET)).addFilesToBuild(filesToBuild).registerActions(xcodeProviderBuilder.build());
    XcodeProvider xcodeProvider = xcodeProviderBuilder.build();
    NestedSet<Artifact> filesToBuildSet = filesToBuild.build();
    Runfiles.Builder runfilesBuilder = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES);
    NestedSetBuilder<Artifact> filesToBuildBuilder = NestedSetBuilder.<Artifact>stableOrder().addTransitive(filesToBuildSet);
    InstrumentedFilesProvider instrumentedFilesProvider = CompilationSupport.create(ruleContext).getInstrumentedFilesProvider(common);
    TestSupport testSupport = new TestSupport(ruleContext).registerTestRunnerActions().addRunfiles(runfilesBuilder, instrumentedFilesProvider).addFilesToBuild(filesToBuildBuilder);
    Artifact executable = testSupport.generatedTestScript();
    Runfiles runfiles = runfilesBuilder.build();
    RunfilesSupport runfilesSupport = RunfilesSupport.withExecutable(ruleContext, runfiles, executable);
    ImmutableMap.Builder<String, String> execInfoMapBuilder = new ImmutableMap.Builder<>();
    execInfoMapBuilder.put(ExecutionRequirements.REQUIRES_DARWIN, "");
    if (ruleContext.getFragment(ObjcConfiguration.class).runMemleaks()) {
        execInfoMapBuilder.put("nosandbox", "");
    }
    return new RuleConfiguredTargetBuilder(ruleContext).setFilesToBuild(filesToBuildBuilder.build()).addProvider(xcodeProvider).addProvider(RunfilesProvider.simple(runfiles)).addNativeDeclaredProvider(new ExecutionInfoProvider(execInfoMapBuilder.build())).addNativeDeclaredProviders(testSupport.getExtraProviders()).addProvider(InstrumentedFilesProvider.class, instrumentedFilesProvider).setRunfilesSupport(runfilesSupport, executable).build();
}
Also used : NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) ExecutionInfoProvider(com.google.devtools.build.lib.rules.test.ExecutionInfoProvider) RunfilesSupport(com.google.devtools.build.lib.analysis.RunfilesSupport) ExtraLinkArgs(com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs) InstrumentedFilesProvider(com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) ImmutableMap(com.google.common.collect.ImmutableMap) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)

Example 37 with RuleConfiguredTargetBuilder

use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.

the class JavaRuntime method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    NestedSet<Artifact> filesToBuild = PrerequisiteArtifacts.nestedSet(ruleContext, "srcs", Mode.TARGET);
    NestedSet<Artifact> middleman = CompilationHelper.getAggregatingMiddleman(ruleContext, Actions.escapeLabel(ruleContext.getLabel()), filesToBuild);
    // TODO(cushon): clean up uses of java_runtime in data deps and remove this
    Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName()).addTransitiveArtifacts(filesToBuild).build();
    return new RuleConfiguredTargetBuilder(ruleContext).addProvider(RunfilesProvider.class, RunfilesProvider.simple(runfiles)).setFilesToBuild(filesToBuild).addProvider(JavaRuntimeProvider.class, JavaRuntimeProvider.create(filesToBuild)).addProvider(MiddlemanProvider.class, new MiddlemanProvider(middleman)).build();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) MiddlemanProvider(com.google.devtools.build.lib.analysis.MiddlemanProvider) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 38 with RuleConfiguredTargetBuilder

use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.

the class JavaToolchain method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorException {
    final String source = ruleContext.attributes().get("source_version", Type.STRING);
    final String target = ruleContext.attributes().get("target_version", Type.STRING);
    final NestedSet<Artifact> bootclasspath = getArtifactList("bootclasspath", ruleContext);
    final NestedSet<Artifact> extclasspath = getArtifactList("extclasspath", ruleContext);
    final String encoding = ruleContext.attributes().get("encoding", Type.STRING);
    final List<String> xlint = ruleContext.attributes().get("xlint", Type.STRING_LIST);
    final List<String> misc = ruleContext.getTokenizedStringListAttr("misc");
    final List<String> jvmOpts = ruleContext.attributes().get("jvm_opts", Type.STRING_LIST);
    final boolean javacSupportsWorkers = ruleContext.attributes().get("javac_supports_workers", Type.BOOLEAN);
    Artifact javac = getArtifact("javac", ruleContext);
    Artifact javabuilder = getArtifact("javabuilder", ruleContext);
    Artifact headerCompiler = getArtifact("header_compiler", ruleContext);
    boolean forciblyDisableHeaderCompilation = ruleContext.attributes().get("forcibly_disable_header_compilation", Type.BOOLEAN);
    Artifact singleJar = getArtifact("singlejar", ruleContext);
    Artifact oneVersion = getArtifact("oneversion", ruleContext);
    Artifact oneVersionWhitelist = getArtifact("oneversion_whitelist", ruleContext);
    Artifact genClass = getArtifact("genclass", ruleContext);
    Artifact resourceJarBuilder = getArtifact("resourcejar", ruleContext);
    Artifact timezoneData = getArtifact("timezone_data", ruleContext);
    FilesToRunProvider ijar = ruleContext.getExecutablePrerequisite("ijar", Mode.HOST);
    ImmutableListMultimap<String, String> compatibleJavacOptions = getCompatibleJavacOptions(ruleContext);
    final JavaToolchainData toolchainData = new JavaToolchainData(source, target, Artifact.toExecPaths(bootclasspath), Artifact.toExecPaths(extclasspath), encoding, xlint, misc, jvmOpts, javacSupportsWorkers ? SupportsWorkers.YES : SupportsWorkers.NO);
    final JavaConfiguration configuration = ruleContext.getFragment(JavaConfiguration.class);
    JavaToolchainProvider provider = JavaToolchainProvider.create(ruleContext.getLabel(), toolchainData, bootclasspath, extclasspath, configuration.getDefaultJavacFlags(), javac, javabuilder, headerCompiler, forciblyDisableHeaderCompilation, singleJar, oneVersion, oneVersionWhitelist, genClass, resourceJarBuilder, timezoneData, ijar, compatibleJavacOptions);
    RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext).addSkylarkTransitiveInfo(JavaToolchainSkylarkApiProvider.NAME, new JavaToolchainSkylarkApiProvider()).add(JavaToolchainProvider.class, provider).setFilesToBuild(new NestedSetBuilder<Artifact>(Order.STABLE_ORDER).build()).add(RunfilesProvider.class, RunfilesProvider.simple(Runfiles.EMPTY));
    return builder.build();
}
Also used : FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)

Example 39 with RuleConfiguredTargetBuilder

use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.

the class AppleWatch1Extension method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    ObjcProvider.Builder extensionObjcProviderBuilder = new ObjcProvider.Builder();
    XcodeProvider.Builder applicationXcodeProviderBuilder = new XcodeProvider.Builder();
    XcodeProvider.Builder extensionXcodeProviderBuilder = new XcodeProvider.Builder();
    NestedSetBuilder<Artifact> applicationFilesToBuild = NestedSetBuilder.stableOrder();
    NestedSetBuilder<Artifact> extensionfilesToBuild = NestedSetBuilder.stableOrder();
    // 1. Build watch application bundle.
    createWatchApplicationBundle(ruleContext, applicationXcodeProviderBuilder, applicationFilesToBuild);
    // 2. Build watch extension bundle.
    createWatchExtensionBundle(ruleContext, extensionXcodeProviderBuilder, applicationXcodeProviderBuilder, extensionObjcProviderBuilder, extensionfilesToBuild);
    // 3. Extract the watch application bundle into the extension bundle.
    registerWatchApplicationUnBundlingAction(ruleContext);
    RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, extensionfilesToBuild.build()).addProvider(XcodeProvider.class, extensionXcodeProviderBuilder.build()).addProvider(InstrumentedFilesProvider.class, InstrumentedFilesCollector.forward(ruleContext, "binary"));
    // 4. Exposed {@ObjcProvider} for bundling into final IPA.
    exposeObjcProvider(ruleContext, targetBuilder, extensionObjcProviderBuilder);
    return targetBuilder.build();
}
Also used : NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 40 with RuleConfiguredTargetBuilder

use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.

the class AppleWatch2Extension method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    validateAttributesAndConfiguration(ruleContext);
    ObjcProvider.Builder exposedObjcProviderBuilder = new ObjcProvider.Builder();
    NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
    // 1. Build watch extension bundle.
    createWatchExtensionBundle(ruleContext, filesToBuild, exposedObjcProviderBuilder);
    // 2. Build watch application bundle, which will contain the extension bundle.
    createWatchApplicationBundle(ruleContext, watchExtensionIpaArtifact(ruleContext), filesToBuild);
    RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()).addProvider(InstrumentedFilesProvider.class, InstrumentedFilesCollector.forward(ruleContext, "binary"));
    // 3. Add final watch application artifacts to the ObjcProvider, for bundling the watch
    // application bundle into the final iOS application IPA depending on this rule.
    exposedObjcProviderBuilder.add(MERGE_ZIP, ruleContext.getImplicitOutputArtifact(APP_NAME_IPA));
    WatchUtils.registerActionsToAddWatchSupport(ruleContext, exposedObjcProviderBuilder, WatchOSVersion.OS2);
    exposedObjcProviderBuilder.add(FLAG, HAS_WATCH2_EXTENSION);
    targetBuilder.addProvider(ObjcProvider.class, exposedObjcProviderBuilder.build());
    return targetBuilder.build();
}
Also used : NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)48 Artifact (com.google.devtools.build.lib.actions.Artifact)36 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)21 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)19 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)17 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)11 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)7 AppleConfiguration (com.google.devtools.build.lib.rules.apple.AppleConfiguration)6 CcLinkParamsProvider (com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider)5 ArrayList (java.util.ArrayList)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 FileProvider (com.google.devtools.build.lib.analysis.FileProvider)4 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)4 Label (com.google.devtools.build.lib.cmdline.Label)4 CcLinkParamsStore (com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)3 JavaRuleOutputJarsProvider (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider)3 CompositeRunfilesSupplier (com.google.devtools.build.lib.actions.CompositeRunfilesSupplier)2 CommandHelper (com.google.devtools.build.lib.analysis.CommandHelper)2