diff --git a/scripts/extract_configure.py b/scripts/extract_configure.py index 711ca55..22a6cb3 100644 --- a/scripts/extract_configure.py +++ b/scripts/extract_configure.py @@ -88,7 +88,10 @@ def parse_configure_trace( e = json.loads(line) except json.JSONDecodeError: continue - if e.get("cmd") != "configure_file": + # CMake command names are case-insensitive, and the trace reports + # the spelling used in the CMakeLists (large projects commonly + # write CONFIGURE_FILE); match either. + if (e.get("cmd") or "").lower() != "configure_file": continue args = [a for a in e.get("args", []) if a] if len(args) < 2: diff --git a/tests/test_configure.py b/tests/test_configure.py index 704abb8..9273b52 100644 --- a/tests/test_configure.py +++ b/tests/test_configure.py @@ -90,6 +90,27 @@ def test_options_captured(): assert cfs[0].options == ("@ONLY",) +def test_uppercase_command_spelling_is_matched(): + # CMake commands are case-insensitive and the trace keeps the spelling the + # CMakeLists used; CONFIGURE_FILE and Configure_File are the same command. + upper = dict(_cf(f"{SRC}/my_config.h.cmake", f"{BUILD}/my_config.h"), + cmd="CONFIGURE_FILE") + mixed = dict(_cf(f"{SRC}/version.h.in", f"{BUILD}/version.h"), + cmd="Configure_File") + t = _trace(upper, mixed, _cf(f"{SRC}/zconf.h.cmakein", f"{BUILD}/zconf.h")) + cfs = parse_configure_trace(t, SRC, BUILD, include_dirs=[BUILD]) + os.unlink(t) + assert sorted(c.name for c in cfs) == ["my_config.h", "version.h", "zconf.h"] + + +def test_other_commands_are_ignored(): + t = _trace({"cmd": "file", "args": ["WRITE", f"{BUILD}/x.h", "y"]}, + {"cmd": "CONFIGURE_FILE_EXTRA", "args": [f"{SRC}/a.in", f"{BUILD}/a.h"]}) + cfs = parse_configure_trace(t, SRC, BUILD, include_dirs=[BUILD]) + os.unlink(t) + assert cfs == [] + + def test_no_include_dirs_means_not_compile_input(): # without include dirs we cannot assert compile-input status -> False (we do # not guess); the file is still recorded.