File tree 3 files changed +24
-5
lines changed
java/com/google/devtools/build/lib/rules/python
starlark/builtins_bzl/common/python
3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 13
13
// limitations under the License.
14
14
package com .google .devtools .build .lib .rules .python ;
15
15
16
+ import com .google .devtools .build .lib .collect .nestedset .Depset ;
17
+ import net .starlark .java .annot .Param ;
16
18
import net .starlark .java .annot .StarlarkBuiltin ;
19
+ import net .starlark .java .annot .StarlarkMethod ;
17
20
import net .starlark .java .eval .StarlarkValue ;
18
21
19
22
/** Bridge to allow builtins bzl code to call Java code. */
20
23
@ StarlarkBuiltin (name = "py_builtins" , documented = false )
21
24
public abstract class PyBuiltins implements StarlarkValue {
22
25
public static final String NAME = "py_builtins" ;
26
+
27
+ @ StarlarkMethod (
28
+ name = "is_singleton_depset" ,
29
+ doc = "Efficiently checks if the depset is a singleton." ,
30
+ parameters = {
31
+ @ Param (
32
+ name = "value" ,
33
+ positional = true ,
34
+ named = false ,
35
+ defaultValue = "unbound" ,
36
+ doc = "depset to check for being a singleton" )
37
+ })
38
+ public boolean isSingletonDepset (Depset depset ) {
39
+ return depset .getSet ().isSingleton ();
40
+ }
23
41
}
Original file line number Diff line number Diff line change 14
14
"""PYTHON RULE IMPLEMENTATION ONLY: Do not use outside of the rule implementations and their tests.
15
15
16
16
Various builtin Starlark defined objects exposed for non-builtin Starlark.
17
+
18
+ These may change at any time and are closely coupled to the rule implementation.
17
19
"""
18
20
19
21
# This replaces the Java-defined name using exports.bzl toplevels mapping.
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ load(":common/paths.bzl", "paths")
17
17
18
18
_PyRuntimeInfo = _builtins .toplevel .PyRuntimeInfo
19
19
20
+ _py_builtins = _builtins .internal .py_builtins
21
+
20
22
def _py_runtime_impl (ctx ):
21
23
interpreter_path = ctx .attr .interpreter_path or None # Convert empty string to None
22
24
interpreter = ctx .file .interpreter
@@ -38,11 +40,8 @@ def _py_runtime_impl(ctx):
38
40
if ctx .attr .coverage_tool :
39
41
coverage_di = ctx .attr .coverage_tool [DefaultInfo ]
40
42
41
- # TODO(b/254866025): Use a Java helper to call NestedSet.isSingleton
42
- # instead of always flattening to a list
43
- coverage_di_files = coverage_di .files .to_list ()
44
- if len (coverage_di_files ) == 1 :
45
- coverage_tool = coverage_di_files [0 ]
43
+ if _py_builtins .is_singleton_depset (coverage_di .files ):
44
+ coverage_tool = coverage_di .files .to_list ()[0 ]
46
45
elif coverage_di .files_to_run and coverage_di .files_to_run .executable :
47
46
coverage_tool = coverage_di .files_to_run .executable
48
47
else :
You can’t perform that action at this time.
0 commit comments