Follow Makefile includes when completing make targets#275
Open
maxmilian wants to merge 1 commit into
Open
Conversation
4 tasks
5cf3bb0 to
adb42f0
Compare
The `make` `list_targets` generator ran `cat [Mm]akefile`, which reads only the top-level Makefile, so targets defined in files pulled in via `include`/`-include`/`sinclude` were never suggested (warpdotdev/warp#11705). Replace the command with a self-contained awk program that echoes the root Makefile and recurses into included files, using a `seen` set to guard against include cycles. Included paths are opened directly with `getline` rather than interpolated into a shell command, so a Makefile cannot inject commands. The behavior is identical across sh/bash/zsh because all parsing happens inside awk, not via shell word-splitting. awk output is captured and only emitted on a clean exit; otherwise the command falls back to `cat [Mm]akefile`. This keeps top-level targets working when an `include` points at a real directory (an invalid Makefile that aborts some awk builds with an i/o error) instead of returning nothing. Glob (`include dir/*.mk`) and variable (`include $(VAR)`) include paths are intentionally left unresolved. Add end-to-end tests that run the generator command against temp projects: one with targets split across a nested include and a missing optional include (also asserting `##` descriptions survive), and one with a directory include to lock in the fallback.
adb42f0 to
1c60a56
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes warpdotdev/warp#11705.
makeTab-completion only suggested targets defined directly in the top-level Makefile; targets pulled in throughincludedirectives were invisible (other terminals show them, since GNU make treats included files as one unified ruleset).Root cause
The
makelist_targetsgenerator (command-signatures/src/generators/make.rs) rancat [Mm]akefile, which reads only the root Makefile and never followsinclude/-include/sincludedirectives.Fix
Replace the command with a single self-contained
awkprogram that echoes the root Makefile and recurses into included files, with aseenset guarding against include cycles. Design choices:sh/bash/zshdiffer in word-splitting and this sidesteps that entirely.getline < path, never interpolated into a shell command, so a malicious Makefile can't inject commands.cat [Mm]akefile. Anincludepointing at a real directory (an invalid Makefile thatmakeitself rejects) aborts some awk builds with an i/o error — the fallback keeps top-level targets working instead of returning nothing.The Rust
post_process(target +##description parsing) is unchanged.Tests
Two end-to-end tests run the actual generator command via
sh -cagainst temp projects:test_list_targets_command_follows_includes— targets split across a nested include + a missing optional-include; also asserts a##description defined in an included file survives.test_list_targets_command_survives_directory_include— a directoryincludestill succeeds and falls back to top-level targets.cargo fmt --check,cargo clippy --all-targets --all-features -- -D warnings, andcargo testall pass locally (61 tests).Scope / known limitations
Include paths that rely on globbing (
include dir/*.mk) or make variables (include $(VAR)) are intentionally left unresolved — expanding them safely would require either a shell (injection risk) or evaluating the Makefile. Explicit file paths (the reported case and the common case) and arbitrarily nested includes are handled.