From abe1f660a314621b949e839275ccc1bff7ebafca Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 24 Sep 2024 13:21:17 -0700 Subject: [PATCH] Extract a `HasExecPath` interface from `ActionInput`. PiperOrigin-RevId: 678372011 Change-Id: I640e2e8adceed167ce87d039cbc24b490beec58f --- .../build/lib/actions/ActionInput.java | 26 +++++----------- .../google/devtools/build/lib/actions/BUILD | 1 + .../build/lib/actions/HasExecPathString.java | 30 +++++++++++++++++++ 3 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/actions/HasExecPathString.java diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionInput.java b/src/main/java/com/google/devtools/build/lib/actions/ActionInput.java index 2d26ad57155f3e..66c55c1e15947a 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionInput.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionInput.java @@ -19,26 +19,16 @@ /** * Represents an input file to a build action, with an appropriate relative path. * - *

Artifact is the only notable implementer of the interface, but the interface remains - * because 1) some Google specific rules ship files that could be Artifacts to remote execution - * by instantiating ad-hoc derived classes of ActionInput. 2) historically, Google C++ rules - * allow underspecified C++ builds. For that case, we have extra logic to guess the undeclared - * header inclusions (eg. computed inclusions). The extra logic lives in a file that is not - * needed for remote execution, but is a dependency, and it is inserted as a non-Artifact - * ActionInput. - * - *

ActionInput is used as a cache "key" for ActionInputFileCache: for Artifacts, the - * digest/size is already stored in Artifact, but for non-artifacts, we use getExecPathString - * to find this data in a filesystem related cache. + *

Artifact is the only notable implementer of the interface, but the interface remains because + * 1) some Google specific rules ship files that could be Artifacts to remote execution by + * instantiating ad-hoc derived classes of ActionInput. 2) historically, Google C++ rules allow + * underspecified C++ builds. For that case, we have extra logic to guess the undeclared header + * inclusions (eg. computed inclusions). The extra logic lives in a file that is not needed for + * remote execution, but is a dependency, and it is inserted as a non-Artifact ActionInput. */ -public interface ActionInput { - - /** @return the relative path to the input file. */ - String getExecPathString(); +public interface ActionInput extends HasExecPathString { - /** - * @return the relative path to the input file. - */ + /** Same as {@link #getExecPathString}, but returns a {@link PathFragment}. */ PathFragment getExecPath(); /** The input is a directory. */ diff --git a/src/main/java/com/google/devtools/build/lib/actions/BUILD b/src/main/java/com/google/devtools/build/lib/actions/BUILD index 9d563607b6db3e..fb343c00766b29 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/BUILD +++ b/src/main/java/com/google/devtools/build/lib/actions/BUILD @@ -317,6 +317,7 @@ java_library( "ArtifactResolver.java", "ArtifactRoot.java", "Artifacts.java", + "HasExecPathString.java", "PathMapper.java", ], deps = [ diff --git a/src/main/java/com/google/devtools/build/lib/actions/HasExecPathString.java b/src/main/java/com/google/devtools/build/lib/actions/HasExecPathString.java new file mode 100644 index 00000000000000..3c6ab455c1bcd6 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/actions/HasExecPathString.java @@ -0,0 +1,30 @@ +// Copyright 2024 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 + +package com.google.devtools.build.lib.actions; + +/** + * A file that has an exec path string. + * + *

Mainly implemented by classes that also implement {@link ActionInput}, but has other + * implementations in the Google-internal spawn execution service. + */ +public interface HasExecPathString { + + /** + * Returns the path to this file. + * + *

The path may be relative to the exec root or absolute. + */ + String getExecPathString(); +}