mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-10 09:01:34 +11:00
No longer hardcode the crates to publish
This commit is contained in:
parent
c74c231863
commit
0e1eb41852
|
@ -7,14 +7,6 @@ use std::time::Duration;
|
||||||
use std::{env, thread};
|
use std::{env, thread};
|
||||||
use toml_edit::Document;
|
use toml_edit::Document;
|
||||||
|
|
||||||
const CRATES_TO_PUBLISH: &[&str] = &[
|
|
||||||
"agb-macros",
|
|
||||||
"agb-fixnum",
|
|
||||||
"agb-image-converter",
|
|
||||||
"agb-sound-converter",
|
|
||||||
"agb",
|
|
||||||
];
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
FindRootDirectory,
|
FindRootDirectory,
|
||||||
|
@ -44,11 +36,12 @@ pub fn publish(matches: &ArgMatches) -> Result<(), Error> {
|
||||||
let mut fully_published_crates: HashSet<String> = HashSet::new();
|
let mut fully_published_crates: HashSet<String> = HashSet::new();
|
||||||
let mut published_crates: HashSet<String> = HashSet::new();
|
let mut published_crates: HashSet<String> = HashSet::new();
|
||||||
|
|
||||||
let dependencies = build_dependency_graph(&root_directory, CRATES_TO_PUBLISH)?;
|
let dependencies = build_dependency_graph(&root_directory)?;
|
||||||
|
let crates_to_publish: Vec<_> = dependencies.keys().collect();
|
||||||
|
|
||||||
while published_crates.len() != CRATES_TO_PUBLISH.len() {
|
while published_crates.len() != crates_to_publish.len() {
|
||||||
// find all crates which can be published now but haven't
|
// find all crates which can be published now but haven't
|
||||||
let publishable_crates: Vec<_> = CRATES_TO_PUBLISH
|
let publishable_crates: Vec<_> = crates_to_publish
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&crate_to_publish| !published_crates.contains(crate_to_publish))
|
.filter(|&&crate_to_publish| !published_crates.contains(crate_to_publish))
|
||||||
.filter(|&&crate_to_publish| {
|
.filter(|&&crate_to_publish| {
|
||||||
|
@ -146,17 +139,27 @@ fn read_cargo_toml_version(folder: &Path) -> Result<String, Error> {
|
||||||
Ok(version_value.to_owned())
|
Ok(version_value.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_dependency_graph(
|
fn build_dependency_graph(root: &Path) -> Result<HashMap<String, Vec<String>>, Error> {
|
||||||
root: &Path,
|
|
||||||
agb_crates: &[&str],
|
|
||||||
) -> Result<HashMap<String, Vec<String>>, Error> {
|
|
||||||
let mut result = HashMap::new();
|
let mut result = HashMap::new();
|
||||||
|
result.insert("agb".to_owned(), get_agb_dependencies(&root.join("agb"))?);
|
||||||
|
|
||||||
for agb_crate in agb_crates {
|
let mut added_new_crates = true;
|
||||||
result.insert(
|
while added_new_crates {
|
||||||
agb_crate.to_string(),
|
added_new_crates = false;
|
||||||
get_agb_dependencies(&root.join(agb_crate))?,
|
|
||||||
);
|
let all_crates: HashSet<String> = HashSet::from_iter(result.values().flatten().cloned());
|
||||||
|
|
||||||
|
for dep_crate in all_crates {
|
||||||
|
if result.contains_key(&dep_crate) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
added_new_crates = true;
|
||||||
|
result.insert(
|
||||||
|
dep_crate.to_owned(),
|
||||||
|
get_agb_dependencies(&root.join(dep_crate))?,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
|
Loading…
Reference in a new issue