-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
231 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::fs::File; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
|
||
use flate2::write::GzEncoder; | ||
use flate2::Compression; | ||
use rwf::config::ConfigFile; | ||
use tokio::process::Command; | ||
|
||
use crate::logging::*; | ||
use crate::util::*; | ||
|
||
pub async fn build() -> Result<bool, Box<dyn std::error::Error + 'static>> { | ||
let build = Command::new("cargo") | ||
.arg("build") | ||
.arg("--release") | ||
.status() | ||
.await?; | ||
|
||
if !build.success() { | ||
error("couldn't build the application, check build logs for error"); | ||
return Ok(false); | ||
} | ||
|
||
Ok(true) | ||
} | ||
|
||
pub async fn package(config: Option<PathBuf>) -> Result<(), Box<dyn std::error::Error + 'static>> { | ||
if !build().await? { | ||
return Ok(()); | ||
} | ||
|
||
let archive = File::create("build.tar.gz")?; | ||
let enc = GzEncoder::new(archive, Compression::default()); | ||
let mut tar = tar::Builder::new(enc); | ||
|
||
let info = package_info().await?; | ||
let executable = Path::new(&info.target_dir).join("release").join(&info.name); | ||
|
||
packaging("binary"); | ||
tar.append_file(&info.name, &mut File::open(executable).expect("binary")) | ||
.expect("binary"); | ||
|
||
for path in ["static", "templates"] { | ||
let p = Path::new(path); | ||
|
||
if p.is_dir() { | ||
packaging(path); | ||
tar.append_dir_all(path, p)?; | ||
} | ||
} | ||
|
||
if let Some(config) = config { | ||
if config.is_file() { | ||
if let Err(_) = ConfigFile::load(&config) { | ||
warning(format!( | ||
"{} doesn't seem to be be valid Rwf config file, but we'll use it anyway", | ||
config.display() | ||
)); | ||
} | ||
packaging(config.display()); | ||
tar.append_file("rwf.toml", &mut File::open(config)?)?; | ||
} else { | ||
warning(format!("{} does not exist, skipping", config.display())); | ||
} | ||
} | ||
|
||
created("build.tar.gz"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,43 @@ | ||
use tokio::fs::read_to_string; | ||
use tokio::process::Command; | ||
use toml::Value; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct PackageInfo { | ||
pub name: String, | ||
pub version: String, | ||
pub target_dir: String, | ||
} | ||
|
||
async fn cargo_toml() -> Result<Value, Box<dyn std::error::Error + 'static>> { | ||
let cargo_toml = read_to_string("Cargo.toml").await?; | ||
let toml: Value = toml::from_str(&cargo_toml)?; | ||
|
||
Ok(toml) | ||
} | ||
|
||
pub async fn package_info() -> Result<PackageInfo, Box<dyn std::error::Error + 'static>> { | ||
let toml = cargo_toml().await?; | ||
|
||
let name = toml | ||
.get("package") | ||
.expect("Cargo.toml to have a valid [package] attribute") | ||
.get("name") | ||
.expect("Cargo.toml to have a valid \"name\" field"); | ||
|
||
let version = toml | ||
.get("package") | ||
.expect("Cargo.toml to have a valid [package] attribute") | ||
.get("version") | ||
.expect("Cargo.toml to have a valid \"name\" field"); | ||
|
||
let metadata = Command::new("cargo").arg("metadata").output().await?.stdout; | ||
let json: serde_json::Value = serde_json::from_slice(&metadata)?; | ||
let target_dir = json["target_directory"].as_str().unwrap().to_string(); | ||
|
||
Ok(PackageInfo { | ||
name: name.as_str().unwrap().to_string(), | ||
version: version.as_str().unwrap().to_string(), | ||
target_dir, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![allow(unused_imports)] | ||
use std::path::PathBuf; | ||
use std::time::Duration; | ||
|
||
|