Skip to content

Commit

Permalink
Fix dependency path handling to be relative to parent
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchmindtree committed Feb 28, 2022
1 parent 39a174f commit 1b27b39
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions forc/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use petgraph::{self, Directed};
use serde::{Deserialize, Serialize};
use std::{
collections::{hash_map::Entry, HashMap},
path::PathBuf,
path::{Path, PathBuf},
};
use sway_core::{
source_map::SourceMap, BuildConfig, BytecodeCompilationResult, CompileAstResult, NamespaceRef,
Expand Down Expand Up @@ -171,15 +171,16 @@ fn fetch_children(
graph: &mut Graph,
visited: &mut HashMap<Pinned, NodeIx>,
) -> Result<(), String> {
let fetched = &graph[node];
let manifest = read_manifest(&fetched.path)?;
let parent = &graph[node];
let parent_path = parent.path.clone();
let manifest = read_manifest(&parent_path)?;
let deps = match &manifest.dependencies {
None => return Ok(()),
Some(deps) => deps,
};
for (name, dep) in deps {
let name = name.clone();
let source = dep_to_source(dep)?;
let source = dep_to_source(&parent_path, dep)?;
if offline_mode && !matches!(source, Source::Path(_)) {
return Err(format!("Unable to fetch pkg {:?} in offline mode", source));
}
Expand Down Expand Up @@ -367,12 +368,17 @@ fn fetch_pinned(pkg: Pinned) -> Result<PinnedFetched, String> {
Ok(fetched)
}

fn dep_to_source(dep: &Dependency) -> Result<Source, String> {
/// Given the path to a package and a `Dependency` parsed from one of its forc dependencies,
/// produce the `Source` for that dependendency.
fn dep_to_source(pkg_path: &Path, dep: &Dependency) -> Result<Source, String> {
let source = match dep {
Dependency::Simple(ref _ver_str) => unimplemented!(),
Dependency::Detailed(ref det) => {
match (&det.path, &det.version, &det.git, &det.branch, &det.tag) {
(Some(path), _, _, _, _) => Source::Path(PathBuf::from(path)),
(Some(relative_path), _, _, _, _) => {
let path = pkg_path.join(relative_path);
Source::Path(path)
}
(_, _, Some(repo), branch, tag) => {
let reference = match (branch, tag) {
(Some(branch), None) => branch.clone(),
Expand Down

0 comments on commit 1b27b39

Please sign in to comment.