Skip to content

Add a reproducibility option for building ecodes.c #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ecodes_c_path = curdir / "src/evdev/ecodes.c"


def create_ecodes(headers=None):
def create_ecodes(headers=None, reproducibility=False):
if not headers:
include_paths = set()
cpath = os.environ.get("CPATH", "").strip()
Expand Down Expand Up @@ -65,7 +65,10 @@ def create_ecodes(headers=None):

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


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

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

def initialize_options(self):
self.evdev_headers = None
self.reproducibility = False

def finalize_options(self):
if self.evdev_headers:
self.evdev_headers = self.evdev_headers.split(":")
if self.reproducibility is None:
self.reproducibility = False

def run(self):
create_ecodes(self.evdev_headers)
create_ecodes(self.evdev_headers, reproducibility=self.reproducibility)


class build_ext(_build_ext.build_ext):
Expand Down
17 changes: 11 additions & 6 deletions src/evdev/genecodes_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@
"/usr/include/linux/uinput.h",
]

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

if args:
headers = args

reproducibility = ("--reproducibility", "") in opts


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

# Uname without hostname.
uname = list(os.uname())
uname = " ".join((uname[0], *uname[2:]))
if reproducibility:
uname = "hidden for reproducibility"
else:
# Uname without hostname.
uname = list(os.uname())
uname = " ".join((uname[0], *uname[2:]))


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -138,5 +143,5 @@ def parse_headers(headers=headers):
template = template_stubs

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