Skip to content

Commit

Permalink
Get rid of custom invocation policy in tests.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 236487741
  • Loading branch information
janakdr authored and copybara-github committed Mar 3, 2019
1 parent 1bc7d14 commit dd1d148
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.common.options.InvocationPolicyEnforcer;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
Expand Down Expand Up @@ -74,11 +73,6 @@ public PackageFactoryBuilderWithSkyframeForTesting getPackageFactoryBuilderForTe
.setExtraSkyFunctions(getSkyFunctions(directories));
}

@Override
public InvocationPolicyEnforcer getInvocationPolicyEnforcer() {
return new InvocationPolicyEnforcer(TestConstants.TEST_INVOCATION_POLICY);
}

/**
* This is called from test setup to create the mock directory layout needed to create the
* configuration.
Expand Down Expand Up @@ -184,11 +178,6 @@ public ConfiguredRuleClassProvider createRuleClassProvider() {
return delegate.createRuleClassProvider();
}

@Override
public InvocationPolicyEnforcer getInvocationPolicyEnforcer() {
return delegate.getInvocationPolicyEnforcer();
}

@Override
public boolean isThisBazel() {
return delegate.isThisBazel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import com.google.devtools.build.lib.vfs.Root;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.common.options.InvocationPolicyEnforcer;
import com.google.devtools.common.options.Options;
import com.google.devtools.common.options.OptionsParser;
import java.util.Arrays;
Expand Down Expand Up @@ -282,13 +281,12 @@ public final void useConfiguration(String... args) throws Exception {
LoadingPhaseThreadsOption.class,
LoadingOptions.class),
ruleClassProvider.getConfigurationOptions()));
optionsParser.parse(new String[] {"--default_visibility=public", "--cpu=k8", "--host_cpu=k8"});
optionsParser.parse("--default_visibility=public", "--cpu=k8", "--host_cpu=k8");
optionsParser.parse(TestConstants.PRODUCT_SPECIFIC_FLAGS);
optionsParser.parse(args);
if (defaultFlags().contains(Flag.TRIMMED_CONFIGURATIONS)) {
optionsParser.parse("--experimental_dynamic_configs=on");
}
InvocationPolicyEnforcer optionsPolicyEnforcer = analysisMock.getInvocationPolicyEnforcer();
optionsPolicyEnforcer.enforce(optionsParser);

buildOptions = ruleClassProvider.createBuildOptions(optionsParser);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@
import com.google.devtools.build.skyframe.ErrorInfo;
import com.google.devtools.build.skyframe.MemoizingEvaluator;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.common.options.InvocationPolicyEnforcer;
import com.google.devtools.common.options.Options;
import com.google.devtools.common.options.OptionsParser;
import com.google.devtools.common.options.OptionsParsingException;
Expand Down Expand Up @@ -365,10 +364,6 @@ protected final BuildConfigurationCollection createConfigurations(
// TODO(juliexxia): when the starlark options parsing work goes in, add type verification here.
optionsParser.setStarlarkOptions(skylarkOptions);

InvocationPolicyEnforcer optionsPolicyEnforcer =
getAnalysisMock().getInvocationPolicyEnforcer();
optionsPolicyEnforcer.enforce(optionsParser);

BuildOptions buildOptions = ruleClassProvider.createBuildOptions(optionsParser);
return skyframeExecutor.createConfigurations(
reporter, buildOptions, ImmutableSet.<String>of(), false);
Expand Down Expand Up @@ -518,14 +513,17 @@ protected void invalidatePackages(boolean alsoConfigs) throws InterruptedExcepti
*/
protected void useConfiguration(ImmutableMap<String, Object> skylarkOptions, String... args)
throws Exception {
String[] actualArgs;
actualArgs = Arrays.copyOf(args, args.length + 1);
actualArgs[args.length] =
"--experimental_dynamic_configs=" + Ascii.toLowerCase(configsMode.toString());
masterConfig = createConfigurations(skylarkOptions, actualArgs);
ImmutableList<String> actualArgs =
ImmutableList.<String>builder()
.addAll(TestConstants.PRODUCT_SPECIFIC_FLAGS)
.add(args)
.add("--experimental_dynamic_configs=" + Ascii.toLowerCase(configsMode.toString()))
.build();

masterConfig = createConfigurations(skylarkOptions, actualArgs.toArray(new String[0]));
targetConfig = getTargetConfiguration();
targetConfigKey = BuildConfigurationValue.key(targetConfig);
configurationArgs = Arrays.asList(actualArgs);
configurationArgs = actualArgs;
createBuildView();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.google.devtools.build.lib.vfs.Root;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.common.options.Converters;
import com.google.devtools.common.options.InvocationPolicyEnforcer;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
Expand Down Expand Up @@ -205,9 +204,7 @@ protected BuildConfigurationCollection createCollection(String... args) throws E
.add(TestOptions.class)
.build());
parser.parse(args);

InvocationPolicyEnforcer optionsPolicyEnforcer = analysisMock.getInvocationPolicyEnforcer();
optionsPolicyEnforcer.enforce(parser);
parser.parse(TestConstants.PRODUCT_SPECIFIC_FLAGS);

ImmutableSortedSet<String> multiCpu = ImmutableSortedSet.copyOf(
parser.getOptions(TestOptions.class).multiCpus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.devtools.build.lib.skyframe.packages.PackageFactoryBuilderWithSkyframeForTesting;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.common.options.InvocationPolicyEnforcer;

/** Create a mock client for the loading phase, as well as a configuration factory. */
public class LoadingMock {
Expand All @@ -39,8 +38,4 @@ public PackageFactoryBuilderWithSkyframeForTesting getPackageFactoryBuilderForTe
public ConfiguredRuleClassProvider createRuleClassProvider() {
return TestRuleClassProvider.getRuleClassProvider();
}

public InvocationPolicyEnforcer getInvocationPolicyEnforcer() {
return new InvocationPolicyEnforcer(TestConstants.TEST_INVOCATION_POLICY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public final void initializeSkyframeExecutor() throws Exception {
TestConstants.processSkyframeExecutorForTesting(skyframeExecutor);
OptionsParser parser =
OptionsParser.newOptionsParser(PackageCacheOptions.class, StarlarkSemanticsOptions.class);
analysisMock.getInvocationPolicyEnforcer().enforce(parser);
setUpSkyframe(
parser.getOptions(PackageCacheOptions.class),
parser.getOptions(StarlarkSemanticsOptions.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Root;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.common.options.InvocationPolicyEnforcer;
import com.google.devtools.common.options.OptionsParser;
import com.google.devtools.common.options.OptionsParsingException;
import java.io.IOException;
Expand Down Expand Up @@ -158,13 +157,6 @@ private OptionsParser parse(String... options) throws Exception {
parser.parse("--default_visibility=public");
parser.parse(options);

InvocationPolicyEnforcer optionsPolicyEnforcer = analysisMock.getInvocationPolicyEnforcer();
try {
optionsPolicyEnforcer.enforce(parser);
} catch (OptionsParsingException e) {
throw new IllegalStateException(e);
}

return parser;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@

package com.google.devtools.build.lib.testutil;

import static com.google.common.collect.ImmutableList.toImmutableList;

import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.Streams;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

/**
* Some static utility functions for testing Blaze code. In contrast to {@link TestUtils}, these
Expand Down Expand Up @@ -97,7 +95,15 @@ public static Label convertLabel(Label label) {
}
}

public static List<Label> convertLabels(Iterable<Label> labels) {
return Streams.stream(labels).map(BlazeTestUtils::convertLabel).collect(toImmutableList());
/**
* Creates a list of arguments to pass to Bazel, with flags necessary for Bazel to work properly
* appended to the original {@code args} array.
*/
public static ArrayList<String> makeArgs(String... args) {
ArrayList<String> result =
new ArrayList<>(args.length + TestConstants.PRODUCT_SPECIFIC_FLAGS.size());
Collections.addAll(result, args);
result.addAll(TestConstants.PRODUCT_SPECIFIC_FLAGS);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ public static void processSkyframeExecutorForTesting(SkyframeExecutor skyframeEx
public static final ImmutableList<String> OSX_CROSSTOOL_FLAGS =
ImmutableList.of();

public static final InvocationPolicy TEST_INVOCATION_POLICY =
InvocationPolicy.getDefaultInstance();
/**
* Flags that must be set for Bazel to work properly, if the default values are unusable for
* some reason.
*/
public static final ImmutableList<String> PRODUCT_SPECIFIC_FLAGS =
ImmutableList.of();

public static final BuilderFactoryForTesting PACKAGE_FACTORY_BUILDER_FACTORY_FOR_TESTING =
PackageFactoryBuilderFactoryForBazelUnitTests.INSTANCE;
Expand Down

0 comments on commit dd1d148

Please sign in to comment.