Skip to content

Commit

Permalink
Review a number of action subclasses and update them according to the…
Browse files Browse the repository at this point in the history
… spec.

Second pass.

Consists of adding @immutable annotations, adding final modifiers, and changing
the types of fields to immutable types.

--
MOS_MIGRATED_REVID=120216592
  • Loading branch information
ulfjack authored and damienmg committed Apr 19, 2016
1 parent 0dbe07f commit 83fce40
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
package com.google.devtools.build.lib.actions;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;

/**
* FailAction is an Action that always fails to execute. (Used as scaffolding
* for rules we haven't yet implemented. Also useful for testing.)
*/
@ThreadSafe
@Immutable
public final class FailAction extends AbstractAction {

private static final String GUID = "626cb78a-810f-4af3-979c-ee194955f04c";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.util.Preconditions;

/**
* An action that depends on a set of inputs and creates a single output file whenever it
* runs. This is useful for bundling up a bunch of dependencies that are shared
* between individual targets in the action graph; for example generated header files.
*/
public class MiddlemanAction extends AbstractAction {
@Immutable
public final class MiddlemanAction extends AbstractAction {

public static final String MIDDLEMAN_MNEMONIC = "Middleman";
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* about rules to extra_actions.
*/
public class PseudoAction<InfoType extends MessageLite> extends AbstractAction {

private final UUID uuid;
private final String mnemonic;
private final GeneratedExtension<ExtraActionInfo, InfoType> infoExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Executor;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand All @@ -32,7 +33,8 @@
* Action responsible for the symlink tree creation.
* Used to generate runfiles and fileset symlink farms.
*/
public class SymlinkTreeAction extends AbstractAction {
@Immutable
public final class SymlinkTreeAction extends AbstractAction {

private static final String GUID = "63412bda-4026-4c8e-a3ad-7deb397728d4";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Executor;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.vfs.Path;

Expand All @@ -35,9 +36,9 @@
/**
* This action creates a set of symbolic links.
*/
@Immutable
public final class CreateIncSymlinkAction extends AbstractAction {

private final SortedMap<Artifact, Artifact> symlinks;
private final ImmutableSortedMap<Artifact, Artifact> symlinks;

/**
* Creates a new instance. The symlinks map maps symlinks to their targets, i.e. the symlink paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.actions.Executor;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;

import java.io.IOException;

Expand All @@ -38,6 +39,7 @@
* library depends on it, and only references one of the headers, the other
* grep-includes will have been wasted.
*/
@Immutable
final class ExtractInclusionAction extends AbstractAction {

private static final String GUID = "45b43e5a-4734-43bb-a05e-012313808142";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Executor;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.vfs.Path;

/**
Expand All @@ -30,7 +31,8 @@
* would complain that these files have no generating action if we did not set it to an instance of
* this class.
*/
public class FdoStubAction extends AbstractAction {
@Immutable
public final class FdoStubAction extends AbstractAction {
public FdoStubAction(ActionOwner owner, Artifact output) {
// TODO(bazel-team): Make extracting the zip file a honest-to-God action so that we can do away
// with this ugliness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.actions.Root;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink;
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.util.Preconditions;
Expand All @@ -44,8 +45,8 @@
* Such symlinks are used by the linker to ensure that all rpath entries can be
* specified relative to the $ORIGIN.
*/
@Immutable
public final class SolibSymlinkAction extends AbstractAction {

private final Artifact library;
private final Path target;
private final Artifact symlink;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible;
import com.google.devtools.build.lib.rules.java.JavaConfiguration.JavaClasspathMode;
import com.google.devtools.build.lib.util.Fingerprint;
Expand All @@ -71,8 +72,8 @@
/**
* Action that represents a Java compilation.
*/
@ThreadCompatible
public class JavaCompileAction extends AbstractAction {
@ThreadCompatible @Immutable
public final class JavaCompileAction extends AbstractAction {
private static final String GUID = "786e174d-ed97-4e79-9f61-ae74430714cf";

private static final ResourceSet LOCAL_RESOURCES =
Expand Down Expand Up @@ -100,7 +101,7 @@ public class JavaCompileAction extends AbstractAction {
/**
* The path to the extdir to specify to javac.
*/
private final Collection<Artifact> extdirInputs;
private final ImmutableList<Artifact> extdirInputs;

/**
* The list of classpath entries to search for annotation processors.
Expand Down Expand Up @@ -181,7 +182,7 @@ private JavaCompileAction(
Artifact outputJar,
NestedSet<Artifact> classpathEntries,
ImmutableList<Artifact> bootclasspathEntries,
Collection<Artifact> extdirInputs,
ImmutableList<Artifact> extdirInputs,
List<Artifact> processorPath,
List<String> processorNames,
Collection<Artifact> messages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction;
import com.google.devtools.build.lib.packages.TargetUtils;
Expand Down Expand Up @@ -1069,8 +1070,8 @@ private CommandLine linkCommandLine(
* <p>Required as a hack to the link command line because that may contain two commands, which are
* then passed to {@code /bin/bash -c}, and accordingly need to be a single argument.
*/
private static class SingleArgCommandLine extends CommandLine {

@Immutable // if original is immutable
private static final class SingleArgCommandLine extends CommandLine {
private final CommandLine original;

private SingleArgCommandLine(CommandLine original) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
Expand Down Expand Up @@ -560,7 +561,8 @@ private static String buildNoMainMatchesErrorText(boolean explicit, String propo
}

// Used purely to set the legacy ActionType of the ExtraActionInfo.
private static class PyPseudoAction extends PseudoAction<PythonInfo> {
@Immutable
private static final class PyPseudoAction extends PseudoAction<PythonInfo> {
private static final UUID ACTION_UUID = UUID.fromString("8d720129-bc1a-481f-8c4c-dbe11dcef319");

public PyPseudoAction(ActionOwner owner,
Expand All @@ -569,10 +571,5 @@ public PyPseudoAction(ActionOwner owner,
PythonInfo info) {
super(ACTION_UUID, owner, inputs, outputs, mnemonic, infoExtension, info);
}

@Override
public ExtraActionInfo.Builder getExtraActionInfo() {
return super.getExtraActionInfo();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory.BuildInfoKey;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand Down Expand Up @@ -185,7 +186,8 @@ public ImmutableSet<Artifact> getOrphanArtifacts() {
}
}

public static class DummyWorkspaceStatusAction extends WorkspaceStatusAction {
@Immutable
public static final class DummyWorkspaceStatusAction extends WorkspaceStatusAction {
private final String key;
private final Artifact stableStatus;
private final Artifact volatileStatus;
Expand Down

0 comments on commit 83fce40

Please sign in to comment.