diff --git a/cli/src/cache.rs b/cli/src/cache.rs index 7a216524..fd530c8d 100644 --- a/cli/src/cache.rs +++ b/cli/src/cache.rs @@ -34,16 +34,10 @@ impl BuildCache { /// Loads the cache database from the build directory. pub fn load(cache_dir: &Path) -> anyhow::Result { let db_path = cache_dir.join("fingerprints.json"); - let db = if db_path.exists() { - if let Ok(content) = std::fs::read_to_string(&db_path) { - serde_json::from_str(&content).unwrap_or_else(|_| CacheDatabase { - fingerprints: HashMap::new(), - }) - } else { - CacheDatabase { - fingerprints: HashMap::new(), - } - } + let db = if let Ok(content) = std::fs::read_to_string(&db_path) { + serde_json::from_str(&content).unwrap_or_else(|_| CacheDatabase { + fingerprints: HashMap::new(), + }) } else { CacheDatabase { fingerprints: HashMap::new(), @@ -98,8 +92,7 @@ impl BuildCache { .cache_dir .join("ir") .join(hash_path_filename(path) + ".ir"); - if cache_file.exists() { - let data = std::fs::read(cache_file)?; + if let Ok(data) = std::fs::read(cache_file) { let module = bincode::deserialize(&data) .map_err(|e| anyhow::anyhow!("Deserialization failed: {}", e))?; Ok(Some(module)) @@ -132,8 +125,7 @@ impl BuildCache { .cache_dir .join("bytecode") .join(hash_path_filename(path) + ".tsb"); - if cache_file.exists() { - let data = std::fs::read(cache_file)?; + if let Ok(data) = std::fs::read(cache_file) { let module = techscript_bytecode::BytecodeSerializer::deserialize(&data) .map_err(|e| anyhow::anyhow!("Bytecode deserialization failed: {}", e))?; Ok(Some(module)) diff --git a/cli/src/config.rs b/cli/src/config.rs index 5c96c3ea..3c6de852 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -99,11 +99,9 @@ impl ConfigManager { // 2. Global user config (~/.techscript/config.toml) if let Some(home) = dirs::home_dir() { let global_path = home.join(".techscript").join("config.toml"); - if global_path.exists() { - if let Ok(content) = std::fs::read_to_string(global_path) { - if let Ok(toml_cfg) = toml::from_str::(&content) { - apply_toml(&mut base, &toml_cfg); - } + if let Ok(content) = std::fs::read_to_string(global_path) { + if let Ok(toml_cfg) = toml::from_str::(&content) { + apply_toml(&mut base, &toml_cfg); } } } @@ -111,15 +109,12 @@ impl ConfigManager { // 3. Workspace config if let Some(ws) = workspace_root { let ws_manifest = ws.join("tech.toml"); - if ws_manifest.exists() { - if let Ok(content) = std::fs::read_to_string(ws_manifest) { - if let Ok(manifest_toml) = toml::from_str::(&content) { - if let Some(cfg_val) = manifest_toml.get("config") { - if let Ok(toml_cfg) = - serde_json::from_value::(cfg_val.clone()) - { - apply_toml(&mut base, &toml_cfg); - } + if let Ok(content) = std::fs::read_to_string(ws_manifest) { + if let Ok(manifest_toml) = toml::from_str::(&content) { + if let Some(cfg_val) = manifest_toml.get("config") { + if let Ok(toml_cfg) = serde_json::from_value::(cfg_val.clone()) + { + apply_toml(&mut base, &toml_cfg); } } } @@ -129,15 +124,12 @@ impl ConfigManager { // 4. Project config if let Some(proj) = project_root { let proj_manifest = proj.join("tech.toml"); - if proj_manifest.exists() { - if let Ok(content) = std::fs::read_to_string(proj_manifest) { - if let Ok(manifest_toml) = toml::from_str::(&content) { - if let Some(cfg_val) = manifest_toml.get("config") { - if let Ok(toml_cfg) = - serde_json::from_value::(cfg_val.clone()) - { - apply_toml(&mut base, &toml_cfg); - } + if let Ok(content) = std::fs::read_to_string(proj_manifest) { + if let Ok(manifest_toml) = toml::from_str::(&content) { + if let Some(cfg_val) = manifest_toml.get("config") { + if let Ok(toml_cfg) = serde_json::from_value::(cfg_val.clone()) + { + apply_toml(&mut base, &toml_cfg); } } } diff --git a/cli/src/project.rs b/cli/src/project.rs index 3e10ab78..8b15e1c7 100644 --- a/cli/src/project.rs +++ b/cli/src/project.rs @@ -75,28 +75,34 @@ impl ProjectBuildGraph { let mut packages = HashMap::new(); let mut members = Vec::new(); - if manifest_path.exists() { - let content = std::fs::read_to_string(&manifest_path)?; - let manifest: Manifest = toml::from_str(&content)?; - - if let Some(workspace_cfg) = &manifest.workspace { - // Workspace mode - members = workspace_cfg.members.clone(); - for member_glob in &members { - // Simulating directory lookup for member folders - let member_dir = root.join(member_glob); - if member_dir.exists() { - let pkg = load_package(&member_dir)?; - packages.insert(pkg.name.clone(), pkg); + match std::fs::read_to_string(&manifest_path) { + Ok(content) => { + let manifest: Manifest = toml::from_str(&content)?; + + if let Some(workspace_cfg) = &manifest.workspace { + // Workspace mode + members = workspace_cfg.members.clone(); + for member_glob in &members { + // Simulating directory lookup for member folders + let member_dir = root.join(member_glob); + if member_dir.exists() { + let pkg = load_package(&member_dir)?; + packages.insert(pkg.name.clone(), pkg); + } } + } else { + // Single package mode + let pkg = load_package(root)?; + packages.insert(pkg.name.clone(), pkg); } - } else { - // Single package mode - let pkg = load_package(root)?; - packages.insert(pkg.name.clone(), pkg); } - } else { - // No tech.toml, single file virtual package mode + Err(e) if e.kind() == std::io::ErrorKind::NotFound => { + // No tech.toml, single file virtual package mode + } + Err(e) => return Err(e.into()), + } + + if packages.is_empty() { let entry = root.to_path_buf(); let parent = entry.parent().unwrap_or(root).to_path_buf(); let pkg = Package { @@ -148,12 +154,10 @@ impl ProjectBuildGraph { // 1. Add all entry points to compilation list for pkg in self.workspace.packages.values_mut() { - if pkg.entry_file.exists() { - if let Ok(source) = std::fs::read_to_string(&pkg.entry_file) { - let fid = source_mgr.add_file(pkg.entry_file.clone(), source.clone()); - pkg.entry_file_id = Some(fid); - to_resolve.push((fid, pkg.entry_file.clone(), pkg.name.clone())); - } + if let Ok(source) = std::fs::read_to_string(&pkg.entry_file) { + let fid = source_mgr.add_file(pkg.entry_file.clone(), source.clone()); + pkg.entry_file_id = Some(fid); + to_resolve.push((fid, pkg.entry_file.clone(), pkg.name.clone())); } } @@ -269,12 +273,10 @@ impl ProjectBuildGraph { } } - if import_file.exists() { - if let Ok(source) = std::fs::read_to_string(&import_file) { - let dep_fid = source_mgr.add_file(import_file.clone(), source); - dep_fids.push(dep_fid); - to_resolve.push((dep_fid, import_file, pkg_name.clone())); - } + if let Ok(source) = std::fs::read_to_string(&import_file) { + let dep_fid = source_mgr.add_file(import_file.clone(), source); + dep_fids.push(dep_fid); + to_resolve.push((dep_fid, import_file, pkg_name.clone())); } }