Search in sources :

Example 1 with BlazeDirectories

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);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Label(com.google.devtools.build.lib.cmdline.Label) InputFile(com.google.devtools.build.lib.packages.InputFile) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) Target(com.google.devtools.build.lib.packages.Target) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) Rule(com.google.devtools.build.lib.packages.Rule) CrosstoolConfig(com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig) Nullable(javax.annotation.Nullable)

Example 2 with BlazeDirectories

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);
}
Also used : RecordingDifferencer(com.google.devtools.build.skyframe.RecordingDifferencer) ConfiguredRuleClassProvider(com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider) HashMap(java.util.HashMap) PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) SequentialBuildDriver(com.google.devtools.build.skyframe.SequentialBuildDriver) SkyFunctionName(com.google.devtools.build.skyframe.SkyFunctionName) ImmutableSet(com.google.common.collect.ImmutableSet) SkyFunction(com.google.devtools.build.skyframe.SkyFunction) InMemoryMemoizingEvaluator(com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator) AtomicReference(java.util.concurrent.atomic.AtomicReference) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) AnalysisMock(com.google.devtools.build.lib.analysis.util.AnalysisMock) Before(org.junit.Before)

Example 3 with BlazeDirectories

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);
}
Also used : BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) Before(org.junit.Before)

Example 4 with BlazeDirectories

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());
}
Also used : MockToolsConfig(com.google.devtools.build.lib.packages.util.MockToolsConfig) PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) MapBasedActionGraph(com.google.devtools.build.lib.actions.MapBasedActionGraph) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) PackageFactory(com.google.devtools.build.lib.packages.PackageFactory) MiddlemanFactory(com.google.devtools.build.lib.actions.MiddlemanFactory) ConfigurationFactory(com.google.devtools.build.lib.analysis.config.ConfigurationFactory) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor) SkyValueDirtinessChecker(com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker) Before(org.junit.Before)

Example 5 with BlazeDirectories

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());
}
Also used : BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SkyValueDirtinessChecker(com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker) Before(org.junit.Before)

Aggregations

BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)25 Before (org.junit.Before)16 PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 InMemoryMemoizingEvaluator (com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator)9 RecordingDifferencer (com.google.devtools.build.skyframe.RecordingDifferencer)9 SequentialBuildDriver (com.google.devtools.build.skyframe.SequentialBuildDriver)9 SkyFunction (com.google.devtools.build.skyframe.SkyFunction)9 SkyFunctionName (com.google.devtools.build.skyframe.SkyFunctionName)9 HashMap (java.util.HashMap)8 Path (com.google.devtools.build.lib.vfs.Path)7 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 PackageFactory (com.google.devtools.build.lib.packages.PackageFactory)4 Nullable (javax.annotation.Nullable)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ConfiguredRuleClassProvider (com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider)3 ServerDirectories (com.google.devtools.build.lib.analysis.ServerDirectories)3 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)3 MockToolsConfig (com.google.devtools.build.lib.packages.util.MockToolsConfig)3