Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a struct instead of String for package ids (fix dependencies ordering) #70

Merged
merged 2 commits into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ All notable changes to this project will be documented in this file.
by correct error handling thanks to the `anyhow` crate.
- Fix some Junit and JSON reports issues.
- Fix `--compiler` error when using relative paths.
- Fix the indentation of generated elm.json. Now uses 4 spaces.
- Fix the order of packages in the elm.json dependencies.


## [0.6.1] - (2021-01-23) [(diff)][diff-0.6.1]
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 21 additions & 22 deletions src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use pubgrub_dependency_provider_elm::dependency_provider::{
ElmPackageProviderOffline, ElmPackageProviderOnline, ProjectAdapter, VersionStrategy,
};
use pubgrub_dependency_provider_elm::project_config::{
AppDependencies, ApplicationConfig, PackageConfig, ProjectConfig,
AppDependencies, ApplicationConfig, PackageConfig, Pkg, ProjectConfig,
};

#[derive(Debug)]
Expand Down Expand Up @@ -67,7 +67,7 @@ fn init_app(
) -> anyhow::Result<ApplicationConfig> {
// Retrieve all direct and indirect dependencies
let indirect_test_deps = app_config.test_dependencies.indirect.iter();
let mut all_deps: Map<String, Range<SemVer>> = indirect_test_deps
let mut all_deps: Map<Pkg, Range<SemVer>> = indirect_test_deps
.chain(app_config.dependencies.indirect.iter())
.chain(app_config.test_dependencies.direct.iter())
.chain(app_config.dependencies.direct.iter())
Expand All @@ -79,7 +79,7 @@ fn init_app(
.context("The app dependencies are incorrect")?;

// Check if elm-explorations/test is already in the dependencies.
let test_pkg = "elm-explorations/test".to_string();
let test_pkg = Pkg::new("elm-explorations", "test");
if all_deps.contains_key(&test_pkg) {
if app_config
.test_dependencies
Expand Down Expand Up @@ -113,7 +113,7 @@ fn init_app(
elm_home,
&strategy,
&all_deps,
"root".to_string(),
Pkg::new("root", ""),
SemVer::zero(),
)
.context("Adding elm-explorations/test to the dependencies failed")?;
Expand All @@ -127,7 +127,7 @@ fn init_app(

// Add all other new deps to indirect tests deps
for (p, v) in solution.into_iter() {
if !all_deps.contains_key(&p) && &p != "root" {
if !all_deps.contains_key(&p) && p != Pkg::new("root", "") {
app_config.test_dependencies.indirect.insert(p, v);
}
}
Expand All @@ -141,7 +141,7 @@ fn init_pkg(
) -> anyhow::Result<PackageConfig> {
// Retrieve all dependencies
let test_deps = pkg_config.test_dependencies.iter();
let mut all_deps: Map<String, Range<SemVer>> = test_deps
let mut all_deps: Map<Pkg, Range<SemVer>> = test_deps
.chain(pkg_config.dependencies.iter())
.map(|(p, c)| (p.clone(), c.0.clone()))
.collect();
Expand All @@ -151,7 +151,7 @@ fn init_pkg(
.context("The package dependencies are incorrect")?;

// Check if elm-explorations/test is already in the dependencies.
let test_pkg = "elm-explorations/test".to_string();
let test_pkg = Pkg::new("elm-explorations", "test");
if all_deps.contains_key(&test_pkg) {
eprintln!("elm-explorations/test is already in your dependencies.");
return Ok(pkg_config);
Expand Down Expand Up @@ -188,7 +188,7 @@ pub fn solve<P: AsRef<Path>>(
match config {
ProjectConfig::Application(app_config) => {
let normal_deps = app_config.dependencies.direct.iter();
let direct_deps: Map<String, Range<SemVer>> = normal_deps
let direct_deps: Map<Pkg, Range<SemVer>> = normal_deps
.chain(app_config.test_dependencies.direct.iter())
.map(|(p, v)| (p.clone(), Range::exact(*v)))
.collect();
Expand All @@ -197,14 +197,14 @@ pub fn solve<P: AsRef<Path>>(
elm_home,
connectivity,
src_dirs,
&"root".to_string(),
&Pkg::new("root", ""),
SemVer::zero(),
direct_deps,
)
}
ProjectConfig::Package(pkg_config) => {
let normal_deps = pkg_config.dependencies.iter();
let deps: Map<String, Range<SemVer>> = normal_deps
let deps: Map<Pkg, Range<SemVer>> = normal_deps
.chain(pkg_config.test_dependencies.iter())
.map(|(p, c)| (p.clone(), c.0.clone()))
.collect();
Expand All @@ -225,21 +225,20 @@ fn solve_helper<P: AsRef<Path>>(
elm_home: &Path,
connectivity: &ConnectivityStrategy,
src_dirs: &[P],
pkg_id: &String,
pkg_id: &Pkg,
version: SemVer,
direct_deps: Map<String, Range<SemVer>>,
direct_deps: Map<Pkg, Range<SemVer>>,
) -> anyhow::Result<ApplicationConfig> {
// TODO: there might be an issue if that was already in the dependencies.
let mut deps = direct_deps;
deps.insert(
"mpizenberg/elm-test-runner".to_string(),
Pkg::new("mpizenberg", "elm-test-runner"),
Range::exact((4, 0, 2)),
);
// Add elm/json to the deps since it's used in Runner.elm and Reporter.elm.
if !deps.contains_key("elm/json") {
// TODO: maybe not the best way to handle but should work most of the time.
deps.insert("elm/json".to_string(), Range::between((1, 0, 0), (2, 0, 0)));
}
// TODO: maybe not the best way to handle but should work most of the time.
deps.entry(Pkg::new("elm", "json"))
.or_insert_with(|| Range::between((1, 0, 0), (2, 0, 0)));
let mut solution = solve_deps(elm_home, connectivity, &deps, pkg_id.clone(), version)
.context("Combining the project dependencies with the ones of the test runner failed")?;
solution.remove(pkg_id);
Expand Down Expand Up @@ -278,11 +277,11 @@ fn solve_helper<P: AsRef<Path>>(
/// Use progressive connectivity mode.
fn solve_check(
elm_home: &Path,
deps: &Map<String, Range<SemVer>>,
deps: &Map<Pkg, Range<SemVer>>,
strategy: &ConnectivityStrategy,
is_app: bool,
) -> anyhow::Result<()> {
let pkg_id = "root".to_string();
let pkg_id = Pkg::new("root", "");
let version = SemVer::zero();
let mut solution = solve_deps(elm_home, strategy, deps, pkg_id.clone(), version)?;
// Check that indirect deps are correct if this is for an application.
Expand All @@ -302,10 +301,10 @@ fn solve_check(
fn solve_deps(
elm_home: &Path,
connectivity: &ConnectivityStrategy,
deps: &Map<String, Range<SemVer>>,
pkg_id: String,
deps: &Map<Pkg, Range<SemVer>>,
pkg_id: Pkg,
version: SemVer,
) -> anyhow::Result<Map<String, SemVer>> {
) -> anyhow::Result<Map<Pkg, SemVer>> {
let solution = |resolution| match resolution {
Ok(sol) => Ok(sol),
Err(PubGrubError::NoSolution(tree)) => {
Expand Down