use of com.google.devtools.build.lib.analysis.BlazeDirectories in project bazel by bazelbuild.
the class CppConfigurationLoader method createParameters.
@Nullable
protected CppConfigurationParameters createParameters(ConfigurationEnvironment env, BuildOptions options) throws InvalidConfigurationException, InterruptedException {
BlazeDirectories directories = env.getBlazeDirectories();
if (directories == null) {
return null;
}
Label crosstoolTopLabel = RedirectChaser.followRedirects(env, options.get(CppOptions.class).crosstoolTop, "crosstool_top");
if (crosstoolTopLabel == null) {
return null;
}
CrosstoolConfigurationLoader.CrosstoolFile file = CrosstoolConfigurationLoader.readCrosstool(env, crosstoolTopLabel);
if (file == null) {
return null;
}
CrosstoolConfig.CToolchain toolchain = CrosstoolConfigurationLoader.selectToolchain(file.getProto(), options, cpuTransformer);
// FDO
// TODO(bazel-team): move this to CppConfiguration.prepareHook
CppOptions cppOptions = options.get(CppOptions.class);
Path fdoZip;
if (cppOptions.fdoOptimize == null) {
fdoZip = null;
} else if (cppOptions.fdoOptimize.startsWith("//")) {
try {
Target target = env.getTarget(Label.parseAbsolute(cppOptions.fdoOptimize));
if (target == null) {
return null;
}
if (!(target instanceof InputFile)) {
throw new InvalidConfigurationException("--fdo_optimize cannot accept targets that do not refer to input files");
}
fdoZip = env.getPath(target.getPackage(), target.getName());
if (fdoZip == null) {
throw new InvalidConfigurationException("The --fdo_optimize parameter you specified resolves to a file that does not exist");
}
} catch (NoSuchPackageException | NoSuchTargetException | LabelSyntaxException e) {
env.getEventHandler().handle(Event.error(e.getMessage()));
throw new InvalidConfigurationException(e);
}
} else {
fdoZip = directories.getWorkspace().getRelative(cppOptions.fdoOptimize);
try {
// We don't check for file existence, but at least the filename should be well-formed.
FileSystemUtils.checkBaseName(fdoZip.getBaseName());
} catch (IllegalArgumentException e) {
throw new InvalidConfigurationException(e);
}
}
Label ccToolchainLabel;
Target crosstoolTop;
try {
crosstoolTop = env.getTarget(crosstoolTopLabel);
} catch (NoSuchThingException e) {
// Should have been found out during redirect chasing
throw new IllegalStateException(e);
}
if (crosstoolTop instanceof Rule && ((Rule) crosstoolTop).getRuleClass().equals("cc_toolchain_suite")) {
Rule ccToolchainSuite = (Rule) crosstoolTop;
ccToolchainLabel = NonconfigurableAttributeMapper.of(ccToolchainSuite).get("toolchains", BuildType.LABEL_DICT_UNARY).get(toolchain.getTargetCpu() + "|" + toolchain.getCompiler());
if (ccToolchainLabel == null) {
throw new InvalidConfigurationException(String.format("cc_toolchain_suite '%s' does not contain a toolchain for CPU '%s' and compiler '%s'", crosstoolTopLabel, toolchain.getTargetCpu(), toolchain.getCompiler()));
}
} else {
throw new InvalidConfigurationException(String.format("The specified --crosstool_top '%s' is not a valid cc_toolchain_suite rule", crosstoolTopLabel));
}
Target ccToolchain;
try {
ccToolchain = env.getTarget(ccToolchainLabel);
if (ccToolchain == null) {
return null;
}
} catch (NoSuchThingException e) {
throw new InvalidConfigurationException(String.format("The toolchain rule '%s' does not exist", ccToolchainLabel));
}
if (!(ccToolchain instanceof Rule) || !CcToolchainRule.isCcToolchain(ccToolchain)) {
throw new InvalidConfigurationException(String.format("The label '%s' is not a cc_toolchain rule", ccToolchainLabel));
}
return new CppConfigurationParameters(toolchain, file.getMd5(), options, fdoZip, crosstoolTopLabel, ccToolchainLabel);
}
use of com.google.devtools.build.lib.analysis.BlazeDirectories in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method setUp.
@Before
public final void setUp() throws Exception {
AnalysisMock analysisMock = AnalysisMock.get();
pkgLocator = new AtomicReference<>(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)));
AtomicReference<ImmutableSet<PackageIdentifier>> deletedPackages = new AtomicReference<>(ImmutableSet.<PackageIdentifier>of());
BlazeDirectories directories = new BlazeDirectories(rootDirectory, outputBase, rootDirectory, analysisMock.getProductName());
ExternalFilesHelper externalFilesHelper = new ExternalFilesHelper(pkgLocator, ExternalFileAction.DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS, directories);
ConfiguredRuleClassProvider ruleClassProvider = analysisMock.createRuleClassProvider();
Map<SkyFunctionName, SkyFunction> skyFunctions = new HashMap<>();
skyFunctions.put(SkyFunctions.FILE_STATE, new FileStateFunction(new AtomicReference<TimestampGranularityMonitor>(), externalFilesHelper));
skyFunctions.put(SkyFunctions.FILE, new FileFunction(pkgLocator));
skyFunctions.put(SkyFunctions.DIRECTORY_LISTING, new DirectoryListingFunction());
skyFunctions.put(SkyFunctions.DIRECTORY_LISTING_STATE, new DirectoryListingStateFunction(externalFilesHelper));
skyFunctions.put(SkyFunctions.RECURSIVE_FILESYSTEM_TRAVERSAL, new RecursiveFilesystemTraversalFunction());
skyFunctions.put(SkyFunctions.PACKAGE_LOOKUP, new PackageLookupFunction(deletedPackages, CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD)));
skyFunctions.put(SkyFunctions.BLACKLISTED_PACKAGE_PREFIXES, new BlacklistedPackagePrefixesFunction());
skyFunctions.put(SkyFunctions.PACKAGE, new PackageFunction(null, null, null, null, null, null, null));
skyFunctions.put(SkyFunctions.WORKSPACE_AST, new WorkspaceASTFunction(ruleClassProvider));
skyFunctions.put(SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction(ruleClassProvider, analysisMock.getPackageFactoryForTesting().create(ruleClassProvider, scratch.getFileSystem()), directories));
skyFunctions.put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction());
skyFunctions.put(SkyFunctions.LOCAL_REPOSITORY_LOOKUP, new LocalRepositoryLookupFunction());
progressReceiver = new RecordingEvaluationProgressReceiver();
differencer = new RecordingDifferencer();
evaluator = new InMemoryMemoizingEvaluator(skyFunctions, differencer, progressReceiver);
driver = new SequentialBuildDriver(evaluator);
PrecomputedValue.BUILD_ID.set(differencer, UUID.randomUUID());
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
PrecomputedValue.BLACKLISTED_PACKAGE_PREFIXES_FILE.set(differencer, PathFragment.EMPTY_FRAGMENT);
}
use of com.google.devtools.build.lib.analysis.BlazeDirectories in project bazel by bazelbuild.
the class TemplateExpansionActionTest method createDirectoriesAndTools.
@Before
public final void createDirectoriesAndTools() throws Exception {
createArtifacts(TEMPLATE);
substitutions = Lists.newArrayList();
substitutions.add(Substitution.of("%key%", "foo"));
substitutions.add(Substitution.of("%value%", "bar"));
directories = new BlazeDirectories(scratch.resolve("/install"), scratch.resolve("/base"), scratch.resolve("/workspace"), "mock-product-name");
binTools = BinTools.empty(directories);
}
use of com.google.devtools.build.lib.analysis.BlazeDirectories in project bazel by bazelbuild.
the class BuildViewTestCase method initializeSkyframeExecutor.
@Before
public final void initializeSkyframeExecutor() throws Exception {
analysisMock = getAnalysisMock();
directories = new BlazeDirectories(outputBase, outputBase, rootDirectory, analysisMock.getProductName());
binTools = BinTools.forUnitTesting(directories, analysisMock.getEmbeddedTools());
mockToolsConfig = new MockToolsConfig(rootDirectory, false);
analysisMock.setupMockClient(mockToolsConfig);
analysisMock.setupMockWorkspaceFiles(directories.getEmbeddedBinariesRoot());
packageCacheOptions = parsePackageCacheOptions();
workspaceStatusActionFactory = new AnalysisTestUtil.DummyWorkspaceStatusActionFactory(directories);
mutableActionGraph = new MapBasedActionGraph();
ruleClassProvider = getRuleClassProvider();
configurationFactory = analysisMock.createConfigurationFactory(ruleClassProvider.getConfigurationFragments());
pkgFactory = analysisMock.getPackageFactoryForTesting().create(ruleClassProvider, getPlatformSetRegexps(), getEnvironmentExtensions(), scratch.getFileSystem());
tsgm = new TimestampGranularityMonitor(BlazeClock.instance());
skyframeExecutor = SequencedSkyframeExecutor.create(pkgFactory, directories, binTools, workspaceStatusActionFactory, ruleClassProvider.getBuildInfoFactories(), ImmutableList.<DiffAwareness.Factory>of(), Predicates.<PathFragment>alwaysFalse(), getPreprocessorFactorySupplier(), analysisMock.getSkyFunctions(), getPrecomputedValues(), ImmutableList.<SkyValueDirtinessChecker>of(), analysisMock.getProductName(), CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD));
packageCacheOptions.defaultVisibility = ConstantRuleVisibility.PUBLIC;
packageCacheOptions.showLoadingProgress = true;
packageCacheOptions.globbingThreads = 7;
skyframeExecutor.preparePackageLoading(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)), packageCacheOptions, "", UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), tsgm);
useConfiguration();
setUpSkyframe();
// Also initializes ResourceManager.
ResourceManager.instance().setAvailableResources(getStartingResources());
}
use of com.google.devtools.build.lib.analysis.BlazeDirectories in project bazel by bazelbuild.
the class PackageCacheTest method initializeSkyframeExecutor.
@Before
public final void initializeSkyframeExecutor() throws Exception {
analysisMock = AnalysisMock.get();
ruleClassProvider = analysisMock.createRuleClassProvider();
BlazeDirectories directories = new BlazeDirectories(outputBase, outputBase, rootDirectory, analysisMock.getProductName());
skyframeExecutor = SequencedSkyframeExecutor.create(analysisMock.getPackageFactoryForTesting().create(ruleClassProvider, scratch.getFileSystem()), directories, null, /* BinTools */
null, /* workspaceStatusActionFactory */
ruleClassProvider.getBuildInfoFactories(), ImmutableList.<DiffAwareness.Factory>of(), Predicates.<PathFragment>alwaysFalse(), Preprocessor.Factory.Supplier.NullSupplier.INSTANCE, AnalysisMock.get().getSkyFunctions(), ImmutableList.<PrecomputedValue.Injected>of(), ImmutableList.<SkyValueDirtinessChecker>of(), analysisMock.getProductName(), CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD));
setUpSkyframe(parsePackageCacheOptions());
}
Aggregations