Create a new dict representing the environment to use. The changes made to the execution environment are printed out.
(updates={})
| 69 | |
| 70 | |
| 71 | def updated_env(updates={}): |
| 72 | """Create a new dict representing the environment to use. |
| 73 | |
| 74 | The changes made to the execution environment are printed out. |
| 75 | """ |
| 76 | env_defaults = {} |
| 77 | # https://reproducible-builds.org/docs/source-date-epoch/ |
| 78 | git_epoch_cmd = ["git", "log", "-1", "--pretty=%ct"] |
| 79 | try: |
| 80 | epoch = subprocess.check_output( |
| 81 | git_epoch_cmd, encoding="utf-8" |
| 82 | ).strip() |
| 83 | env_defaults["SOURCE_DATE_EPOCH"] = epoch |
| 84 | except subprocess.CalledProcessError: |
| 85 | pass # Might be building from a tarball. |
| 86 | # This layering lets SOURCE_DATE_EPOCH from os.environ takes precedence. |
| 87 | environment = env_defaults | os.environ | updates |
| 88 | |
| 89 | env_diff = {} |
| 90 | for key, value in environment.items(): |
| 91 | if os.environ.get(key) != value: |
| 92 | env_diff[key] = value |
| 93 | |
| 94 | env_vars = [ |
| 95 | f"\n {key}={item}" for key, item in sorted(env_diff.items()) |
| 96 | ] |
| 97 | log("🌎", f"Environment changes:{''.join(env_vars)}") |
| 98 | |
| 99 | return environment |
| 100 | |
| 101 | |
| 102 | def subdir(working_dir, *, clean_ok=False): |