Skip to content

Commit 24b9c51

Browse files
authored
chore: remove semantics.bzl (#2725)
semantics.bzl is an artifact of how the rules avoided patching when they were part of Bazel. With the code moved out of Bazel, such helper files aren't necessary anymore. Work towards #2522
1 parent 7d431d8 commit 24b9c51

File tree

4 files changed

+12
-75
lines changed

4 files changed

+12
-75
lines changed

python/private/BUILD.bazel

-9
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ bzl_library(
7272
":py_internal_bzl",
7373
":reexports_bzl",
7474
":rules_cc_srcs_bzl",
75-
":semantics_bzl",
7675
"@bazel_skylib//rules:common_settings",
7776
],
7877
)
@@ -131,7 +130,6 @@ bzl_library(
131130
":py_internal_bzl",
132131
":reexports_bzl",
133132
":rules_cc_srcs_bzl",
134-
":semantics_bzl",
135133
"@bazel_skylib//lib:paths",
136134
],
137135
)
@@ -302,7 +300,6 @@ bzl_library(
302300
":attributes_bzl",
303301
":py_executable_bzl",
304302
":rule_builders_bzl",
305-
":semantics_bzl",
306303
"@bazel_skylib//lib:dicts",
307304
],
308305
)
@@ -537,7 +534,6 @@ bzl_library(
537534
":common_bzl",
538535
":py_executable_bzl",
539536
":rule_builders_bzl",
540-
":semantics_bzl",
541537
"@bazel_skylib//lib:dicts",
542538
],
543539
)
@@ -677,11 +673,6 @@ bzl_library(
677673
],
678674
)
679675

680-
bzl_library(
681-
name = "semantics_bzl",
682-
srcs = ["semantics.bzl"],
683-
)
684-
685676
# Needed to define bzl_library targets for docgen. (We don't define the
686677
# bzl_library target here because it'd give our users a transitive dependency
687678
# on Skylib.)

python/private/attributes.bzl

+1-10
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ load(":py_info.bzl", "PyInfo")
2323
load(":py_internal.bzl", "py_internal")
2424
load(":reexports.bzl", "BuiltinPyInfo")
2525
load(":rule_builders.bzl", "ruleb")
26-
load(
27-
":semantics.bzl",
28-
"DEPS_ATTR_ALLOW_RULES",
29-
"SRCS_ATTR_ALLOW_FILES",
30-
)
3126

3227
_PackageSpecificationInfo = getattr(py_internal, "PackageSpecificationInfo", None)
3328

@@ -250,9 +245,6 @@ PY_SRCS_ATTRS = dicts.add(
250245
[PyInfo],
251246
[CcInfo],
252247
] + _MaybeBuiltinPyInfo,
253-
# TODO(b/228692666): Google-specific; remove these allowances once
254-
# the depot is cleaned up.
255-
allow_rules = DEPS_ATTR_ALLOW_RULES,
256248
doc = """
257249
List of additional libraries to be linked in to the target.
258250
See comments about
@@ -359,8 +351,7 @@ as part of a runnable program (packaging rules may include them, however).
359351
allow_files = True,
360352
),
361353
"srcs": lambda: attrb.LabelList(
362-
# Google builds change the set of allowed files.
363-
allow_files = SRCS_ATTR_ALLOW_FILES,
354+
allow_files = [".py", ".py3"],
364355
# Necessary for --compile_one_dependency to work.
365356
flags = ["DIRECT_COMPILE_TIME_INPUT"],
366357
doc = """

python/private/py_executable.bzl

+11-25
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ load(":py_internal.bzl", "py_internal")
5959
load(":py_runtime_info.bzl", "DEFAULT_STUB_SHEBANG", "PyRuntimeInfo")
6060
load(":reexports.bzl", "BuiltinPyInfo", "BuiltinPyRuntimeInfo")
6161
load(":rule_builders.bzl", "ruleb")
62-
load(
63-
":semantics.bzl",
64-
"ALLOWED_MAIN_EXTENSIONS",
65-
"BUILD_DATA_SYMLINK_PATH",
66-
"IS_BAZEL",
67-
"PY_RUNTIME_ATTR_NAME",
68-
)
6962
load(
7063
":toolchain_types.bzl",
7164
"EXEC_TOOLS_TOOLCHAIN_TYPE",
@@ -1116,19 +1109,12 @@ def _get_runtime_details(ctx, semantics):
11161109
#
11171110
# TOOD(bazelbuild/bazel#7901): Remove this once --python_path flag is removed.
11181111

1119-
if IS_BAZEL:
1120-
flag_interpreter_path = ctx.fragments.bazel_py.python_path
1121-
toolchain_runtime, effective_runtime = _maybe_get_runtime_from_ctx(ctx)
1122-
if not effective_runtime:
1123-
# Clear these just in case
1124-
toolchain_runtime = None
1125-
effective_runtime = None
1126-
1127-
else: # Google code path
1128-
flag_interpreter_path = None
1129-
toolchain_runtime, effective_runtime = _maybe_get_runtime_from_ctx(ctx)
1130-
if not effective_runtime:
1131-
fail("Unable to find Python runtime")
1112+
flag_interpreter_path = ctx.fragments.bazel_py.python_path
1113+
toolchain_runtime, effective_runtime = _maybe_get_runtime_from_ctx(ctx)
1114+
if not effective_runtime:
1115+
# Clear these just in case
1116+
toolchain_runtime = None
1117+
effective_runtime = None
11321118

11331119
if effective_runtime:
11341120
direct = [] # List of files
@@ -1207,7 +1193,7 @@ def _maybe_get_runtime_from_ctx(ctx):
12071193
effective_runtime = toolchain_runtime
12081194
else:
12091195
toolchain_runtime = None
1210-
attr_target = getattr(ctx.attr, PY_RUNTIME_ATTR_NAME)
1196+
attr_target = ctx.attr._py_interpreter
12111197

12121198
# In Bazel, --python_top is null by default.
12131199
if attr_target and PyRuntimeInfo in attr_target:
@@ -1335,9 +1321,9 @@ def _create_runfiles_with_build_data(
13351321
central_uncachable_version_file,
13361322
extra_write_build_data_env,
13371323
)
1338-
build_data_runfiles = ctx.runfiles(symlinks = {
1339-
BUILD_DATA_SYMLINK_PATH: build_data_file,
1340-
})
1324+
build_data_runfiles = ctx.runfiles(files = [
1325+
build_data_file,
1326+
])
13411327
return build_data_file, build_data_runfiles
13421328

13431329
def _write_build_data(ctx, central_uncachable_version_file, extra_write_build_data_env):
@@ -1552,7 +1538,7 @@ def determine_main(ctx):
15521538
"""
15531539
if ctx.attr.main:
15541540
proposed_main = ctx.attr.main.label.name
1555-
if not proposed_main.endswith(tuple(ALLOWED_MAIN_EXTENSIONS)):
1541+
if not proposed_main.endswith(".py"):
15561542
fail("main must end in '.py'")
15571543
else:
15581544
if ctx.label.name.endswith(".py"):

python/private/semantics.bzl

-31
This file was deleted.

0 commit comments

Comments
 (0)