-
Notifications
You must be signed in to change notification settings - Fork 0
Separate Ninja generation steps from runner reporting (#343) #374
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
Open
leynos
wants to merge
7
commits into
main
Choose a base branch
from
issue-343-pure-ninja-generation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9163f45
Separate Ninja generation steps from runner reporting (#343)
leynos cc6c21e
Document runner generation reuse boundary (#343)
leynos 7367568
Document generation-step composition (#343)
leynos 9c5f93e
Enforce pure runner generation boundaries (#343)
leynos f6fd127
Add public generation reporting coverage (#343)
leynos 0d5111a
Remove duplicate runner stage callback (#343)
leynos 8206ea8
Isolate packaging smoke Cargo artefacts (#343)
leynos 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 |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| //! Query-style Ninja-generation steps and the build manifest loader. | ||
| //! | ||
| //! Generation decomposes into three query-style steps — load the manifest, | ||
| //! build the graph, generate the Ninja text — none of which require a status | ||
| //! reporter. Progress reporting stays in the thin orchestration wrappers in | ||
| //! [`super`] (`generate_ninja`, | ||
| //! `load_manifest_with_stage_reporting`), so generation can be reused as a | ||
| //! pure operation (for example for dry runs or background generation). | ||
| //! | ||
| //! [`load_manifest`] is the read-only query step: it rejects template helpers | ||
| //! that can access the environment, filesystem, network, clock, or shell. | ||
| //! [`load_manifest_for_build`] is deliberately separate because command | ||
| //! execution needs the full, effectful manifest stdlib. | ||
|
|
||
| use anyhow::{Context, Result}; | ||
| use camino::Utf8Path; | ||
|
|
||
| use crate::ast::NetsukeManifest; | ||
| use crate::ir::BuildGraph; | ||
| use crate::localization::{self, keys}; | ||
| use crate::stdlib::NetworkPolicy; | ||
| use crate::{manifest, ninja_gen}; | ||
|
|
||
| /// Optional observer for manifest-loading stages. | ||
| /// | ||
| /// Callers that want progress reporting pass a callback translating | ||
| /// [`manifest::ManifestLoadStage`] values into their own reporting; passing | ||
| /// `None` keeps the pipeline free of side effects. | ||
| pub(super) type StageObserver<'a> = Option<&'a mut dyn FnMut(manifest::ManifestLoadStage)>; | ||
|
|
||
| /// Load and render the Netsuke manifest at `path` without effectful helpers. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```rust,ignore | ||
| /// let manifest = load_manifest(Utf8Path::new("Netsukefile"), None)?; | ||
| /// // `manifest` is rendered and ready for `build_graph`. | ||
| /// ``` | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error when the manifest cannot be read, parsed, or rendered. | ||
| pub(super) fn load_manifest( | ||
| path: &Utf8Path, | ||
| on_stage: StageObserver<'_>, | ||
| ) -> Result<NetsukeManifest> { | ||
| manifest::from_path_for_manifest_query(path.as_std_path(), on_stage).with_context(|| { | ||
| localization::message(keys::RUNNER_CONTEXT_LOAD_MANIFEST).with_arg("path", path.as_str()) | ||
| }) | ||
| } | ||
|
|
||
| /// Load and render a manifest with the full, effectful build stdlib. | ||
| /// | ||
| /// This loader is only for command execution. Templates may use configured | ||
| /// network, cache, environment, filesystem, clock, and shell helpers. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```rust,ignore | ||
| /// let manifest = load_manifest_for_build( | ||
| /// Utf8Path::new("Netsukefile"), | ||
| /// NetworkPolicy::default(), | ||
| /// None, | ||
| /// )?; | ||
| /// // `manifest` may use build-time template helpers before `build_graph`. | ||
| /// ``` | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error when the manifest cannot be read, parsed, or rendered. | ||
| pub(super) fn load_manifest_for_build( | ||
| path: &Utf8Path, | ||
| policy: NetworkPolicy, | ||
| on_stage: StageObserver<'_>, | ||
| ) -> Result<NetsukeManifest> { | ||
| manifest::from_path_with_policy(path.as_std_path(), policy, on_stage).with_context(|| { | ||
| localization::message(keys::RUNNER_CONTEXT_LOAD_MANIFEST).with_arg("path", path.as_str()) | ||
| }) | ||
| } | ||
|
|
||
| /// Translate a manifest into the build graph intermediate representation. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```rust,ignore | ||
| /// let graph = build_graph(&manifest)?; | ||
| /// // `graph` contains the validated targets and actions for `ninja_text`. | ||
| /// ``` | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error when graph construction or validation fails (for example | ||
| /// on circular dependencies or duplicate outputs). | ||
| pub(super) fn build_graph(manifest: &NetsukeManifest) -> Result<BuildGraph> { | ||
| BuildGraph::from_manifest(manifest) | ||
| .context(localization::message(keys::RUNNER_CONTEXT_BUILD_GRAPH)) | ||
| } | ||
|
|
||
| /// Generate the Ninja bundle for a build graph. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```rust,ignore | ||
| /// let generated = ninja_text(&graph)?; | ||
| /// let (text, sidecars) = generated.into_parts(); | ||
| /// assert!(text.contains("build hello:")); | ||
| /// assert!(sidecars.is_empty()); | ||
| /// ``` | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error when Ninja synthesis fails. | ||
| pub(super) fn ninja_text( | ||
| graph: &BuildGraph, | ||
| ) -> Result<ninja_gen::GeneratedNinja, ninja_gen::NinjaGenError> { | ||
| ninja_gen::generate_bundle(graph) | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.