Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions cli/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,10 @@ impl BuildCache {
/// Loads the cache database from the build directory.
pub fn load(cache_dir: &Path) -> anyhow::Result<Self> {
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(),
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
38 changes: 15 additions & 23 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,22 @@ 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::<TomlConfig>(&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::<TomlConfig>(&content) {
apply_toml(&mut base, &toml_cfg);
}
}
}

// 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::<serde_json::Value>(&content) {
if let Some(cfg_val) = manifest_toml.get("config") {
if let Ok(toml_cfg) =
serde_json::from_value::<TomlConfig>(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::<serde_json::Value>(&content) {
if let Some(cfg_val) = manifest_toml.get("config") {
if let Ok(toml_cfg) = serde_json::from_value::<TomlConfig>(cfg_val.clone())
{
apply_toml(&mut base, &toml_cfg);
}
}
}
Expand All @@ -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::<serde_json::Value>(&content) {
if let Some(cfg_val) = manifest_toml.get("config") {
if let Ok(toml_cfg) =
serde_json::from_value::<TomlConfig>(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::<serde_json::Value>(&content) {
if let Some(cfg_val) = manifest_toml.get("config") {
if let Ok(toml_cfg) = serde_json::from_value::<TomlConfig>(cfg_val.clone())
{
apply_toml(&mut base, &toml_cfg);
}
}
}
Expand Down
64 changes: 33 additions & 31 deletions cli/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()));
}
}

Expand Down Expand Up @@ -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()));
}
}

Expand Down
Loading