Skip to content

Commit 6f4a488

Browse files
authored
Merge pull request #4 from joshuous/clap-cli
Implement recursive search and add clap
2 parents d93a140 + 8d600d3 commit 6f4a488

File tree

4 files changed

+214
-27
lines changed

4 files changed

+214
-27
lines changed

Cargo.lock

Lines changed: 140 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
[package]
22
name = "aosp-missing-blobs"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors = ["Josh Choo <dev@joshuous.com>"]
55
edition = "2018"
66
description = """
7-
aosp-missing-blobs is a nifty tool to identify required blobs (.so) that are missing from AOSP ROM builds,
8-
and to show which existing blobs rely on them. This will be particularly useful for ROM developers who want
9-
to ensure that they have not missed out any required proprietary OEM blobs.
7+
A tool to identify required blobs (.so) that are missing from AOSP ROM builds, and to show which existing blobs depend on them.
108
"""
119
license = "MIT"
1210
homepage = "https://github.com/joshuous/aosp-missing-blobs"
1311
repository = "https://github.com/joshuous/aosp-missing-blobs"
1412

1513
[dependencies]
1614
clap = "2.33"
17-
goblin = "0.4"
15+
goblin = "0.4"
16+
ignore = "0.4"

src/lib.rs

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,82 @@
11
use goblin::{self, Object};
2+
use ignore::WalkBuilder;
23
use std::collections::HashMap;
34
use std::fs;
45
use std::path::{Path, PathBuf};
56

6-
pub fn run(paths: &[&str]) {
7-
let blob_paths = find_blobs_in_paths(&paths);
8-
let blobs_to_dependencies = get_dependencies(&blob_paths);
9-
let missing_blobs = identify_missing(&blobs_to_dependencies);
10-
display_missing_blobs(&missing_blobs);
7+
pub struct MissingBlobs {
8+
recursive: bool,
119
}
1210

13-
fn find_blobs_in_paths(paths: &[&str]) -> Vec<PathBuf> {
11+
impl MissingBlobs {
12+
pub fn new(recursive: bool) -> Self {
13+
Self { recursive }
14+
}
15+
16+
pub fn run(&self, paths: &[&str]) {
17+
let file_paths: Vec<PathBuf> = if self.recursive {
18+
find_files_recursively(&paths)
19+
} else {
20+
find_files(&paths)
21+
};
22+
23+
let blob_paths: Vec<&PathBuf> = file_paths
24+
.iter()
25+
.filter(|path| match path.extension() {
26+
// Assume that valid blobs have ".so" extension.
27+
Some(ext) => ext == "so",
28+
None => false,
29+
})
30+
.collect();
31+
32+
let blobs_to_dependencies = get_dependencies(&blob_paths);
33+
let missing_blobs = identify_missing(&blobs_to_dependencies);
34+
display_missing_blobs(&missing_blobs);
35+
}
36+
}
37+
38+
fn find_files(paths: &[&str]) -> Vec<PathBuf> {
1439
let dirs = paths
1540
.iter()
1641
.map(Path::new)
1742
.filter(|path| path.is_dir())
1843
.collect::<Vec<_>>();
1944

20-
let blob_paths: Vec<PathBuf> = dirs
45+
let file_paths: Vec<PathBuf> = dirs
2146
.iter()
2247
.map(|dir| fs::read_dir(dir).expect("Could not read directory."))
2348
.flat_map(|read_dir| {
2449
read_dir.map(|dir_entry| dir_entry.expect("Could not read directory entry.").path())
2550
})
26-
.filter(|path| match path.extension() {
27-
// Assume that valid blobs have ".so" extension.
28-
Some(ext) => ext == "so",
29-
None => false,
30-
})
3151
.collect();
3252

33-
blob_paths
53+
file_paths
54+
}
55+
56+
fn find_files_recursively(paths: &[&str]) -> Vec<PathBuf> {
57+
let mut walker = WalkBuilder::new(paths[0]);
58+
for path in &paths[1..] {
59+
walker.add(path);
60+
}
61+
62+
// Don't read from ignore configs
63+
walker
64+
.ignore(false)
65+
.git_ignore(false)
66+
.git_exclude(false)
67+
.git_global(false);
68+
69+
walker
70+
.build()
71+
.map(|dir_entry| {
72+
dir_entry
73+
.expect("Could not read directory entry.")
74+
.into_path()
75+
})
76+
.collect()
3477
}
3578

36-
fn get_dependencies(blob_paths: &Vec<PathBuf>) -> HashMap<String, Vec<String>> {
79+
fn get_dependencies(blob_paths: &[&PathBuf]) -> HashMap<String, Vec<String>> {
3780
let mut dependencies: HashMap<String, Vec<String>> = HashMap::new();
3881

3982
blob_paths.iter().for_each(|path| {

src/main.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
use aosp_missing_blobs::run;
2-
use clap::{App, Arg};
1+
use aosp_missing_blobs::MissingBlobs;
2+
use clap::{crate_description, crate_name, crate_version, App, Arg};
33

44
fn main() {
5-
let matches = App::new("aosp-missing-blobs")
6-
.version("0.3.0")
7-
.author("Josh Choo <dev@joshuous.com>")
8-
.about("An AOSP tool to generate a list of required missing blobs.")
5+
let matches = App::new(crate_name!())
6+
.version(crate_version!())
7+
.about(crate_description!())
98
.arg(
109
Arg::with_name("PATHS")
1110
.help("Paths to blobs")
1211
.required(true)
1312
.multiple(true),
1413
)
14+
.arg(
15+
Arg::with_name("recursive")
16+
.short("r")
17+
.long("recursive")
18+
.help("Read blobs in each path recursively"),
19+
)
1520
.get_matches();
1621

1722
let paths = matches.values_of("PATHS").unwrap().collect::<Vec<_>>();
23+
let recursive = matches.is_present("recursive");
1824

19-
run(&paths);
25+
MissingBlobs::new(recursive).run(&paths);
2026
}

0 commit comments

Comments
 (0)