Search in sources :

Example 16 with BlazeDirectories

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

the class AnalysisTestCase method createMocks.

@Before
public final void createMocks() throws Exception {
    analysisMock = getAnalysisMock();
    pkgLocator = new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory));
    directories = new BlazeDirectories(outputBase, outputBase, rootDirectory, analysisMock.getProductName());
    workspaceStatusActionFactory = new AnalysisTestUtil.DummyWorkspaceStatusActionFactory(directories);
    mockToolsConfig = new MockToolsConfig(rootDirectory);
    analysisMock.setupMockClient(mockToolsConfig);
    analysisMock.setupMockWorkspaceFiles(directories.getEmbeddedBinariesRoot());
    configurationFactory = analysisMock.createConfigurationFactory();
    useRuleClassProvider(analysisMock.createRuleClassProvider());
}
Also used : PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) MockToolsConfig(com.google.devtools.build.lib.packages.util.MockToolsConfig) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) Before(org.junit.Before)

Example 17 with BlazeDirectories

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

the class TimestampBuilderTestCase method createBuilder.

protected Builder createBuilder(final ActionCache actionCache, final int threadCount, final boolean keepGoing, @Nullable EvaluationProgressReceiver evaluationProgressReceiver) throws Exception {
    AtomicReference<PathPackageLocator> pkgLocator = new AtomicReference<>(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)));
    AtomicReference<TimestampGranularityMonitor> tsgmRef = new AtomicReference<>(tsgm);
    BlazeDirectories directories = new BlazeDirectories(rootDirectory, outputBase, rootDirectory, TestConstants.PRODUCT_NAME);
    ExternalFilesHelper externalFilesHelper = new ExternalFilesHelper(pkgLocator, ExternalFileAction.DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS, directories);
    differencer = new RecordingDifferencer();
    ActionExecutionStatusReporter statusReporter = ActionExecutionStatusReporter.create(new StoredEventHandler());
    final SkyframeActionExecutor skyframeActionExecutor = new SkyframeActionExecutor(eventBusRef, new AtomicReference<>(statusReporter));
    Path actionOutputBase = scratch.dir("/usr/local/google/_blaze_jrluser/FAKEMD5/action_out/");
    skyframeActionExecutor.setActionLogBufferPathGenerator(new ActionLogBufferPathGenerator(actionOutputBase));
    ActionInputFileCache cache = new SingleBuildFileCache(rootDirectory.getPathString(), scratch.getFileSystem());
    skyframeActionExecutor.setFileCache(cache);
    final InMemoryMemoizingEvaluator evaluator = new InMemoryMemoizingEvaluator(ImmutableMap.<SkyFunctionName, SkyFunction>builder().put(SkyFunctions.FILE_STATE, new FileStateFunction(tsgmRef, externalFilesHelper)).put(SkyFunctions.FILE, new FileFunction(pkgLocator)).put(SkyFunctions.ARTIFACT, new ArtifactFunction(Predicates.<PathFragment>alwaysFalse())).put(SkyFunctions.ACTION_EXECUTION, new ActionExecutionFunction(skyframeActionExecutor, tsgmRef)).put(SkyFunctions.PACKAGE, new PackageFunction(null, null, null, null, null, null, null)).put(SkyFunctions.PACKAGE_LOOKUP, new PackageLookupFunction(null, CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD))).put(SkyFunctions.WORKSPACE_AST, new WorkspaceASTFunction(TestRuleClassProvider.getRuleClassProvider())).put(SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction(TestRuleClassProvider.getRuleClassProvider(), TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING.create(TestRuleClassProvider.getRuleClassProvider(), scratch.getFileSystem()), directories)).put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()).put(SkyFunctions.ACTION_TEMPLATE_EXPANSION, new DelegatingActionTemplateExpansionFunction()).build(), differencer, evaluationProgressReceiver);
    final SequentialBuildDriver driver = new SequentialBuildDriver(evaluator);
    PrecomputedValue.BUILD_ID.set(differencer, UUID.randomUUID());
    PrecomputedValue.ACTION_ENV.set(differencer, ImmutableMap.<String, String>of());
    PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
    return new Builder() {

        private void setGeneratingActions() {
            if (evaluator.getExistingValueForTesting(OWNER_KEY) == null) {
                differencer.inject(ImmutableMap.of(OWNER_KEY, new ActionLookupValue(ImmutableList.copyOf(actions))));
            }
        }

        @Override
        public void buildArtifacts(Reporter reporter, Set<Artifact> artifacts, Set<ConfiguredTarget> parallelTests, Set<ConfiguredTarget> exclusiveTests, Collection<ConfiguredTarget> targetsToBuild, Collection<AspectValue> aspects, Executor executor, Set<ConfiguredTarget> builtTargets, boolean explain, Range<Long> lastExecutionTimeRange, TopLevelArtifactContext topLevelArtifactContext) throws BuildFailedException, AbruptExitException, InterruptedException, TestExecException {
            skyframeActionExecutor.prepareForExecution(reporter, executor, keepGoing, /*explain=*/
            false, new ActionCacheChecker(actionCache, null, ALWAYS_EXECUTE_FILTER, null), null);
            List<SkyKey> keys = new ArrayList<>();
            for (Artifact artifact : artifacts) {
                keys.add(ArtifactSkyKey.key(artifact, true));
            }
            setGeneratingActions();
            EvaluationResult<SkyValue> result = driver.evaluate(keys, keepGoing, threadCount, reporter);
            if (result.hasError()) {
                boolean hasCycles = false;
                for (Map.Entry<SkyKey, ErrorInfo> entry : result.errorMap().entrySet()) {
                    Iterable<CycleInfo> cycles = entry.getValue().getCycleInfo();
                    hasCycles |= !Iterables.isEmpty(cycles);
                }
                if (hasCycles) {
                    throw new BuildFailedException(CYCLE_MSG);
                } else if (result.errorMap().isEmpty() || keepGoing) {
                    throw new BuildFailedException();
                } else {
                    SkyframeBuilder.rethrow(Preconditions.checkNotNull(result.getError().getException()));
                }
            }
        }
    };
}
Also used : SkyframeBuilder(com.google.devtools.build.lib.buildtool.SkyframeBuilder) ArrayList(java.util.ArrayList) PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) SequentialBuildDriver(com.google.devtools.build.skyframe.SequentialBuildDriver) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) SkyKey(com.google.devtools.build.skyframe.SkyKey) InMemoryMemoizingEvaluator(com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator) SkyFunction(com.google.devtools.build.skyframe.SkyFunction) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Range(com.google.common.collect.Range) ActionLogBufferPathGenerator(com.google.devtools.build.lib.actions.ActionLogBufferPathGenerator) ActionCacheChecker(com.google.devtools.build.lib.actions.ActionCacheChecker) Collection(java.util.Collection) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) RecordingDifferencer(com.google.devtools.build.skyframe.RecordingDifferencer) ResourceSet(com.google.devtools.build.lib.actions.ResourceSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) CycleInfo(com.google.devtools.build.skyframe.CycleInfo) SkyValue(com.google.devtools.build.skyframe.SkyValue) SkyFunctionName(com.google.devtools.build.skyframe.SkyFunctionName) Executor(com.google.devtools.build.lib.actions.Executor) DummyExecutor(com.google.devtools.build.lib.actions.util.DummyExecutor) ActionExecutionStatusReporter(com.google.devtools.build.lib.actions.ActionExecutionStatusReporter) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor) SingleBuildFileCache(com.google.devtools.build.lib.exec.SingleBuildFileCache) Path(com.google.devtools.build.lib.vfs.Path) Reporter(com.google.devtools.build.lib.events.Reporter) ActionExecutionStatusReporter(com.google.devtools.build.lib.actions.ActionExecutionStatusReporter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Artifact(com.google.devtools.build.lib.actions.Artifact) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) TopLevelArtifactContext(com.google.devtools.build.lib.analysis.TopLevelArtifactContext)

Example 18 with BlazeDirectories

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

the class BlazeExecutorTest method setUpDirectoriesAndTools.

@Before
public final void setUpDirectoriesAndTools() throws Exception {
    InMemoryFileSystem fs = new InMemoryFileSystem();
    directories = new BlazeDirectories(fs.getPath("/install"), fs.getPath("/base"), fs.getPath("/workspace"), "mock-product-name");
    binTools = BinTools.empty(directories);
}
Also used : BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) Before(org.junit.Before)

Example 19 with BlazeDirectories

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

the class BlazeCommandDispatcherRcoptionsTest method initializeRuntime.

@Before
public final void initializeRuntime() throws Exception {
    String productName = TestConstants.PRODUCT_NAME;
    ServerDirectories serverDirectories = new ServerDirectories(scratch.dir("install_base"), scratch.dir("output_base"));
    this.runtime = new BlazeRuntime.Builder().setProductName(productName).setServerDirectories(serverDirectories).setStartupOptionsProvider(OptionsParser.newOptionsParser(BlazeServerStartupOptions.class)).addBlazeModule(new BlazeModule() {

        @Override
        public void initializeRuleClasses(ConfiguredRuleClassProvider.Builder builder) {
            // We must add these options so that the defaults package can be created.
            builder.addConfigurationOptions(BuildConfiguration.Options.class);
            // The defaults package asserts that it is not empty, so we provide options.
            builder.addConfigurationOptions(MockFragmentOptions.class);
            // The tools repository is needed for createGlobals
            builder.setToolsRepository(TestConstants.TOOLS_REPOSITORY);
            builder.setConfigurationCollectionFactory(Mockito.mock(ConfigurationCollectionFactory.class));
        }
    }).build();
    BlazeDirectories directories = new BlazeDirectories(serverDirectories, scratch.dir("pkg"), productName);
    this.runtime.initWorkspace(directories, /*binTools=*/
    null);
}
Also used : ServerDirectories(com.google.devtools.build.lib.analysis.ServerDirectories) FragmentOptions(com.google.devtools.build.lib.analysis.config.FragmentOptions) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) ConfiguredRuleClassProvider(com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider) Before(org.junit.Before)

Example 20 with BlazeDirectories

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

the class StandaloneSpawnStrategyTest method setUp.

@Before
public final void setUp() throws Exception {
    Path testRoot = createTestRoot();
    Path workspaceDir = testRoot.getRelative("workspace-name");
    workspaceDir.createDirectory();
    // setup output base & directories
    Path outputBase = testRoot.getRelative("outputBase");
    outputBase.createDirectory();
    BlazeDirectories directories = new BlazeDirectories(outputBase, outputBase, workspaceDir, "mock-product-name");
    // This call implicitly symlinks the integration bin tools into the exec root.
    IntegrationMock.get().getIntegrationBinTools(directories);
    OptionsParser optionsParser = OptionsParser.newOptionsParser(ExecutionOptions.class);
    optionsParser.parse("--verbose_failures");
    EventBus bus = new EventBus();
    ResourceManager resourceManager = ResourceManager.instanceForTestingOnly();
    resourceManager.setAvailableResources(ResourceSet.create(/*memoryMb=*/
    1, /*cpuUsage=*/
    1, /*ioUsage=*/
    1, /*localTestCount=*/
    1));
    this.executor = new BlazeExecutor(directories.getExecRoot(), reporter, bus, BlazeClock.instance(), optionsParser, ImmutableList.<ActionContext>of(), ImmutableMap.<String, SpawnActionContext>of("", new StandaloneSpawnStrategy(directories.getExecRoot(), false, "mock-product-name", resourceManager)), ImmutableList.<ActionContextProvider>of());
    executor.getExecRoot().createDirectory();
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) BlazeExecutor(com.google.devtools.build.lib.exec.BlazeExecutor) EventBus(com.google.common.eventbus.EventBus) ResourceManager(com.google.devtools.build.lib.actions.ResourceManager) OptionsParser(com.google.devtools.common.options.OptionsParser) ActionContext(com.google.devtools.build.lib.actions.Executor.ActionContext) SpawnActionContext(com.google.devtools.build.lib.actions.SpawnActionContext) SpawnActionContext(com.google.devtools.build.lib.actions.SpawnActionContext) ActionContextProvider(com.google.devtools.build.lib.exec.ActionContextProvider) 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