Skip to content

Commit

Permalink
[cpclib-runner] Several bndbuild refactoring to add cpclib-runner tha…
Browse files Browse the repository at this point in the history
…t will ease some additional refactorings to include emucontrol within bndbuild
  • Loading branch information
Krusty/Benediction committed Aug 17, 2024
1 parent 3b091b4 commit 57878e7
Show file tree
Hide file tree
Showing 26 changed files with 259 additions and 349 deletions.
23 changes: 16 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@
members = [
"cpclib-asm",
"cpclib-basic",
"cpclib-basm",
"cpclib-bdasm",
"cpclib-bndbuild",
"cpclib-common",
"cpclib-cpr",
"cpclib-cprcli",
"cpclib-crunchers",
"cpclib-disc",
"cpclib-emucontrol",
"cpclib-image",
"cpclib-imgconverter",
"cpclib-macros",
"cpclib-runner",
"cpclib-sna",
"cpclib-tokens",
"cpclib-visual-basm",
"cpclib-visual-bndbuild",
"cpclib-wasm",
"cpclib-xfer",
"cpclib-xfertool",
# "cpclib-xferfs",
"cpclib-z80emu",
"cpclib",
"cpclib-basm",
"cpclib-bdasm",
"cpclib-imgconverter",
"cpclib-visual-basm",
"cpclib-visual-bndbuild",
"cpclib-wasm", "cpclib-cprcli", "cpclib-emucontrol",
# "cpclib-xferfs",
]

resolver = "2"
Expand All @@ -48,6 +51,7 @@ cpclib-disc = { version = "0.8.0", path = "cpclib-disc", default-features = fals
cpclib-image = { version = "0.8.0", path = "cpclib-image", default-features = false }
cpclib-imgconverter = { version = "0.8.0", path = "cpclib-imgconverter", default-features = false }
cpclib-macros = { version = "0.8.0", path = "cpclib-macros", default-features = false }
cpclib-runner = { version = "0.1.0", path = "cpclib-runner", default-features = false }
cpclib-sna = { version = "0.8.0", path = "cpclib-sna", default-features = false }
cpclib-tokens = { version = "0.8.0", path = "cpclib-tokens", default-features = false }
cpclib-visual-bndbuild = { version = "0.4.0", path = "cpclib-visual-bndbuild", default-features = false }
Expand Down Expand Up @@ -144,6 +148,7 @@ self_cell = "1.0.4"
semver = "1.0.23"
serde = { version = "1.0.204", features = ["derive"] }
serial_test = "3.1.1"
shlex = "1.3.0"
similar-asserts = "1.5.0"
simple_logger = { version = "4.3.3" }
smallvec = "1.13.2"
Expand Down
Empty file modified cpclib-basm/pgo.sh
100644 → 100755
Empty file.
Empty file modified cpclib-bdasm/tries.sh
100644 → 100755
Empty file.
10 changes: 2 additions & 8 deletions cpclib-bndbuild/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exclude = ["examples", "tests/dummy", "*.gif"]

[dependencies]


cpclib-runner.workspace = true
cpclib-common = {workspace=true, features=["cmdline"]}
cpclib-basm = { workspace=true, default-features=false, features=["xferlib"] }
cpclib-asm.workspace = true
Expand All @@ -26,22 +26,16 @@ cpclib-imgconverter = { workspace=true, features=["xferlib"]}
cpclib-xfertool.workspace = true

anyhow = "1.0.86"
directories = "5.0.1"
dot-writer = "0.1.3"
flate2 = "1.0.31"
glob = "0.3.1"
globmatch = "0.3"
lazy-regex = "3.2.0"
minijinja = {version="2.1.1", features=["loader"]}
self_cell = "1.0.4"
serde_yaml = "0.9.34"
serde.workspace = true
shlex = "1.3.0"
tar = "0.4.41"
shlex.workspace = true
thiserror = "1.0"
topologic = "1.1.0"
ureq.workspace = true
zip-extract = "=0.1.3"

[build-dependencies]
built.workspace = true
Expand Down
18 changes: 9 additions & 9 deletions cpclib-bndbuild/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::sync::LazyLock;

use crate::delegated::DelegatedRunner;
use crate::runners::assembler::BasmRunner;
use cpclib_runner::delegated::DelegatedRunner;
use cpclib_runner::runner::impdisc::ImpDskVersion;
use cpclib_runner::runner::martine::MartineVersion;
use cpclib_runner::runner::{ExternRunner, Runner};

use crate::runners::assembler::{Assembler, BasmRunner};
use crate::runners::bndbuild::BndBuildRunner;
use crate::runners::cp::CpRunner;
use crate::runners::disc::DiscManagerRunner;
use crate::runners::echo::EchoRunner;
use crate::runners::imgconverter::ImgConverterRunner;
use crate::runners::impdisc::ImpDskVersion;
use crate::runners::martine::MartineVersion;
use crate::runners::r#extern::ExternRunner;
use crate::runners::rm::RmRunner;
use crate::runners::xfer::XferRunner;
use crate::runners::Runner;
use crate::task::Task;

pub static BASM_RUNNER: LazyLock<BasmRunner> = LazyLock::new(BasmRunner::default);
Expand All @@ -37,10 +37,10 @@ pub fn execute(task: &Task) -> Result<(), String> {
},
Task::Assembler(a, _) => {
match a {
crate::runners::assembler::Assembler::Basm => BASM_RUNNER.run(task.args()),
crate::runners::assembler::Assembler::Rasm(v) => {
Assembler::Basm => BASM_RUNNER.run(task.args()),
Assembler::Extern(e) => {
DelegatedRunner {
app: v.configuration(),
app: e.configuration(),
cmd: a.get_command().to_owned()
}
.run(task.args())
Expand Down
1 change: 0 additions & 1 deletion cpclib-bndbuild/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub use crate::BndBuilder;

pub mod builder;
pub mod constraints;
pub mod delegated;
pub mod executor;
pub mod rules;
pub mod runners;
Expand Down
74 changes: 4 additions & 70 deletions cpclib-bndbuild/src/runners/assembler.rs
Original file line number Diff line number Diff line change
@@ -1,92 +1,26 @@
use cpclib_common::camino::Utf8Path;
use cpclib_common::clap::{self, Arg, ArgAction, Command};
use cpclib_common::itertools::Itertools;
use cpclib_runner::runner::assembler::ExternAssembler;

use super::r#extern::ExternRunner;
use super::{Runner, RunnerWithClap};
use crate::built_info;
use crate::delegated::{ArchiveFormat, DelegateApplicationDescription};
use crate::task::{BASM_CMDS, RASM_CMDS};
use crate::task::BASM_CMDS;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Assembler {
Basm,
Rasm(RasmVersion)
Extern(ExternAssembler)
}

impl Assembler {
pub fn get_command(&self) -> &str {
match self {
Assembler::Basm => &BASM_CMDS[0],
Assembler::Rasm(_) => &RASM_CMDS[0]
Assembler::Extern(a) => a.get_command()
}
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum RasmVersion {
Consolidation2024 // V2_2_5
}

impl Default for RasmVersion {
fn default() -> Self {
Self::Consolidation2024
}
}

cfg_match! {
cfg(target_os = "linux") =>
{
impl RasmVersion {
pub fn configuration(&self) -> DelegateApplicationDescription {
match self {
RasmVersion::Consolidation2024 =>
DelegateApplicationDescription {
download_url: "https://github.com/EdouardBERGE/rasm/archive/refs/tags/v2.2.5.zip", // we assume a modern CPU
folder : "rasm_consolidation",
archive_format: ArchiveFormat::Zip,
exec_fname: "rasm",
compile: Some(Box::new(|path: &Utf8Path| -> Result<(), String>{
let command = vec!["make"];
ExternRunner::default().inner_run(&command)?;

let command = vec!["mv", "rasm.exe", "rasm"];
ExternRunner::default().inner_run(&command)?;

Ok(())
}))
}
}
}
}

}
cfg(target_os = "windows") =>
{
impl RasmVersion {
pub fn configuration(&self) -> DelegateApplicationDescription {
match self {
RasmVersion::Consolidation2024 =>
DelegateApplicationDescription {
download_url: "https://github.com/EdouardBERGE/rasm/releases/download/v2.2.5/rasm_win64.exe", // we assume a modern CPU
folder : "rasm_consolidation",
archive_format: ArchiveFormat::Raw,
exec_fname: "rasm.exe",
compile: None
}
}
}
}

}
cfg(target_os = "macos") =>
{

}
_ => {
}
}

pub struct BasmRunner {
command: clap::Command
}
Expand Down
46 changes: 1 addition & 45 deletions cpclib-bndbuild/src/runners/mod.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,15 @@
use cpclib_common::clap::{ArgMatches, Command};
use glob::glob;
use shlex::split;
use cpclib_runner::runner::Runner;

pub mod assembler;
pub mod bndbuild;
pub mod cp;
pub mod disc;
pub mod echo;
pub mod emulator;
pub mod r#extern;
pub mod imgconverter;
pub mod impdisc;
pub mod martine;
pub mod rm;
pub mod xfer;

/// Get all args (split string as done in shell and apply glob matching)
fn get_all_args(arguments: &str) -> Vec<String> {
let init_args = split(arguments).unwrap_or_default();
let mut res = Vec::new();
for p in init_args {
match glob(&p) {
Ok(entries) => {
let mut added = 0;
for entry in entries {
match entry {
Ok(p) => res.push(p.display().to_string()),
Err(e) => res.push(e.path().display().to_string())
}
added += 1;
}
if added == 0 {
res.push(p);
}
},
Err(_) => res.push(p)
}
}
res
}

pub trait Runner {
/// Run the task and return true if successfull
fn run(&self, arguments: &str) -> Result<(), String> {
println!("\t$ {} {}", self.get_command(), arguments);
let args = get_all_args(&arguments.replace(r"\", r"\\").replace("\"", "\\\""));
self.inner_run(&args)
}

/// Implement the command specific action
fn inner_run<S: AsRef<str>>(&self, itr: &[S]) -> Result<(), String>;

fn get_command(&self) -> &str;
}

pub trait RunnerWithClap: Runner {
fn get_clap_command(&self) -> &Command;

Expand Down
Loading

0 comments on commit 57878e7

Please sign in to comment.