mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Merge pull request #366 from Arcterus/src-uutils
Move all of the utils into src
This commit is contained in:
commit
63e9679bee
88 changed files with 60 additions and 57 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
/build/
|
/build/
|
||||||
/target/
|
/target/
|
||||||
|
/busybox/
|
||||||
*~
|
*~
|
||||||
.*.swp
|
.*.swp
|
||||||
.*.swo
|
.*.swo
|
||||||
|
|
102
Makefile
102
Makefile
|
@ -22,10 +22,12 @@ ENABLE_STRIP :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Install directories
|
# Install directories
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
BINDIR ?= /bin
|
BINDIR ?= /bin
|
||||||
|
|
||||||
SRC_DIR=$(shell pwd)
|
BASEDIR ?= .
|
||||||
|
SRCDIR := $(BASEDIR)/src
|
||||||
|
BUILDDIR := $(BASEDIR)/build
|
||||||
|
|
||||||
# Possible programs
|
# Possible programs
|
||||||
PROGS := \
|
PROGS := \
|
||||||
|
@ -133,32 +135,32 @@ TESTS := \
|
||||||
|
|
||||||
# Setup for building crates
|
# Setup for building crates
|
||||||
define BUILD_SETUP
|
define BUILD_SETUP
|
||||||
X := $(shell $(RUSTC) --print-file-name --crate-type rlib $(1)/$(1).rs)
|
X := $(shell $(RUSTC) --print-file-name --crate-type rlib $(SRCDIR)/$(1)/$(1).rs)
|
||||||
$(1)_RLIB := $$(X)
|
$(1)_RLIB := $$(X)
|
||||||
CRATE_RLIBS += $$(X)
|
CRATE_RLIBS += $$(X)
|
||||||
endef
|
endef
|
||||||
$(foreach crate,$(EXES),$(eval $(call BUILD_SETUP,$(crate))))
|
$(foreach crate,$(EXES),$(eval $(call BUILD_SETUP,$(crate))))
|
||||||
|
|
||||||
# Utils stuff
|
# Utils stuff
|
||||||
EXES_PATHS := $(addprefix build/,$(EXES))
|
EXES_PATHS := $(addprefix $(BUILDDIR)/,$(EXES))
|
||||||
RLIB_PATHS := $(addprefix build/,$(CRATE_RLIBS))
|
RLIB_PATHS := $(addprefix $(BUILDDIR)/,$(CRATE_RLIBS))
|
||||||
command = sh -c '$(1)'
|
command = sh -c '$(1)'
|
||||||
|
|
||||||
# Main exe build rule
|
# Main exe build rule
|
||||||
define EXE_BUILD
|
define EXE_BUILD
|
||||||
build/gen/$(1).rs: build/mkmain
|
$(BUILDDIR)/gen/$(1).rs: $(BUILDDIR)/mkmain
|
||||||
build/mkmain $(1) build/gen/$(1).rs
|
$(BUILDDIR)/mkmain $(1) $$@
|
||||||
|
|
||||||
build/$(1): build/gen/$(1).rs build/$($(1)_RLIB) | build deps
|
$(BUILDDIR)/$(1): $(BUILDDIR)/gen/$(1).rs $(BUILDDIR)/$($(1)_RLIB) | $(BUILDDIR) deps
|
||||||
$(RUSTC) $(RUSTCBINFLAGS) -L build/ -o build/$(1) build/gen/$(1).rs
|
$(RUSTC) $(RUSTCBINFLAGS) -L $(BUILDDIR)/ -o $$@ $$<
|
||||||
$(if $(ENABLE_STRIP),strip build/$(1),)
|
$(if $(ENABLE_STRIP),strip $$@,)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define CRATE_BUILD
|
define CRATE_BUILD
|
||||||
-include build/$(1).d
|
-include $(BUILDDIR)/$(1).d
|
||||||
|
|
||||||
build/$($(1)_RLIB): $(1)/$(1).rs | build deps
|
$(BUILDDIR)/$($(1)_RLIB): $(SRCDIR)/$(1)/$(1).rs | $(BUILDDIR) deps
|
||||||
$(RUSTC) $(RUSTCFLAGS) -L build/ --crate-type rlib --dep-info build/$(1).d $(1)/$(1).rs --out-dir build
|
$(RUSTC) $(RUSTCFLAGS) -L $(BUILDDIR)/ --crate-type rlib --dep-info $(BUILDDIR)/$(1).d $$< --out-dir $(BUILDDIR)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Aliases build rule
|
# Aliases build rule
|
||||||
|
@ -167,24 +169,24 @@ ALIAS_TARGET = $(word 2,$(subst :, ,$(1)))
|
||||||
define MAKE_ALIAS
|
define MAKE_ALIAS
|
||||||
|
|
||||||
ifneq ($(ALIAS_TARGET,$(1)),)
|
ifneq ($(ALIAS_TARGET,$(1)),)
|
||||||
all: build/$(call ALIAS_TARGET,$(1))
|
all: $(BUILDDIR)/$(call ALIAS_TARGET,$(1))
|
||||||
build/$(call ALIAS_TARGET,$(1)): build/$(call ALIAS_SOURCE,$(1))
|
$(BUILDDIR)/$(call ALIAS_TARGET,$(1)): $(BUILDDIR)/$(call ALIAS_SOURCE,$(1))
|
||||||
$(call command,install build/$(call ALIAS_SOURCE,$(1)) build/$(call ALIAS_TARGET,$(1)))
|
$(call command,install $$@ $$<)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Test exe built rules
|
# Test exe built rules
|
||||||
define TEST_BUILD
|
define TEST_BUILD
|
||||||
test_$(1): tmp/$(1)_test build/$(1)
|
test_$(1): tmp/$(1)_test $(BUILDDIR)/$(1)
|
||||||
$(call command,tmp/$(1)_test)
|
$(call command,$$<)
|
||||||
|
|
||||||
tmp/$(1)_test: $(1)/test.rs
|
tmp/$(1)_test: $(SRCDIR)/$(1)/test.rs
|
||||||
$(call command,$(RUSTC) $(RUSTCFLAGS) --test -o tmp/$(1)_test $(1)/test.rs)
|
$(call command,$(RUSTC) $(RUSTCFLAGS) --test -o $$@ $$<)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Main rules
|
# Main rules
|
||||||
all: $(EXES_PATHS) build/uutils
|
all: $(EXES_PATHS) $(BUILDDIR)/uutils
|
||||||
|
|
||||||
# Creating necessary rules for each targets
|
# Creating necessary rules for each targets
|
||||||
$(foreach crate,$(EXES),$(eval $(call CRATE_BUILD,$(crate))))
|
$(foreach crate,$(EXES),$(eval $(call CRATE_BUILD,$(crate))))
|
||||||
|
@ -192,28 +194,28 @@ $(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe))))
|
||||||
$(foreach alias,$(ALIASES),$(eval $(call MAKE_ALIAS,$(alias))))
|
$(foreach alias,$(ALIASES),$(eval $(call MAKE_ALIAS,$(alias))))
|
||||||
$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test))))
|
$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test))))
|
||||||
|
|
||||||
-include build/uutils.d
|
-include $(BUILDDIR)/uutils.d
|
||||||
build/uutils: uutils/uutils.rs build/mkuutils $(RLIB_PATHS)
|
$(BUILDDIR)/uutils: $(SRCDIR)/uutils/uutils.rs $(BUILDDIR)/mkuutils $(RLIB_PATHS)
|
||||||
build/mkuutils build/gen/uutils.rs $(BUILD)
|
$(BUILDDIR)/mkuutils $(BUILDDIR)/gen/uutils.rs $(BUILD)
|
||||||
$(RUSTC) $(RUSTCBINFLAGS) -L build/ --dep-info $@.d build/gen/uutils.rs -o $@
|
$(RUSTC) $(RUSTCBINFLAGS) -L $(BUILDDIR)/ --dep-info $@.d $(BUILDDIR)/gen/uutils.rs -o $@
|
||||||
$(if $(ENABLE_STRIP),strip build/uutils)
|
$(if $(ENABLE_STRIP),strip $@)
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
-include build/rust-crypto.d
|
-include $(BUILDDIR)/rust-crypto.d
|
||||||
build/.rust-crypto: | build
|
$(BUILDDIR)/.rust-crypto: | $(BUILDDIR)
|
||||||
$(RUSTC) $(RUSTCFLAGS) --crate-type rlib --dep-info build/rust-crypto.d deps/rust-crypto/src/rust-crypto/lib.rs --out-dir build/
|
$(RUSTC) $(RUSTCFLAGS) --crate-type rlib --dep-info $(BUILDDIR)/rust-crypto.d $(BASEDIR)/deps/rust-crypto/src/rust-crypto/lib.rs --out-dir $(BUILDDIR)/
|
||||||
@touch $@
|
@touch $@
|
||||||
|
|
||||||
build/mkmain: mkmain.rs | build
|
$(BUILDDIR)/mkmain: mkmain.rs | $(BUILDDIR)
|
||||||
$(RUSTC) $(RUSTCFLAGS) -L build mkmain.rs -o $@
|
$(RUSTC) $(RUSTCFLAGS) -L $(BUILDDIR) $< -o $@
|
||||||
|
|
||||||
build/mkuutils: mkuutils.rs | build
|
$(BUILDDIR)/mkuutils: mkuutils.rs | $(BUILDDIR)
|
||||||
$(RUSTC) $(RUSTCFLAGS) -L build mkuutils.rs -o $@
|
$(RUSTC) $(RUSTCFLAGS) -L $(BUILDDIR) $< -o $@
|
||||||
|
|
||||||
cksum/crc_table.rs: cksum/gen_table.rs
|
$(SRCDIR)/cksum/crc_table.rs: $(SRCDIR)/cksum/gen_table.rs
|
||||||
cd cksum && $(RUSTC) $(RUSTCFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table
|
cd $(SRCDIR)/cksum && $(RUSTC) $(RUSTCFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table
|
||||||
|
|
||||||
deps: build/.rust-crypto cksum/crc_table.rs
|
deps: $(BUILDDIR)/.rust-crypto $(SRCDIR)/cksum/crc_table.rs
|
||||||
|
|
||||||
crates:
|
crates:
|
||||||
echo $(EXES)
|
echo $(EXES)
|
||||||
|
@ -222,25 +224,25 @@ test: tmp $(addprefix test_,$(TESTS))
|
||||||
$(RM) -rf tmp
|
$(RM) -rf tmp
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) -rf build tmp
|
$(RM) -rf $(BUILDDIR) tmp
|
||||||
|
|
||||||
build:
|
$(BUILDDIR):
|
||||||
git submodule update --init
|
git submodule update --init
|
||||||
mkdir -p build/gen
|
mkdir -p $(BUILDDIR)/gen
|
||||||
|
|
||||||
tmp:
|
tmp:
|
||||||
mkdir tmp
|
mkdir tmp
|
||||||
|
|
||||||
install: $(addprefix build/,$(INSTALLEES))
|
install: $(addprefix $(BUILDDIR)/,$(INSTALLEES))
|
||||||
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)
|
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)
|
||||||
for prog in $(INSTALLEES); do \
|
for prog in $(INSTALLEES); do \
|
||||||
install build/$$prog $(DESTDIR)$(PREFIX)$(BINDIR)/$(PROG_PREFIX)$$prog; \
|
install $(BUILDDIR)/$$prog $(DESTDIR)$(PREFIX)$(BINDIR)/$(PROG_PREFIX)$$prog; \
|
||||||
done
|
done
|
||||||
|
|
||||||
# TODO: figure out if there is way for prefixes to work with the symlinks
|
# TODO: figure out if there is way for prefixes to work with the symlinks
|
||||||
install-multicall: build/uutils
|
install-multicall: $(BUILDDIR)/uutils
|
||||||
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)
|
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)
|
||||||
install build/uutils $(DESTDIR)$(PREFIX)$(BINDIR)/$(PROG_PREFIX)uutils
|
install $(BUILDDIR)/uutils $(DESTDIR)$(PREFIX)$(BINDIR)/$(PROG_PREFIX)uutils
|
||||||
cd $(DESTDIR)$(PREFIX)$(BINDIR)
|
cd $(DESTDIR)$(PREFIX)$(BINDIR)
|
||||||
for prog in $(INSTALLEES); do \
|
for prog in $(INSTALLEES); do \
|
||||||
ln -s $(PROG_PREFIX)uutils $$prog; \
|
ln -s $(PROG_PREFIX)uutils $$prog; \
|
||||||
|
@ -253,13 +255,13 @@ uninstall-multicall:
|
||||||
rm -f $(addprefix $(DESTDIR)$(PREFIX)$(BINDIR)/,$(PROGS) $(PROG_PREFIX)uutils)
|
rm -f $(addprefix $(DESTDIR)$(PREFIX)$(BINDIR)/,$(PROGS) $(PROG_PREFIX)uutils)
|
||||||
|
|
||||||
# Test under the busybox testsuite
|
# Test under the busybox testsuite
|
||||||
build/busybox: build/uutils
|
$(BUILDDIR)/busybox: $(BUILDDIR)/uutils
|
||||||
rm -f build/busybox
|
rm -f $(BUILDDIR)/busybox
|
||||||
ln -s $(SRC_DIR)/build/uutils build/busybox
|
ln -s $(BUILDDIR)/uutils $(BUILDDIR)/busybox
|
||||||
|
|
||||||
# This is a busybox-specific config file their test suite wants to parse.
|
# This is a busybox-specific config file their test suite wants to parse.
|
||||||
# For now it's blank.
|
# For now it's blank.
|
||||||
build/.config: build/uutils
|
$(BUILDDIR)/.config: $(BUILDDIR)/uutils
|
||||||
touch $@
|
touch $@
|
||||||
|
|
||||||
ifeq ($(BUSYBOX_SRC),)
|
ifeq ($(BUSYBOX_SRC),)
|
||||||
|
@ -270,8 +272,8 @@ busytest:
|
||||||
@echo
|
@echo
|
||||||
@false
|
@false
|
||||||
else
|
else
|
||||||
busytest: build/busybox build/.config
|
busytest: $(BUILDDIR)/busybox $(BUILDDIR)/.config
|
||||||
(cd $(BUSYBOX_SRC)/testsuite && bindir=$(SRC_DIR)/build ./runtest $(RUNTEST_ARGS))
|
(cd $(BUSYBOX_SRC)/testsuite && bindir=$(BUILDDIR) ./runtest $(RUNTEST_ARGS))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: all deps test clean busytest install uninstall
|
.PHONY: all deps test clean busytest install uninstall
|
||||||
|
|
|
@ -48,7 +48,7 @@ fn main() {
|
||||||
|
|
||||||
// XXX: this all just assumes that the IO works correctly
|
// XXX: this all just assumes that the IO works correctly
|
||||||
let mut out = File::open_mode(&Path::new(outfile), Truncate, Write).unwrap();
|
let mut out = File::open_mode(&Path::new(outfile), Truncate, Write).unwrap();
|
||||||
let mut input = File::open(&Path::new("uutils/uutils.rs")).unwrap();
|
let mut input = File::open(&Path::new("src/uutils/uutils.rs")).unwrap();
|
||||||
let main = input.read_to_string().unwrap().replace("@CRATES@", crates.as_slice()).replace("@UTIL_MAP@", util_map.as_slice());
|
let main = input.read_to_string().unwrap().replace("@CRATES@", crates.as_slice()).replace("@UTIL_MAP@", util_map.as_slice());
|
||||||
|
|
||||||
match out.write(main.as_bytes()) {
|
match out.write(main.as_bytes()) {
|
||||||
|
|
|
@ -4,8 +4,8 @@ use std::str;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_output_multi_files_print_all_chars() {
|
fn test_output_multi_files_print_all_chars() {
|
||||||
let po = match Command::new("build/cat")
|
let po = match Command::new("build/cat")
|
||||||
.arg("cat/fixtures/alpha.txt")
|
.arg("src/cat/fixtures/alpha.txt")
|
||||||
.arg("cat/fixtures/256.txt")
|
.arg("src/cat/fixtures/256.txt")
|
||||||
.arg("-A")
|
.arg("-A")
|
||||||
.arg("-n").output() {
|
.arg("-n").output() {
|
||||||
|
|
0
env/env.rs → src/env/env.rs
vendored
0
env/env.rs → src/env/env.rs
vendored
|
@ -27,7 +27,7 @@ fn test_stdin_newline() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_padding_without_overflow() {
|
fn test_padding_without_overflow() {
|
||||||
let po = Command::new("build/nl").arg("-i").arg("1000").arg("-s").arg("x")
|
let po = Command::new("build/nl").arg("-i").arg("1000").arg("-s").arg("x")
|
||||||
.arg("-n").arg("rz").arg("nl/fixtures/simple.txt").output().unwrap();
|
.arg("-n").arg("rz").arg("src/nl/fixtures/simple.txt").output().unwrap();
|
||||||
|
|
||||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||||
assert_eq!(out, "000001xL1\n001001xL2\n002001xL3\n003001xL4\n004001xL5\n005001xL6\n006001xL7\n007001xL8\n008001xL9\n009001xL10\n010001xL11\n011001xL12\n012001xL13\n013001xL14\n014001xL15\n");
|
assert_eq!(out, "000001xL1\n001001xL2\n002001xL3\n003001xL4\n004001xL5\n005001xL6\n006001xL7\n007001xL8\n008001xL9\n009001xL10\n010001xL11\n011001xL12\n012001xL13\n013001xL14\n014001xL15\n");
|
||||||
|
@ -37,7 +37,7 @@ fn test_padding_without_overflow() {
|
||||||
fn test_padding_with_overflow() {
|
fn test_padding_with_overflow() {
|
||||||
let po = Command::new("build/nl").arg("-i").arg("1000").arg("-s").arg("x")
|
let po = Command::new("build/nl").arg("-i").arg("1000").arg("-s").arg("x")
|
||||||
.arg("-n").arg("rz").arg("-w").arg("4")
|
.arg("-n").arg("rz").arg("-w").arg("4")
|
||||||
.arg("nl/fixtures/simple.txt").output().unwrap();
|
.arg("src/nl/fixtures/simple.txt").output().unwrap();
|
||||||
|
|
||||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||||
assert_eq!(out, "0001xL1\n1001xL2\n2001xL3\n3001xL4\n4001xL5\n5001xL6\n6001xL7\n7001xL8\n8001xL9\n9001xL10\n10001xL11\n11001xL12\n12001xL13\n13001xL14\n14001xL15\n");
|
assert_eq!(out, "0001xL1\n1001xL2\n2001xL3\n3001xL4\n4001xL5\n5001xL6\n6001xL7\n7001xL8\n8001xL9\n9001xL10\n10001xL11\n11001xL12\n12001xL13\n13001xL14\n14001xL15\n");
|
||||||
|
@ -47,11 +47,11 @@ fn test_padding_with_overflow() {
|
||||||
fn test_sections_and_styles() {
|
fn test_sections_and_styles() {
|
||||||
for &(fixture, output) in [
|
for &(fixture, output) in [
|
||||||
(
|
(
|
||||||
"nl/fixtures/section.txt",
|
"src/nl/fixtures/section.txt",
|
||||||
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 |BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 |NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"
|
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 |BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 |NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"nl/fixtures/joinblanklines.txt",
|
"src/nl/fixtures/joinblanklines.txt",
|
||||||
"1 |Nonempty\n2 |Nonempty\n3 |Followed by 10x empty\n\n\n\n\n4 |\n\n\n\n\n5 |\n6 |Followed by 5x empty\n\n\n\n\n7 |\n8 |Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 |Nonempty.\n"
|
"1 |Nonempty\n2 |Nonempty\n3 |Followed by 10x empty\n\n\n\n\n4 |\n\n\n\n\n5 |\n6 |Followed by 5x empty\n\n\n\n\n7 |\n8 |Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 |Nonempty.\n"
|
||||||
),
|
),
|
||||||
].iter() {
|
].iter() {
|
Loading…
Add table
Add a link
Reference in a new issue