-
Notifications
You must be signed in to change notification settings - Fork 2
fix(env): stop shipping the development profile #666
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,20 @@ use std::path::Path; | |
| use std::process::Command; | ||
|
|
||
| /// Embed `apps/native/env.{development,release,e2e}.json` selected by `NIXMAC_ENV`. | ||
| /// | ||
| /// Accepted values must stay in sync with `apps/native/nixmac-profile.ts`. | ||
| /// Unset means development; anything else stops the build rather than falling | ||
| /// through to the development profile. | ||
| fn embed_build_profile() { | ||
| let native_app_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join(".."); | ||
| let profile = std::env::var("NIXMAC_ENV").unwrap_or_else(|_| "development".to_string()); | ||
| let file = match profile.as_str() { | ||
| "prod" | "production" => "env.release.json", | ||
| let selector = std::env::var("NIXMAC_ENV").unwrap_or_else(|_| "development".to_string()); | ||
| let file = match selector.as_str() { | ||
| "development" => "env.development.json", | ||
| "production" => "env.release.json", | ||
| "e2e" => "env.e2e.json", | ||
| _ => "env.development.json", | ||
| other => { | ||
| panic!("NIXMAC_ENV must be unset or one of development, production, e2e; got {other:?}") | ||
| } | ||
| }; | ||
| let path = native_app_dir.join(file); | ||
|
|
||
|
|
@@ -25,11 +32,30 @@ fn embed_build_profile() { | |
| ); | ||
| } | ||
|
|
||
| let json = std::fs::read_to_string(&path).unwrap_or_else(|_| "{}".to_string()); | ||
| let minified = serde_json::from_str::<serde_json::Value>(&json) | ||
| .ok() | ||
| .and_then(|value| serde_json::to_string(&value).ok()) | ||
| .unwrap_or_else(|| "{}".to_string()); | ||
| // An unreadable or malformed profile stops the build. Degrading to "{}" | ||
| // compiles an app whose every setting silently falls back to its default. | ||
| let json = std::fs::read_to_string(&path) | ||
| .unwrap_or_else(|error| panic!("cannot read {}: {error}", path.display())); | ||
| let value: serde_json::Value = serde_json::from_str(&json) | ||
| .unwrap_or_else(|error| panic!("cannot parse {}: {error}", path.display())); | ||
| // The selector picks the file; the file names the same environment in its own | ||
|
Collaborator
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. After seeing related comments in several places I wonder if maybe they should just all be consolidated to a single location in README or another md file as design documentation.
Contributor
Author
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. I'm more afraid of those docs becoming stale |
||
| // `NIXMAC_ENV` key. That key is what `crate::env::nixmac_env()` reports for | ||
| // telemetry and the startup log, unless `NIXMAC_ENV` is set in the running | ||
| // process, which takes precedence over the embed. A profile mislabelled | ||
| // `development` would therefore have a release build report itself as a | ||
| // development one. The frontend is baked from its own copy of the profile | ||
| // and makes the same check there (`apps/native/nixmac-profile.ts`). | ||
| let declared = value.get("NIXMAC_ENV"); | ||
| if declared.and_then(serde_json::Value::as_str) != Some(selector.as_str()) { | ||
| panic!( | ||
| "{} declares NIXMAC_ENV {}, but this build selected {selector:?}; the two must name the same environment", | ||
| path.display(), | ||
| declared.map_or_else(|| "no value at all".to_string(), ToString::to_string) | ||
| ); | ||
| } | ||
|
|
||
| let minified = serde_json::to_string(&value) | ||
| .unwrap_or_else(|error| panic!("cannot re-encode {}: {error}", path.display())); | ||
| println!("cargo:rustc-env=NIXMAC_ENV_PROFILE_JSON={minified}"); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another comment that can probably be cut down to just what's needed later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've adjusted the comments to focus on the future maintenance