mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 23:17:46 +00:00
change ~ reorganize code layout/structure
This commit is contained in:
parent
6a8a677e8b
commit
b0d02e7f43
22 changed files with 141 additions and 53 deletions
|
@ -15,6 +15,9 @@ license = "MIT"
|
|||
appveyor = { repository = "uutils/uucore" }
|
||||
travis-ci = { repository = "uutils/uucore" }
|
||||
|
||||
[lib]
|
||||
path="src/lib/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
dunce = "1.0.0"
|
||||
getopts = "<= 0.2.21"
|
||||
|
@ -34,7 +37,6 @@ data-encoding = { version = "~2.1", optional = true }
|
|||
# * libc: initial utmp support added in 0.2.15, but 0.2.68 break the build for MinSRV 1.31.0
|
||||
libc = { version = "0.2.15, <= 0.2.66", optional = true }
|
||||
|
||||
|
||||
[target.'cfg(target_os = "redox")'.dependencies]
|
||||
termion = "1.5"
|
||||
|
||||
|
|
|
@ -1,33 +1,6 @@
|
|||
extern crate wild;
|
||||
// features ~ feature-gated modules (core/bundler file)
|
||||
|
||||
pub fn args() -> impl Iterator<Item = String> {
|
||||
wild::args()
|
||||
}
|
||||
|
||||
#[cfg(feature = "failure")]
|
||||
extern crate failure;
|
||||
#[cfg(feature = "libc")]
|
||||
pub extern crate libc;
|
||||
#[cfg(feature = "winapi")]
|
||||
pub extern crate winapi;
|
||||
#[cfg(feature = "failure_derive")]
|
||||
#[macro_use]
|
||||
extern crate failure_derive;
|
||||
#[cfg(feature = "nix")]
|
||||
extern crate nix;
|
||||
#[cfg(all(feature = "lazy_static", target_os = "linux"))]
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[cfg(feature = "platform-info")]
|
||||
extern crate platform_info;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
#[macro_use]
|
||||
pub mod coreopts;
|
||||
|
||||
pub mod panic;
|
||||
// spell-checker:ignore (uucore/uutils) coreopts libc musl utmpx uucore uutils winapi
|
||||
|
||||
#[cfg(feature = "encoding")]
|
||||
pub mod encoding;
|
||||
|
@ -35,11 +8,16 @@ pub mod encoding;
|
|||
pub mod fs;
|
||||
#[cfg(feature = "parse_time")]
|
||||
pub mod parse_time;
|
||||
#[cfg(feature = "zero-copy")]
|
||||
pub mod zero_copy;
|
||||
|
||||
#[cfg(all(unix, feature = "entries"))]
|
||||
pub mod entries;
|
||||
// * (platform-specific) feature-gated modules
|
||||
// ** non-windows
|
||||
#[cfg(all(not(windows), feature = "mode"))]
|
||||
pub mod mode;
|
||||
// ** unix-only
|
||||
#[cfg(all(unix, feature = "entries"))]
|
||||
pub mod entries;
|
||||
#[cfg(all(unix, feature = "process"))]
|
||||
pub mod process;
|
||||
#[cfg(all(unix, not(target_os = "fuchsia"), feature = "signals"))]
|
||||
|
@ -51,9 +29,6 @@ pub mod signals;
|
|||
feature = "utmpx"
|
||||
))]
|
||||
pub mod utmpx;
|
||||
|
||||
#[cfg(feature = "zero-copy")]
|
||||
pub mod zero_copy;
|
||||
|
||||
// ** windows-only
|
||||
#[cfg(all(windows, feature = "wide"))]
|
||||
pub mod wide;
|
|
@ -7,7 +7,11 @@
|
|||
//
|
||||
|
||||
extern crate data_encoding;
|
||||
extern crate failure;
|
||||
|
||||
use self::data_encoding::{DecodeError, BASE32, BASE64};
|
||||
|
||||
use failure::Fail;
|
||||
use std::io::{self, Read, Write};
|
||||
|
||||
#[derive(Fail, Debug)]
|
|
@ -12,9 +12,7 @@ extern crate dunce;
|
|||
extern crate termion;
|
||||
|
||||
#[cfg(unix)]
|
||||
use super::libc;
|
||||
#[cfg(unix)]
|
||||
use super::libc::{
|
||||
use libc::{
|
||||
mode_t, S_IRGRP, S_IROTH, S_IRUSR, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH, S_IWUSR,
|
||||
S_IXGRP, S_IXOTH, S_IXUSR,
|
||||
};
|
|
@ -6,8 +6,6 @@
|
|||
// file that was distributed with this source code.
|
||||
//
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
pub fn parse_numeric(fperm: u32, mut mode: &str) -> Result<u32, String> {
|
||||
let (op, pos) = parse_op(mode, Some('='))?;
|
||||
mode = mode[pos..].trim_start_matches('0');
|
||||
|
@ -21,7 +19,7 @@ pub fn parse_numeric(fperm: u32, mut mode: &str) -> Result<u32, String> {
|
|||
'=' => change,
|
||||
_ => unreachable!(),
|
||||
}),
|
||||
Err(err) => Err(err.description().to_owned()),
|
||||
Err(err) => Err(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,7 +7,6 @@
|
|||
// that was distributed with this source code.
|
||||
//
|
||||
|
||||
use super::libc;
|
||||
use libc::{c_int, gid_t, pid_t, uid_t};
|
||||
use std::fmt;
|
||||
use std::io;
|
|
@ -31,7 +31,6 @@
|
|||
//! }
|
||||
//! ```
|
||||
|
||||
use super::libc;
|
||||
pub extern crate time;
|
||||
use self::time::{Timespec, Tm};
|
||||
|
||||
|
@ -111,8 +110,6 @@ mod ut {
|
|||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
mod ut {
|
||||
use super::libc;
|
||||
|
||||
pub static DEFAULT_FILE: &str = "";
|
||||
|
||||
pub const UT_LINESIZE: usize = 16;
|
|
@ -1,4 +1,4 @@
|
|||
use crate::zero_copy::RawObject;
|
||||
use crate::features::zero_copy::RawObject;
|
||||
|
||||
use std::io::{self, Write};
|
||||
|
|
@ -9,9 +9,9 @@ use nix::sys::uio::IoVec;
|
|||
use nix::unistd::pipe;
|
||||
use platform_info::{PlatformInfo, Uname};
|
||||
|
||||
use crate::zero_copy::{FromRawObject, RawObject};
|
||||
use crate::features::zero_copy::{FromRawObject, RawObject};
|
||||
|
||||
lazy_static! {
|
||||
lazy_static::lazy_static! {
|
||||
static ref IN_WSL: bool = {
|
||||
let info = PlatformInfo::new().unwrap();
|
||||
info.release().contains("Microsoft")
|
|
@ -1,6 +1,6 @@
|
|||
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
|
||||
|
||||
use crate::zero_copy::{AsRawObject, FromRawObject};
|
||||
use crate::features::zero_copy::{AsRawObject, FromRawObject};
|
||||
|
||||
pub type RawObject = RawFd;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
use std::os::windows::io::{AsRawHandle, FromRawHandle, RawHandle};
|
||||
|
||||
use crate::zero_copy::{AsRawObject, FromRawObject};
|
||||
use crate::features::zero_copy::{AsRawObject, FromRawObject};
|
||||
|
||||
pub type RawObject = RawHandle;
|
||||
|
75
src/uucore/src/lib/lib.rs
Normal file
75
src/uucore/src/lib/lib.rs
Normal file
|
@ -0,0 +1,75 @@
|
|||
// library ~ (core/bundler file)
|
||||
|
||||
// spell-checker:ignore (uucore/uutils) coreopts libc musl utmpx uucore uutils winapi
|
||||
|
||||
//## external crates
|
||||
|
||||
extern crate wild;
|
||||
|
||||
// * feature-gated external crates
|
||||
#[cfg(feature = "failure")]
|
||||
extern crate failure;
|
||||
#[cfg(feature = "failure_derive")]
|
||||
extern crate failure_derive;
|
||||
#[cfg(all(feature = "lazy_static", target_os = "linux"))]
|
||||
extern crate lazy_static;
|
||||
#[cfg(feature = "nix")]
|
||||
extern crate nix;
|
||||
#[cfg(feature = "platform-info")]
|
||||
extern crate platform_info;
|
||||
|
||||
// * feature-gated external crates (re-shared as public internal modules)
|
||||
#[cfg(feature = "libc")]
|
||||
pub extern crate libc;
|
||||
#[cfg(feature = "winapi")]
|
||||
pub extern crate winapi;
|
||||
|
||||
//## internal modules
|
||||
|
||||
mod macros; // crate macros (macro_rules-type; exported to `crate::...`)
|
||||
|
||||
mod features; // feature-gated code modules
|
||||
mod mods; // core cross-platform modules
|
||||
|
||||
// * cross-platform modules
|
||||
pub use mods::coreopts;
|
||||
pub use mods::panic;
|
||||
|
||||
// * feature-gated modules
|
||||
#[cfg(feature = "encoding")]
|
||||
pub use features::encoding;
|
||||
#[cfg(feature = "fs")]
|
||||
pub use features::fs;
|
||||
#[cfg(feature = "parse_time")]
|
||||
pub use features::parse_time;
|
||||
#[cfg(feature = "zero-copy")]
|
||||
pub use features::zero_copy;
|
||||
|
||||
// * (platform-specific) feature-gated modules
|
||||
// ** non-windows
|
||||
#[cfg(all(not(windows), feature = "mode"))]
|
||||
pub use features::mode;
|
||||
// ** unix-only
|
||||
#[cfg(all(unix, feature = "entries"))]
|
||||
pub use features::entries;
|
||||
#[cfg(all(unix, feature = "process"))]
|
||||
pub use features::process;
|
||||
#[cfg(all(unix, not(target_os = "fuchsia"), feature = "signals"))]
|
||||
pub use features::signals;
|
||||
#[cfg(all(
|
||||
unix,
|
||||
not(target_os = "fuchsia"),
|
||||
not(target_env = "musl"),
|
||||
feature = "utmpx"
|
||||
))]
|
||||
pub use features::utmpx;
|
||||
// ** windows-only
|
||||
#[cfg(all(windows, feature = "wide"))]
|
||||
pub use features::wide;
|
||||
|
||||
//## core functions
|
||||
|
||||
// args() ...
|
||||
pub fn args() -> impl Iterator<Item = String> {
|
||||
wild::args()
|
||||
}
|
|
@ -7,6 +7,40 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
// #[macro_export]
|
||||
// macro_rules! main { ($($arg:tt)+) => ({
|
||||
// extern crate uu_arch;
|
||||
// use std::io::Write;
|
||||
// use uu_arch::uumain;
|
||||
|
||||
// fn main() {
|
||||
// uucore::panic::install_sigpipe_hook();
|
||||
|
||||
// let code = uumain(uucore::args().collect());
|
||||
// // Since stdout is line-buffered by default, we need to ensure any pending
|
||||
// // writes are flushed before exiting. Ideally, this should be enforced by
|
||||
// // each utility.
|
||||
// //
|
||||
// // See: https://github.com/rust-lang/rust/issues/23818
|
||||
// //
|
||||
// std::io::stdout().flush().expect("could not flush stdout");
|
||||
// std::process::exit(code);
|
||||
// }
|
||||
// })}
|
||||
|
||||
// extern crate proc_macro;
|
||||
// use proc_macro::TokenStream;
|
||||
// #[proc_macro_attribute]
|
||||
// pub fn hello(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
// let result = quote! {
|
||||
// fn main() {
|
||||
// uucore::panic::install_sigpipe_hook();
|
||||
// std::io::stdout().flush().expect("could not flush stdout");
|
||||
// std::process::exit(code);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! executable(
|
||||
() => ({
|
6
src/uucore/src/lib/mods.rs
Normal file
6
src/uucore/src/lib/mods.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
// mods ~ cross-platforms modules (core/bundler file)
|
||||
|
||||
// spell-checker:ignore (uucore/uutils) coreopts libc musl utmpx uucore uutils winapi
|
||||
|
||||
pub mod coreopts;
|
||||
pub mod panic;
|
|
@ -109,10 +109,10 @@ impl<'a> CoreOptions<'a> {
|
|||
usage_str,
|
||||
self.help_text.long_help
|
||||
);
|
||||
exit!(0);
|
||||
crate::exit!(0);
|
||||
} else if matches.opt_present("version") {
|
||||
println!("{} {}", self.help_text.name, self.help_text.version);
|
||||
exit!(0);
|
||||
crate::exit!(0);
|
||||
}
|
||||
matches
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue