public CcLibraryHelper( RuleContext ruleContext, CppSemantics semantics, FeatureConfiguration featureConfiguration) { this.ruleContext = Preconditions.checkNotNull(ruleContext); this.configuration = ruleContext.getConfiguration(); this.semantics = Preconditions.checkNotNull(semantics); this.featureConfiguration = Preconditions.checkNotNull(featureConfiguration); }
private NodeEntry getEntryForValue(SkyKey key) { NodeEntry entry = Preconditions.checkNotNull( graph.getBatch(null, Reason.WALKABLE_GRAPH_VALUE, ImmutableList.of(key)).get(key), key); Preconditions.checkState(entry.isDone(), "%s %s", key, entry); return entry; }
/** * Create a GlobValue wrapping {@code matches}. {@code matches} must have order {@link * Order#STABLE_ORDER}. */ public GlobValue(NestedSet<PathFragment> matches) { this.matches = Preconditions.checkNotNull(matches); Preconditions.checkState( matches.getOrder() == Order.STABLE_ORDER, "Only STABLE_ORDER is supported, but got %s", matches.getOrder()); }
/** * A not type safe constructor for SkylarkNestedSet. It's discouraged to use it unless type * generic safety is guaranteed from the caller side. */ SkylarkNestedSet(SkylarkType contentType, NestedSet<?> set) { // This is here for the sake of FuncallExpression. this.contentType = Preconditions.checkNotNull(contentType, "type cannot be null"); this.set = Preconditions.checkNotNull(set, "set cannot be null"); this.items = null; this.transitiveItems = null; }
private void init() throws InterruptedException { EvaluationResult<SkyValue> result; try (AutoProfiler p = AutoProfiler.logged("evaluation and walkable graph", LOG)) { result = graphFactory.prepareAndGet( universeScope, parserPrefix, loadingPhaseThreads, eventHandler); } graph = result.getWalkableGraph(); SkyKey universeKey = graphFactory.getUniverseKey(universeScope, parserPrefix); universeTargetPatternKeys = PrepareDepsOfPatternsFunction.getTargetPatternKeys( PrepareDepsOfPatternsFunction.getSkyKeys(universeKey, eventHandler)); // The prepareAndGet call above evaluates a single PrepareDepsOfPatterns SkyKey. // We expect to see either a single successfully evaluated value or a cycle in the result. Collection<SkyValue> values = result.values(); if (!values.isEmpty()) { Preconditions.checkState( values.size() == 1, "Universe query \"%s\" returned multiple" + " values unexpectedly (%s values in result)", universeScope, values.size()); Preconditions.checkNotNull(result.get(universeKey), result); } else { // No values in the result, so there must be an error. We expect the error to be a cycle. boolean foundCycle = !Iterables.isEmpty(result.getError().getCycleInfo()); Preconditions.checkState( foundCycle, "Universe query \"%s\" failed with non-cycle error: %s", universeScope, result.getError()); } }
@Nullable private AspectValue createAspect( Environment env, AspectKey key, ConfiguredAspectFactory aspectFactory, RuleConfiguredTarget associatedTarget, Set<ConfigMatchingProvider> configConditions, ListMultimap<Attribute, ConfiguredTarget> directDeps, NestedSetBuilder<Package> transitivePackages) throws AspectFunctionException, InterruptedException { SkyframeBuildView view = buildViewProvider.getSkyframeBuildView(); BuildConfiguration configuration = associatedTarget.getConfiguration(); StoredEventHandler events = new StoredEventHandler(); CachingAnalysisEnvironment analysisEnvironment = view.createAnalysisEnvironment(key, false, events, env, configuration); if (env.valuesMissing()) { return null; } ConfiguredAspect configuredAspect = view.getConfiguredTargetFactory() .createAspect( analysisEnvironment, associatedTarget, aspectFactory, key.getAspect(), directDeps, configConditions, view.getHostConfiguration(associatedTarget.getConfiguration())); events.replayOn(env.getListener()); if (events.hasErrors()) { analysisEnvironment.disable(associatedTarget.getTarget()); throw new AspectFunctionException( new AspectCreationException( "Analysis of target '" + associatedTarget.getLabel() + "' failed; build aborted")); } Preconditions.checkState( !analysisEnvironment.hasErrors(), "Analysis environment hasError() but no errors reported"); if (env.valuesMissing()) { return null; } analysisEnvironment.disable(associatedTarget.getTarget()); Preconditions.checkNotNull(configuredAspect); return new AspectValue( key, associatedTarget.getLabel(), associatedTarget.getTarget().getLocation(), configuredAspect, ImmutableList.copyOf(analysisEnvironment.getRegisteredActions()), transitivePackages.build()); }
IntermediateArtifacts( RuleContext ruleContext, String archiveFileNameSuffix, String outputPrefix, BuildConfiguration buildConfiguration) { this.ruleContext = ruleContext; this.buildConfiguration = buildConfiguration; this.archiveFileNameSuffix = Preconditions.checkNotNull(archiveFileNameSuffix); this.outputPrefix = Preconditions.checkNotNull(outputPrefix); }
/** * Adds multiple compilation prerequisites. * * <p>There are two kinds of "compilation prerequisites": declared header files and pregrepped * headers. */ public Builder addCompilationPrerequisites(Iterable<Artifact> prerequisites) { // LIPO collector must not add compilation prerequisites in order to avoid // the creation of a middleman action. for (Artifact prerequisite : prerequisites) { String basename = prerequisite.getFilename(); Preconditions.checkArgument(!Link.OBJECT_FILETYPES.matches(basename)); Preconditions.checkArgument(!Link.ARCHIVE_LIBRARY_FILETYPES.matches(basename)); Preconditions.checkArgument(!Link.SHARED_LIBRARY_FILETYPES.matches(basename)); } Iterables.addAll(compilationPrerequisites, prerequisites); return this; }
public CppModel(RuleContext ruleContext, CppSemantics semantics) { this.ruleContext = Preconditions.checkNotNull(ruleContext); this.semantics = semantics; configuration = ruleContext.getConfiguration(); cppConfiguration = ruleContext.getFragment(CppConfiguration.class); features = CppHelper.getToolchain(ruleContext).getFeatures(); }
/** * Returns the configurable attribute conditions necessary to evaluate the given configured * target, or null if not all dependencies have yet been SkyFrame-evaluated. */ @Nullable private Set<ConfigMatchingProvider> getConfigurableAttributeConditions( TargetAndConfiguration ctg, Environment env) { if (!(ctg.getTarget() instanceof Rule)) { return ImmutableSet.of(); } Rule rule = (Rule) ctg.getTarget(); RawAttributeMapper mapper = RawAttributeMapper.of(rule); Set<SkyKey> depKeys = new LinkedHashSet<>(); for (Attribute attribute : rule.getAttributes()) { for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) { if (!BuildType.Selector.isReservedLabel(label)) { depKeys.add(ConfiguredTargetValue.key(label, ctg.getConfiguration())); } } } Map<SkyKey, SkyValue> cts = env.getValues(depKeys); if (env.valuesMissing()) { return null; } ImmutableSet.Builder<ConfigMatchingProvider> conditions = ImmutableSet.builder(); for (SkyValue ctValue : cts.values()) { ConfiguredTarget ct = ((ConfiguredTargetValue) ctValue).getConfiguredTarget(); conditions.add(Preconditions.checkNotNull(ct.getProvider(ConfigMatchingProvider.class))); } return conditions.build(); }
@Override public List<Target> getLabelListAttr( QueryExpression caller, Target target, String attrName, String errorMsgPrefix) throws QueryException { Preconditions.checkArgument(target instanceof Rule); List<Target> result = new ArrayList<>(); Rule rule = (Rule) target; AggregatingAttributeMapper attrMap = AggregatingAttributeMapper.of(rule); Type<?> attrType = attrMap.getAttributeType(attrName); if (attrType == null) { // Return an empty list if the attribute isn't defined for this rule. return ImmutableList.of(); } for (Label label : attrMap.getReachableLabels(attrName, false)) { try { result.add(queryEnvironment.getTarget(label)); } catch (TargetNotFoundException e) { queryEnvironment.reportBuildFileError(caller, errorMsgPrefix + e.getMessage()); } } return result; }
private TransitiveLipoInfoProvider collectTransitiveLipoInfo(CcCompilationOutputs outputs) { if (CppHelper.getFdoSupport(ruleContext).getFdoRoot() == null) { return TransitiveLipoInfoProvider.EMPTY; } NestedSetBuilder<IncludeScannable> scannableBuilder = NestedSetBuilder.stableOrder(); // TODO(bazel-team): Only fetch the STL prerequisite in one place. TransitiveInfoCollection stl = ruleContext.getPrerequisite(":stl", Mode.TARGET); if (stl != null) { TransitiveLipoInfoProvider provider = stl.getProvider(TransitiveLipoInfoProvider.class); if (provider != null) { scannableBuilder.addTransitive(provider.getTransitiveIncludeScannables()); } } for (TransitiveLipoInfoProvider dep : AnalysisUtils.getProviders(deps, TransitiveLipoInfoProvider.class)) { scannableBuilder.addTransitive(dep.getTransitiveIncludeScannables()); } for (IncludeScannable scannable : outputs.getLipoScannables()) { Preconditions.checkState(scannable.getIncludeScannerSources().size() == 1); scannableBuilder.add(scannable); } return new TransitiveLipoInfoProvider(scannableBuilder.build()); }
private CppCompilationContext( CommandLineContext commandLineContext, ImmutableSet<Artifact> compilationPrerequisites, NestedSet<PathFragment> declaredIncludeDirs, NestedSet<PathFragment> declaredIncludeWarnDirs, NestedSet<Artifact> declaredIncludeSrcs, NestedSet<Pair<Artifact, Artifact>> pregreppedHdrs, ModuleInfo moduleInfo, ModuleInfo picModuleInfo, NestedSet<Artifact> transitiveModuleMaps, NestedSet<Artifact> directModuleMaps, CppModuleMap cppModuleMap, boolean provideTransitiveModuleMaps, boolean useHeaderModules) { Preconditions.checkNotNull(commandLineContext); this.commandLineContext = commandLineContext; this.declaredIncludeDirs = declaredIncludeDirs; this.declaredIncludeWarnDirs = declaredIncludeWarnDirs; this.declaredIncludeSrcs = declaredIncludeSrcs; this.directModuleMaps = directModuleMaps; this.pregreppedHdrs = pregreppedHdrs; this.moduleInfo = moduleInfo; this.picModuleInfo = picModuleInfo; this.transitiveModuleMaps = transitiveModuleMaps; this.cppModuleMap = cppModuleMap; this.provideTransitiveModuleMaps = provideTransitiveModuleMaps; this.useHeaderModules = useHeaderModules; this.compilationPrerequisites = compilationPrerequisites; }
/** * Merges the context of a dependency into this one by adding the contents of all of its * attributes. */ public Builder mergeDependentContext(CppCompilationContext otherContext) { Preconditions.checkNotNull(otherContext); compilationPrerequisites.addAll(otherContext.getTransitiveCompilationPrerequisites()); includeDirs.addAll(otherContext.getIncludeDirs()); quoteIncludeDirs.addAll(otherContext.getQuoteIncludeDirs()); systemIncludeDirs.addAll(otherContext.getSystemIncludeDirs()); declaredIncludeDirs.addTransitive(otherContext.getDeclaredIncludeDirs()); declaredIncludeWarnDirs.addTransitive(otherContext.getDeclaredIncludeWarnDirs()); declaredIncludeSrcs.addTransitive(otherContext.getDeclaredIncludeSrcs()); pregreppedHdrs.addTransitive(otherContext.getPregreppedHeaders()); moduleInfo.addTransitive(otherContext.moduleInfo); picModuleInfo.addTransitive(otherContext.picModuleInfo); NestedSet<Artifact> othersTransitiveModuleMaps = otherContext.getTransitiveModuleMaps(); NestedSet<Artifact> othersDirectModuleMaps = otherContext.getDirectModuleMaps(); // Forward transitive information. // The other target's transitive module maps do not include its direct module maps, so we // add both. transitiveModuleMaps.addTransitive(othersTransitiveModuleMaps); transitiveModuleMaps.addTransitive(othersDirectModuleMaps); // All module maps of direct dependencies are inputs to the current compile independently of // the build type. if (otherContext.getCppModuleMap() != null) { directModuleMaps.add(otherContext.getCppModuleMap().getArtifact()); } defines.addAll(otherContext.getDefines()); return this; }
/** Exits a scope by restoring state from the current continuation */ void exitScope() { Preconditions.checkNotNull(continuation); lexicalFrame = continuation.lexicalFrame; globalFrame = continuation.globalFrame; knownGlobalVariables = continuation.knownGlobalVariables; isSkylark = continuation.isSkylark; continuation = continuation.continuation; }
/** * Like {@link #lookup(String)}, but instead of throwing an exception in the case where <code> * varname</code> is not defined, <code>defaultValue</code> is returned instead. */ public Object lookup(String varname, Object defaultValue) { Preconditions.checkState(!isSkylark); try { return lookup(varname); } catch (NoSuchVariableException e) { return defaultValue; } }
public XcodeProvider build() { Preconditions.checkState( !testHost.isPresent() || (productType == XcodeProductType.UNIT_TEST), "%s product types cannot have a test host (test host: %s).", productType, testHost); return new XcodeProvider(this); }
/** * Constructs an Environment. This is the main, most basic constructor. * * @param globalFrame a frame for the global Environment * @param dynamicFrame a frame for the dynamic Environment * @param eventHandler an EventHandler for warnings, errors, etc * @param importedExtensions Extension-s from which to import bindings with load() * @param isSkylark true if in Skylark context * @param fileContentHashCode a hash for the source file being evaluated, if any * @param isLoadingPhase true if in loading phase */ private Environment( Frame globalFrame, Frame dynamicFrame, EventHandler eventHandler, Map<String, Extension> importedExtensions, boolean isSkylark, @Nullable String fileContentHashCode, boolean isLoadingPhase) { this.globalFrame = Preconditions.checkNotNull(globalFrame); this.dynamicFrame = Preconditions.checkNotNull(dynamicFrame); Preconditions.checkArgument(globalFrame.mutability().isMutable()); Preconditions.checkArgument(dynamicFrame.mutability().isMutable()); this.eventHandler = eventHandler; this.importedExtensions = importedExtensions; this.isSkylark = isSkylark; this.fileContentHashCode = fileContentHashCode; this.isLoadingPhase = isLoadingPhase; }
/** * Returns just the .params file portion of the command-line as a {@link CommandLine}. * * @throws IllegalStateException if the command-line cannot be split */ CommandLine paramCmdLine() { Preconditions.checkNotNull(paramFile); return new CommandLine() { @Override public Iterable<String> arguments() { return splitCommandline().getSecond(); } }; }
/** Builds the Environment. */ public Environment build() { Preconditions.checkArgument(mutability.isMutable()); if (parent != null) { Preconditions.checkArgument(!parent.mutability().isMutable()); } Frame globalFrame = new Frame(mutability, parent); Frame dynamicFrame = new Frame(mutability, null); if (importedExtensions == null) { importedExtensions = ImmutableMap.of(); } return new Environment( globalFrame, dynamicFrame, eventHandler, importedExtensions, isSkylark, fileContentHashCode, isLoadingPhase); }
@Override public Map<SkyKey, Iterable<SkyKey>> getDirectDeps(Iterable<SkyKey> keys) { Map<SkyKey, NodeEntry> entries = graph.getBatch(null, Reason.WALKABLE_GRAPH_DEPS, keys); Map<SkyKey, Iterable<SkyKey>> result = new HashMap<>(entries.size()); for (Entry<SkyKey, NodeEntry> entry : entries.entrySet()) { Preconditions.checkState(entry.getValue().isDone(), entry); result.put(entry.getKey(), entry.getValue().getDirectDeps()); } return result; }
@Override public void process(Iterable<Target> partialResult) throws QueryException, InterruptedException { Preconditions.checkNotNull(pending, "Reuse of the callback is not allowed"); pending.addAll(uniquifier.unique(partialResult)); if (pending.size() >= batchThreshold) { callback.process(pending); pending = new ArrayList<>(); } }
/** * Adds the given targets as dependencies - this can include explicit dependencies on other rules * (like from a "deps" attribute) and also implicit dependencies on runtime libraries. */ public CcLibraryHelper addDeps(Iterable<? extends TransitiveInfoCollection> deps) { for (TransitiveInfoCollection dep : deps) { Preconditions.checkArgument( dep.getConfiguration() == null || configuration.equalsOrIsSupersetOf(dep.getConfiguration()), "dep " + dep.getLabel() + " has a different config than " + ruleContext.getLabel()); this.deps.add(dep); } return this; }
/** Configure a BaseFunction from a @SkylarkSignature annotation */ public void configure(SkylarkSignature annotation) { Preconditions.checkState(!isConfigured()); // must not be configured yet this.paramDoc = new ArrayList<>(); this.signature = SkylarkSignatureProcessor.getSignature( getName(), annotation, unconfiguredDefaultValues, paramDoc, getEnforcedArgumentTypes()); this.objectType = annotation.objectType().equals(Object.class) ? null : annotation.objectType(); configure(); }
/** * Returns a hash code calculated from the hash code of this Environment and the transitive * closure of other Environments it loads. */ public String getTransitiveContentHashCode() { // Calculate a new hash from the hash of the loaded Extension-s. Fingerprint fingerprint = new Fingerprint(); fingerprint.addString(Preconditions.checkNotNull(fileContentHashCode)); TreeSet<String> importStrings = new TreeSet<>(importedExtensions.keySet()); for (String importString : importStrings) { fingerprint.addString(importedExtensions.get(importString).getTransitiveContentHashCode()); } return fingerprint.hexDigestAndReset(); }
FakeCppCompileAction( ActionOwner owner, ImmutableList<String> features, FeatureConfiguration featureConfiguration, CcToolchainFeatures.Variables variables, Artifact sourceFile, boolean shouldScanIncludes, Label sourceLabel, NestedSet<Artifact> mandatoryInputs, Artifact outputFile, PathFragment tempOutputFile, DotdFile dotdFile, BuildConfiguration configuration, CppConfiguration cppConfiguration, CppCompilationContext context, Class<? extends CppCompileActionContext> actionContext, ImmutableList<String> copts, Predicate<String> nocopts, RuleContext ruleContext) { super( owner, features, featureConfiguration, variables, sourceFile, shouldScanIncludes, sourceLabel, mandatoryInputs, outputFile, dotdFile, null, null, null, configuration, cppConfiguration, // We only allow inclusion of header files explicitly declared in // "srcs", so we only use declaredIncludeSrcs, not declaredIncludeDirs. // (Disallowing use of undeclared headers for cc_fake_binary is needed // because the header files get included in the runfiles for the // cc_fake_binary and for the negative compilation tests that depend on // the cc_fake_binary, and the runfiles must be determined at analysis // time, so they can't depend on the contents of the ".d" file.) CppCompilationContext.disallowUndeclaredHeaders(context), actionContext, copts, nocopts, VOID_SPECIAL_INPUTS_HANDLER, ImmutableList.<IncludeScannable>of(), GUID, ImmutableSet.<String>of(), CppCompileAction.CPP_COMPILE, ruleContext); this.tempOutputFile = Preconditions.checkNotNull(tempOutputFile); }
public SkyQueryEnvironment( boolean keepGoing, boolean strictScope, int loadingPhaseThreads, Predicate<Label> labelFilter, EventHandler eventHandler, Set<Setting> settings, Iterable<QueryFunction> extraFunctions, String parserPrefix, WalkableGraphFactory graphFactory, List<String> universeScope, PathPackageLocator pkgPath) { super(keepGoing, strictScope, labelFilter, eventHandler, settings, extraFunctions); this.loadingPhaseThreads = loadingPhaseThreads; this.graphFactory = graphFactory; this.pkgPath = pkgPath; this.universeScope = Preconditions.checkNotNull(universeScope); this.parserPrefix = parserPrefix; Preconditions.checkState( !universeScope.isEmpty(), "No queries can be performed with an empty universe"); }
private XcodeProvider(Builder builder) { this.label = Preconditions.checkNotNull(builder.label); this.propagatedUserHeaderSearchPaths = builder.propagatedUserHeaderSearchPaths.build(); this.nonPropagatedUserHeaderSearchPaths = builder.nonPropagatedUserHeaderSearchPaths.build(); this.propagatedHeaderSearchPaths = builder.propagatedHeaderSearchPaths.build(); this.nonPropagatedHeaderSearchPaths = builder.nonPropagatedHeaderSearchPaths.build(); this.bundleInfoplist = builder.bundleInfoplist; this.propagatedDependencies = builder.propagatedDependencies.build(); this.nonPropagatedDependencies = builder.nonPropagatedDependencies.build(); this.jreDependencies = builder.jreDependencies.build(); this.xcodeprojBuildSettings = builder.xcodeprojBuildSettings.build(); this.companionTargetXcodeprojBuildSettings = builder.companionTargetXcodeprojBuildSettings.build(); this.copts = builder.copts.build(); this.compilationModeCopts = builder.compilationModeCopts.build(); this.productType = Preconditions.checkNotNull(builder.productType); this.headers = builder.headers.build(); this.compilationArtifacts = builder.compilationArtifacts; this.objcProvider = Preconditions.checkNotNull(builder.objcProvider); this.testHost = Preconditions.checkNotNull(builder.testHost); this.inputsToXcodegen = builder.inputsToXcodegen.build(); this.additionalSources = builder.additionalSources.build(); this.extensions = builder.extensions.build(); this.architecture = Preconditions.checkNotNull(builder.architecture); this.generateCompanionLibTarget = builder.generateCompanionLibTarget; this.configurationDistinguisher = Preconditions.checkNotNull(builder.configurationDistinguisher); }
/** * Invokes the appropriate constructor to create a {@link ConfiguredTarget} instance. * * <p>For use in {@code ConfiguredTargetFunction}. * * <p>Returns null if Skyframe deps are missing or upon certain errors. */ @Nullable ConfiguredTarget createConfiguredTarget( Target target, BuildConfiguration configuration, CachingAnalysisEnvironment analysisEnvironment, ListMultimap<Attribute, ConfiguredTarget> prerequisiteMap, Set<ConfigMatchingProvider> configConditions) throws InterruptedException { Preconditions.checkState( enableAnalysis, "Already in execution phase %s %s", target, configuration); Preconditions.checkNotNull(analysisEnvironment); Preconditions.checkNotNull(target); Preconditions.checkNotNull(prerequisiteMap); return factory.createConfiguredTarget( analysisEnvironment, artifactFactory, target, configuration, getHostConfiguration(configuration), prerequisiteMap, configConditions); }
// The precondition ensures generic type safety @SuppressWarnings("unchecked") public <T> NestedSet<T> getSet(Class<T> type) { // Empty sets don't need have to have a type since they don't have items if (set.isEmpty()) { return (NestedSet<T>) set; } Preconditions.checkArgument( contentType.canBeCastTo(type), String.format( "Expected a set of '%s' but got a set of '%s'", EvalUtils.getDataTypeNameFromClass(type), contentType)); return (NestedSet<T>) set; }