// Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.skyframe;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.actions.Action;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
import com.google.devtools.build.lib.analysis.WorkspaceStatusAction;
import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory;
import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory.BuildInfoKey;
import com.google.devtools.build.lib.packages.RuleVisibility;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ConflictException;
import com.google.devtools.build.skyframe.Injectable;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Nullable;
/**
* A value that represents something computed outside of the skyframe framework. These values are
* "precomputed" from skyframe's perspective and so the graph needs to be prepopulated with them
* (e.g. via injection).
*/
public class PrecomputedValue implements SkyValue {
/**
* An externally-injected precomputed value. Exists so that modules can inject precomputed values
* into Skyframe's graph.
*
*
{@see com.google.devtools.build.lib.blaze.BlazeModule#getPrecomputedValues}.
*/
public static final class Injected {
private final Precomputed> precomputed;
private final Supplier extends Object> supplier;
private Injected(Precomputed> precomputed, Supplier extends Object> supplier) {
this.precomputed = precomputed;
this.supplier = supplier;
}
void inject(Injectable injectable) {
injectable.inject(ImmutableMap.of(precomputed.key, new PrecomputedValue(supplier.get())));
}
}
public static Injected injected(Precomputed precomputed, Supplier value) {
return new Injected(precomputed, value);
}
public static Injected injected(Precomputed precomputed, T value) {
return new Injected(precomputed, Suppliers.ofInstance(value));
}
static final Precomputed DEFAULTS_PACKAGE_CONTENTS =
new Precomputed<>(new SkyKey(SkyFunctions.PRECOMPUTED, "default_pkg"));
static final Precomputed DEFAULT_VISIBILITY =
new Precomputed<>(new SkyKey(SkyFunctions.PRECOMPUTED, "default_visibility"));
static final Precomputed BUILD_ID =
new Precomputed<>(new SkyKey(SkyFunctions.PRECOMPUTED, "build_id"));
static final Precomputed WORKSPACE_STATUS_KEY =
new Precomputed<>(new SkyKey(SkyFunctions.PRECOMPUTED, "workspace_status_action"));
static final Precomputed> COVERAGE_REPORT_KEY =
new Precomputed<>(new SkyKey(SkyFunctions.PRECOMPUTED, "coverage_report_actions"));
static final Precomputed TOP_LEVEL_CONTEXT =
new Precomputed<>(new SkyKey(SkyFunctions.PRECOMPUTED, "top_level_context"));
static final Precomputed