From a3a2bf22916cb95c6f6c408eeaaba13f4edc736a Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 1 Dec 2023 10:40:26 -0800 Subject: [PATCH] python: Remove PythonSemantics classes All they contain is the GET_INIT_PY_FILES function, which is really only used by the PyBuiltins class. PiperOrigin-RevId: 587053249 Change-Id: Iebd9db51513029d47a5148d4855334b44d7638d4 --- .../bazel/rules/python/BazelPyBuiltins.java | 13 ++++++- .../rules/python/BazelPythonSemantics.java | 36 ------------------- .../lib/rules/python/PythonSemantics.java | 32 ----------------- .../analysis/SourceManifestActionTest.java | 3 +- .../packages/util/BazelMockPythonSupport.java | 8 ++--- .../lib/packages/util/MockPythonSupport.java | 4 +-- 6 files changed, 19 insertions(+), 77 deletions(-) delete mode 100644 src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyBuiltins.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyBuiltins.java index f479a9c187b98b..5e2190e1774caa 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyBuiltins.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyBuiltins.java @@ -14,11 +14,22 @@ package com.google.devtools.build.lib.bazel.rules.python; +import com.google.devtools.build.lib.analysis.Runfiles; import com.google.devtools.build.lib.rules.python.PyBuiltins; +import com.google.devtools.build.lib.rules.python.PythonUtils; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; +import java.util.UUID; /** PyBuiltins with Bazel-specific functionality. */ public final class BazelPyBuiltins extends PyBuiltins { + + private static final UUID GUID = UUID.fromString("0211a192-1b1e-40e6-80e9-7352360b12b1"); + + @SerializationConstant + public static final Runfiles.EmptyFilesSupplier GET_INIT_PY_FILES = + new PythonUtils.GetInitPyFiles(source -> false, GUID); + public BazelPyBuiltins() { - super(BazelPythonSemantics.GET_INIT_PY_FILES); + super(GET_INIT_PY_FILES); } } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java deleted file mode 100644 index 5a6c783a15d11c..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java +++ /dev/null @@ -1,36 +0,0 @@ -// 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.bazel.rules.python; - -import com.google.devtools.build.lib.analysis.Runfiles; -import com.google.devtools.build.lib.rules.python.PythonSemantics; -import com.google.devtools.build.lib.rules.python.PythonUtils; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; -import java.util.UUID; - -/** Functionality specific to the Python rules in Bazel. */ -public class BazelPythonSemantics implements PythonSemantics { - - private static final UUID GUID = UUID.fromString("0211a192-1b1e-40e6-80e9-7352360b12b1"); - - @SerializationConstant - public static final Runfiles.EmptyFilesSupplier GET_INIT_PY_FILES = - new PythonUtils.GetInitPyFiles(source -> false, GUID); - - @Override - public Runfiles.EmptyFilesSupplier getEmptyRunfilesSupplier() { - return GET_INIT_PY_FILES; - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java deleted file mode 100644 index 89b6e3f65ae017..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java +++ /dev/null @@ -1,32 +0,0 @@ -// 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.rules.python; - -import com.google.devtools.build.lib.analysis.Runfiles; - -/** - * Pluggable semantics for Python rules. - * - *

A new instance of this class is created for each configured target, therefore, it is allowed - * to keep state. - */ -public interface PythonSemantics { - /** - * Called when building executables or packages to fill in missing empty __init__.py files if the - * --incompatible_default_to_explicit_init_py has not yet been enabled. This usually returns a - * public static final reference, code is free to use that directly on specific implementations - * instead of making this call. - */ - Runfiles.EmptyFilesSupplier getEmptyRunfilesSupplier(); -} diff --git a/src/test/java/com/google/devtools/build/lib/analysis/SourceManifestActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/SourceManifestActionTest.java index 793b43bab02670..7242963c6e1a4b 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/SourceManifestActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/SourceManifestActionTest.java @@ -117,8 +117,7 @@ private SourceManifestAction createAction(ManifestType type, boolean addInitPy) Runfiles.Builder builder = new Runfiles.Builder("TESTING", false); builder.addSymlinks(fakeManifest); if (addInitPy) { - builder.setEmptyFilesSupplier( - analysisMock.pySupport().getPythonSemantics().getEmptyRunfilesSupplier()); + builder.setEmptyFilesSupplier(analysisMock.pySupport().getEmptyRunfilesSupplier()); } return new SourceManifestAction(type, NULL_ACTION_OWNER, manifestOutputFile, builder.build()); } diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockPythonSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockPythonSupport.java index 64817162ffbe26..10b15545d2a91c 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockPythonSupport.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockPythonSupport.java @@ -14,8 +14,8 @@ package com.google.devtools.build.lib.packages.util; -import com.google.devtools.build.lib.bazel.rules.python.BazelPythonSemantics; -import com.google.devtools.build.lib.rules.python.PythonSemantics; +import com.google.devtools.build.lib.analysis.Runfiles; +import com.google.devtools.build.lib.bazel.rules.python.BazelPyBuiltins; import com.google.devtools.build.lib.testutil.TestConstants; import java.io.IOException; @@ -85,7 +85,7 @@ public String createPythonTopEntryPoint(MockToolsConfig config, String pyRuntime } @Override - public PythonSemantics getPythonSemantics() { - return new BazelPythonSemantics(); + public Runfiles.EmptyFilesSupplier getEmptyRunfilesSupplier() { + return BazelPyBuiltins.GET_INIT_PY_FILES; } } diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockPythonSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockPythonSupport.java index e488ac80e8afdf..89d76d06d7afaa 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/MockPythonSupport.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockPythonSupport.java @@ -14,7 +14,7 @@ package com.google.devtools.build.lib.packages.util; -import com.google.devtools.build.lib.rules.python.PythonSemantics; +import com.google.devtools.build.lib.analysis.Runfiles; import java.io.IOException; /** Creates mock BUILD files required for the python rules. */ @@ -31,5 +31,5 @@ public abstract class MockPythonSupport { public abstract String createPythonTopEntryPoint(MockToolsConfig config, String pyRuntimeLabel) throws IOException; - public abstract PythonSemantics getPythonSemantics(); + public abstract Runfiles.EmptyFilesSupplier getEmptyRunfilesSupplier(); }