From bde25c1c1a21f4670fb56ab8111f342f30aca1a9 Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Mon, 4 Dec 2017 14:00:26 -0500 Subject: [PATCH] pex_rules.bzl: Avoid spurious rebuild of virtualenv due to pyc (#57) I noticed that when running anything that used the pex rules for the second time, it would always rebuild pex_wrapper. The cause is that when virtualenv is run, Python creates a .pyc file. The virtualenv target uses a glob of "**/*", which detects a change. After that, it will stay constant. To fix it: exclude .pyc files from the glob. I suspect the Linux sandbox would not cause this error, but on Mac the error can be reproduced as follows: bazel clean --expunge bazel build --subcommands //examples:foo bazel build --subcommands --explain=explain.log //examples:foo The second run will rebuild the target with the explaination: Executing action 'Creating source manifest for @virtualenv//:virtualenv [for host]': action command has changed. Looking at the output of the command shows that the contents of virtualenv.runfiles_manifest has added virtualenv.pyc --- pex/pex_rules.bzl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pex/pex_rules.bzl b/pex/pex_rules.bzl index a8be8e94..a02cd880 100644 --- a/pex/pex_rules.bzl +++ b/pex/pex_rules.bzl @@ -580,7 +580,8 @@ def pex_repositories(): "py_binary(", " name = 'virtualenv',", " srcs = ['virtualenv.py'],", - " data = glob(['**/*']),", + # exclude .pyc: Otherwise bazel detects a change after running virtualenv.py + " data = glob(['**/*'], exclude=['*.pyc']),", " visibility = ['//visibility:public'],", ")", ])