Skip to content

Commit

Permalink
Adds codecs for types in test classes, ConfigSettingTest, LateBoundSp…
Browse files Browse the repository at this point in the history
…litUtil and fixes codec in

RunUnderConverter.

PiperOrigin-RevId: 183003383
  • Loading branch information
aoeui authored and Copybara-Service committed Jan 23, 2018
1 parent f8af7ae commit 344b08c
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.analysis.config;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.shell.ShellUtils;
Expand Down Expand Up @@ -41,15 +42,17 @@ public RunUnder convert(final String input) throws OptionsParsingException {
throw new OptionsParsingException("Empty command");
}
final String runUnderCommand = runUnderList.get(0);
ImmutableList<String> runUnderSuffix =
ImmutableList.copyOf(runUnderList.subList(1, runUnderList.size()));
if (runUnderCommand.startsWith("//")) {
try {
final Label runUnderLabel = Label.parseAbsolute(runUnderCommand);
return new RunUnderLabel(input, runUnderLabel, runUnderList);
return new RunUnderLabel(input, runUnderLabel, runUnderSuffix);
} catch (LabelSyntaxException e) {
throw new OptionsParsingException("Not a valid label " + e.getMessage());
}
} else {
return new RunUnderCommand(input, runUnderCommand, runUnderList);
return new RunUnderCommand(input, runUnderCommand, runUnderSuffix);
}
}

Expand All @@ -60,32 +63,40 @@ static final class RunUnderLabel implements RunUnder {

private final String input;
private final Label runUnderLabel;
private final List<String> runUnderList;
private final ImmutableList<String> runUnderList;

public RunUnderLabel(String input, Label runUnderLabel, List<String> runUnderList) {
@AutoCodec.Constructor
RunUnderLabel(String input, Label runUnderLabel, ImmutableList<String> runUnderList) {
this.input = input;
this.runUnderLabel = runUnderLabel;
this.runUnderList = new ArrayList<>(runUnderList.subList(1, runUnderList.size()));
this.runUnderList = runUnderList;
}

@Override public String getValue() { return input; }
@Override public Label getLabel() { return runUnderLabel; }
@Override public String getCommand() { return null; }
@Override public List<String> getOptions() { return runUnderList; }
@Override public String toString() { return input; }

String getInput() {
@Override
public String getValue() {
return input;
}

Label getRunUnderLabel() {
@Override
public Label getLabel() {
return runUnderLabel;
}

List<String> getRunUnderList() {
@Override
public String getCommand() {
return null;
}

@Override
public ImmutableList<String> getOptions() {
return runUnderList;
}

@Override
public String toString() {
return input;
}

@Override
public boolean equals(Object other) {
if (this == other) {
Expand Down Expand Up @@ -113,32 +124,40 @@ static final class RunUnderCommand implements RunUnder {

private final String input;
private final String runUnderCommand;
private final List<String> runUnderList;
private final ImmutableList<String> runUnderList;

public RunUnderCommand(String input, String runUnderCommand, List<String> runUnderList) {
@AutoCodec.Constructor
RunUnderCommand(String input, String runUnderCommand, ImmutableList<String> runUnderList) {
this.input = input;
this.runUnderCommand = runUnderCommand;
this.runUnderList = new ArrayList<>(runUnderList.subList(1, runUnderList.size()));
this.runUnderList = runUnderList;
}

@Override public String getValue() { return input; }
@Override public Label getLabel() { return null; }
@Override public String getCommand() { return runUnderCommand; }
@Override public List<String> getOptions() { return runUnderList; }
@Override public String toString() { return input; }

String getInput() {
@Override
public String getValue() {
return input;
}

String getRunUnderCommand() {
@Override
public Label getLabel() {
return null;
}

@Override
public String getCommand() {
return runUnderCommand;
}

List<String> getRunUnderList() {
@Override
public ImmutableList<String> getOptions() {
return runUnderList;
}

@Override
public String toString() {
return input;
}

@Override
public boolean equals(Object other) {
if (this == other) {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.build.lib.util.FileTypeSet;
import com.google.devtools.common.options.Option;
Expand All @@ -39,10 +41,12 @@
* Rule and configuration class definitions for testing late-bound split attributes.
*/
public class LateBoundSplitUtil {
/**
* A custom {@link FragmentOptions} with the option to be split.
*/
/** A custom {@link FragmentOptions} with the option to be split. */
@AutoCodec(strategy = AutoCodec.Strategy.PUBLIC_FIELDS)
public static class TestOptions extends FragmentOptions { // public for options loader
public static final ObjectCodec<TestOptions> CODEC =
new LateBoundSplitUtil_TestOptions_AutoCodec();

@Option(
name = "foo",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
Expand All @@ -64,10 +68,11 @@ public static class TestOptions extends FragmentOptions { // public for options
return ImmutableList.of(split1, split2);
};

/**
* The {@link BuildConfiguration.Fragment} that contains the options.
*/
/** The {@link BuildConfiguration.Fragment} that contains the options. */
@AutoCodec
static class TestFragment extends BuildConfiguration.Fragment {
public static final ObjectCodec<TestFragment> CODEC =
new LateBoundSplitUtil_TestFragment_AutoCodec();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/collect",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/rules/config",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
"//src/main/java/com/google/devtools/common/options",
"//src/test/java/com/google/devtools/build/lib:actions_testutil",
"//src/test/java/com/google/devtools/build/lib:analysis_testutil",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.common.options.Option;
Expand All @@ -45,10 +47,12 @@
@RunWith(JUnit4.class)
public class ConfigSettingTest extends BuildViewTestCase {

/**
* Test option that has its null default overridden by its fragment.
*/
/** Test option that has its null default overridden by its fragment. */
@AutoCodec(strategy = AutoCodec.Strategy.PUBLIC_FIELDS)
public static class LateBoundTestOptions extends FragmentOptions {
public static final ObjectCodec<LateBoundTestOptions> CODEC =
new ConfigSettingTest_LateBoundTestOptions_AutoCodec();

public LateBoundTestOptions() {}

@Option(
Expand All @@ -60,7 +64,11 @@ public LateBoundTestOptions() {}
public String optwithDefault;
}

private static class LateBoundTestOptionsFragment extends BuildConfiguration.Fragment {
@AutoCodec
static class LateBoundTestOptionsFragment extends BuildConfiguration.Fragment {
public static final ObjectCodec<LateBoundTestOptionsFragment> CODEC =
new ConfigSettingTest_LateBoundTestOptionsFragment_AutoCodec();

@Override
public Map<String, Object> lateBoundOptionDefaults() {
return ImmutableMap.<String, Object>of("opt_with_default", "overridden");
Expand All @@ -85,10 +93,12 @@ public ImmutableSet<Class<? extends FragmentOptions>> requiredOptions() {
}
}

/**
* Test option which is private.
*/
/** Test option which is private. */
@AutoCodec(strategy = AutoCodec.Strategy.PUBLIC_FIELDS)
public static class InternalTestOptions extends FragmentOptions {
public static final ObjectCodec<InternalTestOptions> CODEC =
new ConfigSettingTest_InternalTestOptions_AutoCodec();

public InternalTestOptions() {}

@Option(
Expand All @@ -101,7 +111,11 @@ public InternalTestOptions() {}
public String optwithDefault;
}

private static class InternalTestOptionsFragment extends BuildConfiguration.Fragment {}
@AutoCodec
static class InternalTestOptionsFragment extends BuildConfiguration.Fragment {
public static final ObjectCodec<InternalTestOptionsFragment> CODEC =
new ConfigSettingTest_InternalTestOptionsFragment_AutoCodec();
}

private static class InternalTestOptionsLoader implements ConfigurationFragmentFactory {
@Override
Expand Down

0 comments on commit 344b08c

Please sign in to comment.