Skip to content

Commit

Permalink
more clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Jun 2, 2024
1 parent dd1f7d1 commit 5b50321
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 87 deletions.
34 changes: 17 additions & 17 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BuildSystem>,

/// Which target to build
#[clap(short, long)]
#[arg(short, long)]
pub language: Option<TargetLanguage>,

/// Overwrites any possible board definition in Lingo.toml
#[clap(long)]
#[arg(long)]
pub platform: Option<Platform>,

/// Tell lingo where the lfc toolchain can be found
#[clap(long)]
#[arg(long)]
pub lfc: Option<PathBuf>,

/// 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<String>,

/// 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,
}

Expand All @@ -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<TargetLanguage>,
#[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 {
Expand Down Expand Up @@ -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,
}
9 changes: 4 additions & 5 deletions src/backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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"),
Expand All @@ -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;
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/package/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct DependencyLock {
}

impl DependencyLock {
pub fn from(
pub(crate) fn create(
mut unlocked_locations: HashMap<String, LocationDescription>,
loaded_dependencies: Vec<DependencyTreeNode>,
) -> DependencyLock {
Expand Down
23 changes: 10 additions & 13 deletions src/package/management.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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"))?;
Expand All @@ -137,7 +134,7 @@ impl DependencyManager {
) -> anyhow::Result<Vec<DependencyTreeNode>> {
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)?;

Expand Down Expand Up @@ -173,9 +170,9 @@ impl DependencyManager {
base_path: &Path,
) -> anyhow::Result<DependencyTreeNode> {
// 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)?;

Expand All @@ -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::<ConfigFile>(&lingo_toml_text)?.to_config(&temporary_path);
Expand All @@ -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);
Expand All @@ -232,7 +229,7 @@ impl DependencyManager {
})
}

pub fn flatten(
fn flatten(
root_nodes: Vec<DependencyTreeNode>,
) -> anyhow::Result<HashMap<String, LocationDescription>> {
// implementation idea:
Expand Down
7 changes: 2 additions & 5 deletions src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"))
}
}

Expand All @@ -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<ConfigFile> {
let src_path = Path::new("./src");
let main_reactors = if src_path.exists() {
Expand Down
17 changes: 1 addition & 16 deletions src/package/target_properties.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -113,19 +111,6 @@ impl AppTargetPropertiesFile {
}
}

fn merge<T>(
a: Option<T>,
b: Option<T>,
f: fn(T, T) -> anyhow::Result<Option<T>>,
) -> anyhow::Result<Option<T>> {
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<()>;
}
Expand Down
16 changes: 0 additions & 16 deletions src/package/tree.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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(),
Expand Down
14 changes: 0 additions & 14 deletions src/util/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ pub enum LingoError {
InvalidMainReactor,
NoLibraryInLingoToml(String),
LingoVersionMismatch(String),
NotCombineableTargetProperties(String),
UnmergableTargetProperties,
}

impl Display for LingoError {
Expand Down Expand Up @@ -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."
)
}
}
}
}
Expand Down

0 comments on commit 5b50321

Please sign in to comment.