blob: 9b873444de9143123de89cde1907c6a23901f9ad [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use failure::{Error, ResultExt};
use serde_derive::Deserialize;
use std::{fs, path::PathBuf};
#[derive(Clone, Debug, Default, Deserialize)]
pub struct DataFile {
pub src: String,
pub dst: String,
}
#[derive(Clone, Debug, Default, Deserialize)]
pub struct Manifest {
#[serde(default)]
pub library_search_paths: Vec<String>,
#[serde(default)]
pub additional_shared_libraries: Vec<String>,
#[serde(default)]
pub additional_static_libraries: Vec<String>,
#[serde(default)]
pub data_files: Vec<DataFile>,
}
pub fn load_manifest(manifest_path: &Option<PathBuf>) -> Result<Manifest, Error> {
let cwd: PathBuf = if let Some(actual_manifest_path) = manifest_path.as_ref() {
actual_manifest_path.parent().expect("manifest_path parent").to_path_buf()
} else {
std::fs::canonicalize(std::env::current_dir()?)
.context("autotest: canonicalize working directory")?
};
let manifest_path = cwd.join("Fargo.toml");
if !manifest_path.exists() {
return Ok(Manifest::default());
}
let manifest_contents = fs::read_to_string(manifest_path)?;
let manifest = toml::from_str(&manifest_contents)?;
Ok(manifest)
}