diff options
author | shahan <shahan@google.com> | 2018-06-18 08:14:01 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-18 08:15:26 -0700 |
commit | e35e8cfabd33e2e35b88d3693083350cf3c9d006 (patch) | |
tree | 2e05bb4f65801724b43fb6908cbdcb71438012f2 /src/main/java/com/google/devtools/build/lib/actions | |
parent | 200837c2368d6b3383eb9dbcd25e293f818637bd (diff) |
Refactoring: uses OutputService for ActionFileSystem injection
Moves more Action-oriented from skyframe package, which has become very unwieldy, to action package. This is needed to avoid circular dependencies caused when build-base is needed for skyframe.
PiperOrigin-RevId: 200996982
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/actions')
4 files changed, 165 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactSkyKey.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactSkyKey.java new file mode 100644 index 0000000000..701aacaec4 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactSkyKey.java @@ -0,0 +1,94 @@ +// Copyright 2014 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.actions; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Interner; +import com.google.devtools.build.lib.concurrent.BlazeInterners; +import com.google.devtools.build.lib.concurrent.ThreadSafety; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.skyframe.SkyFunctionName; +import com.google.devtools.build.skyframe.SkyKey; + +/** + * A {@link SkyKey} coming from an {@link Artifact} that is not mandatory: absence of the Artifact + * does not imply any error. + * + * <p>Since {@link Artifact} is already a {@link SkyKey}, this wrapper is only needed when the + * {@link Artifact} is not mandatory (discovered during include scanning). + */ +// TODO(janakr): pull mandatory/non-mandatory handling up to consumers and get rid of this wrapper. +@AutoCodec +public class ArtifactSkyKey implements SkyKey { + private static final Interner<ArtifactSkyKey> INTERNER = BlazeInterners.newWeakInterner(); + + private final Artifact.SourceArtifact artifact; + + private ArtifactSkyKey(Artifact.SourceArtifact sourceArtifact) { + this.artifact = Preconditions.checkNotNull(sourceArtifact); + } + + @ThreadSafety.ThreadSafe + public static SkyKey key(Artifact artifact, boolean isMandatory) { + if (isMandatory || !artifact.isSourceArtifact()) { + return artifact; + } + return create(((Artifact.SourceArtifact) artifact)); + } + + @AutoCodec.VisibleForSerialization + @AutoCodec.Instantiator + static ArtifactSkyKey create(Artifact.SourceArtifact artifact) { + return INTERNER.intern(new ArtifactSkyKey(artifact)); + } + + public static Artifact artifact(SkyKey key) { + return key instanceof Artifact ? (Artifact) key : ((ArtifactSkyKey) key).artifact; + } + + public static boolean isMandatory(SkyKey key) { + return key instanceof Artifact; + } + + @Override + public SkyFunctionName functionName() { + return Artifact.ARTIFACT; + } + + @Override + public int hashCode() { + return artifact.hashCode(); + } + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (!(that instanceof ArtifactSkyKey)) { + return false; + } + ArtifactSkyKey thatArtifactSkyKey = ((ArtifactSkyKey) that); + return artifact.equals(thatArtifactSkyKey.artifact); + } + + public Artifact getArtifact() { + return artifact; + } + + @Override + public String toString() { + return artifact.prettyPrint() + " " + artifact.getArtifactOwner(); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/actions/InjectionListener.java b/src/main/java/com/google/devtools/build/lib/actions/InjectionListener.java new file mode 100644 index 0000000000..28d773f8d0 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/actions/InjectionListener.java @@ -0,0 +1,25 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.actions; + +import java.io.IOException; + +/** + * An {@link InjectionListener} is notified when a remote file metadata is inserted into its + * associated storage. + */ +public interface InjectionListener { + void onInsert(ActionInput dest, byte[] digest, long size, int backendIndex) throws IOException; +} diff --git a/src/main/java/com/google/devtools/build/lib/actions/MetadataConsumer.java b/src/main/java/com/google/devtools/build/lib/actions/MetadataConsumer.java new file mode 100644 index 0000000000..d737d54f41 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/actions/MetadataConsumer.java @@ -0,0 +1,26 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.actions; + +import java.io.IOException; + +/** + * Consumes metadata for artifacts. + * + * <p>May be called when metadata isn't otherwise propagated at the spawn level. + */ +@FunctionalInterface +public interface MetadataConsumer { + void accept(Artifact artifact, FileArtifactValue value) throws IOException; +} diff --git a/src/main/java/com/google/devtools/build/lib/actions/MissingDepException.java b/src/main/java/com/google/devtools/build/lib/actions/MissingDepException.java new file mode 100644 index 0000000000..17de74f180 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/actions/MissingDepException.java @@ -0,0 +1,20 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.actions; + +/** + * Exception to be thrown if an action is missing Skyframe dependencies that it finds are missing + * during execution/input discovery. + */ +public final class MissingDepException extends RuntimeException {} |