-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build archive files for packages (#234)
* Build archive files for packages * Sort packages * Update dictionary * Fix linting * Refactor * Refactor * Define FFI archive suffix * Modify lib/os * Remove unused argument * Ignore entire lib/os * Refactor
- Loading branch information
Showing
18 changed files
with
380 additions
and
152 deletions.
There are no files selected for viewing
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
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
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,44 @@ | ||
use crate::{ | ||
external_package_configuration_reader, | ||
infra::{FilePath, Infrastructure, PackageConfiguration}, | ||
}; | ||
use petgraph::{algo::toposort, Graph}; | ||
use std::{collections::HashMap, error::Error}; | ||
|
||
pub fn sort( | ||
infrastructure: &Infrastructure, | ||
package_directory: &FilePath, | ||
output_directory: &FilePath, | ||
) -> Result<Vec<url::Url>, Box<dyn Error>> { | ||
sort_external_packages(&external_package_configuration_reader::read_recursively( | ||
infrastructure, | ||
package_directory, | ||
output_directory, | ||
)?) | ||
} | ||
|
||
fn sort_external_packages( | ||
package_configurations: &HashMap<url::Url, PackageConfiguration>, | ||
) -> Result<Vec<url::Url>, Box<dyn std::error::Error>> { | ||
let mut graph = Graph::<url::Url, ()>::new(); | ||
let mut indices = HashMap::<url::Url, _>::new(); | ||
|
||
for external_package in package_configurations.keys() { | ||
indices.insert( | ||
external_package.clone(), | ||
graph.add_node(external_package.clone()), | ||
); | ||
} | ||
|
||
for (url, package_configuration) in package_configurations { | ||
for dependency_url in package_configuration.dependencies.values() { | ||
graph.add_edge(indices[dependency_url], indices[url], ()); | ||
} | ||
} | ||
|
||
Ok(toposort(&graph, None) | ||
.unwrap() | ||
.into_iter() | ||
.map(|index| graph[index].clone()) | ||
.collect()) | ||
} |
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,47 @@ | ||
use crate::{ | ||
common::file_path_resolver, | ||
infra::{FilePath, Infrastructure, PackageConfiguration}, | ||
}; | ||
use std::{collections::HashMap, error::Error}; | ||
|
||
pub fn read_recursively( | ||
infrastructure: &Infrastructure, | ||
package_directory: &FilePath, | ||
output_directory: &FilePath, | ||
) -> Result<HashMap<url::Url, PackageConfiguration>, Box<dyn Error>> { | ||
read_dependencies( | ||
infrastructure, | ||
&infrastructure | ||
.package_configuration_reader | ||
.read(package_directory)?, | ||
output_directory, | ||
) | ||
} | ||
|
||
fn read_dependencies( | ||
infrastructure: &Infrastructure, | ||
configuration: &PackageConfiguration, | ||
output_directory: &FilePath, | ||
) -> Result<HashMap<url::Url, PackageConfiguration>, Box<dyn Error>> { | ||
Ok(configuration | ||
.dependencies | ||
.values() | ||
.map(|url| -> Result<_, Box<dyn Error>> { | ||
let configuration = infrastructure.package_configuration_reader.read( | ||
&file_path_resolver::resolve_package_directory(output_directory, url), | ||
)?; | ||
|
||
Ok(vec![(url.clone(), configuration.clone())] | ||
.into_iter() | ||
.chain(read_dependencies( | ||
infrastructure, | ||
&configuration, | ||
output_directory, | ||
)?) | ||
.collect::<Vec<_>>()) | ||
}) | ||
.collect::<Result<Vec<_>, _>>()? | ||
.into_iter() | ||
.flatten() | ||
.collect()) | ||
} |
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
Oops, something went wrong.