Skip to content

Commit 4af17dd

Browse files
Don't re-write shared_libraries list
Summary: We pass around the same list of shared_libraries in the forms `list[(str, SharedLibrary, bool)]` `list[SharedLibrary]` `list[(SharedLibrary, str)]` This diff moves everything to use `list[(SharedLibrary, str)]` to match the format used in `prelude/linking/shared_libraries.bzl::zip_shlibs` Reviewed By: jtbraun Differential Revision: D72982021 fbshipit-source-id: 97ead99a9f50fc2bb1a472aef53fb989e2fc2aa6
1 parent 1dab315 commit 4af17dd

File tree

4 files changed

+24
-31
lines changed

4 files changed

+24
-31
lines changed

Diff for: prelude/python/linking/native.bzl

+3-3
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def _get_link_group_info(
233233
return (link_group_info, link_group_specs)
234234

235235
def process_native_linking(ctx, deps, python_toolchain, extra, package_style, allow_cache_upload, extra_artifacts) -> (
236-
list[(str, SharedLibrary)],
236+
list[(SharedLibrary, str)],
237237
dict[str, (LinkedObject, Label)],
238238
list[LinkArgs],
239239
):
@@ -369,12 +369,11 @@ def process_native_linking(ctx, deps, python_toolchain, extra, package_style, al
369369

370370
# Put native libraries into the runtime location, as we need to unpack
371371
# potentially all of them before startup.
372-
shared_libs = [("runtime/lib", s) for s in executable_info.shared_libs]
372+
shared_libs = [(s, "runtime/lib") for s in executable_info.shared_libs]
373373

374374
# TODO expect(len(executable_info.runtime_files) == 0, "OH NO THERE ARE RUNTIME FILES")
375375
extra_artifacts.update(extension_info_reduced.artifacts)
376376
shared_libs.append((
377-
"runtime/bin",
378377
create_shlib(
379378
soname = ctx.attrs.executable_name,
380379
label = ctx.label,
@@ -384,6 +383,7 @@ def process_native_linking(ctx, deps, python_toolchain, extra, package_style, al
384383
dwp = executable_info.dwp,
385384
),
386385
),
386+
"runtime/bin",
387387
))
388388

389389
link_args = executable_info.link_args

Diff for: prelude/python/linking/omnibus.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def process_omnibus_linking(
3838
extensions: dict[str, (LinkedObject, Label)],
3939
python_toolchain: PythonToolchainInfo,
4040
extra: dict[str, typing.Any]) -> (
41-
list[(str, SharedLibrary)],
41+
list[(SharedLibrary, str)],
4242
dict[str, (LinkedObject, Label)],
4343
):
4444
# If we're using omnibus linking, re-link libraries and extensions and
@@ -78,7 +78,7 @@ def process_omnibus_linking(
7878
dest: (omnibus_libs.roots[label].shared_library, label)
7979
for dest, (_, label) in extensions.items()
8080
}
81-
shared_libs = [("", shlib) for shlib in omnibus_libs.libraries]
81+
shared_libs = [(shlib, "") for shlib in omnibus_libs.libraries]
8282

8383
omnibus_providers = []
8484

Diff for: prelude/python/make_py_package.bzl

+13-12
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def make_py_package(
186186
package_style: PackageStyle,
187187
build_args: list[ArgLike],
188188
pex_modules: PexModules,
189-
shared_libraries: list[(str, SharedLibrary, bool)],
189+
shared_libraries: list[(SharedLibrary, str)],
190+
preload_labels: set[Label],
190191
main: EntryPoint,
191192
allow_cache_upload: bool,
192193
link_args: list[LinkArgs] = [],
@@ -216,13 +217,13 @@ def make_py_package(
216217
ctx = ctx,
217218
shared_libraries = [
218219
(shlib, libdir)
219-
for libdir, shlib, preload in shared_libraries
220-
if preload
220+
for shlib, libdir in shared_libraries
221+
if shlib.label in preload_labels
221222
],
222223
)
223224

224225
# Add link metadata to manifest_module_entries if requested.
225-
manifest_module_entries = _add_dep_metadata_to_manifest_module(ctx, map(lambda s: s[1], shared_libraries), link_args)
226+
manifest_module_entries = _add_dep_metadata_to_manifest_module(ctx, shared_libraries, link_args)
226227
generated_files = []
227228

228229
startup_functions_loader = generate_startup_function_loader(ctx, manifest_module_entries)
@@ -244,7 +245,7 @@ def make_py_package(
244245
ctx,
245246
pex_modules,
246247
[startup_function] if startup_function else [],
247-
[(shlib, libdir) for libdir, shlib, _ in shared_libraries],
248+
shared_libraries,
248249
debuginfo_files = debuginfo_files,
249250
)
250251

@@ -254,7 +255,7 @@ def make_py_package(
254255
make_py_package_cmd,
255256
package_style,
256257
build_args,
257-
map(lambda s: (s[1], s[0]), shared_libraries),
258+
shared_libraries,
258259
generated_files,
259260
preload_libraries,
260261
common_modules_args,
@@ -284,7 +285,7 @@ def make_py_package(
284285
ctx,
285286
repl_pex_modules,
286287
[startup_function] if startup_function else [],
287-
[(shlib, libdir) for libdir, shlib, _ in shared_libraries],
288+
shared_libraries,
288289
debuginfo_files = debuginfo_files,
289290
suffix = "_repl",
290291
)
@@ -296,7 +297,7 @@ def make_py_package(
296297
make_py_package_cmd,
297298
PackageStyle("inplace"),
298299
build_args,
299-
map(lambda s: (s[1], s[0]), shared_libraries),
300+
shared_libraries,
300301
generated_files,
301302
preload_libraries,
302303
repl_common_modules_args,
@@ -317,7 +318,7 @@ def make_py_package(
317318
make_py_package_cmd,
318319
PackageStyle(style),
319320
build_args,
320-
map(lambda s: (s[1], s[0]), shared_libraries),
321+
shared_libraries,
321322
generated_files,
322323
preload_libraries,
323324
common_modules_args,
@@ -993,7 +994,7 @@ def _hidden_resources_error_message(current_target: Label, hidden_resources: lis
993994

994995
def _get_shared_library_dep_metadata(
995996
ctx: AnalysisContext,
996-
shared_libraries: list[SharedLibrary],
997+
shared_libraries: list[(SharedLibrary, str)],
997998
link_args: list[LinkArgs]) -> list[DepMetadata]:
998999
"""
9991000
Dedupes the linker metadata for each shared library into a single string.
@@ -1015,7 +1016,7 @@ def _get_shared_library_dep_metadata(
10151016
for args in link_args:
10161017
add_inner_infos(args)
10171018

1018-
for lib in shared_libraries:
1019+
for lib, _ in shared_libraries:
10191020
# Note: refer to SharedLibrary.LinkedObject.link_args here. SharedLibrary.link_args isn't
10201021
# always populated.
10211022
for args in lib.lib.link_args or []:
@@ -1033,7 +1034,7 @@ def _get_shared_library_dep_metadata(
10331034

10341035
def _add_dep_metadata_to_manifest_module(
10351036
ctx: AnalysisContext,
1036-
shared_libraries: list[SharedLibrary],
1037+
shared_libraries: list[(SharedLibrary, str)],
10371038
link_args: list[LinkArgs]) -> dict[str, typing.Any] | None:
10381039
"""
10391040
Updates manifest_module_entries with link metadata if they exist.

Diff for: prelude/python/python_binary.bzl

+6-14
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def _convert_python_library_to_executable(
256256
package_style = get_package_style(ctx)
257257

258258
# Convert preloaded deps to a set of their names to be loaded by.
259-
preload_labels = {_linkable_graph(d).label: None for d in ctx.attrs.preload_deps if _linkable_graph(d)}
259+
preload_labels = set([_linkable_graph(d).label for d in ctx.attrs.preload_deps if _linkable_graph(d)])
260260

261261
extra_artifacts = {}
262262
link_args = []
@@ -284,14 +284,14 @@ def _convert_python_library_to_executable(
284284
shared_libs, extensions = process_omnibus_linking(ctx, deps, extensions, python_toolchain, extra)
285285
else:
286286
shared_libs = [
287-
("", shared_lib)
287+
(shared_lib, "")
288288
for shared_lib in traverse_shared_library_info(library.shared_libraries)
289289
]
290290

291291
# darwin and windows expect self-contained dynamically linked
292292
# python extensions without additional transitive shared libraries
293293
shared_libs += [
294-
("", extension_shared_lib)
294+
(extension_shared_lib, "")
295295
for extension_shared_lib in traverse_shared_library_info(library.extension_shared_libraries)
296296
]
297297

@@ -318,22 +318,13 @@ def _convert_python_library_to_executable(
318318

319319
extra_manifests = create_manifest_for_source_map(ctx, "extra_manifests", extra_artifacts)
320320

321-
# Create the map of native libraries to their artifacts and whether they
322-
# need to be preloaded. Note that we merge preload deps into regular deps
323-
# above, before gathering up all native libraries, so we're guaranteed to
324-
# have all preload libraries (and their transitive deps) here.
325-
shared_libs = [
326-
(libdir, shlib, shlib.label in preload_labels)
327-
for libdir, shlib in shared_libs
328-
]
329-
330321
# Strip native libraries and extensions and update the .gnu_debuglink references if we are extracting
331322
# debug symbols from the par
332323
debuginfo_files = []
333324
debuginfos = {}
334325
if ctx.attrs.strip_libpar == "extract" and package_style == PackageStyle("standalone") and cxx_is_gnu(ctx):
335326
stripped_shlibs = []
336-
for libdir, shlib, preload in shared_libs:
327+
for shlib, libdir in shared_libs:
337328
name = paths.join(
338329
libdir,
339330
value_or(
@@ -360,7 +351,7 @@ def _convert_python_library_to_executable(
360351
dwp = shlib.lib.dwp,
361352
),
362353
)
363-
stripped_shlibs.append((libdir, shlib, preload))
354+
stripped_shlibs.append((shlib, libdir))
364355
debuginfo_files.append(((libdir, shlib, ".debuginfo"), debuginfo))
365356
shared_libs = stripped_shlibs
366357
for name, (extension, label) in extensions.items():
@@ -400,6 +391,7 @@ def _convert_python_library_to_executable(
400391
build_args = build_args,
401392
pex_modules = pex_modules,
402393
shared_libraries = shared_libs,
394+
preload_labels = preload_labels,
403395
main = main,
404396
allow_cache_upload = allow_cache_upload,
405397
debuginfo_files = debuginfo_files,

0 commit comments

Comments
 (0)