From 4f888e27c3867b0d04740275afd7a03d71d4df3b Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Sun, 27 Aug 2023 09:45:55 +0300 Subject: [PATCH] feature: Automatically pass SOURCE_DATE_EPOCH to Linux containers Co-authored-by: Joe Rickerby --- cibuildwheel/oci_container.py | 1 + docs/options.md | 3 +++ unit_test/oci_container_test.py | 11 +++++++++++ 3 files changed, 15 insertions(+) diff --git a/cibuildwheel/oci_container.py b/cibuildwheel/oci_container.py index 1ea22edd9..9f080edaa 100644 --- a/cibuildwheel/oci_container.py +++ b/cibuildwheel/oci_container.py @@ -115,6 +115,7 @@ def __enter__(self) -> OCIContainer: self.engine.name, "create", "--env=CIBUILDWHEEL", + "--env=SOURCE_DATE_EPOCH", f"--name={self.name}", "--interactive", "--volume=/:/host", # ignored on CircleCI diff --git a/docs/options.md b/docs/options.md index 8df4e8f25..4fffcb352 100644 --- a/docs/options.md +++ b/docs/options.md @@ -664,6 +664,9 @@ A list of environment variables to pass into the linux container during the buil To specify more than one environment variable, separate the variable names by spaces. +!!! note + cibuildwheel automatically passes the environment variable [`SOURCE_DATE_EPOCH`](https://reproducible-builds.org/docs/source-date-epoch/) if defined. + #### Examples !!! tab examples "Environment passthrough" diff --git a/unit_test/oci_container_test.py b/unit_test/oci_container_test.py index ccbd05555..a4b200d99 100644 --- a/unit_test/oci_container_test.py +++ b/unit_test/oci_container_test.py @@ -72,6 +72,17 @@ def test_environment(container_engine): ) +def test_environment_pass(container_engine, monkeypatch): + monkeypatch.setenv("CIBUILDWHEEL", "1") + monkeypatch.setenv("SOURCE_DATE_EPOCH", "1489957071") + with OCIContainer(engine=container_engine, image=DEFAULT_IMAGE) as container: + assert container.call(["sh", "-c", "echo $CIBUILDWHEEL"], capture_output=True) == "1\n" + assert ( + container.call(["sh", "-c", "echo $SOURCE_DATE_EPOCH"], capture_output=True) + == "1489957071\n" + ) + + def test_cwd(container_engine): with OCIContainer( engine=container_engine, image=DEFAULT_IMAGE, cwd="/cibuildwheel/working_directory"