Replace deprecated fs::walk_dir call with walkdir crate

This commit is contained in:
Cengiz Can 2016-03-07 12:16:39 +02:00
parent 743e0c9c87
commit 12100edffc
3 changed files with 54 additions and 20 deletions

View file

@ -1,4 +1,35 @@
[root] [root]
name = "build-apk" name = "build-apk"
version = "0.0.1" version = "0.0.1"
dependencies = [
"walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "kernel32-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "walkdir"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

View file

@ -11,3 +11,5 @@ test = false
doc = false doc = false
bench = false bench = false
[dependencies]
walkdir = "0.1.5"

View file

@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//extern crate num; extern crate walkdir;
#![feature(dir_builder, fs_walk)]
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::env; use std::env;
use std::fs; use std::fs;
@ -11,6 +11,7 @@ use std::fs::DirBuilder;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process; use std::process;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use walkdir::WalkDir;
fn main() { fn main() {
let (args, passthrough) = parse_arguments(); let (args, passthrough) = parse_arguments();
@ -167,7 +168,7 @@ fn main() {
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.current_dir(directory.clone()) .current_dir(directory.clone())
.status(); .status();
if keytoolcreatecmd.is_err() || if keytoolcreatecmd.is_err() ||
keytoolcreatecmd.unwrap().code().unwrap() != 0 { keytoolcreatecmd.unwrap().code().unwrap() != 0 {
println!("Error while using `keytool` to create the debug keystore."); println!("Error while using `keytool` to create the debug keystore.");
process::exit(1); process::exit(1);
@ -193,7 +194,7 @@ fn main() {
println!("Error while using `jarsign` to sign the APK."); println!("Error while using `jarsign` to sign the APK.");
process::exit(1); process::exit(1);
} }
fs::copy(&directory.join("bin").join("Servo-release-unsigned.apk"), fs::copy(&directory.join("bin").join("Servo-release-unsigned.apk"),
&args.output).unwrap(); &args.output).unwrap();
} }
@ -263,25 +264,25 @@ fn find_native_libs(args: &Args) -> HashMap<String, PathBuf> {
let mut native_shared_libs: HashMap<String, PathBuf> = HashMap::new(); let mut native_shared_libs: HashMap<String, PathBuf> = HashMap::new();
// Add requested .so files // Add requested .so files
fs::walk_dir(&args.target_path).and_then(|dir_walker| { for dir_entry in WalkDir::new(&args.target_path) {
for path in dir_walker { let dir_entry = dir_entry.unwrap();
let path = path.unwrap().path(); let path = dir_entry.path();
match (path.file_name(), path.extension()) {
(Some(filename), Some(ext)) => { match (path.file_name(), path.extension()) {
let filename = filename.to_str().unwrap(); (Some(file_name), Some(extension)) => {
if filename.starts_with("lib") let file_name = file_name.to_str().unwrap();
&& ext == "so"
&& args.shared_libraries.contains(filename) { if file_name.starts_with("lib")
println!("Adding the file {:?}", filename); && extension == "so"
native_shared_libs.insert(filename.to_string(), path.clone()); && args.shared_libraries.contains(file_name) {
break; println!("Adding the file {:?}", file_name);
} native_shared_libs.insert(file_name.to_string(), path.to_path_buf().clone());
break;
} }
_ => {}
} }
_ => {}
} }
Ok(()) }
}).ok();
native_shared_libs native_shared_libs
} }