-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grant Wuerker
committed
Sep 3, 2024
1 parent
a9c2741
commit 6bbb4af
Showing
13 changed files
with
352 additions
and
140 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// use camino::Utf8PathBuf; | ||
// use indexmap::IndexSet; | ||
// use serde::{Deserialize, Serialize}; | ||
// use toml::Table; | ||
|
||
// use crate::resolver::ingot::IngotDesc; | ||
|
||
// #[derive(Deserialize, Serialize)] | ||
// pub struct Config { | ||
// pub modes: Table, | ||
// pub base_registry: Table, | ||
// } | ||
|
||
// impl Config { | ||
// pub fn new() -> Self { | ||
// Self { | ||
// base_registry: Table::new(), | ||
// } | ||
// } | ||
|
||
// pub fn base_registry(&self) -> IndexSet<IngotDesc> { | ||
// self.base_registry | ||
// .iter() | ||
// .map(|(name, value)| IngotDesc::from(name, value)) | ||
// .collect() | ||
// } | ||
// } | ||
|
||
// pub fn load_config(path: Utf8PathBuf) -> Config { | ||
// let text = std::fs::read_to_string(path).unwrap(); | ||
// toml::from_str(&text).unwrap() | ||
// } | ||
|
||
// pub fn write_config(path: Utf8PathBuf, config: Config) { | ||
// let text = toml::to_string(&config).unwrap(); | ||
// std::fs::write(path, text).unwrap(); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pub mod fs; | ||
pub mod git; | ||
pub mod ingot; | ||
|
||
pub trait Resolver { | ||
type ResourceDesc; | ||
type Resource; | ||
type ResolutionError; | ||
|
||
fn resolve(&self, id: &Self::ResourceDesc) -> Result<Self::Resource, Self::ResolutionError>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use camino::Utf8PathBuf; | ||
use serde::Deserialize; | ||
|
||
use super::Resolver; | ||
|
||
#[derive(Deserialize)] | ||
pub struct DirPath { | ||
pub path: String, | ||
} | ||
|
||
pub struct DirReader { | ||
path: Utf8PathBuf, | ||
} | ||
|
||
pub struct LazyDirResolver; | ||
|
||
impl Resolver for LazyDirResolver { | ||
type ResourceDesc = DirPath; | ||
type Resource = DirReader; | ||
type ResolutionError = String; | ||
|
||
fn resolve(&self, desc: &DirPath) -> Result<DirReader, String> { | ||
if let Ok(path) = Utf8PathBuf::try_from(desc.path.clone()) { | ||
if !path.exists() { | ||
Err("Path does not exist".to_string()) | ||
} else { | ||
Ok(DirReader { path }) | ||
} | ||
} else { | ||
Err("Invalid path".to_string()) | ||
} | ||
} | ||
} | ||
|
||
// fn collect_file_paths( | ||
// path: &Utf8PathBuf, | ||
// files: &mut IndexSet<Utf8PathBuf>, | ||
// ) -> std::io::Result<()> { | ||
// if path.is_dir() { | ||
// for entry in path.read_dir()? { | ||
// let entry = entry?; | ||
// let path = Utf8PathBuf::from_path_buf(entry.path()) | ||
// .expect("could not covert PathBuf to Utf8PathBuf"); | ||
|
||
// if path.is_dir() { | ||
// collect_file_paths(&path, files)?; | ||
// } else { | ||
// files.insert(path); | ||
// } | ||
// } | ||
// } | ||
// Ok(()) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use camino::Utf8PathBuf; | ||
use serde::Deserialize; | ||
|
||
use super::Resolver; | ||
|
||
#[derive(Deserialize)] | ||
pub struct GitRepoDesc { | ||
remote: String, | ||
refspec: String, | ||
local_path: Option<String>, | ||
} | ||
|
||
pub struct GitRepo { | ||
repo: git2::Repository, | ||
} | ||
|
||
pub struct GitResolver { | ||
pub default_clone_path: Utf8PathBuf, | ||
} | ||
|
||
// pub enum GitResolutionError { | ||
// GitResolutionError(()), | ||
// FsResolutionError(std::io::Error), | ||
// } | ||
|
||
impl Resolver for GitResolver { | ||
type ResourceDesc = GitRepoDesc; | ||
type Resource = GitRepo; | ||
type ResolutionError = String; | ||
|
||
fn resolve(&self, desc: &GitRepoDesc) -> Result<GitRepo, String> { | ||
todo!("") | ||
} | ||
} | ||
|
||
// use git2::{FetchOptions, Oid, Repository}; | ||
// use std::error::Error; | ||
// use std::path::Path; | ||
|
||
// /// Fetch and checkout the specified refspec from the remote repository without | ||
// /// fetching any additional history. | ||
// pub fn fetch_and_checkout<P: AsRef<Path>>( | ||
// remote: &str, | ||
// target_directory: P, | ||
// refspec: &str, | ||
// ) -> Result<(), Box<dyn Error>> { | ||
// // We initialize the repo here so that we can be sure that we created a directory that | ||
// // needs to be clean up in case of an error. If the init fails, there won't be anything | ||
// // to clean up. | ||
// let repo = Repository::init(&target_directory)?; | ||
// let res = _fetch_and_checkout(remote, repo, refspec); | ||
// if res.is_err() { | ||
// std::fs::remove_dir_all(target_directory).expect("Failed to clean up directory"); | ||
// } | ||
|
||
// res | ||
// } | ||
|
||
// fn _fetch_and_checkout( | ||
// remote: &str, | ||
// repo: Repository, | ||
// refspec: &str, | ||
// ) -> Result<(), Box<dyn Error>> { | ||
// let mut remote = repo.remote("origin", remote)?; | ||
|
||
// let mut fetch_options = FetchOptions::new(); | ||
|
||
// fetch_options.depth(1); | ||
|
||
// // Fetch the specified SHA1 with depth 1 | ||
// if let Err(e) = remote.fetch(&[refspec], Some(&mut fetch_options), None) { | ||
// if let (git2::ErrorClass::Net, git2::ErrorCode::GenericError) = (e.class(), e.code()) { | ||
// // That's a pretty cryptic error for the common case of the refspec not existing. | ||
// // We keep the cryptic error (because it might have other causes) but add a hint. | ||
// return Err(format!("{}\nMake sure revision {} exists in remote", e, refspec).into()); | ||
// } else { | ||
// return Err(e.into()); | ||
// } | ||
// } | ||
|
||
// // Find the fetched commit by SHA1 | ||
// let oid = Oid::from_str(refspec)?; | ||
// let commit = repo.find_commit(oid)?; | ||
|
||
// // Checkout the commit | ||
// repo.checkout_tree(commit.as_object(), None)?; | ||
// repo.set_head_detached(oid)?; | ||
|
||
// Ok(()) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::marker::PhantomData; | ||
|
||
use camino::Utf8PathBuf; | ||
use indexmap::IndexSet; | ||
use semver::Version; | ||
use serde::Deserialize; | ||
use smol_str::SmolStr; | ||
use toml::Table; | ||
|
||
use super::{fs::LazyDirResolver, git::GitResolver, Resolver}; | ||
|
||
#[derive(Deserialize)] | ||
pub struct IngotDesc<FD> { | ||
name: SmolStr, | ||
version: String, | ||
#[serde(flatten)] | ||
files_desc: FD, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct Config { | ||
pub name: SmolStr, | ||
pub version: SmolStr, | ||
dependencies: Table, | ||
} | ||
|
||
impl Config { | ||
fn dependencies<FD>(&self) -> IndexSet<IngotDesc<FD>> { | ||
todo!("dependency") | ||
} | ||
} | ||
|
||
trait IngotFiles { | ||
fn config(&self) -> Config; | ||
fn src(&self) -> IndexSet<(Utf8PathBuf, Vec<u8>)>; | ||
fn root_path(&self) -> Utf8PathBuf; | ||
} | ||
|
||
pub struct Ingot<F> | ||
where | ||
F: IngotFiles, | ||
{ | ||
desc_name: SmolStr, | ||
desc_version: Version, | ||
files: F, | ||
} | ||
|
||
pub struct IngotResolver<FR> { | ||
files_resolver: FR, | ||
} | ||
|
||
pub type FsIngotResolver = IngotResolver<LazyDirResolver>; | ||
pub type GitIngotResolver = IngotResolver<GitResolver>; | ||
|
||
impl<FR> Resolver for IngotResolver<FR> | ||
where | ||
FR: Resolver, | ||
FR::Resource: IngotFiles, | ||
{ | ||
type ResourceDesc = IngotDesc<FR::ResourceDesc>; | ||
type Resource = Ingot<FR::Resource>; | ||
type ResolutionError = (); | ||
|
||
fn resolve(&self, desc: &IngotDesc<FR::ResourceDesc>) -> Result<Ingot<FR::Resource>, ()> { | ||
Err(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.