From 5b50321116d5b649865c9c128910877ad33d109d Mon Sep 17 00:00:00 2001 From: tanneberger Date: Sun, 2 Jun 2024 23:17:01 +0200 Subject: [PATCH] more clean up --- src/args.rs | 34 ++++++++++++++++---------------- src/backends/mod.rs | 9 ++++----- src/package/lock.rs | 2 +- src/package/management.rs | 23 ++++++++++----------- src/package/mod.rs | 7 ++----- src/package/target_properties.rs | 17 +--------------- src/package/tree.rs | 16 --------------- src/util/errors.rs | 14 ------------- 8 files changed, 35 insertions(+), 87 deletions(-) diff --git a/src/args.rs b/src/args.rs index 0149425..3c6b4b9 100644 --- a/src/args.rs +++ b/src/args.rs @@ -32,39 +32,39 @@ pub enum BuildSystem { pub struct BuildArgs { /// Which build system to use /// TODO: discuss this - #[clap(short, long)] + #[arg(short, long)] pub build_system: Option, /// Which target to build - #[clap(short, long)] + #[arg(short, long)] pub language: Option, /// Overwrites any possible board definition in Lingo.toml - #[clap(long)] + #[arg(long)] pub platform: Option, /// Tell lingo where the lfc toolchain can be found - #[clap(long)] + #[arg(long)] pub lfc: Option, /// Skips building aka invoking the build system so it only generates code - #[clap(short, long, action)] + #[arg(short, long)] pub no_compile: bool, /// If one of the apps fails to build dont interrupt the build process - #[clap(short, long, action)] + #[arg(short, long)] pub keep_going: bool, /// Compiles the binaries with optimizations turned on and strips debug symbols - #[clap(short, long, action)] + #[arg(short, long)] pub release: bool, /// List of apps to build if left empty all apps are built - #[clap(short, long, value_delimiter = ',')] + #[arg(short, long, value_delimiter = ',')] pub apps: Vec, /// Number of threads to use for parallel builds. Zero means it will be determined automatically. - #[clap(short, long, default_value_t = 0)] + #[arg(short, long, default_value_t = 0)] pub threads: usize, } @@ -86,9 +86,9 @@ impl ToString for TargetLanguage { #[derive(Args, Debug)] pub struct InitArgs { - #[clap(value_enum, short, long)] + #[arg(value_enum, short, long)] pub language: Option, - #[clap(value_enum, short, long, default_value_t = Platform::Native)] + #[arg(value_enum, short, long, default_value_t = Platform::Native)] pub platform: Platform, } impl InitArgs { @@ -124,20 +124,20 @@ pub enum Command { } #[derive(Parser)] -#[clap(name = "lingua-franca package manager and build tool")] -#[clap(author = "tassilo.tanneberger@tu-dresden.de")] -#[clap(version = env!("CARGO_PKG_VERSION"))] -#[clap(about = "Build system of lingua-franca projects", long_about = None)] +#[command(name = "lingua-franca package manager and build tool")] +#[command(author = "tassilo.tanneberger@tu-dresden.de")] +#[command(version = env!("CARGO_PKG_VERSION"))] +#[command(about = "Build system of lingua-franca projects", long_about = None)] pub struct CommandLineArgs { /// which command of lingo to use #[clap(subcommand)] pub command: Command, /// lingo wouldn't produce any output - #[clap(short, long, action)] + #[arg(short, long)] pub quiet: bool, /// lingo wouldn't produce any output - #[clap(short, long, action)] + #[arg(short, long)] pub verbose: bool, } diff --git a/src/backends/mod.rs b/src/backends/mod.rs index 66e770e..40a8188 100644 --- a/src/backends/mod.rs +++ b/src/backends/mod.rs @@ -9,7 +9,6 @@ use rayon::prelude::*; use crate::args::{BuildSystem, Platform}; use crate::package::management::DependencyManager; use crate::package::target_properties::MergeTargetProperties; -use crate::package::tree::PackageDetails; use crate::package::{App, Config}; use crate::util::errors::{AnyError, BuildResult, LingoError}; @@ -23,7 +22,7 @@ pub fn execute_command<'a>(command: &CommandSpec, config: &'a mut Config) -> Bat let dependencies = Vec::from_iter(config.dependencies.clone().into_iter()); match command { - CommandSpec::Build(build) => { + CommandSpec::Build(_build) => { let manager = DependencyManager::from_dependencies( dependencies.clone(), &PathBuf::from("./target"), @@ -36,7 +35,7 @@ pub fn execute_command<'a>(command: &CommandSpec, config: &'a mut Config) -> Bat // merging app with library target properties for app in &mut config.apps { if let Err(e) = app.properties.merge(&library_properties) { - error!("cannot merge properties from the libraries with the app."); + error!("cannot merge properties from the libraries with the app. error: {e}"); return result; } } @@ -54,7 +53,7 @@ pub fn execute_command<'a>(command: &CommandSpec, config: &'a mut Config) -> Bat } for (build_system, apps) in by_build_system { - let mut sub_res = BatchBuildResults::for_apps(&apps, dependencies.clone()); + let mut sub_res = BatchBuildResults::for_apps(&apps); sub_res.map(|app| { // TODO: Support using lingo as a thin wrapper around west @@ -133,7 +132,7 @@ impl<'a> BatchBuildResults<'a> { /// Create a result with an entry for each app. This can /// then be used by combinators like map and such. - fn for_apps(apps: &[&'a App], dependencies: Vec<(String, PackageDetails)>) -> Self { + fn for_apps(apps: &[&'a App]) -> Self { Self { results: apps.iter().map(|&a| (a, Ok(()))).collect(), keep_going: false, diff --git a/src/package/lock.rs b/src/package/lock.rs index 255d209..5f635e5 100644 --- a/src/package/lock.rs +++ b/src/package/lock.rs @@ -23,7 +23,7 @@ pub struct DependencyLock { } impl DependencyLock { - pub fn from( + pub(crate) fn create( mut unlocked_locations: HashMap, loaded_dependencies: Vec, ) -> DependencyLock { diff --git a/src/package/management.rs b/src/package/management.rs index bf93487..5ddf907 100644 --- a/src/package/management.rs +++ b/src/package/management.rs @@ -1,17 +1,14 @@ use crate::package::deserialize_version; use crate::package::lock::DependencyLock; use crate::package::serialize_version; -use crate::package::target_properties::{ - AppTargetProperties, GenericTargetProperties, LibraryTargetProperties, MergeTargetProperties, -}; +use crate::package::target_properties::LibraryTargetProperties; use crate::package::tree::ProjectSource::Empty; use crate::package::tree::{DependencyTreeNode, PackageDetails, ProjectSource}; use crate::package::ConfigFile; use crate::package::LIBRARY_DIRECTORY; use crate::util::errors::LingoError; use colored::Colorize; -use git2::ErrorCode::HashsumMismatch; -use log::{debug, error}; +use log::error; use serde_derive::{Deserialize, Serialize}; use std::collections::HashMap; use std::fs; @@ -112,7 +109,7 @@ impl DependencyManager { let selection = DependencyManager::flatten(root_nodes.clone())?; // creates a lock file struct from the selected packages - lock = DependencyLock::from(selection, root_nodes); + lock = DependencyLock::create(selection, root_nodes); // writes the lock file down let mut lock_file = File::create(target_path.join("../Lingo.lock"))?; @@ -137,7 +134,7 @@ impl DependencyManager { ) -> anyhow::Result> { let mut sub_dependencies = vec![]; self.pulling_queue.append(&mut dependencies); - let sub_dependency_path = root_path.clone().join("libraries"); + let sub_dependency_path = root_path.join("libraries"); //fs::remove_dir_all(&sub_dependency_path)?; fs::create_dir_all(&sub_dependency_path)?; @@ -173,9 +170,9 @@ impl DependencyManager { base_path: &Path, ) -> anyhow::Result { // creating the directory where the library will be housed - let library_path = base_path.clone(); //.join("libs"); - // place where to drop the source - let temporary_path = library_path.clone().join("temporary"); + let library_path = base_path; //.join("libs"); + // place where to drop the source + let temporary_path = library_path.join("temporary"); fs::remove_dir_all(&temporary_path)?; fs::create_dir_all(&temporary_path)?; @@ -189,7 +186,7 @@ impl DependencyManager { package.fetch(&temporary_path)?; let hash = sha1dir::checksum_current_dir(&temporary_path, false); - let include_path = library_path.clone().join(hash.to_string()); + let include_path = library_path.join(hash.to_string()); let lingo_toml_text = fs::read_to_string(temporary_path.clone().join("Lingo.toml"))?; let read_toml = toml::from_str::(&lingo_toml_text)?.to_config(&temporary_path); @@ -212,7 +209,7 @@ impl DependencyManager { .into()); } - let mut dependencies = vec![]; + let dependencies = vec![]; for dep in read_toml.dependencies { self.pulling_queue.push(dep); @@ -232,7 +229,7 @@ impl DependencyManager { }) } - pub fn flatten( + fn flatten( root_nodes: Vec, ) -> anyhow::Result> { // implementation idea: diff --git a/src/package/mod.rs b/src/package/mod.rs index d799255..8ac18fe 100644 --- a/src/package/mod.rs +++ b/src/package/mod.rs @@ -18,7 +18,7 @@ use std::{env, fmt, io}; use crate::args::BuildSystem::{CMake, LFC}; use crate::util::errors::{BuildResult, LingoError}; use git2::Repository; -use serde::de::{DeserializeSeed, Error, Visitor}; +use serde::de::{Error, Visitor}; use serde::{Deserializer, Serializer}; use tempfile::tempdir; use versions::Versioning; @@ -281,7 +281,7 @@ impl<'de> Visitor<'de> for VersioningVisitor { where E: Error, { - Versioning::from_str(v).map_err(|e| E::custom("not a valid version {e}")) + Versioning::from_str(v).map_err(|_| E::custom("not a valid version")) } } @@ -308,9 +308,6 @@ pub struct PackageDescription { } impl ConfigFile { - // FIXME: The default should be that it searches the `src` directory for a main reactor - const DEFAULT_MAIN_REACTOR_RELPATH: &'static str = "src/Main.lf"; - pub fn new_for_init_task(init_args: &InitArgs) -> io::Result { let src_path = Path::new("./src"); let main_reactors = if src_path.exists() { diff --git a/src/package/target_properties.rs b/src/package/target_properties.rs index 4458fc0..cbae341 100644 --- a/src/package/target_properties.rs +++ b/src/package/target_properties.rs @@ -1,6 +1,4 @@ -use serde::de::Unexpected::Str; -use serde::de::{DeserializeSeed, Error, Visitor}; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde::{Deserialize, Serialize, Serializer}; use std::fmt; use std::fmt::{Display, Formatter}; use std::io::Write; @@ -113,19 +111,6 @@ impl AppTargetPropertiesFile { } } -fn merge( - a: Option, - b: Option, - f: fn(T, T) -> anyhow::Result>, -) -> anyhow::Result> { - match (a, b) { - (Some(x), Some(y)) => f(x, y), - (None, Some(y)) => Ok(Some(y)), - (Some(x), None) => Ok(Some(x)), - (None, None) => Ok(None), - } -} - pub trait MergeTargetProperty { fn merge(&mut self, other: &Self) -> anyhow::Result<()>; } diff --git a/src/package/tree.rs b/src/package/tree.rs index 4870b00..6178f75 100644 --- a/src/package/tree.rs +++ b/src/package/tree.rs @@ -1,6 +1,5 @@ use crate::package::target_properties::LibraryTargetProperties; use serde::{Deserialize, Serialize}; -use std::hash::Hash; use std::path::PathBuf; use url::Url; use versions::{Requirement, Versioning}; @@ -50,21 +49,6 @@ pub struct DependencyTreeNode { } impl DependencyTreeNode { - pub(crate) fn new() -> DependencyTreeNode { - Self { - name: "root".to_string(), - package: PackageDetails { - version: Requirement::parse("*").unwrap().1, - mutual_exclusive: ProjectSource::Empty, - }, - location: PathBuf::from("/"), - version: Versioning::default(), - hash: "".to_string(), - dependencies: Vec::new(), - properties: Default::default(), - } - } - pub fn shallow_clone(&self) -> Self { Self { name: self.name.clone(), diff --git a/src/util/errors.rs b/src/util/errors.rs index 4f97bf4..4f9daa2 100644 --- a/src/util/errors.rs +++ b/src/util/errors.rs @@ -18,8 +18,6 @@ pub enum LingoError { InvalidMainReactor, NoLibraryInLingoToml(String), LingoVersionMismatch(String), - NotCombineableTargetProperties(String), - UnmergableTargetProperties, } impl Display for LingoError { @@ -58,18 +56,6 @@ impl Display for LingoError { "Version specified in Lingo.toml doesn't match the version in the location {message}" ) } - LingoError::NotCombineableTargetProperties(message) => { - write!( - f, - "Your project has conflicting target property({message}) definitions." - ) - } - LingoError::UnmergableTargetProperties => { - write!( - f, - "The App cannot inherit the target properties of one of the libraries." - ) - } } } }