From 688093895521ce4e0777f5ea5446faf014e1383a Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 3 May 2020 12:39:40 -0500 Subject: [PATCH 01/11] maint/deps ~ refactor/rename pinned 'backtrace' with leading '_' to show lack of local use --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ecdd024c5..31ff7f221 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -311,7 +311,7 @@ whoami = { optional=true, path="src/uu/whoami" } yes = { optional=true, path="src/uu/yes" } # # * transitive dependency via 'failure'; pin to <= v0.3.30 to avoid increasing MinSRV to v1.33.0 -backtrace = ">= 0.3.3, <= 0.3.30" +_backtrace = { version=">= 0.3.3, <= 0.3.30", package="backtrace" } [dev-dependencies] filetime = "0.2" From 100fc8d1e07abfdcb2ee5e220030867db23dae56 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Fri, 24 Apr 2020 02:47:12 -0500 Subject: [PATCH 02/11] maint/deps ~ improve dependency reference for the 'rust-users' external crate --- Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 31ff7f221..2495437a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -324,8 +324,7 @@ time = "0.1" unindent = "0.1" [target.'cfg(unix)'.dev-dependencies] -# FIXME: this should use the normal users crate, but it conflicts with the users utility -rust-users = { git = "https://github.com/uutils/rust-users" } +rust-users = { version="0.10", package="users" } unix_socket = "0.5.0" [[bin]] From bebf36bffb874828299e8a4c8b93d1b23026fca1 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 3 May 2020 15:18:48 -0500 Subject: [PATCH 03/11] change/uutils ~ allow (almost) any name for the multi-binary container - final multi-binary will now function correctly with any binary/executable name - multi-binary container acts as the specified util IF EITHER ... 1. the binary/executable name exactly matches the name of an applet/util 2. the binary/exectuable name matches pattern * where the PREFIX is any string ending in a non-alphanumeric character --- Cargo.toml | 5 +-- src/bin/uutils.rs | 78 +++++++++++++++++++++++------------------------ 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2495437a9..c3697d6f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -214,7 +214,9 @@ feat_os_windows_legacy = [ [workspace] [dependencies] -uucore = "0.0.2" +lazy_static = { version="1.3" } +uucore = { version="0.0.2" } +# * uutils arch = { optional=true, path="src/uu/arch" } base32 = { optional=true, path="src/uu/base32" } base64 = { optional=true, path="src/uu/base64" } @@ -315,7 +317,6 @@ _backtrace = { version=">= 0.3.3, <= 0.3.30", package="backtrace" } [dev-dependencies] filetime = "0.2" -lazy_static = "1.3" libc = "0.2" rand = "0.6" regex = "1.0" diff --git a/src/bin/uutils.rs b/src/bin/uutils.rs index c90c73d02..f57155672 100644 --- a/src/bin/uutils.rs +++ b/src/bin/uutils.rs @@ -1,5 +1,3 @@ -#![crate_name = "uutils"] - /* * This file is part of the uutils coreutils package. * @@ -9,27 +7,37 @@ * file that was distributed with this source code. */ +// spell-checker:ignore (acronyms/names) Gehring +// spell-checker:ignore (rustlang) clippy concat rustlang +// spell-checker:ignore (uutils) coreutils uucore uumain uutils sigpipe +// spell-checker:ignore (shell) busybox + include!(concat!(env!("OUT_DIR"), "/uutils_crates.rs")); -use std::collections::hash_map::HashMap; -use std::io::Write; -use std::path::Path; - +extern crate lazy_static; extern crate uucore; -static NAME: &str = "uutils"; +use lazy_static::lazy_static; +use std::collections::hash_map::HashMap; +use std::io::Write; + static VERSION: &str = env!("CARGO_PKG_VERSION"); +lazy_static! { + static ref BINARY_PATH: std::path::PathBuf = std::env::current_exe().unwrap(); + static ref NAME: &'static str = &*BINARY_PATH.file_stem().unwrap().to_str().unwrap(); +} + include!(concat!(env!("OUT_DIR"), "/uutils_map.rs")); -fn usage(cmap: &UtilityMap) { - println!("{} {}", NAME, VERSION); +fn usage(utils: &UtilityMap) { + println!("{} {}", *NAME, VERSION); println!(); println!("Usage:"); - println!(" {} [util [arguments...]]\n", NAME); + println!(" {} [util [arguments...]]\n", *NAME); println!("Currently defined functions:"); #[allow(clippy::map_clone)] - let mut utils: Vec<&str> = cmap.keys().map(|&s| s).collect(); + let mut utils: Vec<&str> = utils.keys().map(|&s| s).collect(); utils.sort(); for util in utils { println!("\t{}", util); @@ -39,44 +47,36 @@ fn usage(cmap: &UtilityMap) { fn main() { uucore::panic::install_sigpipe_hook(); - let umap = util_map(); + let utils = util_map(); let mut args: Vec = uucore::args().collect(); - // try binary name as util name. - let args0 = args[0].clone(); - let binary = Path::new(&args0[..]); + let binary = &BINARY_PATH; let binary_as_util = binary.file_stem().unwrap().to_str().unwrap(); - if let Some(&uumain) = umap.get(binary_as_util) { + // binary name equals util name? + if let Some(&uumain) = utils.get(binary_as_util) { std::process::exit(uumain(args)); } - if binary_as_util.ends_with("uutils") - || binary_as_util.starts_with("uutils") - || binary_as_util.ends_with("busybox") - || binary_as_util.starts_with("busybox") - { - args.remove(0); + // binary name equals prefixed util name? + // * prefix/stem may be any string ending in a non-alphanumeric character + if let Some(util) = utils.keys().find(|util| { + binary_as_util.ends_with(*util) + && !(&binary_as_util[..binary_as_util.len() - (*util).len()]) + .ends_with(char::is_alphanumeric) + }) { + // prefixed util => replace 0th (aka, executable name) argument + args[0] = (*util).to_owned(); } else { - let mut found = false; - for util in umap.keys() { - if binary_as_util.ends_with(util) { - args[0] = (*util).to_owned(); - found = true; - break; - } - } - if !found { - println!("{}: applet not found", binary_as_util); - std::process::exit(1); - } + // unmatched binary name => regard as multi-binary container and advance argument list + args.remove(0); } - // try first arg as util name. + // 0th argument equals util name? if !args.is_empty() { let util = &args[0][..]; - match umap.get(util) { + match utils.get(util) { Some(&uumain) => { std::process::exit(uumain(args.clone())); } @@ -85,7 +85,7 @@ fn main() { // see if they want help on a specific util if args.len() >= 2 { let util = &args[1][..]; - match umap.get(util) { + match utils.get(util) { Some(&uumain) => { let code = uumain(vec![util.to_owned(), "--help".to_owned()]); std::io::stdout().flush().expect("could not flush stdout"); @@ -97,7 +97,7 @@ fn main() { } } } - usage(&umap); + usage(&utils); std::process::exit(0); } else { println!("{}: applet not found", util); @@ -107,7 +107,7 @@ fn main() { } } else { // no arguments provided - usage(&umap); + usage(&utils); std::process::exit(0); } } From bcdff338fbcb4ca1353859df5c2a24a37110555c Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 3 May 2020 17:19:31 -0500 Subject: [PATCH 04/11] add `busybox` and `uu` examples (both equivalent to `uutils`) --- examples/busybox.rs | 1 + examples/uu.rs | 1 + 2 files changed, 2 insertions(+) create mode 100644 examples/busybox.rs create mode 100644 examples/uu.rs diff --git a/examples/busybox.rs b/examples/busybox.rs new file mode 100644 index 000000000..f2516b124 --- /dev/null +++ b/examples/busybox.rs @@ -0,0 +1 @@ +include!("../src/bin/uutils.rs"); diff --git a/examples/uu.rs b/examples/uu.rs new file mode 100644 index 000000000..f2516b124 --- /dev/null +++ b/examples/uu.rs @@ -0,0 +1 @@ +include!("../src/bin/uutils.rs"); From e759e852a941f73462fde5173d112fb7ba58b0ee Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Tue, 5 May 2020 18:06:42 -0500 Subject: [PATCH 05/11] maint/build ~ add `cargo make` build-examples targets --- Makefile.toml | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index 00345410b..9b1e496e1 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -69,15 +69,23 @@ if eq "${CARGO_MAKE_RUST_TARGET_OS}" "windows" show_utils = set "util/show-utils.BAT" end_if set_env CARGO_MAKE_VAR_SHOW_UTILS "${show_utils}" -# rebuild TASK_ARGS for "--features" and package-build compatibility (using "," instead of ";") +# rebuild CARGO_MAKE_TASK_ARGS for various targets args = set ${CARGO_MAKE_TASK_ARGS} -args = replace ${args} ";" "," -set_env CARGO_MAKE_TASK_BUILD_FEATURES_ARGS "${args}" -args = replace ${args} "," " -p" -if not is_empty "${args}" - args = set "-p${args}" +# * rebuild for 'features' target +args_features = replace ${args} ";" "," +set_env CARGO_MAKE_TASK_BUILD_FEATURES_ARGS "${args_features}" +# * rebuild for 'examples' target +args_examples = replace ${args} ";" " --example " +if is_empty "${args_examples}" + args_examples = set "--examples" end_if -set_env CARGO_MAKE_TASK_BUILD_UTILS_ARGS "${args}" +set_env CARGO_MAKE_TASK_BUILD_EXAMPLES_ARGS "${args_examples}" +# * rebuild for 'utils' target +args_utils = replace ${args} ";" " -p" +if not is_empty "${args_utils}" + args_utils = set "-p${args_utils}" +end_if +set_env CARGO_MAKE_TASK_BUILD_UTILS_ARGS "${args_utils}" ''' ] @@ -109,6 +117,15 @@ dependencies = [ "action-build-debug", ] +[tasks.build-examples] +description = "## Build (release-mode) project example(s); usage: `cargo make (build-examples | examples | example) [EXAMPLE]...`" +category = "[project]" +dependencies = [ + "core::pre-build", + "action-build-examples", + "core::post-build", +] + [tasks.build-features] description = "## Build (with features; release-mode) project; usage: `cargo make (build-features | features) FEATURE...`" category = "[project]" @@ -121,6 +138,12 @@ dependencies = [ [tasks.debug] alias = "build-debug" +[tasks.example] +alias = "build-examples" + +[tasks.examples] +alias = "build-examples" + [tasks.features] alias = "build-features" @@ -212,6 +235,11 @@ description = "`cargo build`" command = "cargo" args = ["build", "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )" ] +[tasks.action-build-examples] +description = "`cargo build (--examples|(--example EXAMPLE)...)`" +command = "cargo" +args = ["build", "--release", "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )", "${CARGO_MAKE_TASK_BUILD_EXAMPLES_ARGS}" ] + [tasks.action-build-features] description = "`cargo build --release --features FEATURES`" command = "cargo" From c457dfbbc469333e7f116971b610a8e3fa1cdf66 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 3 May 2020 17:52:37 -0500 Subject: [PATCH 06/11] fix/uutils ~ support function/util (aka, applet) symlink aliasing where possible ## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible, with fallback to `std::env::current_ext()` if args are missing or empty. - ref: --- src/bin/uutils.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bin/uutils.rs b/src/bin/uutils.rs index f57155672..3fc572c1c 100644 --- a/src/bin/uutils.rs +++ b/src/bin/uutils.rs @@ -10,7 +10,7 @@ // spell-checker:ignore (acronyms/names) Gehring // spell-checker:ignore (rustlang) clippy concat rustlang // spell-checker:ignore (uutils) coreutils uucore uumain uutils sigpipe -// spell-checker:ignore (shell) busybox +// spell-checker:ignore (shell) busybox symlinks include!(concat!(env!("OUT_DIR"), "/uutils_crates.rs")); @@ -24,7 +24,13 @@ use std::io::Write; static VERSION: &str = env!("CARGO_PKG_VERSION"); lazy_static! { - static ref BINARY_PATH: std::path::PathBuf = std::env::current_exe().unwrap(); + static ref BINARY_PATH: std::path::PathBuf = { + // support symlinks by using args[0], when possible, with fallback to current_exe() + match std::env::args().next() { + Some(ref s) if !s.is_empty() => std::path::PathBuf::from(s), + _ => std::env::current_exe().unwrap(), + } + }; static ref NAME: &'static str = &*BINARY_PATH.file_stem().unwrap().to_str().unwrap(); } From 8263d31fbb13a8daf1e15cccaca373d501618ebd Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 3 May 2020 23:32:22 -0500 Subject: [PATCH 07/11] change ~ improve help display for main multi-call binary --- Cargo.toml | 1 + src/bin/uutils.rs | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c3697d6f0..7661a04e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -215,6 +215,7 @@ feat_os_windows_legacy = [ [dependencies] lazy_static = { version="1.3" } +textwrap = { version="0.11.0", features=["term_size"] } uucore = { version="0.0.2" } # * uutils arch = { optional=true, path="src/uu/arch" } diff --git a/src/bin/uutils.rs b/src/bin/uutils.rs index 3fc572c1c..fe8128bb0 100644 --- a/src/bin/uutils.rs +++ b/src/bin/uutils.rs @@ -8,13 +8,14 @@ */ // spell-checker:ignore (acronyms/names) Gehring -// spell-checker:ignore (rustlang) clippy concat rustlang -// spell-checker:ignore (uutils) coreutils uucore uumain uutils sigpipe +// spell-checker:ignore (rustlang/crates) clippy concat rustlang termwidth textwrap +// spell-checker:ignore (uutils) coreutils sigpipe uucore uumain uutils // spell-checker:ignore (shell) busybox symlinks include!(concat!(env!("OUT_DIR"), "/uutils_crates.rs")); extern crate lazy_static; +extern crate textwrap; extern crate uucore; use lazy_static::lazy_static; @@ -37,17 +38,18 @@ lazy_static! { include!(concat!(env!("OUT_DIR"), "/uutils_map.rs")); fn usage(utils: &UtilityMap) { - println!("{} {}", *NAME, VERSION); - println!(); - println!("Usage:"); - println!(" {} [util [arguments...]]\n", *NAME); - println!("Currently defined functions:"); + println!("{} {} (multi-call binary)\n", *NAME, VERSION); + println!("Usage: {} [function [arguments...]]\n", *NAME); + println!("Currently defined functions/utilities:\n"); #[allow(clippy::map_clone)] let mut utils: Vec<&str> = utils.keys().map(|&s| s).collect(); utils.sort(); - for util in utils { - println!("\t{}", util); - } + let display_list = utils.join(", "); + let width = std::cmp::min(textwrap::termwidth(), 100) - 4 * 2; // (opinion/heuristic) max 100 chars wide with 4 character side indentions + println!( + "{}", + textwrap::indent(&textwrap::fill(&display_list, width), " ") + ); } fn main() { @@ -98,7 +100,7 @@ fn main() { std::process::exit(code); } None => { - println!("{}: applet not found", util); + println!("{}: function/utility not found", util); std::process::exit(1); } } @@ -106,7 +108,7 @@ fn main() { usage(&utils); std::process::exit(0); } else { - println!("{}: applet not found", util); + println!("{}: function/utility not found", util); std::process::exit(1); } } From 3877cf4bd3cdce76ef41b03f792d9ed9ed428b92 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 10 May 2020 12:43:44 -0500 Subject: [PATCH 08/11] maint/deps ~ pin unstable 'textwrap' crate (marked for later review) ## [why] 'textwrap' is currently unstable, with "term_size" being an undocumented, but required, feature. The feature name has already changed within the repository 'master' branch. But that branch has never been pushed to a new version. Pin for now with "!maint" mark and comment. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7661a04e7..428c48bfe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -215,7 +215,7 @@ feat_os_windows_legacy = [ [dependencies] lazy_static = { version="1.3" } -textwrap = { version="0.11.0", features=["term_size"] } +textwrap = { version="=0.11.0", features=["term_size"] } # !maint: [2020-05-10; rivy] unstable crate using undocumented features; pinned currently, will review uucore = { version="0.0.2" } # * uutils arch = { optional=true, path="src/uu/arch" } From 6606408ce964a632db04cfba01b181206a2b0c36 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 10 May 2020 21:14:58 -0500 Subject: [PATCH 09/11] refactor/polish ~ whitespace normalization (consistent indentation [either tabs *or* spaces], EOF EOLNs, no trailing whitespace) --- .gitignore | 2 +- Cargo.toml | 284 +++++++++--------- GNUmakefile | 188 ++++++------ Makefile.toml | 30 +- docs/GNUmakefile | 2 +- docs/make.bat | 20 +- src/uu/cut/.gitignore | 2 +- src/uu/expr/src/expr.rs | 8 +- src/uu/numfmt/src/numfmt.rs | 8 +- .../src/tokenize/num_format/num_format.rs | 2 +- 10 files changed, 273 insertions(+), 273 deletions(-) diff --git a/.gitignore b/.gitignore index 3eabba702..b1ac52506 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ target/ .idea Cargo.lock lib*.a -/docs/_build \ No newline at end of file +/docs/_build diff --git a/Cargo.toml b/Cargo.toml index 428c48bfe..bc1eeb23c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,109 +24,109 @@ test_unimplemented = [] ## (common/core and Tier1) feature sets # "feat_common_core" == baseline core set of utilities which can be built/run on most targets feat_common_core = [ - "base32", - "base64", - "basename", - "cat", - "cksum", - "comm", - "cp", - "cut", - "date", - "df", - "dircolors", - "dirname", - "echo", - "env", - "expand", - "expr", - "factor", - "false", - "fmt", - "fold", - "hashsum", - "head", - "join", - "link", - "ln", - "ls", - "mkdir", - "mktemp", - "more", - "mv", - "nl", - "od", - "paste", - "printenv", - "printf", - "ptx", - "pwd", - "readlink", - "realpath", - "relpath", - "rm", - "rmdir", - "seq", - "shred", - "shuf", - "sleep", - "sort", - "split", - "sum", - "tac", - "tail", - "tee", - "test", - "tr", - "true", - "truncate", - "tsort", - "unexpand", - "uniq", - "wc", - "yes", + "base32", + "base64", + "basename", + "cat", + "cksum", + "comm", + "cp", + "cut", + "date", + "df", + "dircolors", + "dirname", + "echo", + "env", + "expand", + "expr", + "factor", + "false", + "fmt", + "fold", + "hashsum", + "head", + "join", + "link", + "ln", + "ls", + "mkdir", + "mktemp", + "more", + "mv", + "nl", + "od", + "paste", + "printenv", + "printf", + "ptx", + "pwd", + "readlink", + "realpath", + "relpath", + "rm", + "rmdir", + "seq", + "shred", + "shuf", + "sleep", + "sort", + "split", + "sum", + "tac", + "tail", + "tee", + "test", + "tr", + "true", + "truncate", + "tsort", + "unexpand", + "uniq", + "wc", + "yes", ] # "feat_Tier1" == expanded set of utilities which can be built/run on the usual rust "Tier 1" target platforms (ref: ) feat_Tier1 = [ - "feat_common_core", - # - "arch", - "hostname", - "nproc", - "sync", - "touch", - "whoami", + "feat_common_core", + # + "arch", + "hostname", + "nproc", + "sync", + "touch", + "whoami", ] ## (primary platforms) feature sets # "feat_os_macos" == set of utilities which can be built/run on the MacOS platform feat_os_macos = [ - "feat_os_unix", ## == a modern/usual *nix platform + "feat_os_unix", ## == a modern/usual *nix platform ] # "feat_os_unix" == set of utilities which can be built/run on modern/usual *nix platforms feat_os_unix = [ - "feat_Tier1", - # - "feat_require_crate_cpp", - "feat_require_unix", - "feat_require_unix_utmpx", + "feat_Tier1", + # + "feat_require_crate_cpp", + "feat_require_unix", + "feat_require_unix_utmpx", ] # "feat_os_windows" == set of utilities which can be built/run on modern/usual windows platforms feat_os_windows = [ - "feat_Tier1", ## == "feat_os_windows_legacy" + "hostname" - ] + "feat_Tier1", ## == "feat_os_windows_legacy" + "hostname" +] ## (secondary platforms) feature sets # "feat_os_unix_gnueabihf" == set of utilities which can be built/run on the "arm-unknown-linux-gnueabihf" target (ARMv6 Linux [hardfloat]) feat_os_unix_gnueabihf = [ - "feat_Tier1", - # - "feat_require_unix", - "feat_require_unix_utmpx", + "feat_Tier1", + # + "feat_require_unix", + "feat_require_unix_utmpx", ] # "feat_os_unix_musl" == set of utilities which can be built/run on targets binding to the "musl" library (ref: ) feat_os_unix_musl = [ - "feat_Tier1", - # - "feat_require_unix", + "feat_Tier1", + # + "feat_require_unix", ] ## feature sets with requirements (restricting cross-platform availability) # @@ -134,81 +134,81 @@ feat_os_unix_musl = [ # # "feat_require_crate_cpp" == set of utilities requiring the `cpp` crate (which fail to compile on several platforms; as of 2020-04-23) feat_require_crate_cpp = [ - "stdbuf", + "stdbuf", ] # "feat_require_unix" == set of utilities requiring support which is only available on unix platforms (as of 2020-04-23) feat_require_unix = [ - "chgrp", - "chmod", - "chown", - "chroot", - "du", - "groups", - "hostid", - "id", - "install", - "kill", - "logname", - "mkfifo", - "mknod", - "nice", - "numfmt", - "nohup", - "pathchk", - "stat", - "timeout", - "tty", - "uname", - "unlink", + "chgrp", + "chmod", + "chown", + "chroot", + "du", + "groups", + "hostid", + "id", + "install", + "kill", + "logname", + "mkfifo", + "mknod", + "nice", + "numfmt", + "nohup", + "pathchk", + "stat", + "timeout", + "tty", + "uname", + "unlink", ] # "feat_require_unix_utmpx" == set of utilities requiring unix utmp/utmpx support # * ref: feat_require_unix_utmpx = [ - "pinky", - "uptime", - "users", - "who", + "pinky", + "uptime", + "users", + "who", ] ## (alternate/newer/smaller platforms) feature sets # "feat_os_unix_fuchsia" == set of utilities which can be built/run on the "Fuchsia" OS (refs: ; ) feat_os_unix_fuchsia = [ - "feat_common_core", - # - "feat_require_crate_cpp", - # - "chgrp", - "chmod", - "chown", - "du", - "groups", - "hostid", - "install", - "logname", - "mkfifo", - "mknod", - "nice", - "pathchk", - "tty", - "uname", - "unlink", + "feat_common_core", + # + "feat_require_crate_cpp", + # + "chgrp", + "chmod", + "chown", + "du", + "groups", + "hostid", + "install", + "logname", + "mkfifo", + "mknod", + "nice", + "pathchk", + "tty", + "uname", + "unlink", ] # "feat_os_unix_redox" == set of utilities which can be built/run on "Redox OS" (refs: ; ) feat_os_unix_redox = [ - "feat_common_core", - # - "uname", - "chmod", - "install", + "feat_common_core", + # + "uname", + "chmod", + "install", ] # "feat_os_windows_legacy" == slightly restricted set of utilities which can be built/run on early windows platforms (eg, "WinXP") feat_os_windows_legacy = [ - "feat_common_core", - # - "arch", - "nproc", - "sync", - "touch", - "whoami", + "feat_common_core", + # + "arch", + "nproc", + "sync", + "touch", + "whoami", ] [workspace] diff --git a/GNUmakefile b/GNUmakefile index 64ceaa5c2..1e24d9445 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -46,101 +46,101 @@ BUSYBOX_SRC := $(BUSYBOX_ROOT)/busybox-$(BUSYBOX_VER) # Possible programs PROGS := \ - base32 \ - base64 \ - basename \ - cat \ - cksum \ - comm \ - cp \ - cut \ - df \ - dircolors \ - dirname \ - echo \ - env \ - expand \ - expr \ - factor \ - false \ - fmt \ - fold \ - hashsum \ - head \ - join \ - link \ - ln \ - ls \ - mkdir \ - mktemp \ - more \ - mv \ - nl \ - numfmt \ - nproc \ - od \ - paste \ - printenv \ - printf \ - ptx \ - pwd \ - readlink \ - realpath \ - relpath \ - rm \ - rmdir \ - seq \ - shred \ - shuf \ - sleep \ - sort \ - split \ - sum \ - sync \ - tac \ - tail \ - tee \ - test \ - tr \ - true \ - truncate \ - tsort \ - unexpand \ - uniq \ - wc \ - whoami \ - yes + base32 \ + base64 \ + basename \ + cat \ + cksum \ + comm \ + cp \ + cut \ + df \ + dircolors \ + dirname \ + echo \ + env \ + expand \ + expr \ + factor \ + false \ + fmt \ + fold \ + hashsum \ + head \ + join \ + link \ + ln \ + ls \ + mkdir \ + mktemp \ + more \ + mv \ + nl \ + numfmt \ + nproc \ + od \ + paste \ + printenv \ + printf \ + ptx \ + pwd \ + readlink \ + realpath \ + relpath \ + rm \ + rmdir \ + seq \ + shred \ + shuf \ + sleep \ + sort \ + split \ + sum \ + sync \ + tac \ + tail \ + tee \ + test \ + tr \ + true \ + truncate \ + tsort \ + unexpand \ + uniq \ + wc \ + whoami \ + yes UNIX_PROGS := \ - arch \ - chgrp \ - chmod \ - chown \ - chroot \ - du \ - groups \ - hostid \ - hostname \ - id \ - install \ - kill \ - logname \ - mkfifo \ - mknod \ - nice \ - nohup \ - pathchk \ - pinky \ - stat \ - stdbuf \ - timeout \ - touch \ - tty \ - uname \ - unlink \ - uptime \ - users \ - who + arch \ + chgrp \ + chmod \ + chown \ + chroot \ + du \ + groups \ + hostid \ + hostname \ + id \ + install \ + kill \ + logname \ + mkfifo \ + mknod \ + nice \ + nohup \ + pathchk \ + pinky \ + stat \ + stdbuf \ + timeout \ + touch \ + tty \ + uname \ + unlink \ + uptime \ + users \ + who ifneq ($(OS),Windows_NT) PROGS := $(PROGS) $(UNIX_PROGS) @@ -229,7 +229,7 @@ endef # Output names EXES := \ - $(sort $(filter $(UTILS),$(filter-out $(SKIP_UTILS),$(PROGS)))) + $(sort $(filter $(UTILS),$(filter-out $(SKIP_UTILS),$(PROGS)))) INSTALLEES := ${EXES} ifeq (${MULTICALL}, y) diff --git a/Makefile.toml b/Makefile.toml index 9b1e496e1..fd301a925 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -36,7 +36,7 @@ set_env CARGO_MAKE_CARGO_BUILD_TEST_FLAGS "" # determine features env_features = get_env CARGO_FEATURES if is_empty "${env_features}" - env_features = get_env FEATURES + env_features = get_env FEATURES end_if if is_empty "${env_features}" if eq "${CARGO_MAKE_RUST_TARGET_OS}" "macos" @@ -61,7 +61,7 @@ end_if # set build flags from features if not is_empty "${features}" set_env CARGO_MAKE_VAR_BUILD_TEST_FEATURES "${features}" - set_env CARGO_MAKE_CARGO_BUILD_TEST_FLAGS "--features ${features}" + set_env CARGO_MAKE_CARGO_BUILD_TEST_FLAGS "--features ${features}" end_if # determine show-utils helper script show_utils = set "util/show-utils.sh" @@ -96,7 +96,7 @@ description = "## *DEFAULT* Build (debug-mode) and test project" category = "[project]" dependencies = [ "action-build-debug", - "test-terse", + "test-terse", ] ## @@ -106,8 +106,8 @@ description = "## Build (release-mode) project" category = "[project]" dependencies = [ "core::pre-build", - "action-build-release", - "core::post-build", + "action-build-release", + "core::post-build", ] [tasks.build-debug] @@ -122,8 +122,8 @@ description = "## Build (release-mode) project example(s); usage: `cargo make (b category = "[project]" dependencies = [ "core::pre-build", - "action-build-examples", - "core::post-build", + "action-build-examples", + "core::post-build", ] [tasks.build-features] @@ -131,8 +131,8 @@ description = "## Build (with features; release-mode) project; usage: `cargo mak category = "[project]" dependencies = [ "core::pre-build", - "action-build-features", - "core::post-build", + "action-build-features", + "core::post-build", ] [tasks.debug] @@ -185,8 +185,8 @@ description = "## Run project tests" category = "[project]" dependencies = [ "core::pre-test", - "core::test", - "core::post-test", + "core::test", + "core::post-test", ] [tasks.test-terse] @@ -194,8 +194,8 @@ description = "## Run project tests (with terse/summary output)" category = "[project]" dependencies = [ "core::pre-test", - "action-test_quiet", - "core::post-test", + "action-test_quiet", + "core::post-test", ] [tasks.uninstall] @@ -213,8 +213,8 @@ category = "[project]" dependencies = [ "core::pre-build", "action-determine-utils", - "action-build-utils", - "core::post-build", + "action-build-utils", + "core::post-build", ] [tasks.uutil] diff --git a/docs/GNUmakefile b/docs/GNUmakefile index 05cef70c1..894a53be0 100644 --- a/docs/GNUmakefile +++ b/docs/GNUmakefile @@ -17,4 +17,4 @@ help: # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: GNUmakefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/make.bat b/docs/make.bat index 0fb8a16c1..1e8ea10a0 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -5,7 +5,7 @@ pushd %~dp0 REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build + set SPHINXBUILD=sphinx-build ) set SOURCEDIR=. set BUILDDIR=_build @@ -15,15 +15,15 @@ if "%1" == "" goto help %SPHINXBUILD% >NUL 2>NUL if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 ) %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% diff --git a/src/uu/cut/.gitignore b/src/uu/cut/.gitignore index 1de565933..eb5a316cb 100644 --- a/src/uu/cut/.gitignore +++ b/src/uu/cut/.gitignore @@ -1 +1 @@ -target \ No newline at end of file +target diff --git a/src/uu/expr/src/expr.rs b/src/uu/expr/src/expr.rs index a3b61f1fd..e2039f918 100644 --- a/src/uu/expr/src/expr.rs +++ b/src/uu/expr/src/expr.rs @@ -128,10 +128,10 @@ Exit status is 0 if EXPRESSION is neither null nor 0, 1 if EXPRESSION is null or 0, 2 if EXPRESSION is syntactically invalid, and 3 if an error occurred. Environment variables: - * EXPR_DEBUG_TOKENS=1 dump expression's tokens - * EXPR_DEBUG_RPN=1 dump expression represented in reverse polish notation - * EXPR_DEBUG_SYA_STEP=1 dump each parser step - * EXPR_DEBUG_AST=1 dump expression represented abstract syntax tree"# + * EXPR_DEBUG_TOKENS=1 dump expression's tokens + * EXPR_DEBUG_RPN=1 dump expression represented in reverse polish notation + * EXPR_DEBUG_SYA_STEP=1 dump each parser step + * EXPR_DEBUG_AST=1 dump expression represented abstract syntax tree"# ); } diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 8a639a37f..164e83ff0 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -331,19 +331,19 @@ pub fn uumain(args: Vec) -> i32 { auto accept optional single/two letter suffix: - 1K = 1000, 1Ki = 1024, 1M = 1000000, 1Mi = 1048576, + 1K = 1000, 1Ki = 1024, 1M = 1000000, 1Mi = 1048576, si accept optional single letter suffix: - 1K = 1000, 1M = 1000000, ... + 1K = 1000, 1M = 1000000, ... iec accept optional single letter suffix: - 1K = 1024, 1M = 1048576, ... + 1K = 1024, 1M = 1048576, ... iec-i accept optional two-letter suffix: - 1Ki = 1024, 1Mi = 1048576, ..." + 1Ki = 1024, 1Mi = 1048576, ..." ); return 0; diff --git a/src/uu/printf/src/tokenize/num_format/num_format.rs b/src/uu/printf/src/tokenize/num_format/num_format.rs index e84116bfc..8b3f245fe 100644 --- a/src/uu/printf/src/tokenize/num_format/num_format.rs +++ b/src/uu/printf/src/tokenize/num_format/num_format.rs @@ -245,7 +245,7 @@ pub fn num_format(field: &FormatField, in_str_opt: Option<&String>) -> Option Date: Sun, 10 May 2020 21:34:48 -0500 Subject: [PATCH 10/11] maint/dev ~ add `test-repo-whitespace.BAT` dev utility --- util/test-repo-whitespace.BAT | 91 +++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 util/test-repo-whitespace.BAT diff --git a/util/test-repo-whitespace.BAT b/util/test-repo-whitespace.BAT new file mode 100644 index 000000000..86fd369a5 --- /dev/null +++ b/util/test-repo-whitespace.BAT @@ -0,0 +1,91 @@ +@setLocal +@echo off + +:: `test-repo-whitespace [DIR]...` +:: style inspector ~ whitespace: find nonconforming files in repository + +:: Copyright (C) 2016-2020 ~ Roy Ivy III +:: License: MIT/Apache-2.0 (see https://opensource.org/licenses/Apache-2.0 , https://opensource.org/licenses/MIT) +:: * this software is provided for free, WITHOUT ANY EXPRESS OR IMPLIED WARRANTY (see the license for details) + +:: spell-checker:ignore (shell/cmd) COMSPEC ERRORLEVEL +:: spell-checker:ignore () CTYPE POSIX Tval Tvar akefile makefile makefiles multiline + +:config +set "_exclude_dir=(?i)[_.#]build|[.]git|[.]gpg|[.]vs|fixtures|vendor" +set "_exclude=(?i)[.](cache|dll|exe|gif|gz|zip)$" +:config_done + +set _dp0=%~dp0. +set _nx0=%~nx0 +set dirs=%* +if NOT DEFINED dirs if EXIST "%CD%\repo" ( set dirs="%CD%\repo" ) +if NOT DEFINED dirs if EXIST "%_dp0%\..\.git" ( set dirs="%_dp0%\.." ) +if NOT DEFINED dirs ( set "dirs=." ) + +set PCREGREP=pcregrep +if EXIST "%_dp0%\pcregrep.EXE" ( set "PCREGREP=%_dp0%\pcregrep.EXE" ) +"%PCREGREP%" --version >NUL 2>NUL || ( echo ERR!: Missing required `pcregrep` [try `scoop install pcregrep`] 1>&2 & goto _undefined_ 2>NUL || "%COMSPEC%" /d/c exit 1 ) + +echo [ %dirs% ] + +if /i "%LC_CTYPE%"=="posix" (set "LC_CTYPE=C") &:: `pcregrep` doesn't understand the common "POSIX", replace with the equivalent "C" + +set "ERRORLEVEL=" +set "ERROR=" +:: 1. Test for TABs within leading whitespace (except go files makefiles) +"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --exclude "(?i)[.]go$" --exclude "go[.](mod|sum)" --exclude "(GNU)?[Mm]akefile([.].*)?" --count --files-with-matches --recursive "^\s*\t" %dirs% +if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: files found with TABs within leading whitespace [file:#lines_matched]) + +:: 2. Test for lines with internal TABs +"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --count --files-with-matches --recursive "^.*[^\t]\t" %dirs% +if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: files found with lines containing internal TABs [file:#lines_matched]) + +:: 3. Test that makefiles have ONLY initial-TAB leading whitespace +"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --include "(GNU)?[Mm]akefile([.].*)?" --exclude "[.](to|y)ml$" --recursive --line-number --invert-match "^([\t]\s*\S|\S|$)" %dirs% +if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: Makefiles found with lines having non-TAB leading whitespace [file:line_number]) + +:: 4. Test for non-LF line endings +set "HAVE_NonLF_ERROR=" +"%PCREGREP%" --buffer-size=1M -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" -NLF --files-with-matches --multiline --recursive "\r[^\n]" %dirs% +if NOT "%ERRORLEVEL%" == "1" ( set HAVE_NonLF_ERROR=1 & echo ## files found with CR line endings) +"%PCREGREP%" --buffer-size=1M -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --exclude "(?i)\.bat$|\.cmd$" -NLF --files-with-matches --multiline --recursive "\r\n" %dirs% +if NOT "%ERRORLEVEL%" == "1" ( set HAVE_NonLF_ERROR=1 & echo ## files found with CRLF line endings) +if DEFINED HAVE_NonLF_ERROR ( set ERROR=1 & echo ERROR: files found with non-LF line endings) + +:: 5. Test for files without trailing newline +:: "%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --files-without-match --multiline --recursive "\r?[\r\n]\z" %dirs% +"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --files-with-matches --multiline --recursive "\z" %dirs% +if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: files found without trailing newline) + +:: 6. Test for files with lines having trailing whitespace +"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --recursive --line-number "\s$" %dirs% +if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: files found with lines having trailing whitespace [file:line_number]) + +:: 7. Test for files with BOM +"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --files-with-matches --multiline --recursive "\A[\xEF][\xBB][\xBF]" %dirs% +if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: files found with leading BOM) + +:script_done +if NOT DEFINED ERROR ( + echo success: no file errors found + ) +call :#exit__title __exit_title "%COMSPEC%" +set "__exit_title=" && title %__exit_title% && set "ERRORLEVEL=" & goto _undefined_ 2>NUL || "%COMSPEC%" /d/c "exit %ERROR%" + +@rem:::: +@rem:: FUNCTIONS +@goto :EOF + +:: +:#exit__title ( ref_RETURN PATH ) +:: RETURN == name of PATH +setLocal +set "_RETvar=%~1" +set "_RETval=%~2" +if NOT DEFINED _RETval ( set "_RETval=cmd" & goto :#exit__title_RETURN ) +set "_RETval=%~n2" +:#exit__title_RETURN +endLocal & set %_RETvar%^=%_RETval% +goto :EOF +:: From b0361c2b64997d0dc61b017958a038d8e055bad8 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 24 May 2020 16:08:36 -0500 Subject: [PATCH 11/11] build/dev ~ add EditorConfig file to suggest whitespace standards --- .editorconfig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..95dfec676 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +# EditorConfig (is awesome): http://EditorConfig.org + +# * top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{bat,cmd,[Bb][Aa][Tt],[Cc][Mm][Dd]}] +# DOS/Win requires BAT/CMD files to have CRLF EOLNs +end_of_line = crlf + +[[Mm]akefile{,.*}] +# TAB-style indentation +indent_style = tab + +[*.{yml,[Yy][Mm][Ll]}] +indent_size = 2