Skip to content

Commit 0264e98

Browse files
authored
Merge pull request #293 from pulp-platform/template_cleanup
Various cleanup items
2 parents 3de4f4c + 5bcb0cf commit 0264e98

27 files changed

Lines changed: 418 additions & 418 deletions

src/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,18 @@ pub fn main() -> Result<()> {
250250
log::debug!("maintaining link to {} at {:?}", pkg_name, path);
251251

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

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

261261
// Convert to relative path
262262
let pkg_path = path
263263
.parent()
264-
.and_then(|path| pathdiff::diff_paths(pkg_path.clone(), path))
264+
.and_then(|path| pathdiff::diff_paths(&pkg_path, path))
265265
.unwrap_or(pkg_path);
266266

267267
// Check if there is something at the destination path that needs to be

src/cmd/audit.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pub fn run(sess: &Session, args: &AuditArgs) -> Result<()> {
4343
let io_ref = &io;
4444
let dep_versions = rt.block_on(async {
4545
let futures = pkgs
46-
.clone()
4746
.iter()
4847
.map(|&pkg| async move {
4948
futures::join!(
@@ -80,18 +79,17 @@ pub fn run(sess: &Session, args: &AuditArgs) -> Result<()> {
8079
let parent_array = get_parent_array(sess, &rt, &io, pkg_name, false)?;
8180
let current_version = sess.dependency(*pkg).version.clone();
8281
let current_version_unwrapped = current_version
83-
.clone()
82+
.as_ref()
8483
.map(|v| v.to_string())
8584
.unwrap_or_default();
8685
let current_revision = sess.dependency(*pkg).revision.clone();
87-
let current_revision_unwrapped = current_revision.clone().unwrap_or_default();
88-
let available_versions = match dep_versions.get(pkg).unwrap().clone() {
89-
DependencyVersions::Git(versions) => versions.versions,
86+
let current_revision_unwrapped = current_revision.as_deref().unwrap_or_default();
87+
let available_versions = match dep_versions.get(pkg).unwrap() {
88+
DependencyVersions::Git(versions) => {
89+
versions.versions.iter().map(|(v, _)| v.clone()).collect()
90+
}
9091
_ => vec![],
91-
}
92-
.into_iter()
93-
.map(|(v, _)| v)
94-
.collect::<Vec<semver::Version>>();
92+
};
9593
let highest_version = available_versions.iter().max();
9694

9795
let mut conflicting = false;

src/cmd/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ pub fn get_path_subdeps(
329329
depref: DependencyRef,
330330
) -> Result<IndexMap<String, PathBuf>> {
331331
let binding = IndexMap::new();
332-
let old_path = io.get_package_path(depref);
332+
let old_path = io.sess.get_package_path(depref);
333333
let mut path_deps = match rt.block_on(io.dependency_manifest(depref, false, &[]))? {
334334
Some(m) => &m.dependencies,
335335
None => &binding,

src/cmd/fusesoc.rs

Lines changed: 38 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::fs;
1010
use std::fs::read_to_string;
1111
use std::io::IsTerminal;
1212
use std::io::{self, Write};
13-
use std::path::PathBuf;
13+
use std::path::{Path, PathBuf};
1414

1515
use clap::{ArgAction, Args};
1616
use indexmap::IndexMap;
@@ -125,7 +125,7 @@ pub fn run_single(sess: &Session, args: &FusesocArgs) -> Result<()> {
125125
&srcs,
126126
&fuse_depend_string,
127127
&pkg_manifest_paths,
128-
bender_generate_flag.to_string(),
128+
bender_generate_flag,
129129
&args.license,
130130
)?;
131131

@@ -162,7 +162,7 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {
162162
pkgs.iter().map(|&id| {
163163
(
164164
sess.dependency_name(id).to_string(),
165-
io.get_package_path(id),
165+
sess.get_package_path(id),
166166
)
167167
})
168168
})
@@ -205,13 +205,7 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {
205205

206206
fuse_depend_string.insert(
207207
pkg.to_string(),
208-
get_fuse_depend_string(
209-
pkg,
210-
&srcs,
211-
vendor_string.to_string(),
212-
top,
213-
version_string.clone(),
214-
),
208+
get_fuse_depend_string(pkg, &srcs, vendor_string, top, version_string.clone()),
215209
);
216210
} else {
217211
let mut index = 0;
@@ -235,8 +229,8 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {
235229
})?;
236230

237231
let fuse_core = parse_fuse_file(
238-
file_str,
239-
present_core_files[pkg][i].display().to_string(),
232+
&file_str,
233+
&present_core_files[pkg][i].display().to_string(),
240234
)?;
241235
writeln!(
242236
msg,
@@ -294,18 +288,12 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {
294288

295289
fuse_depend_string.insert(
296290
pkg.to_string(),
297-
get_fuse_depend_string(
298-
pkg,
299-
&srcs,
300-
vendor_string.to_string(),
301-
top,
302-
version_string.clone(),
303-
),
291+
get_fuse_depend_string(pkg, &srcs, vendor_string, top, version_string.clone()),
304292
);
305293
} else {
306294
let fuse_core = parse_fuse_file(
307-
file_str,
308-
present_core_files[pkg][index].display().to_string(),
295+
&file_str,
296+
&present_core_files[pkg][index].display().to_string(),
309297
)?;
310298
fuse_depend_string.insert(pkg.to_string(), fuse_core.name.clone());
311299
}
@@ -324,7 +312,7 @@ pub fn run(sess: &Session, args: &FusesocArgs) -> Result<()> {
324312
src_packages,
325313
&fuse_depend_string,
326314
&pkg_manifest_paths,
327-
bender_generate_flag.to_string(),
315+
bender_generate_flag,
328316
&args.license,
329317
)?;
330318

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

339327
fn get_fuse_file_str(
340-
pkg: &String,
328+
pkg: &str,
341329
src_packages: &[SourceGroup],
342330
fuse_depend_string: &IndexMap<String, String>,
343331
pkg_manifest_paths: &IndexMap<String, PathBuf>,
344-
bender_generate_flag: String,
332+
bender_generate_flag: &str,
345333
lic_string: &[String],
346334
) -> Result<String> {
347335
let mut fuse_str = "CAPI=2:\n".to_string();
@@ -354,7 +342,7 @@ fn get_fuse_file_str(
354342
}
355343

356344
let fuse_pkg = FuseSoCCAPI2 {
357-
name: fuse_depend_string[&pkg.to_string()].clone(),
345+
name: fuse_depend_string[pkg].clone(),
358346
description: None,
359347
filesets: {
360348
src_packages
@@ -366,13 +354,10 @@ fn get_fuse_file_str(
366354
file_type: Some("systemVerilogSource".to_string()),
367355
// logical_name: None,
368356
files: {
369-
get_fileset_files(file_pkg, pkg_manifest_paths[pkg].clone())
357+
get_fileset_files(file_pkg, &pkg_manifest_paths[pkg])
370358
.into_iter()
371359
.chain(file_pkg.include_dirs.iter().flat_map(|(_, incdir)| {
372-
get_include_files(
373-
&incdir.to_path_buf(),
374-
pkg_manifest_paths[pkg].clone(),
375-
)
360+
get_include_files(incdir, &pkg_manifest_paths[pkg])
376361
}))
377362
.collect()
378363
},
@@ -404,10 +389,7 @@ fn get_fuse_file_str(
404389
.unwrap_or(&Vec::new())
405390
.iter()
406391
.flat_map(|(_, incdir)| {
407-
get_include_files(
408-
&incdir.to_path_buf(),
409-
pkg_manifest_paths[pkg].clone(),
410-
)
392+
get_include_files(incdir, &pkg_manifest_paths[pkg])
411393
})
412394
.collect()
413395
}
@@ -479,30 +461,30 @@ fn get_fuse_file_str(
479461
Ok(fuse_str)
480462
}
481463

482-
fn parse_fuse_file(file_str: String, filename: String) -> Result<FuseSoCCAPI2> {
464+
fn parse_fuse_file(file_str: &str, filename: &str) -> Result<FuseSoCCAPI2> {
483465
serde_yaml_ng::from_value({
484-
let mut value = serde_yaml_ng::from_str::<Value>(&file_str).map_err(|cause| {
466+
let mut value = serde_yaml_ng::from_str::<Value>(file_str).map_err(|cause| {
485467
Error::chain(
486-
format!("Unable to parse core file to value {:?}.", &filename),
468+
format!("Unable to parse core file to value {:?}.", filename),
487469
cause,
488470
)
489471
})?;
490472
value.apply_merge().map_err(|cause| {
491473
Error::chain(
492-
format!("Unable to apply merge to file {:?}.", &filename),
474+
format!("Unable to apply merge to file {:?}.", filename),
493475
cause,
494476
)
495477
})?;
496478
value
497479
})
498-
.map_err(|cause| Error::chain(format!("Unable to parse core file {:?}.", &filename), cause))
480+
.map_err(|cause| Error::chain(format!("Unable to parse core file {:?}.", filename), cause))
499481
}
500482

501483
fn get_fuse_depend_string(
502-
pkg: &String,
484+
pkg: &str,
503485
srcs: &SourceGroup,
504-
vendor_string: String,
505-
top: &String,
486+
vendor_string: &str,
487+
top: &str,
506488
version_string: Option<semver::Version>,
507489
) -> String {
508490
let src_packages = srcs
@@ -519,15 +501,15 @@ fn get_fuse_depend_string(
519501
})
520502
.collect()
521503
} else {
522-
src_packages.clone()
504+
src_packages
523505
};
524506

525507
format!(
526508
"{}:{}:{}:{}", // VLNV
527509
vendor_string, // Vendor
528510
"", // Library
529511
pkg, // Name
530-
match &src_packages.clone()[0].version {
512+
match &src_packages[0].version {
531513
Some(version) => format!("{}", version),
532514
None => "".to_string(),
533515
} // Version
@@ -536,29 +518,29 @@ fn get_fuse_depend_string(
536518

537519
fn get_fileset_name(spec: &TargetSpec, top: bool) -> String {
538520
let tmp_str = match spec {
539-
TargetSpec::Wildcard => "".to_string(),
521+
TargetSpec::Wildcard => String::new(),
540522
TargetSpec::Name(name) => name.to_string(),
541523
TargetSpec::Any(specs) => {
542-
let mut spec_str = "".to_string();
524+
let mut spec_str = String::new();
543525
for spec in specs.iter() {
544526
let mystr = get_fileset_name(spec, false);
545527
if !spec_str.is_empty() && !mystr.is_empty() {
546528
spec_str.push_str("_or_");
547529
}
548530
spec_str.push_str(&mystr);
549531
}
550-
spec_str.to_string()
532+
spec_str
551533
}
552534
TargetSpec::All(specs) => {
553-
let mut spec_str = "".to_string();
535+
let mut spec_str = String::new();
554536
for spec in specs.iter() {
555537
let mystr = get_fileset_name(spec, false);
556538
if !spec_str.is_empty() && !mystr.is_empty() {
557539
spec_str.push('_');
558540
}
559541
spec_str.push_str(&mystr);
560542
}
561-
spec_str.to_string()
543+
spec_str
562544
}
563545
TargetSpec::Not(spec) => format!("not{}", get_fileset_name(spec, false)),
564546
};
@@ -569,40 +551,31 @@ fn get_fileset_name(spec: &TargetSpec, top: bool) -> String {
569551
}
570552
}
571553

572-
fn get_fileset_files(file_pkg: &SourceGroup, root_dir: PathBuf) -> Vec<FuseFileType> {
554+
fn get_fileset_files(file_pkg: &SourceGroup, root_dir: &Path) -> Vec<FuseFileType> {
573555
file_pkg
574556
.files
575557
.iter()
576558
.filter_map(|src_file| match src_file {
577559
SourceFile::File(intern_file, _) => Some(
578560
match intern_file.extension().and_then(std::ffi::OsStr::to_str) {
579561
Some("vhd") | Some("vhdl") => FuseFileType::IndexMap(IndexMap::from([(
580-
intern_file
581-
.strip_prefix(root_dir.clone())
582-
.unwrap()
583-
.to_path_buf(),
562+
intern_file.strip_prefix(root_dir).unwrap().to_path_buf(),
584563
FuseSoCFile {
585564
is_include_file: None,
586565
include_path: None,
587566
file_type: Some("vhdlSource".to_string()),
588567
},
589568
)])),
590569
Some("v") => FuseFileType::IndexMap(IndexMap::from([(
591-
intern_file
592-
.strip_prefix(root_dir.clone())
593-
.unwrap()
594-
.to_path_buf(),
570+
intern_file.strip_prefix(root_dir).unwrap().to_path_buf(),
595571
FuseSoCFile {
596572
is_include_file: None,
597573
include_path: None,
598574
file_type: Some("verilogSource".to_string()),
599575
},
600576
)])),
601577
_ => FuseFileType::PathBuf(
602-
intern_file
603-
.strip_prefix(root_dir.clone())
604-
.unwrap()
605-
.to_path_buf(),
578+
intern_file.strip_prefix(root_dir).unwrap().to_path_buf(),
606579
),
607580
},
608581
),
@@ -619,7 +592,7 @@ fn is_not_hidden(entry: &DirEntry) -> bool {
619592
.unwrap_or(false)
620593
}
621594

622-
fn get_include_files(dir: &PathBuf, base_path: PathBuf) -> Vec<FuseFileType> {
595+
fn get_include_files(dir: &Path, base_path: &Path) -> Vec<FuseFileType> {
623596
let incdir_files = WalkDir::new(dir)
624597
.follow_links(true)
625598
.into_iter()
@@ -633,13 +606,10 @@ fn get_include_files(dir: &PathBuf, base_path: PathBuf) -> Vec<FuseFileType> {
633606
incdir_files
634607
.map(|incdir_file| {
635608
FuseFileType::IndexMap(IndexMap::from([(
636-
incdir_file
637-
.strip_prefix(base_path.clone())
638-
.unwrap()
639-
.to_path_buf(),
609+
incdir_file.strip_prefix(base_path).unwrap().to_path_buf(),
640610
FuseSoCFile {
641611
is_include_file: Some(true),
642-
include_path: Some(dir.strip_prefix(base_path.clone()).unwrap().to_path_buf()),
612+
include_path: Some(dir.strip_prefix(base_path).unwrap().to_path_buf()),
643613
file_type: None,
644614
},
645615
)]))

0 commit comments

Comments
 (0)