Skip to content

Commit 6bbb4af

Browse files
author
Grant Wuerker
committed
hacking
1 parent a9c2741 commit 6bbb4af

File tree

13 files changed

+352
-140
lines changed

13 files changed

+352
-140
lines changed

Diff for: Cargo.lock

+11-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: crates/common2/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ smol_str = "0.1.24"
1616
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "a1bf3a6" }
1717
indexmap = "2.2"
1818
parser = { path = "../parser2", package = "fe-parser2" }
19+
toml = "0.8.13"
20+
serde = { version = "1", features = ["derive"] }
21+
git2 = "0.18.3"

Diff for: crates/common2/src/config.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// use camino::Utf8PathBuf;
2+
// use indexmap::IndexSet;
3+
// use serde::{Deserialize, Serialize};
4+
// use toml::Table;
5+
6+
// use crate::resolver::ingot::IngotDesc;
7+
8+
// #[derive(Deserialize, Serialize)]
9+
// pub struct Config {
10+
// pub modes: Table,
11+
// pub base_registry: Table,
12+
// }
13+
14+
// impl Config {
15+
// pub fn new() -> Self {
16+
// Self {
17+
// base_registry: Table::new(),
18+
// }
19+
// }
20+
21+
// pub fn base_registry(&self) -> IndexSet<IngotDesc> {
22+
// self.base_registry
23+
// .iter()
24+
// .map(|(name, value)| IngotDesc::from(name, value))
25+
// .collect()
26+
// }
27+
// }
28+
29+
// pub fn load_config(path: Utf8PathBuf) -> Config {
30+
// let text = std::fs::read_to_string(path).unwrap();
31+
// toml::from_str(&text).unwrap()
32+
// }
33+
34+
// pub fn write_config(path: Utf8PathBuf, config: Config) {
35+
// let text = toml::to_string(&config).unwrap();
36+
// std::fs::write(path, text).unwrap();
37+
// }

Diff for: crates/common2/src/input.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl InputIngot {
6060
}
6161

6262
/// Set the list of files which the ingot contains.
63-
/// All files must bee set before the ingot is used.
63+
/// All files must be set before the ingot is used.
6464
pub fn set_files(self, db: &mut dyn InputDb, files: IndexSet<InputFile>) {
6565
self.__set_files_impl(db).to(files);
6666
}

Diff for: crates/common2/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
pub mod config;
12
pub mod diagnostics;
23
pub mod indexmap;
34
pub mod input;
5+
pub mod resolver;
46

57
pub use input::{InputFile, InputIngot};
68

Diff for: crates/common2/src/resolver.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub mod fs;
2+
pub mod git;
3+
pub mod ingot;
4+
5+
pub trait Resolver {
6+
type ResourceDesc;
7+
type Resource;
8+
type ResolutionError;
9+
10+
fn resolve(&self, id: &Self::ResourceDesc) -> Result<Self::Resource, Self::ResolutionError>;
11+
}

Diff for: crates/common2/src/resolver/fs.rs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use camino::Utf8PathBuf;
2+
use serde::Deserialize;
3+
4+
use super::Resolver;
5+
6+
#[derive(Deserialize)]
7+
pub struct DirPath {
8+
pub path: String,
9+
}
10+
11+
pub struct DirReader {
12+
path: Utf8PathBuf,
13+
}
14+
15+
pub struct LazyDirResolver;
16+
17+
impl Resolver for LazyDirResolver {
18+
type ResourceDesc = DirPath;
19+
type Resource = DirReader;
20+
type ResolutionError = String;
21+
22+
fn resolve(&self, desc: &DirPath) -> Result<DirReader, String> {
23+
if let Ok(path) = Utf8PathBuf::try_from(desc.path.clone()) {
24+
if !path.exists() {
25+
Err("Path does not exist".to_string())
26+
} else {
27+
Ok(DirReader { path })
28+
}
29+
} else {
30+
Err("Invalid path".to_string())
31+
}
32+
}
33+
}
34+
35+
// fn collect_file_paths(
36+
// path: &Utf8PathBuf,
37+
// files: &mut IndexSet<Utf8PathBuf>,
38+
// ) -> std::io::Result<()> {
39+
// if path.is_dir() {
40+
// for entry in path.read_dir()? {
41+
// let entry = entry?;
42+
// let path = Utf8PathBuf::from_path_buf(entry.path())
43+
// .expect("could not covert PathBuf to Utf8PathBuf");
44+
45+
// if path.is_dir() {
46+
// collect_file_paths(&path, files)?;
47+
// } else {
48+
// files.insert(path);
49+
// }
50+
// }
51+
// }
52+
// Ok(())
53+
// }

Diff for: crates/common2/src/resolver/git.rs

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
use camino::Utf8PathBuf;
2+
use serde::Deserialize;
3+
4+
use super::Resolver;
5+
6+
#[derive(Deserialize)]
7+
pub struct GitRepoDesc {
8+
remote: String,
9+
refspec: String,
10+
local_path: Option<String>,
11+
}
12+
13+
pub struct GitRepo {
14+
repo: git2::Repository,
15+
}
16+
17+
pub struct GitResolver {
18+
pub default_clone_path: Utf8PathBuf,
19+
}
20+
21+
// pub enum GitResolutionError {
22+
// GitResolutionError(()),
23+
// FsResolutionError(std::io::Error),
24+
// }
25+
26+
impl Resolver for GitResolver {
27+
type ResourceDesc = GitRepoDesc;
28+
type Resource = GitRepo;
29+
type ResolutionError = String;
30+
31+
fn resolve(&self, desc: &GitRepoDesc) -> Result<GitRepo, String> {
32+
todo!("")
33+
}
34+
}
35+
36+
// use git2::{FetchOptions, Oid, Repository};
37+
// use std::error::Error;
38+
// use std::path::Path;
39+
40+
// /// Fetch and checkout the specified refspec from the remote repository without
41+
// /// fetching any additional history.
42+
// pub fn fetch_and_checkout<P: AsRef<Path>>(
43+
// remote: &str,
44+
// target_directory: P,
45+
// refspec: &str,
46+
// ) -> Result<(), Box<dyn Error>> {
47+
// // We initialize the repo here so that we can be sure that we created a directory that
48+
// // needs to be clean up in case of an error. If the init fails, there won't be anything
49+
// // to clean up.
50+
// let repo = Repository::init(&target_directory)?;
51+
// let res = _fetch_and_checkout(remote, repo, refspec);
52+
// if res.is_err() {
53+
// std::fs::remove_dir_all(target_directory).expect("Failed to clean up directory");
54+
// }
55+
56+
// res
57+
// }
58+
59+
// fn _fetch_and_checkout(
60+
// remote: &str,
61+
// repo: Repository,
62+
// refspec: &str,
63+
// ) -> Result<(), Box<dyn Error>> {
64+
// let mut remote = repo.remote("origin", remote)?;
65+
66+
// let mut fetch_options = FetchOptions::new();
67+
68+
// fetch_options.depth(1);
69+
70+
// // Fetch the specified SHA1 with depth 1
71+
// if let Err(e) = remote.fetch(&[refspec], Some(&mut fetch_options), None) {
72+
// if let (git2::ErrorClass::Net, git2::ErrorCode::GenericError) = (e.class(), e.code()) {
73+
// // That's a pretty cryptic error for the common case of the refspec not existing.
74+
// // We keep the cryptic error (because it might have other causes) but add a hint.
75+
// return Err(format!("{}\nMake sure revision {} exists in remote", e, refspec).into());
76+
// } else {
77+
// return Err(e.into());
78+
// }
79+
// }
80+
81+
// // Find the fetched commit by SHA1
82+
// let oid = Oid::from_str(refspec)?;
83+
// let commit = repo.find_commit(oid)?;
84+
85+
// // Checkout the commit
86+
// repo.checkout_tree(commit.as_object(), None)?;
87+
// repo.set_head_detached(oid)?;
88+
89+
// Ok(())
90+
// }

Diff for: crates/common2/src/resolver/ingot.rs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use std::marker::PhantomData;
2+
3+
use camino::Utf8PathBuf;
4+
use indexmap::IndexSet;
5+
use semver::Version;
6+
use serde::Deserialize;
7+
use smol_str::SmolStr;
8+
use toml::Table;
9+
10+
use super::{fs::LazyDirResolver, git::GitResolver, Resolver};
11+
12+
#[derive(Deserialize)]
13+
pub struct IngotDesc<FD> {
14+
name: SmolStr,
15+
version: String,
16+
#[serde(flatten)]
17+
files_desc: FD,
18+
}
19+
20+
#[derive(Deserialize)]
21+
pub struct Config {
22+
pub name: SmolStr,
23+
pub version: SmolStr,
24+
dependencies: Table,
25+
}
26+
27+
impl Config {
28+
fn dependencies<FD>(&self) -> IndexSet<IngotDesc<FD>> {
29+
todo!("dependency")
30+
}
31+
}
32+
33+
trait IngotFiles {
34+
fn config(&self) -> Config;
35+
fn src(&self) -> IndexSet<(Utf8PathBuf, Vec<u8>)>;
36+
fn root_path(&self) -> Utf8PathBuf;
37+
}
38+
39+
pub struct Ingot<F>
40+
where
41+
F: IngotFiles,
42+
{
43+
desc_name: SmolStr,
44+
desc_version: Version,
45+
files: F,
46+
}
47+
48+
pub struct IngotResolver<FR> {
49+
files_resolver: FR,
50+
}
51+
52+
pub type FsIngotResolver = IngotResolver<LazyDirResolver>;
53+
pub type GitIngotResolver = IngotResolver<GitResolver>;
54+
55+
impl<FR> Resolver for IngotResolver<FR>
56+
where
57+
FR: Resolver,
58+
FR::Resource: IngotFiles,
59+
{
60+
type ResourceDesc = IngotDesc<FR::ResourceDesc>;
61+
type Resource = Ingot<FR::Resource>;
62+
type ResolutionError = ();
63+
64+
fn resolve(&self, desc: &IngotDesc<FR::ResourceDesc>) -> Result<Ingot<FR::Resource>, ()> {
65+
Err(())
66+
}
67+
}

Diff for: crates/driver2/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ common = { path = "../common2", package = "fe-common2" }
1818
hir-analysis = { path = "../hir-analysis", package = "fe-hir-analysis" }
1919
camino = "1.1.4"
2020
clap = { version = "4.3", features = ["derive"] }
21-
toml = "0.8.13"
22-
serde = { version = "1", features = ["derive"] }
2321
semver = "1.0.23"
2422
walkdir = "2"
2523
include_dir = "0.7"
26-
dirs = "5.0.1"
24+
dirs = "5.0.1"

0 commit comments

Comments
 (0)