mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge branch 'main' into hotfix-mktemp
This commit is contained in:
commit
276a6ccbf1
5 changed files with 123 additions and 12 deletions
13
src/uu/comm/comm.md
Normal file
13
src/uu/comm/comm.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# comm
|
||||||
|
|
||||||
|
```
|
||||||
|
comm [OPTION]... FILE1 FILE2
|
||||||
|
```
|
||||||
|
|
||||||
|
Compare two sorted files line by line.
|
||||||
|
|
||||||
|
When FILE1 or FILE2 (not both) is -, read standard input.
|
||||||
|
|
||||||
|
With no options, produce three-column output. Column one contains
|
||||||
|
lines unique to FILE1, column two contains lines unique to FILE2,
|
||||||
|
and column three contains lines common to both files.
|
|
@ -13,13 +13,12 @@ use std::io::{self, stdin, BufRead, BufReader, Stdin};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use uucore::error::FromIo;
|
use uucore::error::FromIo;
|
||||||
use uucore::error::UResult;
|
use uucore::error::UResult;
|
||||||
use uucore::format_usage;
|
use uucore::{format_usage, help_about, help_usage};
|
||||||
|
|
||||||
use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
|
use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
|
||||||
|
|
||||||
static ABOUT: &str = "Compare two sorted files line by line";
|
const ABOUT: &str = help_about!("comm.md");
|
||||||
static LONG_HELP: &str = "";
|
const USAGE: &str = help_usage!("comm.md");
|
||||||
const USAGE: &str = "{} [OPTION]... FILE1 FILE2";
|
|
||||||
|
|
||||||
mod options {
|
mod options {
|
||||||
pub const COLUMN_1: &str = "1";
|
pub const COLUMN_1: &str = "1";
|
||||||
|
@ -160,7 +159,6 @@ pub fn uu_app() -> Command {
|
||||||
Command::new(uucore::util_name())
|
Command::new(uucore::util_name())
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.after_help(LONG_HELP)
|
|
||||||
.override_usage(format_usage(USAGE))
|
.override_usage(format_usage(USAGE))
|
||||||
.infer_long_args(true)
|
.infer_long_args(true)
|
||||||
.arg(
|
.arg(
|
||||||
|
|
12
src/uu/dirname/dirname.md
Normal file
12
src/uu/dirname/dirname.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# dirname
|
||||||
|
|
||||||
|
```
|
||||||
|
dirname [OPTION] NAME...
|
||||||
|
```
|
||||||
|
|
||||||
|
Strip last component from file name
|
||||||
|
|
||||||
|
## After Help
|
||||||
|
|
||||||
|
Output each NAME with its last non-slash component and trailing slashes
|
||||||
|
removed; if NAME contains no /'s, output '.' (meaning the current directory).
|
|
@ -9,13 +9,11 @@ use clap::{crate_version, Arg, ArgAction, Command};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use uucore::display::print_verbatim;
|
use uucore::display::print_verbatim;
|
||||||
use uucore::error::{UResult, UUsageError};
|
use uucore::error::{UResult, UUsageError};
|
||||||
use uucore::format_usage;
|
use uucore::{format_usage, help_about, help_section, help_usage};
|
||||||
|
|
||||||
const ABOUT: &str = "Strip last component from file name";
|
const ABOUT: &str = help_about!("dirname.md");
|
||||||
const USAGE: &str = "{} [OPTION] NAME...";
|
const USAGE: &str = help_usage!("dirname.md");
|
||||||
const LONG_USAGE: &str = "\
|
const AFTER_HELP: &str = help_section!("after help", "dirname.md");
|
||||||
Output each NAME with its last non-slash component and trailing slashes \n\
|
|
||||||
removed; if NAME contains no /'s, output '.' (meaning the current directory).";
|
|
||||||
|
|
||||||
mod options {
|
mod options {
|
||||||
pub const ZERO: &str = "zero";
|
pub const ZERO: &str = "zero";
|
||||||
|
@ -26,7 +24,7 @@ mod options {
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let args = args.collect_lossy();
|
let args = args.collect_lossy();
|
||||||
|
|
||||||
let matches = uu_app().after_help(LONG_USAGE).try_get_matches_from(args)?;
|
let matches = uu_app().after_help(AFTER_HELP).try_get_matches_from(args)?;
|
||||||
|
|
||||||
let separator = if matches.get_flag(options::ZERO) {
|
let separator = if matches.get_flag(options::ZERO) {
|
||||||
"\0"
|
"\0"
|
||||||
|
|
90
util/size-experiment.py
Normal file
90
util/size-experiment.py
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
import subprocess
|
||||||
|
from itertools import product
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
from collections import defaultdict
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Set to false if you've only changed the analysis and do not want to recompile
|
||||||
|
# the binaries.
|
||||||
|
RECOMPILE = True
|
||||||
|
|
||||||
|
STRIP_VALS = ["none", "debuginfo", "symbols"]
|
||||||
|
PANIC_VALS = ["unwind", "abort"]
|
||||||
|
OPT_LEVEL_VALS = [3, "s", "z"]
|
||||||
|
LTO_VALS = ["off", "thin", "fat"]
|
||||||
|
|
||||||
|
|
||||||
|
def config(name, val):
|
||||||
|
return ["--config", f"profile.release.{name}={val!r}"]
|
||||||
|
|
||||||
|
|
||||||
|
sizes = {}
|
||||||
|
|
||||||
|
for (strip, panic, opt, lto) in product(
|
||||||
|
STRIP_VALS, PANIC_VALS, OPT_LEVEL_VALS, LTO_VALS
|
||||||
|
):
|
||||||
|
if RECOMPILE:
|
||||||
|
cmd = [
|
||||||
|
"cargo",
|
||||||
|
"build",
|
||||||
|
"--release",
|
||||||
|
"--features=unix",
|
||||||
|
*config("strip", strip),
|
||||||
|
*config("panic", panic),
|
||||||
|
*config("opt-level", opt),
|
||||||
|
*config("lto", lto),
|
||||||
|
]
|
||||||
|
print("RUN:", " ".join(cmd))
|
||||||
|
res = subprocess.call(cmd)
|
||||||
|
|
||||||
|
shutil.copyfile(
|
||||||
|
"target/release/coreutils",
|
||||||
|
"-".join(["coreutils", strip, panic, str(opt), lto]),
|
||||||
|
)
|
||||||
|
print(res)
|
||||||
|
|
||||||
|
sizes[(strip, panic, opt, lto)] = os.path.getsize(
|
||||||
|
"-".join(["coreutils", strip, panic, str(opt), lto])
|
||||||
|
)
|
||||||
|
|
||||||
|
changes_absolute = defaultdict(list)
|
||||||
|
changes_percent = defaultdict(list)
|
||||||
|
|
||||||
|
|
||||||
|
def with_val_at_idx(val, idx, other):
|
||||||
|
other = list(other)
|
||||||
|
other.insert(idx, val)
|
||||||
|
return tuple(other)
|
||||||
|
|
||||||
|
|
||||||
|
def collect_diff(idx, name):
|
||||||
|
all_params = [STRIP_VALS, PANIC_VALS, OPT_LEVEL_VALS, LTO_VALS]
|
||||||
|
vals = all_params.pop(idx)
|
||||||
|
for other in product(*all_params):
|
||||||
|
baseline = sizes[with_val_at_idx(vals[0], idx, other)]
|
||||||
|
for val in vals[1:]:
|
||||||
|
changes = sizes[with_val_at_idx(val, idx, other)] - baseline
|
||||||
|
changes_absolute[f"{name}={val}"].append(changes)
|
||||||
|
changes_percent[f"{name}={val}"].append(changes / baseline * 100)
|
||||||
|
|
||||||
|
|
||||||
|
collect_diff(0, "strip")
|
||||||
|
collect_diff(1, "panic")
|
||||||
|
collect_diff(2, "opt-level")
|
||||||
|
collect_diff(3, "lto")
|
||||||
|
|
||||||
|
|
||||||
|
def analyze(l):
|
||||||
|
return f"MIN: {float(min(l)):.3}, AVG: {float(sum(l)/len(l)):.3}, MAX: {float(max(l)):.3}"
|
||||||
|
|
||||||
|
|
||||||
|
print("Absolute changes")
|
||||||
|
pprint({k: analyze(v) for k, v in changes_absolute.items()})
|
||||||
|
print()
|
||||||
|
print("Percent changes")
|
||||||
|
pprint({k: analyze(v) for k, v in changes_percent.items()})
|
||||||
|
|
||||||
|
print()
|
||||||
|
print(changes_percent["opt-level=s"])
|
||||||
|
print(changes_percent["opt-level=z"])
|
Loading…
Add table
Add a link
Reference in a new issue