Skip to content
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
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,18 @@ pub fn main() -> Result<()> {
log::debug!("maintaining link to {} at {:?}", pkg_name, path);

// Determine the checkout path for this package.
let pkg_path = io.get_package_path(sess.dependency_with_name(pkg_name)?);
let pkg_path = sess.get_package_path(sess.dependency_with_name(pkg_name)?);

// Checkout if we are running update or package path does not exist yet
if matches!(cli.command, Commands::Update(_)) || !pkg_path.clone().exists() {
if matches!(cli.command, Commands::Update(_)) || !pkg_path.exists() {
let rt = Runtime::new()?;
rt.block_on(io.checkout(sess.dependency_with_name(pkg_name)?, false, &[]))?;
}

// Convert to relative path
let pkg_path = path
.parent()
.and_then(|path| pathdiff::diff_paths(pkg_path.clone(), path))
.and_then(|path| pathdiff::diff_paths(&pkg_path, path))
.unwrap_or(pkg_path);

// Check if there is something at the destination path that needs to be
Expand Down
16 changes: 7 additions & 9 deletions src/cmd/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub fn run(sess: &Session, args: &AuditArgs) -> Result<()> {
let io_ref = &io;
let dep_versions = rt.block_on(async {
let futures = pkgs
.clone()
.iter()
.map(|&pkg| async move {
futures::join!(
Expand Down Expand Up @@ -80,18 +79,17 @@ pub fn run(sess: &Session, args: &AuditArgs) -> Result<()> {
let parent_array = get_parent_array(sess, &rt, &io, pkg_name, false)?;
let current_version = sess.dependency(*pkg).version.clone();
let current_version_unwrapped = current_version
.clone()
.as_ref()
.map(|v| v.to_string())
.unwrap_or_default();
let current_revision = sess.dependency(*pkg).revision.clone();
let current_revision_unwrapped = current_revision.clone().unwrap_or_default();
let available_versions = match dep_versions.get(pkg).unwrap().clone() {
DependencyVersions::Git(versions) => versions.versions,
let current_revision_unwrapped = current_revision.as_deref().unwrap_or_default();
let available_versions = match dep_versions.get(pkg).unwrap() {
DependencyVersions::Git(versions) => {
versions.versions.iter().map(|(v, _)| v.clone()).collect()
}
_ => vec![],
}
.into_iter()
.map(|(v, _)| v)
.collect::<Vec<semver::Version>>();
};
let highest_version = available_versions.iter().max();

let mut conflicting = false;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub fn get_path_subdeps(
depref: DependencyRef,
) -> Result<IndexMap<String, PathBuf>> {
let binding = IndexMap::new();
let old_path = io.get_package_path(depref);
let old_path = io.sess.get_package_path(depref);
let mut path_deps = match rt.block_on(io.dependency_manifest(depref, false, &[]))? {
Some(m) => &m.dependencies,
None => &binding,
Expand Down
106 changes: 38 additions & 68 deletions src/cmd/fusesoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::fs;
use std::fs::read_to_string;
use std::io::IsTerminal;
use std::io::{self, Write};
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use clap::{ArgAction, Args};
use indexmap::IndexMap;
Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn run_single(sess: &Session, args: &FusesocArgs) -> Result<()> {
&srcs,
&fuse_depend_string,
&pkg_manifest_paths,
bender_generate_flag.to_string(),
bender_generate_flag,
&args.license,
)?;

Expand Down Expand Up @@ -162,7 +162,7 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {
pkgs.iter().map(|&id| {
(
sess.dependency_name(id).to_string(),
io.get_package_path(id),
sess.get_package_path(id),
)
})
})
Expand Down Expand Up @@ -205,13 +205,7 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {

fuse_depend_string.insert(
pkg.to_string(),
get_fuse_depend_string(
pkg,
&srcs,
vendor_string.to_string(),
top,
version_string.clone(),
),
get_fuse_depend_string(pkg, &srcs, vendor_string, top, version_string.clone()),
);
} else {
let mut index = 0;
Expand All @@ -235,8 +229,8 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {
})?;

let fuse_core = parse_fuse_file(
file_str,
present_core_files[pkg][i].display().to_string(),
&file_str,
&present_core_files[pkg][i].display().to_string(),
)?;
writeln!(
msg,
Expand Down Expand Up @@ -294,18 +288,12 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {

fuse_depend_string.insert(
pkg.to_string(),
get_fuse_depend_string(
pkg,
&srcs,
vendor_string.to_string(),
top,
version_string.clone(),
),
get_fuse_depend_string(pkg, &srcs, vendor_string, top, version_string.clone()),
);
} else {
let fuse_core = parse_fuse_file(
file_str,
present_core_files[pkg][index].display().to_string(),
&file_str,
&present_core_files[pkg][index].display().to_string(),
)?;
fuse_depend_string.insert(pkg.to_string(), fuse_core.name.clone());
}
Expand All @@ -324,7 +312,7 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {
src_packages,
&fuse_depend_string,
&pkg_manifest_paths,
bender_generate_flag.to_string(),
bender_generate_flag,
&args.license,
)?;

Expand All @@ -337,11 +325,11 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {
}

fn get_fuse_file_str(
pkg: &String,
pkg: &str,
src_packages: &[SourceGroup],
fuse_depend_string: &IndexMap<String, String>,
pkg_manifest_paths: &IndexMap<String, PathBuf>,
bender_generate_flag: String,
bender_generate_flag: &str,
lic_string: &[String],
) -> Result<String> {
let mut fuse_str = "CAPI=2:\n".to_string();
Expand All @@ -354,7 +342,7 @@ fn get_fuse_file_str(
}

let fuse_pkg = FuseSoCCAPI2 {
name: fuse_depend_string[&pkg.to_string()].clone(),
name: fuse_depend_string[pkg].clone(),
description: None,
filesets: {
src_packages
Expand All @@ -366,13 +354,10 @@ fn get_fuse_file_str(
file_type: Some("systemVerilogSource".to_string()),
// logical_name: None,
files: {
get_fileset_files(file_pkg, pkg_manifest_paths[pkg].clone())
get_fileset_files(file_pkg, &pkg_manifest_paths[pkg])
.into_iter()
.chain(file_pkg.include_dirs.iter().flat_map(|(_, incdir)| {
get_include_files(
&incdir.to_path_buf(),
pkg_manifest_paths[pkg].clone(),
)
get_include_files(incdir, &pkg_manifest_paths[pkg])
}))
.collect()
},
Expand Down Expand Up @@ -404,10 +389,7 @@ fn get_fuse_file_str(
.unwrap_or(&Vec::new())
.iter()
.flat_map(|(_, incdir)| {
get_include_files(
&incdir.to_path_buf(),
pkg_manifest_paths[pkg].clone(),
)
get_include_files(incdir, &pkg_manifest_paths[pkg])
})
.collect()
}
Expand Down Expand Up @@ -479,30 +461,30 @@ fn get_fuse_file_str(
Ok(fuse_str)
}

fn parse_fuse_file(file_str: String, filename: String) -> Result<FuseSoCCAPI2> {
fn parse_fuse_file(file_str: &str, filename: &str) -> Result<FuseSoCCAPI2> {
serde_yaml_ng::from_value({
let mut value = serde_yaml_ng::from_str::<Value>(&file_str).map_err(|cause| {
let mut value = serde_yaml_ng::from_str::<Value>(file_str).map_err(|cause| {
Error::chain(
format!("Unable to parse core file to value {:?}.", &filename),
format!("Unable to parse core file to value {:?}.", filename),
cause,
)
})?;
value.apply_merge().map_err(|cause| {
Error::chain(
format!("Unable to apply merge to file {:?}.", &filename),
format!("Unable to apply merge to file {:?}.", filename),
cause,
)
})?;
value
})
.map_err(|cause| Error::chain(format!("Unable to parse core file {:?}.", &filename), cause))
.map_err(|cause| Error::chain(format!("Unable to parse core file {:?}.", filename), cause))
}

fn get_fuse_depend_string(
pkg: &String,
pkg: &str,
srcs: &SourceGroup,
vendor_string: String,
top: &String,
vendor_string: &str,
top: &str,
version_string: Option<semver::Version>,
) -> String {
let src_packages = srcs
Expand All @@ -519,15 +501,15 @@ fn get_fuse_depend_string(
})
.collect()
} else {
src_packages.clone()
src_packages
};

format!(
"{}:{}:{}:{}", // VLNV
vendor_string, // Vendor
"", // Library
pkg, // Name
match &src_packages.clone()[0].version {
match &src_packages[0].version {
Some(version) => format!("{}", version),
None => "".to_string(),
} // Version
Expand All @@ -536,29 +518,29 @@ fn get_fuse_depend_string(

fn get_fileset_name(spec: &TargetSpec, top: bool) -> String {
let tmp_str = match spec {
TargetSpec::Wildcard => "".to_string(),
TargetSpec::Wildcard => String::new(),
TargetSpec::Name(name) => name.to_string(),
TargetSpec::Any(specs) => {
let mut spec_str = "".to_string();
let mut spec_str = String::new();
for spec in specs.iter() {
let mystr = get_fileset_name(spec, false);
if !spec_str.is_empty() && !mystr.is_empty() {
spec_str.push_str("_or_");
}
spec_str.push_str(&mystr);
}
spec_str.to_string()
spec_str
}
TargetSpec::All(specs) => {
let mut spec_str = "".to_string();
let mut spec_str = String::new();
for spec in specs.iter() {
let mystr = get_fileset_name(spec, false);
if !spec_str.is_empty() && !mystr.is_empty() {
spec_str.push('_');
}
spec_str.push_str(&mystr);
}
spec_str.to_string()
spec_str
}
TargetSpec::Not(spec) => format!("not{}", get_fileset_name(spec, false)),
};
Expand All @@ -569,40 +551,31 @@ fn get_fileset_name(spec: &TargetSpec, top: bool) -> String {
}
}

fn get_fileset_files(file_pkg: &SourceGroup, root_dir: PathBuf) -> Vec<FuseFileType> {
fn get_fileset_files(file_pkg: &SourceGroup, root_dir: &Path) -> Vec<FuseFileType> {
file_pkg
.files
.iter()
.filter_map(|src_file| match src_file {
SourceFile::File(intern_file, _) => Some(
match intern_file.extension().and_then(std::ffi::OsStr::to_str) {
Some("vhd") | Some("vhdl") => FuseFileType::IndexMap(IndexMap::from([(
intern_file
.strip_prefix(root_dir.clone())
.unwrap()
.to_path_buf(),
intern_file.strip_prefix(root_dir).unwrap().to_path_buf(),
FuseSoCFile {
is_include_file: None,
include_path: None,
file_type: Some("vhdlSource".to_string()),
},
)])),
Some("v") => FuseFileType::IndexMap(IndexMap::from([(
intern_file
.strip_prefix(root_dir.clone())
.unwrap()
.to_path_buf(),
intern_file.strip_prefix(root_dir).unwrap().to_path_buf(),
FuseSoCFile {
is_include_file: None,
include_path: None,
file_type: Some("verilogSource".to_string()),
},
)])),
_ => FuseFileType::PathBuf(
intern_file
.strip_prefix(root_dir.clone())
.unwrap()
.to_path_buf(),
intern_file.strip_prefix(root_dir).unwrap().to_path_buf(),
),
},
),
Expand All @@ -619,7 +592,7 @@ fn is_not_hidden(entry: &DirEntry) -> bool {
.unwrap_or(false)
}

fn get_include_files(dir: &PathBuf, base_path: PathBuf) -> Vec<FuseFileType> {
fn get_include_files(dir: &Path, base_path: &Path) -> Vec<FuseFileType> {
let incdir_files = WalkDir::new(dir)
.follow_links(true)
.into_iter()
Expand All @@ -633,13 +606,10 @@ fn get_include_files(dir: &PathBuf, base_path: PathBuf) -> Vec<FuseFileType> {
incdir_files
.map(|incdir_file| {
FuseFileType::IndexMap(IndexMap::from([(
incdir_file
.strip_prefix(base_path.clone())
.unwrap()
.to_path_buf(),
incdir_file.strip_prefix(base_path).unwrap().to_path_buf(),
FuseSoCFile {
is_include_file: Some(true),
include_path: Some(dir.strip_prefix(base_path.clone()).unwrap().to_path_buf()),
include_path: Some(dir.strip_prefix(base_path).unwrap().to_path_buf()),
file_type: None,
},
)]))
Expand Down
Loading