MCPcopy Create free account
hub / github.com/FastLED/FastLED / main

Function main

ci/hooks/rust_tool_guard.py:136–193  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134
135
136def main() -> int:
137 try:
138 payload = json.load(sys.stdin)
139 except json.JSONDecodeError:
140 return 0
141
142 if payload.get("tool_name") != "Bash":
143 return 0
144
145 tool_input = payload.get("tool_input", {})
146 command = tool_input.get("command")
147 if not isinstance(command, str) or not command.strip():
148 return 0
149
150 # Override check: command-prefixed or process env.
151 _, command_env_vars = strip_env_prefix(command)
152 override_in_command = command_env_vars.get(OVERRIDE_ENV_VAR, "") in (
153 "1",
154 "true",
155 "True",
156 "TRUE",
157 )
158 override_in_env = os.environ.get(OVERRIDE_ENV_VAR, "") in (
159 "1",
160 "true",
161 "True",
162 "TRUE",
163 )
164 if override_in_command or override_in_env:
165 return 0
166
167 matched = _matches_rust_tool(command)
168 if not matched:
169 return 0
170
171 # Build the suggested rewrite: prefix the offending token with soldr.
172 # We can't safely rewrite mid-chain commands (quoting, subshells),
173 # so emit guidance instead of an exact substitution.
174 rest_no_env, _ = strip_env_prefix(command.lstrip())
175 if re.match(rf"{re.escape(matched)}(\s|$)", rest_no_env):
176 suggested = f"soldr {rest_no_env}"
177 else:
178 suggested = (
179 f"replace each `{matched} …` invocation in this chain with "
180 f"`soldr {matched} …`"
181 )
182
183 msg = (
184 f"Bare `{matched}` invocation is blocked: must run through "
185 f"`soldr {matched}` so zccache + soldr's target-tree cache fire "
186 f"(turns multi-minute cold builds into seconds-long warm hits).\n"
187 f" Try: {suggested}\n"
188 f" Background: FastLED #2871, FastLED/fbuild#429.\n"
189 f" Override (sparingly — `--version`, capability probes, non-Rust "
190 f"shell scripts that shadow the name): {OVERRIDE_ENV_VAR}=1 {command}"
191 )
192 print(msg, file=sys.stderr)
193 return 2

Callers 1

rust_tool_guard.pyFile · 0.70

Calls 5

strip_env_prefixFunction · 0.85
_matches_rust_toolFunction · 0.85
printFunction · 0.50
loadMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected