From 95446cb2bf355f762b02a6e900700158e2d7777d Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 15 Feb 2022 22:27:31 +0100 Subject: [PATCH] Allow specifying custom names for bundles --- Cargo.lock | 11 +++++++++++ xtask/Cargo.toml | 2 ++ xtask/src/main.rs | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 6a128dde..2b92c6ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -811,6 +811,15 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + [[package]] name = "ttf-parser" version = "0.14.0" @@ -1109,4 +1118,6 @@ name = "xtask" version = "0.1.0" dependencies = [ "anyhow", + "serde", + "toml", ] diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index b0cd7b2c..e27edc69 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -7,3 +7,5 @@ license = "ISC" [dependencies] anyhow = "1.0" +serde = { version = "1.0", features = ["derive"] } +toml = "0.5" diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 6dec0ad8..9b77ead3 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,4 +1,6 @@ use anyhow::{bail, Context, Result}; +use serde::Deserialize; +use std::collections::HashMap; use std::fs; use std::path::Path; use std::process::Command; @@ -6,6 +8,15 @@ use std::process::Command; const USAGE_STRING: &str = "Usage: cargo xtask bundle [--release] [--target ] [--bundle-vst3]"; +/// Any additional configuration that might be useful for creating plugin bundles, stored as +/// `bundler.toml` alongside the workspace's main `Cargo.toml` file. +type BundlerConfig = HashMap; + +#[derive(Debug, Clone, Deserialize)] +struct PackageConfig { + name: Option, +} + fn main() -> Result<()> { let project_root = Path::new(env!("CARGO_MANIFEST_DIR")) .parent() @@ -32,6 +43,11 @@ fn main() -> Result<()> { // TODO: This probably needs more work for macOS. I don't know, I don't have a Mac. fn bundle(package: &str, mut args: Vec) -> Result<()> { + let bundle_name = match load_bundler_config()?.and_then(|c| c.get(package).cloned()) { + Some(PackageConfig { name: Some(name) }) => name, + _ => package.to_string(), + }; + let mut is_release_build = false; let mut bundle_vst3 = false; let mut cross_compile_target: Option = None; @@ -83,7 +99,7 @@ fn bundle(package: &str, mut args: Vec) -> Result<()> { eprintln!(); if bundle_vst3 { let vst3_lib_path = Path::new("target").join(vst3_bundle_library_name( - package, + &bundle_name, cross_compile_target.as_deref(), )?); let vst3_bundle_home = vst3_lib_path @@ -106,6 +122,24 @@ fn bundle(package: &str, mut args: Vec) -> Result<()> { Ok(()) } +/// Load the `bundler.toml` file, if it exists. If it does exist but it cannot be parsed, then this +/// will return an error. +fn load_bundler_config() -> Result> { + // We're already in the project root + let bundler_config_path = Path::new("bundler.toml"); + if !bundler_config_path.exists() { + return Ok(None); + } + + let result = toml::from_str( + &fs::read_to_string(&bundler_config_path) + .with_context(|| format!("Could not read '{}'", bundler_config_path.display()))?, + ) + .with_context(|| format!("Could not parse '{}'", bundler_config_path.display()))?; + + Ok(Some(result)) +} + fn target_base(cross_compile_target: Option<&str>) -> Result<&'static str> { match cross_compile_target { Some("x86_64-unknown-linux-gnu") => Ok("target/x86_64-unknown-linux-gnu"),