mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #204 from brson/master
RFC: Improve busybox compatibility using their test suite
This commit is contained in:
commit
e932af9795
12 changed files with 73 additions and 21 deletions
23
Makefile
23
Makefile
|
@ -1,5 +1,7 @@
|
||||||
include common.mk
|
include common.mk
|
||||||
|
|
||||||
|
SRC_DIR=$(shell pwd)
|
||||||
|
|
||||||
# Possible programs
|
# Possible programs
|
||||||
PROGS := \
|
PROGS := \
|
||||||
base64 \
|
base64 \
|
||||||
|
@ -136,4 +138,23 @@ ifeq ($(MULTICALL), 1)
|
||||||
$(foreach crate,$(CRATES),$(eval $(call CRATE_BUILD,$(crate),$(shell $(RUSTC) --crate-type rlib --crate-file-name --out-dir build $(crate)/$(crate).rs))))
|
$(foreach crate,$(CRATES),$(eval $(call CRATE_BUILD,$(crate),$(shell $(RUSTC) --crate-type rlib --crate-file-name --out-dir build $(crate)/$(crate).rs))))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: all test clean
|
# Test under the busybox testsuite
|
||||||
|
ifeq ($(MULTICALL), 1)
|
||||||
|
build/busybox: build/uutils
|
||||||
|
rm -f build/busybox
|
||||||
|
ln -s $(SRC_DIR)/build/uutils build/busybox
|
||||||
|
|
||||||
|
ifeq ($(BUSYBOX_SRC),)
|
||||||
|
busytest:
|
||||||
|
@echo
|
||||||
|
@echo "To run \`busytest\` set BUSYBOX_SRC to the directory of the compiled busybox source code."
|
||||||
|
@echo "Optionally set RUNTEST_ARGS to arguments to pass to the busybox \`runtest\` program."
|
||||||
|
@echo
|
||||||
|
@false
|
||||||
|
else
|
||||||
|
busytest: build/busybox
|
||||||
|
(cd $(BUSYBOX_SRC)/testsuite && bindir=$(SRC_DIR)/build tstdir=$(BUSYBOX_SRC)/testsuite $(BUSYBOX_SRC)/testsuite/runtest $(RUNTEST_ARGS))
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: all test clean busytest
|
||||||
|
|
|
@ -105,7 +105,7 @@ fn decode(input: &mut Reader, ignore_garbage: bool) {
|
||||||
let standard_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
let standard_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
to_decode = to_decode.as_slice()
|
to_decode = to_decode.as_slice()
|
||||||
.trim_chars(|c| !standard_chars.contains_char(c))
|
.trim_chars(|c| !standard_chars.contains_char(c))
|
||||||
.into_owned()
|
.into_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
match to_decode.as_slice().from_base64() {
|
match to_decode.as_slice().from_base64() {
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub fn uumain(args: Vec<String>) {
|
||||||
exec(files, number_mode, show_nonprint, show_ends, show_tabs, squeeze_blank);
|
exec(files, number_mode, show_nonprint, show_ends, show_tabs, squeeze_blank);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq, PartialEq)]
|
||||||
enum NumberingMode {
|
enum NumberingMode {
|
||||||
NumberNone,
|
NumberNone,
|
||||||
NumberNonEmpty,
|
NumberNonEmpty,
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
|
||||||
use std::cmp::TotalOrd;
|
use std::cmp::Ord;
|
||||||
use std::io::{BufferedReader, IoResult, print};
|
use std::io::{BufferedReader, IoResult, print};
|
||||||
use std::io::fs::File;
|
use std::io::fs::File;
|
||||||
use std::io::stdio::stdin;
|
use std::io::stdio::stdin;
|
||||||
|
|
2
cp/cp.rs
2
cp/cp.rs
|
@ -24,7 +24,7 @@ use getopts::{
|
||||||
usage,
|
usage,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq, PartialEq)]
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
Copy,
|
Copy,
|
||||||
Help,
|
Help,
|
||||||
|
|
4
env/env.rs
vendored
4
env/env.rs
vendored
|
@ -87,7 +87,7 @@ pub fn uumain(args: Vec<String>) {
|
||||||
|
|
||||||
match (name, value) {
|
match (name, value) {
|
||||||
(Some(n), Some(v)) => {
|
(Some(n), Some(v)) => {
|
||||||
opts.sets.push((n.into_owned(), v.into_owned()));
|
opts.sets.push((n.into_string(), v.into_string()));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// read the program now
|
// read the program now
|
||||||
|
@ -159,7 +159,7 @@ pub fn uumain(args: Vec<String>) {
|
||||||
match (name, value) {
|
match (name, value) {
|
||||||
(Some(n), Some(v)) => {
|
(Some(n), Some(v)) => {
|
||||||
// yes
|
// yes
|
||||||
opts.sets.push((n.into_owned(), v.into_owned()));
|
opts.sets.push((n.into_string(), v.into_string()));
|
||||||
wait_cmd = true;
|
wait_cmd = true;
|
||||||
}
|
}
|
||||||
// no, its a program-like opt
|
// no, its a program-like opt
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 616786caeba62773a9ff8dc541cc4d50bf384d59
|
Subproject commit adde85617a776ea98249504d653cb547a2353c98
|
|
@ -9,8 +9,8 @@ static test_dir4: &'static str = "tmp/mkdir_test4/mkdir_test4_1";
|
||||||
static test_dir5: &'static str = "tmp/mkdir_test5/mkdir_test5_1";
|
static test_dir5: &'static str = "tmp/mkdir_test5/mkdir_test5_1";
|
||||||
|
|
||||||
fn cleanup(dir: &'static str) {
|
fn cleanup(dir: &'static str) {
|
||||||
let d = dir.into_owned();
|
let d = dir.into_string();
|
||||||
let p = Path::new(d.into_owned());
|
let p = Path::new(d.into_string());
|
||||||
if p.exists() {
|
if p.exists() {
|
||||||
rmdir(&p).unwrap();
|
rmdir(&p).unwrap();
|
||||||
}
|
}
|
||||||
|
|
2
rm/rm.rs
2
rm/rm.rs
|
@ -20,7 +20,7 @@ use std::io::{print, stdin, stdio, fs, BufferedReader};
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq, PartialEq)]
|
||||||
enum InteractiveMode {
|
enum InteractiveMode {
|
||||||
InteractiveNone,
|
InteractiveNone,
|
||||||
InteractiveOnce,
|
InteractiveOnce,
|
||||||
|
|
|
@ -86,7 +86,7 @@ fn tac(filenames: Vec<String>, before: bool, _: bool, separator: &str) {
|
||||||
let mut buf = data.into_string();
|
let mut buf = data.into_string();
|
||||||
let len = buf.len();
|
let len = buf.len();
|
||||||
buf.truncate(len - 1);
|
buf.truncate(len - 1);
|
||||||
data = buf.into_owned();
|
data = buf.into_string();
|
||||||
}
|
}
|
||||||
let split_vec: Vec<&str> = data.as_slice().split_str(separator).collect();
|
let split_vec: Vec<&str> = data.as_slice().split_str(separator).collect();
|
||||||
let rev: String = split_vec.iter().rev().fold(String::new(), |mut a, &b| {
|
let rev: String = split_vec.iter().rev().fold(String::new(), |mut a, &b| {
|
||||||
|
|
|
@ -33,7 +33,7 @@ macro_rules! get_file_size(
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq, PartialEq)]
|
||||||
enum TruncateMode {
|
enum TruncateMode {
|
||||||
Reference,
|
Reference,
|
||||||
Extend,
|
Extend,
|
||||||
|
|
|
@ -114,12 +114,13 @@ fn usage(cmap: &HashMap<&str, fn(Vec<String>)>) {
|
||||||
println!("");
|
println!("");
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {} [util [arguments...]", NAME);
|
println!(" {} [util [arguments...]", NAME);
|
||||||
println!("Utils:");
|
println!("Currently defined functions:");
|
||||||
let mut utils: Vec<&str> = cmap.keys().map(|&s| s).collect();
|
let mut utils: Vec<&str> = cmap.keys().map(|&s| s).collect();
|
||||||
utils.sort();
|
utils.sort();
|
||||||
for util in utils.iter() {
|
for util in utils.iter() {
|
||||||
println!("\t{}", util);
|
println!("\t{}", util);
|
||||||
}
|
}
|
||||||
|
println!("");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -128,24 +129,54 @@ fn main() {
|
||||||
|
|
||||||
// try binary name as util name.
|
// try binary name as util name.
|
||||||
let binary = Path::new(args.get(0).as_slice());
|
let binary = Path::new(args.get(0).as_slice());
|
||||||
let util = binary.filename_str().unwrap();
|
let binary_as_util = binary.filename_str().unwrap();
|
||||||
if umap.contains_key(&util) {
|
if umap.contains_key(&binary_as_util) {
|
||||||
let &uumain = umap.get(&util);
|
let &uumain = umap.get(&binary_as_util);
|
||||||
uumain(args);
|
uumain(args);
|
||||||
return
|
return
|
||||||
|
} else if binary_as_util.starts_with("uutils")
|
||||||
|
|| binary_as_util.starts_with("busybox") {
|
||||||
|
// uutils can be called as either "uutils", "busybox"
|
||||||
|
// "uutils-suffix" or "busybox-suffix". Not sure
|
||||||
|
// what busybox uses the -suffix pattern for.
|
||||||
|
} else {
|
||||||
|
println!("{}: applet not found", binary_as_util);
|
||||||
|
os::set_exit_status(1);
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// try first arg as util name.
|
// try first arg as util name.
|
||||||
if args.len() >= 2 {
|
if args.len() >= 2 {
|
||||||
args.shift();
|
args.shift();
|
||||||
let util = args.get(0).as_slice().clone();
|
let util = args.get(0).as_slice();
|
||||||
if umap.contains_key(&util) {
|
if umap.contains_key(&util) {
|
||||||
let &uumain = umap.get(&util);
|
let &uumain = umap.get(&util);
|
||||||
uumain(args.clone());
|
uumain(args.clone());
|
||||||
return
|
return
|
||||||
|
} else if args.get(0).as_slice() == "--help" {
|
||||||
|
// see if they want help on a specific util
|
||||||
|
if args.len() >= 2 {
|
||||||
|
let util = args.get(1).as_slice();
|
||||||
|
if umap.contains_key(&util) {
|
||||||
|
let &uumain = umap.get(&util);
|
||||||
|
uumain(vec!["--help".to_string()]);
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
println!("{}: applet not found", util);
|
||||||
|
os::set_exit_status(1);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
usage(&umap);
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
println!("{}: applet not found", util);
|
||||||
|
os::set_exit_status(1);
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// no arguments provided
|
||||||
|
usage(&umap);
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
usage(&umap);
|
|
||||||
os::set_exit_status(1);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue