diff --git a/Cargo.lock b/Cargo.lock index fe179d14..fa9e7b05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,6 +109,7 @@ version = "0.0.26" dependencies = [ "aiken-lang", "askama", + "fslock", "hex", "ignore", "itertools", @@ -455,6 +456,14 @@ name = "funty" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" +name = "fslock" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04412b8935272e3a9bae6f48c7bfff74c2911f60525404edfdd28e49884c3bfb" +dependencies = [ + "libc", + "winapi", +] [[package]] name = "getrandom" diff --git a/crates/project/Cargo.toml b/crates/project/Cargo.toml index 01319cae..f2aa005c 100644 --- a/crates/project/Cargo.toml +++ b/crates/project/Cargo.toml @@ -11,6 +11,7 @@ authors = ["Lucas Rosa ", "Kasey White "] [dependencies] aiken-lang = { path = "../lang", version = "0.0.26" } askama = "0.10.5" +fslock = "0.2.1" hex = "0.4.3" ignore = "0.4.18" itertools = "0.10.1" diff --git a/crates/project/src/deps.rs b/crates/project/src/deps.rs new file mode 100644 index 00000000..3c91ce18 --- /dev/null +++ b/crates/project/src/deps.rs @@ -0,0 +1,41 @@ +use std::path::Path; + +use crate::{ + error::Error, + paths, + telemetry::{Event, EventListener}, +}; + +use self::manifest::Manifest; + +pub mod manifest; + +pub enum UseManifest { + Yes, + No, +} + +pub fn download( + event_listener: &T, + new_package: Option<(Vec, bool)>, + use_manifest: UseManifest, + root_path: &Path, +) -> Result +where + T: EventListener, +{ + let build_path = root_path.join(paths::build()); + + let mut build_lock = fslock::LockFile::open(&build_path).expect("Build Lock Creation"); + + if !build_lock + .try_lock_with_pid() + .expect("Trying build locking") + { + event_listener.handle_event(Event::WaitingForBuildDirLock); + + build_lock.lock_with_pid().expect("Build locking") + } + + todo!() +} diff --git a/crates/project/src/deps/manifest.rs b/crates/project/src/deps/manifest.rs new file mode 100644 index 00000000..476ce65c --- /dev/null +++ b/crates/project/src/deps/manifest.rs @@ -0,0 +1,17 @@ +use std::collections::HashMap; + +pub struct Manifest { + pub requirements: HashMap, + pub packages: Vec, +} + +pub struct Package { + pub name: String, + pub version: String, + pub requirements: Vec, + pub source: PackageSource, +} + +pub enum PackageSource { + GitHub { url: String }, +} diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs index e89e4b67..3d286b2c 100644 --- a/crates/project/src/lib.rs +++ b/crates/project/src/lib.rs @@ -1,9 +1,11 @@ pub mod config; +pub mod deps; pub mod docs; pub mod error; pub mod format; pub mod module; pub mod options; +pub mod paths; pub mod pretty; pub mod script; pub mod telemetry; @@ -17,6 +19,7 @@ use aiken_lang::{ uplc::CodeGenerator, IdGenerator, }; +use deps::UseManifest; use miette::NamedSource; use options::{CodeGenMode, Options}; use pallas::{ @@ -148,6 +151,8 @@ where } pub fn compile(&mut self, options: Options) -> Result<(), Error> { + let manifest = deps::download(&self.event_listener, None, UseManifest::Yes, &self.root)?; + self.event_listener .handle_event(Event::StartingCompilation { root: self.root.clone(), @@ -718,7 +723,7 @@ where let cbor_hex = hex::encode(&cbor); - fs::write(script_path, &cbor_hex)?; + fs::write(script_path, cbor_hex)?; // Create the payment script JSON file let payment_script_path = script_output_dir.join("payment_script.json"); diff --git a/crates/project/src/paths.rs b/crates/project/src/paths.rs new file mode 100644 index 00000000..1610eab0 --- /dev/null +++ b/crates/project/src/paths.rs @@ -0,0 +1,5 @@ +use std::path::PathBuf; + +pub fn build() -> PathBuf { + PathBuf::from("build") +} diff --git a/crates/project/src/telemetry.rs b/crates/project/src/telemetry.rs index 99c6265b..84502774 100644 --- a/crates/project/src/telemetry.rs +++ b/crates/project/src/telemetry.rs @@ -35,4 +35,5 @@ pub enum Event { FinishedTests { tests: Vec, }, + WaitingForBuildDirLock, }