Skip to content

Commit

Permalink
perf: change js_helpers gather_* utils to accept list, not depset
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Jun 10, 2024
1 parent 3d5b0cc commit a7f1b74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion js/private/js_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [],

runfiles = gather_runfiles(
ctx = ctx,
sources = [],
sources = depset(),
data = ctx.attr.data,
data_files = [entry_point] + ctx.files.data,
deps = [],
Expand Down
16 changes: 5 additions & 11 deletions js/private/js_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,35 @@ def gather_transitive_sources(sources, targets):
"""Gathers transitive sources from a list of direct sources and targets
Args:
sources: list or depset of direct sources which should be included in `transitive_sources`
sources: list of direct sources which should be included in `transitive_sources`
targets: list of targets to gather `transitive_sources` from `JsInfo`
Returns:
A depset of transitive sources
"""
if type(sources) == "list":
sources = depset(sources)
transitive = [
target[JsInfo].transitive_sources
for target in targets
if JsInfo in target and hasattr(target[JsInfo], "transitive_sources")
]
return depset([], transitive = [sources] + transitive)
return depset(sources, transitive = transitive)

def gather_transitive_types(types, targets):
"""Gathers transitive types from a list of direct types and targets
Args:
types: list or depset of direct sources which should be included in `transitive_types`
types: list of direct sources which should be included in `transitive_types`
targets: list of targets to gather `transitive_types` from `JsInfo`
Returns:
A depset of transitive sources
"""
if type(types) == "list":
types = depset(types)
transitive = [
target[JsInfo].transitive_types
for target in targets
if JsInfo in target and hasattr(target[JsInfo], "transitive_types")
]
return depset([], transitive = [types] + transitive)
return depset(types, transitive = transitive)

def gather_npm_sources(srcs, deps):
"""Gathers npm sources from a list of srcs and deps targets
Expand Down Expand Up @@ -138,7 +134,7 @@ def gather_runfiles(
Args:
ctx: the rule context
sources: list or depset of files which should be included in runfiles
sources: depset which should be included in runfiles
deps: list of dependency targets; only transitive runfiles are gather from these targets
Expand Down Expand Up @@ -177,8 +173,6 @@ def gather_runfiles(
"""

# Includes sources
if type(sources) == "list":
sources = depset(sources)
transitive_files_depsets = [sources]

# Gather the default outputs of data targets
Expand Down

0 comments on commit a7f1b74

Please sign in to comment.