-
Notifications
You must be signed in to change notification settings - Fork 0
Update design with command/script targets #5
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,10 +62,12 @@ before execution, a critical requirement for compatibility with Ninja. | |
|
|
||
| The AST is traversed to construct a canonical, fully resolved Intermediate | ||
| Representation (IR) of the build. This IR represents the build as a static | ||
| dependency graph, with all file paths, commands, and dependencies explicitly | ||
| dependency graph with all file paths, commands, and dependencies explicitly | ||
| defined. During this transformation, Netsuke performs critical validation | ||
| checks, such as verifying the existence of defined rules, detecting circular | ||
| dependencies, and ensuring all required inputs are accounted for. | ||
| checks. It verifies the existence of referenced rules, ensures each rule has | ||
| exactly one of `command` or `script`, and ensures every target specifies | ||
| exactly one of `rule`, `command`, or `script`. Circular dependencies and | ||
| missing inputs are also detected at this stage. | ||
|
|
||
| 5. Stage 5: Ninja Synthesis & Execution | ||
|
|
||
|
|
@@ -162,13 +164,24 @@ top-level keys. | |
|
|
||
| ### 2.3 Defining `rules` | ||
|
|
||
| Each entry in the `rules` list is a mapping that defines a command template. | ||
| Each entry in the `rules` list is a mapping that defines a reusable action. | ||
|
|
||
| - `name`: A unique string identifier for the rule. | ||
|
|
||
| - `command`: The command string to be executed. This string uses placeholders | ||
| like `{ins}` and `{outs}` for input and output files. Netsuke's IR-to-Ninja | ||
| generator will translate these into Ninja's native `$in` and `$out` variables. | ||
| - `command`: A single command string to be executed. This string uses | ||
| placeholders like `{ins}` and `{outs}` for input and output files. Netsuke's | ||
| IR-to-Ninja generator will translate these into Ninja's native `$in` and | ||
| `$out` variables. | ||
|
|
||
| - `script`: A multi-line script declared with the YAML `|` block style. The | ||
| entire block is passed to an interpreter (currently `/bin/sh`). | ||
|
|
||
| Exactly one of `command` or `script` must be provided. The manifest parser | ||
| enforces this rule to prevent invalid states. | ||
|
|
||
| Internally, these options deserialise into a shared `Recipe` enum tagged with | ||
| a `kind` field. Serde aliases ensure manifests that omit the tag continue to | ||
| load correctly. | ||
|
|
||
| - `description`: An optional, user-friendly string that is printed to the | ||
| console when the rule is executed. This maps to Ninja's `description` field | ||
|
|
@@ -190,6 +203,18 @@ Each entry in `targets` defines a build edge; placing a target in the optional | |
| - `rule`: The name of the rule (from the `rules` section) to use for building | ||
| this target. | ||
|
|
||
| - `command`: A single command string to run directly for this target. | ||
|
|
||
| - `script`: A multi-line script passed to the interpreter. When present, it is | ||
| defined using the YAML `|` block style. | ||
|
|
||
| Only one of `rule`, `command`, or `script` may be specified. The parser | ||
| validates this exclusivity during deserialisation. | ||
|
|
||
| This union deserialises into the same `Recipe` enum used for rules. The parser | ||
| enforces that only one variant is present, maintaining backward compatibility | ||
| through serde aliases when `kind` is omitted. | ||
|
|
||
| - `sources`: The input files required by the command. This can be a single | ||
| string or a list of strings. | ||
|
|
||
|
|
@@ -324,18 +349,29 @@ pub struct NetsukeManifest { | |
| #[serde(deny_unknown_fields)] | ||
| pub struct Rule { | ||
| pub name: String, | ||
| pub command: String, | ||
| pub recipe: Recipe, | ||
| pub description: Option<String>, | ||
| pub deps: Option<String>, | ||
| // Additional fields like 'pool' or 'restat' can be added here | ||
| // to map to more advanced Ninja features. | ||
| } | ||
|
|
||
| /// A union of execution styles for both rules and targets. | ||
| #[serde(tag = "kind", rename_all = "lowercase")] | ||
| pub enum Recipe { | ||
| #[serde(alias = "command")] | ||
| Command { command: String }, | ||
| #[serde(alias = "script")] | ||
| Script { script: String }, | ||
| #[serde(alias = "rule")] | ||
| Rule { rule: String }, | ||
| } | ||
|
|
||
| /// Represents a single build target or edge in the dependency graph. | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct Target { | ||
| pub name: StringOrList, | ||
| pub rule: String, | ||
| pub recipe: Recipe, | ||
|
|
||
| #[serde(default)] | ||
| pub sources: StringOrList, | ||
|
|
@@ -358,6 +394,7 @@ pub struct Target { | |
| pub always: bool, | ||
| } | ||
|
|
||
|
|
||
| /// An enum to handle fields that can be either a single string or a list of strings. | ||
| #[serde(untagged)] | ||
| pub enum StringOrList { | ||
|
|
@@ -626,7 +663,7 @@ pub struct BuildGraph { | |
|
|
||
| /// Represents a reusable command, analogous to a Ninja 'rule'. | ||
| pub struct Action { | ||
| pub command: String, | ||
| pub recipe: Recipe, | ||
| pub description: Option<String>, | ||
| pub depfile: Option<String>, // Template for the.d file path, e.g., "$out.d" | ||
| pub deps_format: Option<String>, // "gcc" or "msvc" | ||
|
|
@@ -705,6 +742,10 @@ structures to the Ninja file syntax. | |
| file. The command placeholders (`{ins}`, `{outs}`) are replaced with Ninja's | ||
| variables (`$in`, `$out`). | ||
|
|
||
| When an action's `recipe` is a script, the generated rule wraps the script in | ||
| an invocation of `/bin/sh -e -c` so that multi-line scripts execute | ||
| consistently across platforms. | ||
|
|
||
|
Comment on lines
+745
to
+748
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Wrap explanatory lines to 80 columns The newly added explanation of the 🤖 Prompt for AI Agents |
||
| Code snippet | ||
|
|
||
| ````ninja | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.