Skip to content

Commit

Permalink
create skeleton & pwdx as poc
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Jan 26, 2024
1 parent d303d46 commit 8e9cac5
Show file tree
Hide file tree
Showing 15 changed files with 5,528 additions and 0 deletions.
768 changes: 768 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# procps (uutils)
# * see the repository LICENSE, README, and CONTRIBUTING files for more information

# spell-checker:ignore (libs) bigdecimal datetime fundu gethostid kqueue libselinux mangen memmap procfs uuhelp

[package]
name = "procps"
version = "0.0.1"
authors = ["uutils developers"]
license = "MIT"
description = "procps ~ GNU procps (updated); implemented as universal (cross-platform) utils, written in Rust"
default-run = "procps"

homepage = "https://github.com/uutils/procps"
repository = "https://github.com/uutils/procps"
readme = "README.md"
keywords = ["procps", "uutils", "cross-platform", "cli", "utility"]
categories = ["command-line-utilities"]
rust-version = "1.70.0"
edition = "2021"

build = "build.rs"

[features]
default = ["feat_common_core"]

feat_common_core = [
"pwdx",
]

[workspace.dependencies]
uucore = "0.0.24"
clap = { version = "4.4", features = ["wrap_help", "cargo"] }
clap_complete = "4.4"
clap_mangen = "0.2"
regex = "1.10.2"
sysinfo = "0.30"
libc = "0.2.152"
phf = "0.11.2"
phf_codegen = "0.11.2"
textwrap = { version = "0.16.0", features = ["terminal_size"] }
xattr = "1.3.1"
tempfile = "3.9.0"
rand = { version = "0.8", features = ["small_rng"] }

[dependencies]
clap = { workspace = true }
clap_complete = { workspace = true }
clap_mangen = { workspace = true }
uucore = { workspace = true }
phf = { workspace = true }
textwrap = { workspace = true }


#
pwdx = { optional = true, version = "0.0.1", package = "uu_pwdx", path = "src/uu/pwdx" }

[dev-dependencies]
pretty_assertions = "1"
regex = { workspace = true }
tempfile = { workspace = true }
libc = { workspace = true }
rand = { workspace = true }
uucore = { workspace = true, features = ["entries", "process", "signals"] }

[target.'cfg(unix)'.dev-dependencies]
xattr = { workspace = true }

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dev-dependencies]
procfs = { version = "0.16", default-features = false }
rlimit = "0.10.1"

[build-dependencies]
phf_codegen = { workspace = true }


[[bin]]
name = "procps"
path = "src/bin/procps.rs"

[[bin]]
name = "uudoc"
path = "src/bin/uudoc.rs"
required-features = ["uudoc"]

# The default release profile. It contains all optimizations, without
# sacrificing debug info. With this profile (like in the standard
# release profile), the debug info and the stack traces will still be available.
[profile.release]
lto = true

# A release-like profile that is tuned to be fast, even when being fast
# compromises on binary size. This includes aborting on panic.
[profile.release-fast]
inherits = "release"
panic = "abort"

# A release-like profile that is as small as possible.
[profile.release-small]
inherits = "release"
opt-level = "z"
panic = "abort"
strip = true
101 changes: 101 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore (vars) krate

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;

pub fn main() {
if let Ok(profile) = env::var("PROFILE") {
println!("cargo:rustc-cfg=build={profile:?}");
}

const ENV_FEATURE_PREFIX: &str = "CARGO_FEATURE_";
const FEATURE_PREFIX: &str = "feat_";
const OVERRIDE_PREFIX: &str = "uu_";

let out_dir = env::var("OUT_DIR").unwrap();

let mut crates = Vec::new();
for (key, val) in env::vars() {
if val == "1" && key.starts_with(ENV_FEATURE_PREFIX) {
let krate = key[ENV_FEATURE_PREFIX.len()..].to_lowercase();
// Allow this as we have a bunch of info in the comments
#[allow(clippy::match_same_arms)]
match krate.as_ref() {
"default" | "macos" | "unix" | "windows" | "selinux" | "zip" => continue, // common/standard feature names
"nightly" | "test_unimplemented" => continue, // crate-local custom features
"uudoc" => continue, // is not a utility
"test" => continue, // over-ridden with 'uu_test' to avoid collision with rust core crate 'test'
s if s.starts_with(FEATURE_PREFIX) => continue, // crate feature sets
_ => {} // util feature name
}
crates.push(krate);
}
}
crates.sort();

let mut mf = File::create(Path::new(&out_dir).join("uutils_map.rs")).unwrap();

mf.write_all(
"type UtilityMap<T> = phf::OrderedMap<&'static str, (fn(T) -> i32, fn() -> Command)>;\n\
\n\
#[allow(clippy::too_many_lines)]
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n"
.as_bytes(),
)
.unwrap();

let mut phf_map = phf_codegen::OrderedMap::<&str>::new();
for krate in &crates {
let map_value = format!("({krate}::uumain, {krate}::uu_app)");
match krate.as_ref() {
// 'test' is named uu_test to avoid collision with rust core crate 'test'.
// It can also be invoked by name '[' for the '[ expr ] syntax'.
"uu_test" => {
phf_map.entry("test", &map_value);
phf_map.entry("[", &map_value);
}
k if k.starts_with(OVERRIDE_PREFIX) => {
phf_map.entry(&k[OVERRIDE_PREFIX.len()..], &map_value);
}
"false" | "true" => {
phf_map.entry(krate, &format!("(r#{krate}::uumain, r#{krate}::uu_app)"));
}
"hashsum" => {
phf_map.entry(krate, &format!("({krate}::uumain, {krate}::uu_app_custom)"));

let map_value = format!("({krate}::uumain, {krate}::uu_app_common)");
let map_value_bits = format!("({krate}::uumain, {krate}::uu_app_bits)");
let map_value_b3sum = format!("({krate}::uumain, {krate}::uu_app_b3sum)");
phf_map.entry("md5sum", &map_value);
phf_map.entry("sha1sum", &map_value);
phf_map.entry("sha224sum", &map_value);
phf_map.entry("sha256sum", &map_value);
phf_map.entry("sha384sum", &map_value);
phf_map.entry("sha512sum", &map_value);
phf_map.entry("sha3sum", &map_value_bits);
phf_map.entry("sha3-224sum", &map_value);
phf_map.entry("sha3-256sum", &map_value);
phf_map.entry("sha3-384sum", &map_value);
phf_map.entry("sha3-512sum", &map_value);
phf_map.entry("shake128sum", &map_value_bits);
phf_map.entry("shake256sum", &map_value_bits);
phf_map.entry("b2sum", &map_value);
phf_map.entry("b3sum", &map_value_b3sum);
}
_ => {
phf_map.entry(krate, &map_value);
}
}
}
write!(mf, "{}", phf_map.build()).unwrap();
mf.write_all(b"\n}\n").unwrap();

mf.flush().unwrap();
}
Loading

0 comments on commit 8e9cac5

Please sign in to comment.