Skip to content

Commit

Permalink
Update with partial implementation of auto-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
yamadapc committed Aug 3, 2021
1 parent 1788467 commit 86e08ee
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 3 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

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

14 changes: 14 additions & 0 deletions crates/augmented-dev-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "augmented-dev-cli"
version = "0.1.0"
edition = "2018"

[dependencies]
clap = "^3.0.0-beta.2"
log = "^0.4.14"
wisual-logger = { version = "^0.1.3", path = "../wisual-logger" }
cmd_lib = "^1.1.0"
serde_json = "^1.0"
chrono = "0.4"
serde = { version = "^1.0", features = [ "derive" ] }
toml = "^0.5.8"
26 changes: 26 additions & 0 deletions crates/augmented-dev-cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::process::Command;

fn main() {
{
println!(
"cargo:rustc-env=PROFILE={}",
std::env::var("PROFILE").unwrap()
);
}
{
let output = Command::new("git")
.args(&["rev-parse", "HEAD"])
.output()
.unwrap();
let git_rev = String::from_utf8(output.stdout).unwrap().trim().to_string();
println!("cargo:rustc-env=GIT_REV={}", git_rev);
}
{
let output = Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output()
.unwrap();
let git_rev = String::from_utf8(output.stdout).unwrap().trim().to_string();
println!("cargo:rustc-env=GIT_REV_SHORT={}", git_rev);
}
}
159 changes: 159 additions & 0 deletions crates/augmented-dev-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
use chrono::prelude::*;
use std::fs::read_to_string;
use std::path::Path;

use cmd_lib::run_cmd;

use crate::manifests::{MacosAppConfig, ReleaseJson};
use manifests::CargoToml;

mod manifests;

fn get_cli_version() -> String {
format!(
"{}-{}-{}",
env!("PROFILE"),
env!("CARGO_PKG_VERSION"),
env!("GIT_REV_SHORT")
)
}

fn get_package_version(pkg_version: &str) -> String {
let output = std::process::Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output()
.unwrap();
let git_rev = String::from_utf8(output.stdout).unwrap().trim().to_string();
format!("release-{}-{}", pkg_version, git_rev)
}

fn run_build_release(crate_path: &str) {
let config_path = Path::new(crate_path).join("Cargo.toml");
let input_cargo_file = read_to_string(config_path).expect("Failed to read toml file");
let cargo_toml: CargoToml =
toml::from_str(&input_cargo_file).expect("Failed to parse toml file");
let package_version = get_package_version(&cargo_toml.package.version);

log::info!("Read Cargo.toml:\n{:#?}", cargo_toml);
log::info!("Forcing a build of \"{}\"", cargo_toml.package.name);

run_cmd!(cd ${crate_path}; cargo build --release).unwrap();
let release_json = ReleaseJson {
name: cargo_toml.package.name.clone(),
key: package_version.clone(),
created_at: Utc::now().to_rfc3339(),
};
log::info!("Release:\n{:#?}", release_json);

if let Some(local_package) = create_local_package(crate_path, &cargo_toml, &release_json) {
let artifact_path = compress_release(&cargo_toml, local_package);
upload_release(&release_json, artifact_path);
}
}

fn upload_release(release_json: &ReleaseJson, artifact_path: String) {}

fn compress_release(cargo_toml: &CargoToml, local_package: LocalPackage) -> String {
let path = local_package.path;
let volume_name = cargo_toml.package.name.clone();
let dmg_name = format!("{}.dmg", volume_name);
let target_path = {
let path = Path::new(&*path);
let parent = path.parent().unwrap();
let dmg_path = parent.join(&*dmg_name);
dmg_path.to_str().unwrap().to_string()
};

log::info!(
"Creating DMG file VOLUME_NAME={} SOURCE={} TARGET={}",
volume_name,
path,
target_path
);
run_cmd!(
hdiutil create -volname ${volume_name} -srcfolder ${path} -ov -format UDZO ${target_path}
)
.unwrap();

target_path
}

struct LocalPackage {
path: String,
}

fn create_local_package(
crate_path: &str,
cargo_toml: &CargoToml,
release_json: &ReleaseJson,
) -> Option<LocalPackage> {
let macos_config = cargo_toml
.package
.metadata
.clone()
.map(|m| m.app)
.flatten()
.map(|a| a.macos)
.flatten();
if let Some(macos_config) = macos_config {
match macos_config {
MacosAppConfig::AppTemplate { template_path } => {
let template_path = Path::new(crate_path).join(template_path);
let base_target_path =
Path::new("./target/apps/macos/").join(cargo_toml.package.name.clone());

log::info!(
"Copying template into `{}` directory",
base_target_path.to_str().unwrap()
);
run_cmd!(mkdir -p ${base_target_path}).unwrap();
run_cmd!(cp -r ${template_path} ${base_target_path}).unwrap();

let release_path =
Path::new("./target/release/").join(cargo_toml.package.name.clone());
let target_app_path = base_target_path.join(template_path.file_name().unwrap());
run_cmd!(cp ${release_path} ${target_app_path}/Contents/MacOS/).unwrap();

let release_json_path = base_target_path.join("release.json");
log::info!("Outputting {}", release_json_path.to_str().unwrap());
let release_json_str = serde_json::to_string_pretty(&release_json).unwrap();
std::fs::write(release_json_path, release_json_str).unwrap();

Some(LocalPackage {
path: base_target_path.to_str().unwrap().to_string(),
})
}
}
} else {
None
}
}

fn main() {
wisual_logger::init_from_env();
log::info!(
"Starting augmented-dev-cli VERSION={} GIT_REV={} GIT_REV_SHORT={}",
get_cli_version(),
env!("GIT_REV"),
env!("GIT_REV_SHORT")
);

let version = get_cli_version();
let mut app = clap::App::new("augmented-dev-cli")
.version(&*version)
.about("Development CLI for augmented projects, helps build and deploy apps")
.subcommand(
clap::App::new("build-release")
.about("Build a release package for a given app")
.arg(clap::Arg::from("-c, --crate=<PATH> 'Crate path'")),
);

let matches = app.clone().get_matches();
if matches.is_present("build-release") {
let matches = matches.subcommand_matches("build-release").unwrap();
run_build_release(matches.value_of("crate").unwrap());
} else {
app.print_help().unwrap();
std::process::exit(1);
}
}
42 changes: 42 additions & 0 deletions crates/augmented-dev-cli/src/manifests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use serde::{Deserialize, Serialize};
use toml::map::Map;
use toml::Value;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReleaseJson {
pub name: String,
pub key: String,
pub created_at: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[serde(tag = "type")]
pub enum MacosAppConfig {
#[serde(rename_all = "kebab-case")]
AppTemplate { template_path: String },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppConfig {
pub macos: Option<MacosAppConfig>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CargoTomlPackageMetadata {
pub app: Option<AppConfig>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CargoTomlPackage {
pub name: String,
pub description: String,
pub version: String,
pub metadata: Option<CargoTomlPackageMetadata>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CargoToml {
pub package: CargoTomlPackage,
}
5 changes: 5 additions & 0 deletions crates/plugin-host-gui2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "plugin-host-gui2"
description = "A VST plugin host for development"
version = "0.1.0"
edition = "2018"

Expand Down Expand Up @@ -49,3 +50,7 @@ story = []
[[bench]]
name = "plugin_host_gui_criterion"
harness = false

[package.metadata.app.macos]
type = "app-template"
template-path = "./macos-app/Plugin Host.app"
21 changes: 21 additions & 0 deletions crates/plugin-host-gui2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Pedro Tacla Yamada

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions crates/plugin-host-gui2/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::process::Command;

fn main() {
{
println!(
"cargo:rustc-env=PROFILE={}",
std::env::var("PROFILE").unwrap()
);
}
{
let output = Command::new("git")
.args(&["rev-parse", "HEAD"])
.output()
.unwrap();
let git_rev = String::from_utf8(output.stdout).unwrap().trim().to_string();
println!("cargo:rustc-env=GIT_REV={}", git_rev);
}
{
let output = Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output()
.unwrap();
let git_rev = String::from_utf8(output.stdout).unwrap().trim().to_string();
println!("cargo:rustc-env=GIT_REV_SHORT={}", git_rev);
}
}
6 changes: 5 additions & 1 deletion crates/plugin-host-gui2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ impl Application for App {
type Flags = ();

fn new(_flags: Self::Flags) -> (Self, Command<Self::Message>) {
log::info!("plugin-host-gui2: Application is booting");
let version = utils::get_version();
log::info!(
"plugin-host-gui2: Application is booting - VERSION={}",
version
);
let mut plugin_host = plugin_host_lib::TestPluginHost::default();
let start_result = plugin_host.start().map_err(|err| {
log::error!("Failed to start host: {:?}", err);
Expand Down
9 changes: 9 additions & 0 deletions crates/plugin-host-gui2/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
macro_rules! string_vec {
($($x:expr),*) => (vec![$($x.to_string()), *])
}

pub fn get_version() -> String {
format!(
"{}-{}-{}",
env!("PROFILE"),
env!("CARGO_PKG_VERSION"),
env!("GIT_REV_SHORT")
)
}
2 changes: 2 additions & 0 deletions docs/AUTO_UPDATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Auto-update
This file documents the auto-update process and components.

> This is WIP & only partially implemented. The releases will be uploaded to S3.
## Overview
We'd like the applications to provide prompts for users telling them they may update the software.

Expand Down
11 changes: 9 additions & 2 deletions scripts/plugin-host-bundle-osx.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#!/usr/bin/env bash

set -e
set -x

CARGO_PKG_VERSION=$(cat ./crates/plugin-host-gui2/Cargo.toml | grep version | head -n1 | awk '{ print $3 }' | sed 's/"//g')
GIT_REV=$(git rev-parse --short HEAD)
version="release-$CARGO_PKG_VERSION-$GIT_REV"

echo ">> Building plugin-host-gui2 version=$version"
cargo build --release --package plugin-host-gui2

echo ">> Building \"Plugin Host.app\" bundle"
mkdir -p ./target/apps/macos
cp -r "./crates/plugin-host-gui2/macos-app/Plugin Host.app" ./target/apps/macos/
cp target/release/plugin-host-gui2 "./target/apps/macos/Plugin Host.app/Contents/MacOS/"
cp target/release/plugin-host-gui2 "./target/apps/macos/Plugin Host.app/Contents/MacOS/"

0 comments on commit 86e08ee

Please sign in to comment.