Skip to content

Commit

Permalink
Refactor setupPackageCache to get all BuildConfiguration.Options refe…
Browse files Browse the repository at this point in the history
…rences out of it.

Setting up the package cache is necessary for proper loading. In the future, BuildConfiguration.Option options will be targets that need to be loaded in order to be parsed. Thus, we will need to be able to do loading before BuildConfiguration.Options are parsed.

PiperOrigin-RevId: 206964473
  • Loading branch information
juliexxia authored and Copybara-Service committed Aug 1, 2018
1 parent c3a0878 commit 651797f
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -1090,15 +1089,13 @@ public void preparePackageLoading(
String defaultsPackageContents,
UUID commandId,
Map<String, String> clientEnv,
Map<String, String> actionEnv,
TimestampGranularityMonitor tsgm) {
Preconditions.checkNotNull(pkgLocator);
Preconditions.checkNotNull(tsgm);
setActive(true);

this.tsgm.set(tsgm);
setCommandId(commandId);
PrecomputedValue.ACTION_ENV.set(injectable(), actionEnv);
this.clientEnv.set(clientEnv);
setShowLoadingProgress(packageCacheOptions.showLoadingProgress);
setDefaultVisibility(packageCacheOptions.defaultVisibility);
Expand Down Expand Up @@ -2116,14 +2113,30 @@ public void sync(
TimestampGranularityMonitor tsgm,
OptionsClassProvider options)
throws InterruptedException, AbruptExitException {
// ImmutableMap does not support null values, so use a LinkedHashMap instead.
LinkedHashMap<String, String> actionEnvironment = new LinkedHashMap<>();
BuildConfiguration.Options opt = options.getOptions(BuildConfiguration.Options.class);
if (opt != null) {
for (Map.Entry<String, String> v : opt.actionEnvironment) {
actionEnvironment.put(v.getKey(), v.getValue());
}
}
getActionEnvFromOptions(options);
syncPackageLoading(
eventHandler,
packageCacheOptions,
skylarkSemanticsOptions,
outputBase,
workingDirectory,
defaultsPackageContents,
commandId,
clientEnv,
tsgm);
}

private void syncPackageLoading(
ExtendedEventHandler eventHandler,
PackageCacheOptions packageCacheOptions,
SkylarkSemanticsOptions skylarkSemanticsOptions,
Path outputBase,
Path workingDirectory,
String defaultsPackageContents,
UUID commandId,
Map<String, String> clientEnv,
TimestampGranularityMonitor tsgm)
throws AbruptExitException {
preparePackageLoading(
createPackageLocator(
eventHandler,
Expand All @@ -2136,14 +2149,30 @@ public void sync(
defaultsPackageContents,
commandId,
clientEnv,
Collections.unmodifiableMap(actionEnvironment),
tsgm);
setDeletedPackages(packageCacheOptions.getDeletedPackages());

incrementalBuildMonitor = new SkyframeIncrementalBuildMonitor();
invalidateTransientErrors();
}

private void getActionEnvFromOptions(OptionsClassProvider options) {
// ImmutableMap does not support null values, so use a LinkedHashMap instead.
LinkedHashMap<String, String> actionEnvironment = new LinkedHashMap<>();
BuildConfiguration.Options opt = options.getOptions(BuildConfiguration.Options.class);
if (opt != null) {
for (Map.Entry<String, String> v : opt.actionEnvironment) {
actionEnvironment.put(v.getKey(), v.getValue());
}
}
setActionEnv(actionEnvironment);
}

@VisibleForTesting
public void setActionEnv(Map<String, String> actionEnv) {
PrecomputedValue.ACTION_ENV.set(injectable(), actionEnv);
}

protected PathPackageLocator createPackageLocator(
ExtendedEventHandler eventHandler,
List<String> packagePaths,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ protected void useRuleClassProvider(ConfiguredRuleClassProvider ruleClassProvide
analysisMock.getInvocationPolicyEnforcer().getInvocationPolicy()),
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
skyframeExecutor.injectExtraPrecomputedValues(
ImmutableList.of(
PrecomputedValue.injected(
Expand Down Expand Up @@ -342,8 +342,8 @@ protected AnalysisResult update(
analysisMock.getInvocationPolicyEnforcer().getInvocationPolicy()),
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
skyframeExecutor.invalidateFilesUnderPathForTesting(
reporter, ModifiedFileSet.EVERYTHING_MODIFIED, Root.fromPath(rootDirectory));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ public void initializeSkyframeExecutor(boolean doPackageLoadingChecks) throws Ex
"",
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
tsgm);
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
useConfiguration();
setUpSkyframe();
// Also initializes ResourceManager.
Expand Down Expand Up @@ -404,8 +404,8 @@ private void setUpSkyframe() {
ruleClassProvider.getDefaultsPackageContent(optionsParser),
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
tsgm);
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
skyframeExecutor.setDeletedPackages(ImmutableSet.copyOf(packageCacheOptions.getDeletedPackages()));
skyframeExecutor.injectExtraPrecomputedValues(
ImmutableList.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public final void initializeSkyframeExecutor() throws Exception {
analysisMock.getInvocationPolicyEnforcer().getInvocationPolicy()),
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());

mockToolsConfig = new MockToolsConfig(rootDirectory);
analysisMock.setupMockClient(mockToolsConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ protected void setUpSkyframe(RuleVisibility defaultVisibility, String defaultsPa
defaultsPackageContents,
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
}

private void setUpSkyframe() {
Expand All @@ -174,8 +174,8 @@ private void setUpSkyframe() {
loadingMock.getDefaultsPackageContent(),
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
skyframeExecutor.setDeletedPackages(
ImmutableSet.copyOf(packageCacheOptions.getDeletedPackages()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ private void setUpSkyframe(
analysisMock.getDefaultsPackageContent(),
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(clock));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
skyframeExecutor.setDeletedPackages(
ImmutableSet.copyOf(packageCacheOptions.getDeletedPackages()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ public PackageCacheTester(FileSystem fs, ManualClock clock) throws IOException {
"",
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
}

Path addFile(String fileName, String... content) throws IOException {
Expand Down Expand Up @@ -597,8 +597,8 @@ void sync() throws InterruptedException {
"",
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
skyframeExecutor.invalidateFilesUnderPathForTesting(
new Reporter(new EventBus()), modifiedFileSet, Root.fromPath(workspace));
((SequencedSkyframeExecutor) skyframeExecutor).handleDiffs(new Reporter(new EventBus()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,8 @@ public LoadingPhaseTester() throws IOException {
analysisMock.getDefaultsPackageContent(),
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(clock));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
this.options = Options.getDefaults(LoadingOptions.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ private void setUpSkyframe(
analysisMock.getDefaultsPackageContent(),
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
skyframeExecutor.setDeletedPackages(
ImmutableSet.copyOf(packageCacheOptions.getDeletedPackages()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private void preparePackageLoading(Path... roots) {
"",
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
}

@Override
Expand Down Expand Up @@ -323,8 +323,8 @@ public void testGlobOrderStableWithLegacyAndSkyframeComponents() throws Exceptio
"",
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
tsgm);
getSkyframeExecutor().setActionEnv(ImmutableMap.<String, String>of());
assertSrcs(validPackage(skyKey), "foo", "//foo:a.config", "//foo:b.txt");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public void setUp() throws Exception {
AnalysisMock.get().getDefaultsPackageContent(),
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(null));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
skyframeExecutor.injectExtraPrecomputedValues(
ImmutableList.of(
PrecomputedValue.injected(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ public void testWithNoSubincludes() throws Exception {
loadingMock.getDefaultsPackageContent(),
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
this.visitor = getSkyframeExecutor().pkgLoader();
scratch.file("pkg/BUILD", "sh_library(name = 'x', deps = ['z'])", "sh_library(name = 'z')");
assertLabelsVisited(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ private String getHash(String pkg, String name) throws Exception {
"",
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
SkyKey pkgLookupKey = PackageValue.key(PackageIdentifier.parse("@//" + pkg));
EvaluationResult<PackageValue> result =
SkyframeExecutorTestUtils.evaluate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public final void preparePackageLoading() throws Exception {
"",
UUID.randomUUID(),
ImmutableMap.<String, String>of(),
ImmutableMap.<String, String>of(),
new TimestampGranularityMonitor(BlazeClock.instance()));
skyframeExecutor.setActionEnv(ImmutableMap.<String, String>of());
this.preludeLabelRelativePath =
getRuleClassProvider().getPreludeLabel().toPathFragment().toString();
}
Expand Down

0 comments on commit 651797f

Please sign in to comment.