Skip to content

Commit 6b4e8ef

Browse files
Add a reproducibility option for building ecodes.c (#242)
ecodes.c currently contains the kernel info of the build machine and the full path of the input*.h headers: This is not reproducible as output can change even is headers content do not. Downstream distributions might package ecodes.c and get non-reproducible output. To fix this: introduce a --reproducible option in the build: - in setup.py build_ecodes command - in underlying genecodes_c.py Note: These options are disabled by default so no change is expected in current builds. Signed-off-by: Yoann Congal <[email protected]>
1 parent 5f9fd2c commit 6b4e8ef

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

setup.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ecodes_c_path = curdir / "src/evdev/ecodes.c"
1515

1616

17-
def create_ecodes(headers=None):
17+
def create_ecodes(headers=None, reproducibility=False):
1818
if not headers:
1919
include_paths = set()
2020
cpath = os.environ.get("CPATH", "").strip()
@@ -65,7 +65,10 @@ def create_ecodes(headers=None):
6565

6666
print("writing %s (using %s)" % (ecodes_c_path, " ".join(headers)))
6767
with ecodes_c_path.open("w") as fh:
68-
cmd = [sys.executable, "src/evdev/genecodes_c.py", "--ecodes", *headers]
68+
cmd = [sys.executable, "src/evdev/genecodes_c.py"]
69+
if reproducibility:
70+
cmd.append("--reproducibility")
71+
cmd.extend(["--ecodes", *headers])
6972
run(cmd, check=True, stdout=fh)
7073

7174

@@ -74,17 +77,21 @@ class build_ecodes(Command):
7477

7578
user_options = [
7679
("evdev-headers=", None, "colon-separated paths to input subsystem headers"),
80+
("reproducibility", None, "hide host details (host/paths) to create a reproducible output"),
7781
]
7882

7983
def initialize_options(self):
8084
self.evdev_headers = None
85+
self.reproducibility = False
8186

8287
def finalize_options(self):
8388
if self.evdev_headers:
8489
self.evdev_headers = self.evdev_headers.split(":")
90+
if self.reproducibility is None:
91+
self.reproducibility = False
8592

8693
def run(self):
87-
create_ecodes(self.evdev_headers)
94+
create_ecodes(self.evdev_headers, reproducibility=self.reproducibility)
8895

8996

9097
class build_ext(_build_ext.build_ext):

src/evdev/genecodes_c.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,27 @@
1515
"/usr/include/linux/uinput.h",
1616
]
1717

18-
opts, args = getopt.getopt(sys.argv[1:], "", ["ecodes", "stubs"])
18+
opts, args = getopt.getopt(sys.argv[1:], "", ["ecodes", "stubs", "reproducibility"])
1919
if not opts:
20-
print("usage: genecodes.py [--ecodes|--stubs] <headers>")
20+
print("usage: genecodes.py [--ecodes|--stubs] [--reproducibility] <headers>")
2121
exit(2)
2222

2323
if args:
2424
headers = args
2525

26+
reproducibility = ("--reproducibility", "") in opts
27+
2628

2729
# -----------------------------------------------------------------------------
2830
macro_regex = r"#define\s+((?:KEY|ABS|REL|SW|MSC|LED|BTN|REP|SND|ID|EV|BUS|SYN|FF|UI_FF|INPUT_PROP)_\w+)"
2931
macro_regex = re.compile(macro_regex)
3032

31-
# Uname without hostname.
32-
uname = list(os.uname())
33-
uname = " ".join((uname[0], *uname[2:]))
33+
if reproducibility:
34+
uname = "hidden for reproducibility"
35+
else:
36+
# Uname without hostname.
37+
uname = list(os.uname())
38+
uname = " ".join((uname[0], *uname[2:]))
3439

3540

3641
# -----------------------------------------------------------------------------
@@ -138,5 +143,5 @@ def parse_headers(headers=headers):
138143
template = template_stubs
139144

140145
body = os.linesep.join(body)
141-
text = template % (uname, headers, body)
146+
text = template % (uname, headers if not reproducibility else ["hidden for reproducibility"], body)
142147
print(text.strip())

0 commit comments

Comments
 (0)