Support build time in module manifests (#71)

This commit is contained in:
vms 2021-04-09 10:43:55 +03:00 committed by GitHub
parent 6d4ef8200b
commit 2aa3caee83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 6 deletions

12
Cargo.lock generated
View File

@ -711,6 +711,7 @@ name = "fce-module-info-parser"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono",
"fluence-sdk-main 0.5.0", "fluence-sdk-main 0.5.0",
"semver 0.11.0", "semver 0.11.0",
"serde", "serde",
@ -1148,7 +1149,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"libc", "libc",
"wasi 0.10.2+wasi-snapshot-preview1", "wasi 0.10.0+wasi-snapshot-preview1",
] ]
[[package]] [[package]]
@ -2715,11 +2716,12 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.1.43" version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [ dependencies = [
"libc", "libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi 0.3.9", "winapi 0.3.9",
] ]
@ -3096,9 +3098,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.10.2+wasi-snapshot-preview1" version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"

View File

@ -16,6 +16,7 @@ fluence-sdk-main = "0.5.0"
wasmer-core = { package = "wasmer-runtime-core-fl", version = "0.17.0" } wasmer-core = { package = "wasmer-runtime-core-fl", version = "0.17.0" }
anyhow = "1.0.31" anyhow = "1.0.31"
chrono = "0.4.19"
walrus = "0.18.0" walrus = "0.18.0"
semver = "0.11.0" semver = "0.11.0"

View File

@ -47,4 +47,8 @@ pub enum ManifestError {
/// Manifest contains some trailing characters. /// Manifest contains some trailing characters.
#[error("embedded manifest is corrupted: there are some trailing characters")] #[error("embedded manifest is corrupted: there are some trailing characters")]
ManifestRemainderNotEmpty, ManifestRemainderNotEmpty,
/// Error occurred while parsing embedded build time.
#[error("build time can't be parsed: {0}")]
DateTimeParseError(#[from] chrono::ParseError),
} }

View File

@ -21,6 +21,7 @@ pub struct ModuleManifest {
pub version: semver::Version, pub version: semver::Version,
pub description: String, pub description: String,
pub repository: String, pub repository: String,
pub build_time: chrono::DateTime<chrono::FixedOffset>,
} }
use super::ManifestError; use super::ManifestError;
@ -39,16 +40,20 @@ impl TryFrom<&[u8]> for ModuleManifest {
let (version, next_offset) = try_extract_field_as_version(value, next_offset, "version")?; let (version, next_offset) = try_extract_field_as_version(value, next_offset, "version")?;
let (description, next_offset) = try_extract_field_as_string(value, next_offset, "description")?; let (description, next_offset) = try_extract_field_as_string(value, next_offset, "description")?;
let (repository, next_offset) = try_extract_field_as_string(value, next_offset, "repository")?; let (repository, next_offset) = try_extract_field_as_string(value, next_offset, "repository")?;
let (build_time, next_offset) = try_extract_field_as_string(value, next_offset, "build time")?;
if next_offset != value.len() { if next_offset != value.len() {
return Err(ManifestError::ManifestRemainderNotEmpty) return Err(ManifestError::ManifestRemainderNotEmpty)
} }
let build_time = chrono::DateTime::parse_from_rfc3339(&build_time)?;
let manifest = ModuleManifest { let manifest = ModuleManifest {
authors, authors,
version, version,
description, description,
repository, repository,
build_time
}; };
Ok(manifest) Ok(manifest)
@ -140,6 +145,7 @@ impl fmt::Display for ModuleManifest {
writeln!(f, "authors: {}", self.authors)?; writeln!(f, "authors: {}", self.authors)?;
writeln!(f, "version: {}", self.version)?; writeln!(f, "version: {}", self.version)?;
writeln!(f, "description: {}", self.description)?; writeln!(f, "description: {}", self.description)?;
write!(f, "repository: {}", self.repository) writeln!(f, "repository: {}", self.repository)?;
write!(f, "build time: {} UTC", self.build_time)
} }
} }

View File

@ -71,6 +71,7 @@ fn test_reading_simple_config() {
let version = semver::Version::from_str("0.1.0").unwrap(); let version = semver::Version::from_str("0.1.0").unwrap();
let description = "description".to_string(); let description = "description".to_string();
let repository = "repository".to_string(); let repository = "repository".to_string();
let build_time = chrono::Utc::now();
let mut array = ByteEncoder::new(); let mut array = ByteEncoder::new();
@ -78,6 +79,7 @@ fn test_reading_simple_config() {
array.add_utf8_field(&version.to_string()); array.add_utf8_field(&version.to_string());
array.add_utf8_field(&description); array.add_utf8_field(&description);
array.add_utf8_field(&repository); array.add_utf8_field(&repository);
array.add_utf8_field(&build_time.to_rfc3339());
let actual: ModuleManifest = array let actual: ModuleManifest = array
.as_bytes() .as_bytes()
@ -89,6 +91,7 @@ fn test_reading_simple_config() {
version, version,
description, description,
repository, repository,
build_time: build_time.into(),
}; };
assert_eq!(actual, expected); assert_eq!(actual, expected);