@@ -1254,38 +1254,44 @@ def py_executable_base_impl(ctx, *, semantics, is_test, inherited_environment =
12541254
12551255 providers = []
12561256
1257- _add_provider_default_info (providers , ...)
1258- _add_provider_instrumented_files_info (providers , ctx )
1259- _add_provider_run_environment_info (providers , ctx )
1260- _add_provider_py_executable_info (providers , ...)
1261- _add_provider_py_runtime_info (providers , ...)
1262- _add_provider_py_cc_link_params_info (providers , ...)
1263- _add_provider_py_info (providers , ...)
1264- _add_provider_output_group_info (providers , ...)
1265-
1266- return _create_providers (
1267- ctx = ctx ,
1257+ _add_provider_default_info (
1258+ providers ,
1259+ ctx ,
12681260 executable = executable ,
1261+ default_outputs = default_outputs .build (),
12691262 runfiles_details = runfiles_details ,
1270- main_py = main_py ,
1271- imports = imports ,
1263+ )
1264+ _add_provider_instrumented_files_info (providers , ctx )
1265+ _add_provider_run_environment_info (providers , ctx , inherited_environment )
1266+ _add_provider_py_executable_info (
1267+ providers ,
1268+ app_runfiles = app_runfiles ,
1269+ build_data_file = runfiles_details .build_data_file ,
1270+ interpreter_args = ctx .attr .interpreter_args ,
1271+ interpreter_path = runtime_details .executable_interpreter_path ,
1272+ main = main_py ,
1273+ runfiles_without_exe = runfiles_details .runfiles_without_exe ,
1274+ stage2_bootstrap = exec_result .stage2_bootstrap ,
1275+ venv_interpreter_runfiles = exec_result .venv_interpreter_runfiles ,
1276+ venv_interpreter_symlinks = exec_result .venv_interpreter_symlinks ,
1277+ venv_python_exe = exec_result .venv_python_exe ,
1278+ )
1279+ _add_provider_py_runtime_info (providers , runtime_details )
1280+ _add_provider_py_cc_link_params_info (providers , cc_details .cc_info_for_propagating )
1281+ py_info , builtin_py_info = _add_provider_py_info (
1282+ providers ,
1283+ ctx = ctx ,
12721284 original_sources = direct_sources ,
12731285 required_py_files = required_py_files ,
12741286 required_pyc_files = required_pyc_files ,
12751287 implicit_pyc_files = implicit_pyc_files ,
12761288 implicit_pyc_source_files = implicit_pyc_source_files ,
1277- default_outputs = default_outputs .build (),
1278- runtime_details = runtime_details ,
1279- cc_info = cc_details .cc_info_for_propagating ,
1280- inherited_environment = inherited_environment ,
1281- output_groups = exec_result .output_groups ,
1282- stage2_bootstrap = exec_result .stage2_bootstrap ,
1283- app_runfiles = app_runfiles ,
1284- venv_python_exe = exec_result .venv_python_exe ,
1285- venv_interpreter_runfiles = exec_result .venv_interpreter_runfiles ,
1286- venv_interpreter_symlinks = exec_result .venv_interpreter_symlinks ,
1287- interpreter_args = ctx .attr .interpreter_args ,
1289+ imports = imports ,
12881290 )
1291+ _add_provider_output_group_info (providers , py_info , exec_result .output_groups )
1292+
1293+ return providers
1294+
12891295
12901296def _get_build_info (ctx , cc_toolchain ):
12911297 build_info_files = py_internal .cc_toolchain_build_info_files (cc_toolchain )
@@ -1810,98 +1816,66 @@ def _is_tool_config(ctx):
18101816 # a more public API. Until that's available, py_internal to the rescue.
18111817 return py_internal .is_tool_configuration (ctx )
18121818
1813- def _create_providers (
1819+ def _add_provider_default_info (providers , ctx , * , executable , default_outputs , runfiles_details ):
1820+ providers .append (DefaultInfo (
1821+ executable = executable ,
1822+ files = default_outputs ,
1823+ default_runfiles = _py_builtins .make_runfiles_respect_legacy_external_runfiles (
1824+ ctx ,
1825+ runfiles_details .default_runfiles ,
1826+ ),
1827+ data_runfiles = _py_builtins .make_runfiles_respect_legacy_external_runfiles (
1828+ ctx ,
1829+ runfiles_details .data_runfiles ,
1830+ ),
1831+ ))
1832+
1833+ def _add_provider_instrumented_files_info (providers , ctx ):
1834+ providers .append (create_instrumented_files_info (ctx ))
1835+
1836+ def _add_provider_run_environment_info (providers , ctx , inherited_environment ):
1837+ expanded_env = {}
1838+ for key , value in ctx .attr .env .items ():
1839+ expanded_env [key ] = _py_builtins .expand_location_and_make_variables (
1840+ ctx = ctx ,
1841+ attribute_name = "env[{}]" .format (key ),
1842+ expression = value ,
1843+ targets = ctx .attr .data ,
1844+ )
1845+ if "PYTHONBREAKPOINT" not in inherited_environment :
1846+ inherited_environment = inherited_environment + ["PYTHONBREAKPOINT" ]
1847+ providers .append (RunEnvironmentInfo (
1848+ environment = expanded_env ,
1849+ inherited_environment = inherited_environment ,
1850+ ))
1851+
1852+ def _add_provider_py_executable_info (
1853+ providers ,
18141854 * ,
1815- ctx ,
1816- executable ,
1817- main_py ,
1818- original_sources ,
1819- required_py_files ,
1820- required_pyc_files ,
1821- implicit_pyc_files ,
1822- implicit_pyc_source_files ,
1823- default_outputs ,
1824- runfiles_details ,
1825- imports ,
1826- cc_info ,
1827- inherited_environment ,
1828- runtime_details ,
1829- output_groups ,
1830- stage2_bootstrap ,
18311855 app_runfiles ,
1832- venv_python_exe ,
1856+ build_data_file ,
1857+ interpreter_args ,
1858+ interpreter_path ,
1859+ main ,
1860+ runfiles_without_exe ,
1861+ stage2_bootstrap ,
18331862 venv_interpreter_runfiles ,
18341863 venv_interpreter_symlinks ,
1835- interpreter_args ):
1836- """Creates the providers an executable should return.
1837-
1838- Args:
1839- ctx: The rule ctx.
1840- executable: File; the target's executable file.
1841- main_py: File; the main .py entry point.
1842- original_sources: `depset[File]` the direct `.py` sources for the
1843- target that were the original input sources.
1844- required_py_files: `depset[File]` the direct, `.py` sources for the
1845- target that **must** be included by downstream targets. This should
1846- only be Python source files. It should not include pyc files.
1847- required_pyc_files: `depset[File]` the direct `.pyc` files this target
1848- produces.
1849- implicit_pyc_files: `depset[File]` pyc files that are only used if pyc
1850- collection is enabled.
1851- implicit_pyc_source_files: `depset[File]` source files for implicit pyc
1852- files that are used when the implicit pyc files are not.
1853- default_outputs: depset of Files; the files for DefaultInfo.files
1854- runfiles_details: runfiles that will become the default and data runfiles.
1855- imports: depset of strings; the import paths to propagate
1856- cc_info: optional CcInfo; Linking information to propagate as
1857- PyCcLinkParamsInfo. Note that only the linking information
1858- is propagated, not the whole CcInfo.
1859- inherited_environment: list of strings; Environment variable names
1860- that should be inherited from the environment the executuble
1861- is run within.
1862- runtime_details: struct of runtime information; see _get_runtime_details()
1863- output_groups: dict[str, depset[File]]; used to create OutputGroupInfo
1864- stage2_bootstrap: File; the stage 2 bootstrap script.
1865- app_runfiles: runfiles; the runfiles for the application (deps, etc).
1866- venv_python_exe: File; the python executable in the venv.
1867- venv_interpreter_runfiles: runfiles; runfiles specific to the interpreter
1868- for the venv.
1869- venv_interpreter_symlinks: depset[ExplicitSymlink]; interpreter-specific symlinks
1870- to create for the venv.
1871- interpreter_args: list of strings; arguments to pass to the interpreter.
1872-
1873- Returns:
1874- A list of modern providers.
1875- """
1876- providers = [
1877- DefaultInfo (
1878- executable = executable ,
1879- files = default_outputs ,
1880- default_runfiles = _py_builtins .make_runfiles_respect_legacy_external_runfiles (
1881- ctx ,
1882- runfiles_details .default_runfiles ,
1883- ),
1884- data_runfiles = _py_builtins .make_runfiles_respect_legacy_external_runfiles (
1885- ctx ,
1886- runfiles_details .data_runfiles ,
1887- ),
1888- ),
1889- create_instrumented_files_info (ctx ),
1890- _create_run_environment_info (ctx , inherited_environment ),
1891- PyExecutableInfo (
1892- app_runfiles = app_runfiles ,
1893- build_data_file = runfiles_details .build_data_file ,
1894- interpreter_args = interpreter_args ,
1895- interpreter_path = runtime_details .executable_interpreter_path ,
1896- main = main_py ,
1897- runfiles_without_exe = runfiles_details .runfiles_without_exe ,
1898- stage2_bootstrap = stage2_bootstrap ,
1899- venv_interpreter_runfiles = venv_interpreter_runfiles ,
1900- venv_interpreter_symlinks = venv_interpreter_symlinks ,
1901- venv_python_exe = venv_python_exe ,
1902- ),
1903- ]
1864+ venv_python_exe ):
1865+ providers .append (PyExecutableInfo (
1866+ app_runfiles = app_runfiles ,
1867+ build_data_file = build_data_file ,
1868+ interpreter_args = interpreter_args ,
1869+ interpreter_path = interpreter_path ,
1870+ main = main ,
1871+ runfiles_without_exe = runfiles_without_exe ,
1872+ stage2_bootstrap = stage2_bootstrap ,
1873+ venv_interpreter_runfiles = venv_interpreter_runfiles ,
1874+ venv_interpreter_symlinks = venv_interpreter_symlinks ,
1875+ venv_python_exe = venv_python_exe ,
1876+ ))
19041877
1878+ def _add_provider_py_runtime_info (providers , runtime_details ):
19051879 # TODO - The effective runtime can be None for Windows + auto detecting toolchain.
19061880 # This can be removed once that's fixed; see maybe_get_runtime_from_ctx().
19071881 if runtime_details .effective_runtime :
@@ -1928,13 +1902,24 @@ def _create_providers(
19281902 bootstrap_template = py_runtime_info .bootstrap_template ,
19291903 ))
19301904
1905+ def _add_provider_py_cc_link_params_info (providers , cc_info ):
19311906 # TODO(b/163083591): Remove the PyCcLinkParamsInfo once binaries-in-deps
19321907 # are cleaned up.
19331908 if cc_info :
19341909 providers .append (
19351910 PyCcLinkParamsInfo (cc_info = cc_info ),
19361911 )
19371912
1913+ def _add_provider_py_info (
1914+ providers ,
1915+ * ,
1916+ ctx ,
1917+ original_sources ,
1918+ required_py_files ,
1919+ required_pyc_files ,
1920+ implicit_pyc_files ,
1921+ implicit_pyc_source_files ,
1922+ imports ):
19381923 py_info , builtin_py_info = create_py_info (
19391924 ctx ,
19401925 original_sources = original_sources ,
@@ -1944,28 +1929,14 @@ def _create_providers(
19441929 implicit_pyc_source_files = implicit_pyc_source_files ,
19451930 imports = imports ,
19461931 )
1947-
19481932 providers .append (py_info )
19491933 if builtin_py_info :
19501934 providers .append (builtin_py_info )
1935+ return py_info , builtin_py_info
1936+
1937+ def _add_provider_output_group_info (providers , py_info , output_groups ):
19511938 providers .append (create_output_group_info (py_info .transitive_sources , output_groups ))
1952- return providers
19531939
1954- def _create_run_environment_info (ctx , inherited_environment ):
1955- expanded_env = {}
1956- for key , value in ctx .attr .env .items ():
1957- expanded_env [key ] = _py_builtins .expand_location_and_make_variables (
1958- ctx = ctx ,
1959- attribute_name = "env[{}]" .format (key ),
1960- expression = value ,
1961- targets = ctx .attr .data ,
1962- )
1963- if "PYTHONBREAKPOINT" not in inherited_environment :
1964- inherited_environment = inherited_environment + ["PYTHONBREAKPOINT" ]
1965- return RunEnvironmentInfo (
1966- environment = expanded_env ,
1967- inherited_environment = inherited_environment ,
1968- )
19691940
19701941def _add_config_setting_defaults (kwargs ):
19711942 config_settings = kwargs .get ("config_settings" , None )
0 commit comments