Skip to content

Commit

Permalink
Remove outdated "output directory name" option.
Browse files Browse the repository at this point in the history
This was exclusively used to set the host configuration's output directory to "host". We can achieve that more directly.

This also reduces the conceptual complexity of understanding the various flags affecting output directories.

PiperOrigin-RevId: 395779491
  • Loading branch information
gregestren authored and copybara-github committed Sep 9, 2021
1 parent 625a418 commit af0e20f
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.packages.RuleClassProvider;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
Expand Down Expand Up @@ -181,12 +180,6 @@ public void reportInvalidOptions(EventHandler reporter) {
for (Fragment fragment : fragments.values()) {
fragment.reportInvalidOptions(reporter, this.buildOptions);
}

if (options.outputDirectoryName != null) {
reporter.handle(
Event.error(
"The internal '--output directory name' option cannot be used on the command line"));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,6 @@ public class CoreOptions extends FragmentOptions implements Cloneable {
+ "'fastbuild', 'dbg', 'opt'.")
public CompilationMode hostCompilationMode;

/**
* This option is used internally to set output directory name of the <i>host</i> configuration to
* a constant, so that the output files for the host are completely independent of those for the
* target, no matter what options are in force (k8/piii, opt/dbg, etc).
*/
@Option(
name = "output directory name",
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {
OptionEffectTag.LOSES_INCREMENTAL_STATE,
OptionEffectTag.AFFECTS_OUTPUTS,
OptionEffectTag.LOADING_AND_ANALYSIS
},
metadataTags = {OptionMetadataTag.INTERNAL})
public String outputDirectoryName;

/**
* This option is used by starlark transitions to add a distinguishing element to the output
* directory name, in order to avoid name clashing.
Expand Down Expand Up @@ -841,7 +824,6 @@ public IncludeConfigFragmentsEnumConverter() {
public FragmentOptions getHost() {
CoreOptions host = (CoreOptions) getDefault();

host.outputDirectoryName = "host";
host.transitionDirectoryNameFragment = transitionDirectoryNameFragment;
host.affectedByStarlarkTransition = affectedByStarlarkTransition;
host.compilationMode = hostCompilationMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ private static BuildOptions transitionImpl(BuildOptionsView options, Label execu
CoreOptions coreOptions = checkNotNull(execOptions.get(CoreOptions.class));
coreOptions.isHost = false;
coreOptions.isExec = true;
coreOptions.outputDirectoryName = null;
coreOptions.platformSuffix =
String.format("-exec-%X", executionPlatform.getCanonicalForm().hashCode());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ public ArtifactRoot getRoot(
throws InvalidMnemonicException {
this.directories = directories;
this.mnemonic = buildMnemonic(options, fragments);
this.outputDirName =
(options.outputDirectoryName != null) ? options.outputDirectoryName : mnemonic;
this.outputDirName = options.isHost ? "host" : mnemonic;

this.outputDirectory =
OutputDirectory.OUTPUT.getRoot(outputDirName, directories, mainRepositoryName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.google.devtools.build.lib.actions.Actions;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.FailAction;
import com.google.devtools.build.lib.analysis.config.CoreOptions;
import com.google.devtools.build.lib.analysis.config.transitions.NoTransition;
import com.google.devtools.build.lib.analysis.config.transitions.NullTransition;
import com.google.devtools.build.lib.analysis.configuredtargets.InputFileConfiguredTarget;
Expand All @@ -54,8 +53,6 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.NotifyingHelper.Listener;
import com.google.devtools.common.options.Options;
import com.google.devtools.common.options.OptionsParsingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -550,23 +547,6 @@ reporter, top, getBuildConfigurationCollection(), /* toolchainContexts= */ null)
assertThat(targets).containsExactly(innerDependency, fileDependency);
}

/** Tests that the {@code --output directory name} option cannot be used on the command line. */
@Test
public void testConfigurationShortName() {
// Check that output directory name is still the name, otherwise this test is not testing what
// we expect.
CoreOptions options = Options.getDefaults(CoreOptions.class);
options.outputDirectoryName = "/home/wonkaw/wonka_chocolate/factory/out";
assertWithMessage("The flag's name may have been changed; this test may need to be updated.")
.that(options.asMap().get("output directory name"))
.isEqualTo("/home/wonkaw/wonka_chocolate/factory/out");

OptionsParsingException e =
assertThrows(
OptionsParsingException.class, () -> useConfiguration("--output directory name=foo"));
assertThat(e).hasMessageThat().isEqualTo("Unrecognized option: --output directory name=foo");
}

// Regression test: "output_filter broken (but in a different way)"
@Test
@Ignore("b/182560362 Starlark java_library can't output warnings")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ public void multiplePackagePathsFirstWins() throws Exception {
assertThat(mapped.getOptions().get(CoreOptions.class).cpu).isEqualTo("one");
}

// Internal flags, such as "output directory name", cannot be set from the command-line, but
// Internal flags (OptionMetadataTag.INTERNAL) cannot be set from the command-line, but
// platform mapping needs to access them.
@Test
public void ableToChangeInternalOption() throws Exception {
scratch.file(
"my_mapping_file",
"platforms:", // Force line break
" //platforms:one", // Force line break
" --output directory name=updated_output_dir");
" --transition directory name fragment=updated_output_dir");

PlatformMappingValue platformMappingValue =
executeFunction(PlatformMappingValue.Key.create(PathFragment.create("my_mapping_file")));
Expand All @@ -228,7 +228,7 @@ public void ableToChangeInternalOption() throws Exception {

BuildConfigurationValue.Key mapped = platformMappingValue.map(keyForOptions(modifiedOptions));

assertThat(mapped.getOptions().get(CoreOptions.class).outputDirectoryName)
assertThat(mapped.getOptions().get(CoreOptions.class).transitionDirectoryNameFragment)
.isEqualTo("updated_output_dir");
}

Expand Down

0 comments on commit af0e20f

Please sign in to comment.