Skip to content

Commit

Permalink
Merge pull request #1589 from dalcinl/source_date_epoch
Browse files Browse the repository at this point in the history
feature: Automatically pass SOURCE_DATE_EPOCH to Linux containers
  • Loading branch information
joerick authored Sep 18, 2023
2 parents 76dba0b + 4f888e2 commit 80a54b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions cibuildwheel/oci_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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
Expand Down
3 changes: 3 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,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"
Expand Down
11 changes: 11 additions & 0 deletions unit_test/oci_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 80a54b0

Please sign in to comment.