Allow specifying custom names for bundles
This commit is contained in:
parent
6fbec6393d
commit
95446cb2bf
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -811,6 +811,15 @@ dependencies = [
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ttf-parser"
|
name = "ttf-parser"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
|
@ -1109,4 +1118,6 @@ name = "xtask"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"serde",
|
||||||
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,3 +7,5 @@ license = "ISC"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
toml = "0.5"
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
@ -6,6 +8,15 @@ use std::process::Command;
|
||||||
const USAGE_STRING: &str =
|
const USAGE_STRING: &str =
|
||||||
"Usage: cargo xtask bundle <package> [--release] [--target <triple>] [--bundle-vst3]";
|
"Usage: cargo xtask bundle <package> [--release] [--target <triple>] [--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<String, PackageConfig>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
struct PackageConfig {
|
||||||
|
name: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let project_root = Path::new(env!("CARGO_MANIFEST_DIR"))
|
let project_root = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||||
.parent()
|
.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.
|
// 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<String>) -> Result<()> {
|
fn bundle(package: &str, mut args: Vec<String>) -> 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 is_release_build = false;
|
||||||
let mut bundle_vst3 = false;
|
let mut bundle_vst3 = false;
|
||||||
let mut cross_compile_target: Option<String> = None;
|
let mut cross_compile_target: Option<String> = None;
|
||||||
|
@ -83,7 +99,7 @@ fn bundle(package: &str, mut args: Vec<String>) -> Result<()> {
|
||||||
eprintln!();
|
eprintln!();
|
||||||
if bundle_vst3 {
|
if bundle_vst3 {
|
||||||
let vst3_lib_path = Path::new("target").join(vst3_bundle_library_name(
|
let vst3_lib_path = Path::new("target").join(vst3_bundle_library_name(
|
||||||
package,
|
&bundle_name,
|
||||||
cross_compile_target.as_deref(),
|
cross_compile_target.as_deref(),
|
||||||
)?);
|
)?);
|
||||||
let vst3_bundle_home = vst3_lib_path
|
let vst3_bundle_home = vst3_lib_path
|
||||||
|
@ -106,6 +122,24 @@ fn bundle(package: &str, mut args: Vec<String>) -> Result<()> {
|
||||||
Ok(())
|
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<Option<BundlerConfig>> {
|
||||||
|
// 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> {
|
fn target_base(cross_compile_target: Option<&str>) -> Result<&'static str> {
|
||||||
match cross_compile_target {
|
match cross_compile_target {
|
||||||
Some("x86_64-unknown-linux-gnu") => Ok("target/x86_64-unknown-linux-gnu"),
|
Some("x86_64-unknown-linux-gnu") => Ok("target/x86_64-unknown-linux-gnu"),
|
||||||
|
|
Loading…
Reference in a new issue