runner: centralize resolve env flags
This commit is contained in:
16
src/config/env/using_flags.rs
vendored
16
src/config/env/using_flags.rs
vendored
@ -3,6 +3,7 @@
|
||||
//! This module groups all `using` system and namespace flags.
|
||||
//! Use this for IDE autocomplete to discover using/namespace flags easily.
|
||||
|
||||
use super::env_bool;
|
||||
use super::warn_alias_once;
|
||||
|
||||
pub fn enable_using() -> bool {
|
||||
@ -68,3 +69,18 @@ pub fn using_ast_enabled() -> bool {
|
||||
_ => !using_is_prod(), // dev/ci → true, prod → false
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Using/resolve diagnostics ----
|
||||
pub fn resolve_trace() -> bool {
|
||||
env_bool("NYASH_RESOLVE_TRACE")
|
||||
}
|
||||
|
||||
pub fn resolve_seam_debug() -> bool {
|
||||
env_bool("NYASH_RESOLVE_SEAM_DEBUG")
|
||||
}
|
||||
|
||||
pub fn resolve_dump_merged_path() -> Option<String> {
|
||||
std::env::var("NYASH_RESOLVE_DUMP_MERGED")
|
||||
.ok()
|
||||
.filter(|s| !s.is_empty())
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ impl<'a> PreludeManagerBox<'a> {
|
||||
filename: &str,
|
||||
prelude_paths: &[String],
|
||||
) -> Result<MergeResult, String> {
|
||||
let trace = std::env::var("NYASH_RESOLVE_TRACE").ok().as_deref() == Some("1");
|
||||
let trace = crate::config::env::resolve_trace();
|
||||
|
||||
if prelude_paths.is_empty() {
|
||||
return Ok(MergeResult {
|
||||
@ -83,7 +83,7 @@ impl<'a> PreludeManagerBox<'a> {
|
||||
filename: &str,
|
||||
prelude_paths: &[String],
|
||||
) -> Result<MergeResult, String> {
|
||||
let trace = std::env::var("NYASH_RESOLVE_TRACE").ok().as_deref() == Some("1");
|
||||
let trace = crate::config::env::resolve_trace();
|
||||
|
||||
if prelude_paths.is_empty() {
|
||||
return Ok(MergeResult {
|
||||
@ -154,7 +154,7 @@ impl<'a> PreludeManagerBox<'a> {
|
||||
}
|
||||
|
||||
// デバッグモードなら境界マーカーを追加
|
||||
if std::env::var("NYASH_RESOLVE_SEAM_DEBUG").ok().as_deref() == Some("1") {
|
||||
if crate::config::env::resolve_seam_debug() {
|
||||
merged.push_str("\n/* --- using prelude/main boundary --- */\n\n");
|
||||
// boundary line(s) are attributed to a synthetic "<boundary>" pseudo-file
|
||||
let boundary_lines = 3usize;
|
||||
@ -217,8 +217,8 @@ impl<'a> PreludeManagerBox<'a> {
|
||||
|
||||
// `}` の前の `;` を除去(複数回パス)
|
||||
for _ in 0..2 {
|
||||
let mut tmp = String::with_capacity(out.len());
|
||||
let bytes = out.as_bytes();
|
||||
let mut tmp: Vec<u8> = Vec::with_capacity(bytes.len());
|
||||
let mut i = 0usize;
|
||||
|
||||
while i < bytes.len() {
|
||||
@ -239,10 +239,10 @@ impl<'a> PreludeManagerBox<'a> {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
tmp.push(bytes[i] as char);
|
||||
tmp.push(bytes[i]);
|
||||
i += 1;
|
||||
}
|
||||
out = tmp;
|
||||
out = String::from_utf8(tmp).expect("normalize_text_for_inline: invalid UTF-8");
|
||||
}
|
||||
|
||||
// ファイル末尾に改行を追加
|
||||
|
||||
@ -94,8 +94,8 @@ impl<'a> SelfhostPipelineBox<'a> {
|
||||
PipelineConfig {
|
||||
enable_using: crate::config::env::enable_using(),
|
||||
enable_ast_merge: crate::config::env::using_ast_enabled(),
|
||||
trace_execution: std::env::var("NYASH_RESOLVE_TRACE").ok().as_deref() == Some("1"),
|
||||
debug_mode: std::env::var("NYASH_RESOLVE_SEAM_DEBUG").ok().as_deref() == Some("1"),
|
||||
trace_execution: crate::config::env::resolve_trace(),
|
||||
debug_mode: crate::config::env::resolve_seam_debug(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ pub fn merge_prelude_text(
|
||||
source: &str,
|
||||
filename: &str,
|
||||
) -> Result<String, String> {
|
||||
let trace = crate::config::env::env_bool("NYASH_RESOLVE_TRACE");
|
||||
let trace = crate::config::env::resolve_trace();
|
||||
|
||||
// First pass: collect and resolve prelude paths
|
||||
let (cleaned_main, prelude_paths) = resolve_prelude_paths_profiled(runner, source, filename)?;
|
||||
@ -122,7 +122,7 @@ pub fn merge_prelude_text(
|
||||
}
|
||||
|
||||
// Add boundary marker if debug mode
|
||||
if crate::config::env::env_bool("NYASH_RESOLVE_SEAM_DEBUG") {
|
||||
if crate::config::env::resolve_seam_debug() {
|
||||
merged.push_str("\n/* --- using prelude/main boundary --- */\n\n");
|
||||
let boundary_lines = 3usize;
|
||||
spans.push(crate::runner::modes::common_util::resolve::LineSpan {
|
||||
@ -165,10 +165,8 @@ pub fn merge_prelude_text(
|
||||
}
|
||||
|
||||
// Optional dump of merged text for diagnostics
|
||||
if let Ok(dump_path) = std::env::var("NYASH_RESOLVE_DUMP_MERGED") {
|
||||
if !dump_path.is_empty() {
|
||||
let _ = std::fs::write(&dump_path, &merged);
|
||||
}
|
||||
if let Some(dump_path) = crate::config::env::resolve_dump_merged_path() {
|
||||
let _ = std::fs::write(&dump_path, &merged);
|
||||
}
|
||||
|
||||
crate::runner::modes::common_util::resolve::set_last_text_merge_line_spans(spans);
|
||||
|
||||
@ -53,7 +53,7 @@ fn apply_using_strip_plan(
|
||||
out.push('\n');
|
||||
}
|
||||
// Optional prelude boundary comment (helps manual inspection; parser ignores comments)
|
||||
if crate::config::env::env_bool("NYASH_RESOLVE_SEAM_DEBUG") {
|
||||
if crate::config::env::resolve_seam_debug() {
|
||||
let mut with_marker = String::with_capacity(out.len() + 64);
|
||||
with_marker.push_str("\n/* --- using boundary (AST) --- */\n");
|
||||
with_marker.push_str(&out);
|
||||
@ -70,8 +70,7 @@ fn plan_using_strip(
|
||||
let using_ctx = runner.init_using_context();
|
||||
let prod = crate::config::env::using_is_prod();
|
||||
let strict = crate::config::env::env_bool("NYASH_USING_STRICT");
|
||||
let verbose =
|
||||
crate::config::env::cli_verbose() || crate::config::env::env_bool("NYASH_RESOLVE_TRACE");
|
||||
let verbose = crate::config::env::cli_verbose() || crate::config::env::resolve_trace();
|
||||
let ctx_dir = std::path::Path::new(filename).parent();
|
||||
|
||||
let mut kept_lines: Vec<String> = Vec::new();
|
||||
@ -154,10 +153,10 @@ fn plan_using_strip(
|
||||
p = cand;
|
||||
}
|
||||
}
|
||||
// Also try NYASH_ROOT when available (repo-root relative like "apps/...")
|
||||
// Also try repo root when available (repo-root relative like "apps/...")
|
||||
if p.is_relative() {
|
||||
if let Ok(root) = std::env::var("NYASH_ROOT") {
|
||||
let cand = std::path::Path::new(&root).join(&p);
|
||||
if let Some(root) = crate::runner::modes::common_util::resolve::root::resolve_repo_root(Some(filename)) {
|
||||
let cand = root.join(&p);
|
||||
if cand.exists() {
|
||||
p = cand;
|
||||
}
|
||||
@ -459,22 +458,20 @@ fn plan_using_strip(
|
||||
}
|
||||
}
|
||||
if p.is_relative() {
|
||||
if let Ok(root) = std::env::var("NYASH_ROOT") {
|
||||
let cand = std::path::Path::new(&root).join(&p);
|
||||
if let Some(root) = crate::runner::modes::common_util::resolve::root::resolve_repo_root(Some(filename)) {
|
||||
let cand = root.join(&p);
|
||||
if cand.exists() {
|
||||
p = cand;
|
||||
}
|
||||
} else {
|
||||
if let Ok(exe) = std::env::current_exe() {
|
||||
if let Some(root) = exe
|
||||
.parent()
|
||||
.and_then(|p| p.parent())
|
||||
.and_then(|p| p.parent())
|
||||
{
|
||||
let cand = root.join(&p);
|
||||
if cand.exists() {
|
||||
p = cand;
|
||||
}
|
||||
} else if let Ok(exe) = std::env::current_exe() {
|
||||
if let Some(root) = exe
|
||||
.parent()
|
||||
.and_then(|p| p.parent())
|
||||
.and_then(|p| p.parent())
|
||||
{
|
||||
let cand = root.join(&p);
|
||||
if cand.exists() {
|
||||
p = cand;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ impl<'a> UsingResolutionBox<'a> {
|
||||
prod: crate::config::env::using_is_prod(),
|
||||
strict: crate::config::env::env_bool("NYASH_USING_STRICT"),
|
||||
verbose: crate::config::env::cli_verbose()
|
||||
|| crate::config::env::env_bool("NYASH_RESOLVE_TRACE"),
|
||||
|| crate::config::env::resolve_trace(),
|
||||
allow_file_using: crate::config::env::allow_using_file(),
|
||||
};
|
||||
|
||||
@ -162,8 +162,8 @@ impl<'a> UsingResolutionBox<'a> {
|
||||
|
||||
// NYASH_ROOTも試す
|
||||
if p.is_relative() {
|
||||
if let Ok(root) = std::env::var("NYASH_ROOT") {
|
||||
let cand = Path::new(&root).join(&p);
|
||||
if let Some(root) = crate::runner::modes::common_util::resolve::root::resolve_repo_root(None) {
|
||||
let cand = root.join(&p);
|
||||
if cand.exists() {
|
||||
p = cand;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user