@@ -43,116 +43,40 @@ PYTHON_FILE_EXTENSIONS = [
4343
4444def create_binary_semantics_struct (
4545 * ,
46- create_executable ,
47- get_cc_details_for_binary ,
4846 get_central_uncachable_version_file ,
49- get_coverage_deps ,
5047 get_debugger_deps ,
51- get_extra_common_runfiles_for_binary ,
52- get_extra_providers ,
53- get_extra_write_build_data_env ,
54- get_interpreter_path ,
55- get_imports ,
5648 get_native_deps_dso_name ,
57- get_native_deps_user_link_flags ,
58- get_stamp_flag ,
59- maybe_precompile ,
6049 should_build_native_deps_dso ,
61- should_create_init_files ,
6250 should_include_build_data ):
6351 """Helper to ensure a semantics struct has all necessary fields.
6452
6553 Call this instead of a raw call to `struct(...)`; it'll help ensure all
6654 the necessary functions are being correctly provided.
6755
6856 Args:
69- create_executable: Callable; creates a binary's executable output. See
70- py_executable.bzl#py_executable_base_impl for details.
71- get_cc_details_for_binary: Callable that returns a `CcDetails` struct; see
72- `create_cc_detail_struct`.
7357 get_central_uncachable_version_file: Callable that returns an optional
7458 Artifact; this artifact is special: it is never cached and is a copy
7559 of `ctx.version_file`; see py_builtins.copy_without_caching
76- get_coverage_deps: Callable that returns a list of Targets for making
77- coverage work; only called if coverage is enabled.
7860 get_debugger_deps: Callable that returns a list of Targets that provide
7961 custom debugger support; only called for target-configuration.
80- get_extra_common_runfiles_for_binary: Callable that returns a runfiles
81- object of extra runfiles a binary should include.
82- get_extra_providers: Callable that returns extra providers; see
83- py_executable.bzl#_create_providers for details.
84- get_extra_write_build_data_env: Callable that returns a dict[str, str]
85- of additional environment variable to pass to build data generation.
86- get_interpreter_path: Callable that returns an optional string, which is
87- the path to the Python interpreter to use for running the binary.
88- get_imports: Callable that returns a list of the target's import
89- paths (from the `imports` attribute, so just the target's own import
90- path strings, not from dependencies).
9162 get_native_deps_dso_name: Callable that returns a string, which is the
9263 basename (with extension) of the native deps DSO library.
93- get_native_deps_user_link_flags: Callable that returns a list of strings,
94- which are any extra linker flags to pass onto the native deps DSO
95- linking action.
96- get_stamp_flag: Callable that returns bool of if the --stamp flag was
97- enabled or not.
98- maybe_precompile: Callable that may optional precompile the input `.py`
99- sources and returns the full set of desired outputs derived from
100- the source files (e.g., both py and pyc, only one of them, etc).
10164 should_build_native_deps_dso: Callable that returns bool; True if
10265 building a native deps DSO is supported, False if not.
103- should_create_init_files: Callable that returns bool; True if
104- `__init__.py` files should be generated, False if not.
10566 should_include_build_data: Callable that returns bool; True if
10667 build data should be generated, False if not.
10768 Returns:
10869 A "BinarySemantics" struct.
10970 """
11071 return struct (
11172 # keep-sorted
112- create_executable = create_executable ,
113- get_cc_details_for_binary = get_cc_details_for_binary ,
11473 get_central_uncachable_version_file = get_central_uncachable_version_file ,
115- get_coverage_deps = get_coverage_deps ,
11674 get_debugger_deps = get_debugger_deps ,
117- get_extra_common_runfiles_for_binary = get_extra_common_runfiles_for_binary ,
118- get_extra_providers = get_extra_providers ,
119- get_extra_write_build_data_env = get_extra_write_build_data_env ,
120- get_imports = get_imports ,
121- get_interpreter_path = get_interpreter_path ,
12275 get_native_deps_dso_name = get_native_deps_dso_name ,
123- get_native_deps_user_link_flags = get_native_deps_user_link_flags ,
124- get_stamp_flag = get_stamp_flag ,
125- maybe_precompile = maybe_precompile ,
12676 should_build_native_deps_dso = should_build_native_deps_dso ,
127- should_create_init_files = should_create_init_files ,
12877 should_include_build_data = should_include_build_data ,
12978 )
13079
131- def create_library_semantics_struct (
132- * ,
133- get_cc_info_for_library ,
134- get_imports ,
135- maybe_precompile ):
136- """Create a `LibrarySemantics` struct.
137-
138- Call this instead of a raw call to `struct(...)`; it'll help ensure all
139- the necessary functions are being correctly provided.
140-
141- Args:
142- get_cc_info_for_library: Callable that returns a CcInfo for the library;
143- see py_library_impl for arg details.
144- get_imports: Callable; see create_binary_semantics_struct.
145- maybe_precompile: Callable; see create_binary_semantics_struct.
146- Returns:
147- a `LibrarySemantics` struct.
148- """
149- return struct (
150- # keep sorted
151- get_cc_info_for_library = get_cc_info_for_library ,
152- get_imports = get_imports ,
153- maybe_precompile = maybe_precompile ,
154- )
155-
15680def create_cc_details_struct (
15781 * ,
15882 cc_info_for_propagating ,
@@ -255,12 +179,11 @@ def collect_cc_info(ctx, extra_deps = []):
255179
256180 return cc_common .merge_cc_infos (cc_infos = cc_infos )
257181
258- def collect_imports (ctx , semantics ):
182+ def collect_imports (ctx ):
259183 """Collect the direct and transitive `imports` strings.
260184
261185 Args:
262186 ctx: {type}`ctx` the current target ctx
263- semantics: semantics object for fetching direct imports.
264187
265188 Returns:
266189 {type}`depset[str]` of import paths
@@ -271,13 +194,11 @@ def collect_imports(ctx, semantics):
271194 transitive .append (dep [PyInfo ].imports )
272195 if BuiltinPyInfo != None and BuiltinPyInfo in dep :
273196 transitive .append (dep [BuiltinPyInfo ].imports )
274- return depset (direct = semantics . get_imports (ctx ), transitive = transitive )
197+ return depset (direct = get_imports (ctx ), transitive = transitive )
275198
276199def get_imports (ctx ):
277200 """Gets the imports from a rule's `imports` attribute.
278201
279- See create_binary_semantics_struct for details about this function.
280-
281202 Args:
282203 ctx: Rule ctx.
283204
0 commit comments