From 5e7cf9ffe7e193b00acbc13aa9a1554566a32858 Mon Sep 17 00:00:00 2001 From: Avadhani Jonnavithula Date: Wed, 15 Dec 2021 23:14:28 -0800 Subject: [PATCH 1/2] Upgraded pex version to 2.1.56. Re-arranged positional arguments because Pex is now expecting them in strict order. --- pex/pex_rules.bzl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pex/pex_rules.bzl b/pex/pex_rules.bzl index 341bd469..5cebeb16 100644 --- a/pex/pex_rules.bzl +++ b/pex/pex_rules.bzl @@ -190,6 +190,10 @@ def _pex_binary_impl(ctx): arguments = ["setuptools==44.1.0"] # form the arguments to pex builder + for egg in py.transitive_eggs.to_list(): + arguments += [egg.path] + for req in py.transitive_reqs.to_list(): + arguments += [req] if not ctx.attr.zip_safe: arguments += ["--not-zip-safe"] if not ctx.attr.use_wheels: @@ -206,10 +210,6 @@ def _pex_binary_impl(ctx): arguments += ["--requirement", req_file.path] for repo in repos: arguments += ["--repo", repo] - for egg in py.transitive_eggs.to_list(): - arguments += [egg.path] - for req in py.transitive_reqs.to_list(): - arguments += [req] if main_pkg: arguments += ["--entry-point", main_pkg] elif script: @@ -533,6 +533,6 @@ def pex_repositories(): http_file( name = "pex_bin", executable = True, - urls = ["https://github.com/pantsbuild/pex/releases/download/v2.1.28/pex"], - sha256 = "bfc0add2649bd2d76043ef4ec07edf28aa3bf2654e8ee9b8e39ff5dcffb37665", + urls = ["https://github.com/pantsbuild/pex/releases/download/v2.1.56/pex"], + sha256 = "aff02e2ef0212db4531354e9b7b0d5f61745b3eb49665bc11142f0b603a27db9", ) From c0a6914025260b642d5661788ed96f8311ba4b71 Mon Sep 17 00:00:00 2001 From: Avadhani Jonnavithula Date: Thu, 16 Dec 2021 16:00:33 -0800 Subject: [PATCH 2/2] Added ability to pick up PEX_TMP_DIR from env, to supply as argument to pex through --tmpdir. No longer supply --not-zip-safe argument since its deprecated. The rule will still accept the argument, but it won't do anything. --- pex/pex_rules.bzl | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pex/pex_rules.bzl b/pex/pex_rules.bzl index 5cebeb16..68719250 100644 --- a/pex/pex_rules.bzl +++ b/pex/pex_rules.bzl @@ -163,16 +163,13 @@ def _pex_binary_impl(ctx): ) sources_dir = ctx.actions.declare_directory("{}.sources".format(ctx.attr.name)) - + pex_tmp_dir_provided = ctx.configuration.default_shell_env.get('PEX_TMP_DIR') # Create resource directory and dump files into it # Relocate files according to `strip_prefix` if necessary and get all files into the base resource directory # Cleanup lingering files to prevent them from being added to the pex + # Create tmpdir for pex, if one is provided # Add `__init__.py` files to make the modules findable by pex execution - ctx.actions.run_shell( - mnemonic = "CreateResourceDirectory", - outputs = [sources_dir], - inputs = runfiles.files.to_list(), - command = 'mkdir -p {sources_dir} && rsync -R {transitive_files} {sources_dir} \ + cmd_to_run = 'mkdir -p {sources_dir} && rsync -R {transitive_files} {sources_dir} \ && if [ "{strip_prefix}" != "" ] && [ -n "$(ls -A {sources_dir}/{strip_prefix})" ]; then cp -R {sources_dir}/{strip_prefix}/* {sources_dir}; fi \ && if [ "{strip_prefix}" != "" ]; then rm -rf {sources_dir}/{strip_prefix}; fi \ && if [ -d {sources_dir}/{genfiles_dir}/{strip_prefix} ] && [ -n "$(ls -A {sources_dir}/{genfiles_dir}/{strip_prefix})" ]; then cp -R {sources_dir}/{genfiles_dir}/{strip_prefix}/* {sources_dir}; fi \ @@ -182,8 +179,14 @@ def _pex_binary_impl(ctx): transitive_files = " ".join([file.path for file in runfiles.files.to_list()]), genfiles_dir = ctx.configuration.genfiles_dir.path, genfiles_parent_dir = ctx.configuration.genfiles_dir.path.split("/")[0], - strip_prefix = ctx.attr.strip_prefix.strip("/"), - ), + strip_prefix = ctx.attr.strip_prefix.strip("/")) + if pex_tmp_dir_provided: + cmd_to_run += " && mkdir -p {}".format(pex_tmp_dir_provided) + ctx.actions.run_shell( + mnemonic = "CreateResourceDirectory", + outputs = [sources_dir], + inputs = runfiles.files.to_list(), + command = cmd_to_run, ) pexbuilder = ctx.executable._pexbuilder @@ -194,14 +197,14 @@ def _pex_binary_impl(ctx): arguments += [egg.path] for req in py.transitive_reqs.to_list(): arguments += [req] - if not ctx.attr.zip_safe: - arguments += ["--not-zip-safe"] if not ctx.attr.use_wheels: arguments += ["--no-use-wheel"] if ctx.attr.no_index: arguments += ["--no-index"] if ctx.attr.disable_cache: arguments += ["--disable-cache"] + if pex_tmp_dir_provided: + arguments += ["--tmpdir", pex_tmp_dir_provided] for interpreter in ctx.attr.interpreters: arguments += ["--python", interpreter] for platform in ctx.attr.platforms: