MCPcopy Index your code
hub / github.com/nodejs/node / cmake_configure_in

Function cmake_configure_in

tools/prepare_lief.py:54–87  ·  view source on GitHub ↗
(template: str, values: dict)

Source from the content-addressed store, hash-verified

52
53
54def cmake_configure_in(template: str, values: dict) -> str:
55 # Handle @VAR@ replacement and #cmakedefine VAR @VAR@
56 def repl_at(m):
57 var = m.group(1)
58 return str(values.get(var, ""))
59
60 # Replace @VAR@
61 s = re.sub(r"@([A-Za-z0-9_]+)@", repl_at, template)
62
63 # Process #cmakedefine lines
64 out_lines = []
65 for line in s.splitlines():
66 m = re.match(r"\s*#cmakedefine\s+([A-Za-z0-9_]+)\s+(\S+)", line)
67 if m:
68 name = m.group(1)
69 var_token = m.group(2)
70 # var_token was already replaced above (may still be a token if not found)
71 # try to look it up from values if it's still in @VAR@ format
72 val = 0
73 if var_token.startswith("@") and var_token.endswith("@"):
74 key = var_token.strip("@")
75 val = int(values.get(key, 0) or 0)
76 else:
77 try:
78 val = int(var_token)
79 except Exception:
80 val = 0
81 if val:
82 out_lines.append(f"#define {name} {val}")
83 else:
84 out_lines.append(f"/* #undef {name} */")
85 else:
86 out_lines.append(line)
87 return "\n".join(out_lines) + "\n"
88
89
90def write_file(path: Path, content: str):

Callers 1

mainFunction · 0.85

Calls 6

intFunction · 0.85
matchMethod · 0.65
getMethod · 0.65
splitlinesMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…