Skip to content

Commit ac73400

Browse files
authored
Merge branch 'master' into master
2 parents fb9825f + 6f69d02 commit ac73400

31 files changed

+1449
-609
lines changed

.drone.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.travis.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
language: rust
2+
cache: cargo
3+
rust:
4+
- 1.26.2
5+
- stable
6+
- nightly
7+
env:
8+
- TARGET=x86_64-unknown-linux-gnu TEST=1
9+
- TARGET=x86_64-unknown-linux-musl TEST=1
10+
- TARGET=aarch64-unknown-linux-gnu RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc"
11+
- TARGET=arm-unknown-linux-gnueabi RUSTFLAGS="-C linker=arm-linux-gnueabi-gcc"
12+
matrix:
13+
include:
14+
- os: osx
15+
rust: stable
16+
env: TARGET=x86_64-apple-darwin
17+
- os: osx
18+
rust: nightly
19+
env: TARGET=x86_64-apple-darwin
20+
- rust: nightly
21+
env: TARGET=x86_64-unknown-linux-gnu COVERAGE=1
22+
install:
23+
- ./ci/build-lcov
24+
- sudo apt-get install -qq libclang-common-3.8-dev llvm-3.8-dev
25+
script:
26+
- ./ci/run-cov
27+
- bash <(curl -s https://codecov.io/bash) -f final.info
28+
- rust: stable
29+
env: TARGET=x86_64-unknown-linux-gnu FMT=1
30+
before_install:
31+
install:
32+
before_script:
33+
- rustup component add rustfmt-preview
34+
script:
35+
- cargo fmt -- --write-mode check
36+
- rust: nightly
37+
env: TARGET=x86_64-unknown-linux-gnu CLIPPY=1
38+
before_install:
39+
install:
40+
before_script:
41+
- cargo +nightly install clippy
42+
script:
43+
- cargo clippy
44+
allow_failures:
45+
- rust: nightly
46+
fast_finish: true
47+
before_install:
48+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq; fi
49+
install:
50+
- if [[ "$TARGET" == "x86_64-unknown-linux-musl" ]]; then sudo apt-get install -qq musl-tools; fi
51+
- if [[ "$TARGET" == "aarch64-unknown-linux-gnu" ]]; then sudo apt-get install -qq gcc-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross; fi
52+
- if [[ "$TARGET" == "arm-unknown-linux-gnueabi" ]]; then sudo apt-get install -qq gcc-arm-linux-gnueabi libc6-armel-cross libc6-dev-armel-cross; fi
53+
before_script:
54+
- rustup target add $TARGET || true
55+
script:
56+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cargo build --verbose --no-default-features --features gnu,lsb,networking,posix --target $TARGET; fi
57+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then cargo build --verbose --all --target $TARGET; fi
58+
- if [[ "$TEST" == "1" ]]; then cargo test --verbose --all --target $TARGET; fi
59+
notifications:
60+
email:
61+
on_success: never

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,22 @@ networking = [
3939
cat = []
4040
chmod = ["regex", "walkdir", "uucore"]
4141
head = []
42-
init = ["fnv"]
4342
sh = ["either", "nom", "glob", "rustyline"]
4443
sleep = ["uucore"]
4544
posix = [
4645
"cat",
4746
"chmod",
4847
"head",
49-
"init",
5048
"sh",
5149
"sleep"
5250
]
5351

54-
default = ["gnu", "loginutils", "lsb", "networking", "posix"]
52+
init = ["fnv"]
53+
sysinit = [
54+
"init"
55+
]
56+
57+
default = ["gnu", "loginutils", "lsb", "networking", "posix", "sysinit"]
5558

5659
[dependencies]
5760
clap = "2.31.2"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MesaBox
22
=======
33

4-
[![Build Status](https://ci.mesalock-linux.org/api/badges/mesalock-linux/mesabox/status.svg?branch=master)](https://ci.mesalock-linux.org/mesalock-linux/mesabox)
4+
[![Build Status](https://api.travis-ci.org/mesalock-linux/mesabox.svg?branch=master)](https://travis-ci.org/mesalock-linux/mesabox)
55
[![License](https://img.shields.io/badge/license-BSD-blue.svg)](LICENSE)
66
[![Coverage Status](https://codecov.io/gh/mesalock-linux/mesabox/branch/master/graphs/badge.svg)](https://codecov.io/gh/mesalock-linux/mesabox/branch/master)
77
[![](https://tokei.rs/b1/github/mesalock-linux/mesabox)](https://github.com/mesalock-linux/mesabox).

build.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ fn create_util_map() -> HashMap<&'static str, &'static str> {
2929
hashmap.insert("cat", "posix");
3030
hashmap.insert("chmod", "posix");
3131
hashmap.insert("head", "posix");
32-
hashmap.insert("init", "posix");
3332
hashmap.insert("sh", "posix");
3433
hashmap.insert("sleep", "posix");
3534
hashmap.insert("nc", "networking");
3635

36+
hashmap.insert("init", "sysinit");
37+
3738
hashmap
3839
}
3940

@@ -98,6 +99,22 @@ where
9899
}
99100
writeln!(output, "Ok(())\n}}").unwrap();
100101

102+
for util in &utils {
103+
writeln!(
104+
output,
105+
"pub fn {}<T, U, V>(args: T) -> Result<()>
106+
where
107+
T: IntoIterator<IntoIter = V, Item = U>,
108+
U: Into<OsString> + Clone,
109+
V: ArgsIter<ArgItem = U>,
110+
{{
111+
let mut args = iter::once(OsString::from({0:?})).chain(args.into_iter().map(|s| s.into()));
112+
EasyUtil::new().execute(&mut args, {0}::execute)
113+
}}",
114+
util
115+
).unwrap();
116+
}
117+
101118
let app_path = Path::new(&outdir).join("generate_app.rs");
102119
let app_file = File::create(app_path).expect("could not open generate_app.rs for writing");
103120
let mut app_output = BufWriter::new(app_file);

ci/build-lcov

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh -e
2+
3+
if [ ! -e lcov/ ] ; then
4+
git clone https://github.com/linux-test-project/lcov.git
5+
cd lcov && sudo make install
6+
fi
File renamed without changes.
File renamed without changes.

util/run-cov.sh renamed to ci/run-cov

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash -e
22

33
export COVERAGE_OPTIONS="-Zprofile -Copt-level=1 -Clink-dead-code -Ccodegen-units=1 -Zno-landing-pads"
4-
export RUSTC_WRAPPER="./util/cov-rustc"
4+
export RUSTC_WRAPPER="./ci/cov-rustc"
55
export CARGO_INCREMENTAL=0
66

7-
LCOVOPT="--gcov-tool ./util/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert"
7+
LCOVOPT="--gcov-tool ./ci/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert"
88

99
# cleanup all
1010
rm -rf *.info *.gcda *.gcno
@@ -29,5 +29,7 @@ lcov ${LCOVOPT} --capture --directory . --base-directory . -o tests.info
2929
lcov ${LCOVOPT} --add mesabox.info --add tests.info -o coverage.info
3030
lcov ${LCOVOPT} --extract coverage.info `find "$(cd src; pwd)" -name "*.rs"` -o final.info
3131

32-
# generate report
33-
genhtml --branch-coverage --demangle-cpp --legend final.info -o target/coverage/ --ignore-errors source
32+
# generate report if not in CI
33+
if [[ "$CI" != true ]]; then
34+
genhtml --branch-coverage --demangle-cpp --legend final.info -o target/coverage/ --ignore-errors source
35+
fi

src/lib.rs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ extern crate byteorder;
2020
extern crate chrono;
2121
#[cfg(feature = "crossbeam")]
2222
extern crate crossbeam;
23+
#[cfg(feature = "either")]
24+
extern crate either;
2325
#[cfg(feature = "fnv")]
2426
extern crate fnv;
2527
#[cfg(feature = "globset")]
@@ -38,22 +40,21 @@ extern crate trust_dns_resolver;
3840
extern crate uucore;
3941
#[cfg(feature = "walkdir")]
4042
extern crate walkdir;
41-
#[cfg(feature = "either")]
42-
extern crate either;
4343
#[cfg(feature = "nom")]
4444
#[macro_use]
4545
extern crate nom;
46-
#[cfg(feature = "rustyline")]
47-
extern crate rustyline;
4846
#[cfg(feature = "glob")]
4947
extern crate glob;
5048
#[cfg(feature = "tempfile")]
5149
extern crate tempfile;
50+
#[cfg(feature = "rustyline")]
51+
extern crate rustyline;
5252

5353
use clap::{App, SubCommand};
5454
use libc::EXIT_FAILURE;
55+
use std::env::{self, VarsOs};
5556
use std::ffi::{OsStr, OsString};
56-
use std::io::{BufRead, Read, Write};
57+
use std::io::{self, BufRead, Read, Stderr, Stdin, Stdout, Write};
5758
use std::iter;
5859
use std::os::unix::io::RawFd;
5960
use std::path::{Path, PathBuf};
@@ -96,7 +97,13 @@ where
9697
E: for<'a> UtilWrite<'a>,
9798
T: Iterator<Item = (OsString, OsString)>,
9899
{
99-
pub fn new(stdin: &'b mut I, stdout: &'c mut O, stderr: &'d mut E, env: T, current_dir: Option<PathBuf>) -> Self {
100+
pub fn new(
101+
stdin: &'b mut I,
102+
stdout: &'c mut O,
103+
stderr: &'d mut E,
104+
env: T,
105+
current_dir: Option<PathBuf>,
106+
) -> Self {
100107
Self {
101108
stdin: stdin,
102109
stdout: stdout,
@@ -217,6 +224,42 @@ fn generate_app() -> App<'static, 'static> {
217224
include!(concat!(env!("OUT_DIR"), "/generate_app.rs"))
218225
}
219226

227+
// used by functions generated in build.rs for each utility (the functions allow a user to call
228+
// utilities like cat(&mut ["file", "anotherfile"].iter()), although this could probably be
229+
// simplified)
230+
struct EasyUtil {
231+
stdin: Stdin,
232+
stdout: Stdout,
233+
stderr: Stderr,
234+
}
235+
236+
impl EasyUtil {
237+
pub fn new() -> Self {
238+
Self {
239+
stdin: io::stdin(),
240+
stdout: io::stdout(),
241+
stderr: io::stderr(),
242+
}
243+
}
244+
245+
pub fn execute<'a, T, U, V, F>(&'a mut self, args: T, func: F) -> Result<()>
246+
where
247+
T: IntoIterator<IntoIter = V, Item = U>,
248+
U: Into<OsString> + Clone,
249+
V: ArgsIter<ArgItem = U>,
250+
F: Fn(&mut UtilData<'a, 'a, 'a, Stdin, Stdout, Stderr, VarsOs>, V) -> Result<()>,
251+
{
252+
let mut data = UtilData::new(
253+
&mut self.stdin,
254+
&mut self.stdout,
255+
&mut self.stderr,
256+
env::vars_os(),
257+
None,
258+
);
259+
func(&mut data, args.into_iter())
260+
}
261+
}
262+
220263
pub fn execute<S, T, U, V>(setup: &mut S, args: T) -> Result<()>
221264
where
222265
S: UtilSetup,

0 commit comments

Comments
 (0)