Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
- { os: ubuntu-latest , features: all , workspace: true }
- { os: macos-latest , features: feat_os_unix }
- { os: windows-latest , features: feat_os_windows }
- { os: ubuntu-latest , features: feat_wasm , target: wasm32-wasip1 }
steps:
- uses: actions/checkout@v6
with:
Expand All @@ -82,6 +83,7 @@ jobs:
with:
toolchain: stable
components: clippy
targets: ${{ matrix.job.target || '' }}
- uses: Swatinem/rust-cache@v2
- name: Run sccache-cache
id: sccache-setup
Expand All @@ -105,6 +107,7 @@ jobs:
esac;
outputs FAIL_ON_FAULT FAULT_TYPE
- name: Install/setup prerequisites
if: ${{ ! matrix.job.target }}
shell: bash
run: |
## Install/setup prerequisites
Expand All @@ -124,31 +127,20 @@ jobs:
shell: bash
command: |
## `cargo clippy` lint testing
unset fault
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
if [[ "${{ matrix.job.features }}" == "all" ]]; then
extra="--all-features"
else
extra="--features ${{ matrix.job.features }}"
ARGS="--features ${{ matrix.job.features }}"
ARGS="${ARGS} --fault-type ${{ steps.vars.outputs.FAULT_TYPE }}"
if [[ "${{ matrix.job.workspace }}" =~ ^(1|t|true|y|yes)$ ]]; then
ARGS="${ARGS} --workspace"
fi
case '${{ matrix.job.workspace }}' in
1|t|true|y|yes)
extra="${extra} --workspace"
;;
esac
# * determine sub-crate utility list (similar to FreeBSD workflow)
if [[ "${{ matrix.job.features }}" == "all" ]]; then
UTILITY_LIST="$(./util/show-utils.sh --all-features)"
else
UTILITY_LIST="$(./util/show-utils.sh --features ${{ matrix.job.features }})"
if [[ -n "${{ matrix.job.target }}" ]]; then
ARGS="${ARGS} --target ${{ matrix.job.target }}"
fi
CARGO_UTILITY_LIST_OPTIONS="$(for u in ${UTILITY_LIST}; do echo -n "-puu_${u} "; done;)"
S=$(cargo clippy --all-targets $extra --tests --benches -pcoreutils ${CARGO_UTILITY_LIST_OPTIONS} -- -D warnings 2>&1) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*$/::${fault_type} file=\2,line=\3,col=\4::${fault_prefix}: \`cargo clippy\`: \1 (file:'\2', line:\3)/p;" -e '}' ; fault=true ; }
if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
if [[ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ]]; then
ARGS="${ARGS} --fail-on-fault"
fi
python3 util/run-clippy.py ${ARGS}
- name: "cargo clippy on fuzz dir"
if: runner.os != 'Windows'
if: runner.os != 'Windows' && !matrix.job.target
shell: bash
run: |
cd fuzz
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
sync: rsync
copyback: false
# We need jq and GNU coreutils to run show-utils.sh and bash to use inline shell string replacement
prepare: pkg install -y curl sudo jq coreutils bash
prepare: pkg install -y curl sudo jq coreutils bash python3
run: |
## Prepare, build, and test
# implementation modelled after ref: <https://github.com/rust-lang/rustup/pull/2783>
Expand Down Expand Up @@ -73,7 +73,6 @@ jobs:
FAULT_PREFIX=\$(echo "\${FAULT_TYPE}" | tr '[:lower:]' '[:upper:]')
# * determine sub-crate utility list
UTILITY_LIST="\$(./util/show-utils.sh --features ${{ matrix.job.features }})"
CARGO_UTILITY_LIST_OPTIONS="\$(for u in \${UTILITY_LIST}; do echo -n "-puu_\${u} "; done;)"
## Info
# environment
echo "## environment"
Expand Down Expand Up @@ -101,8 +100,9 @@ jobs:
## cargo clippy lint testing
if [ -z "\${FAULT}" ]; then
echo "## cargo clippy lint testing"
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
S=\$(cargo clippy --all-targets \${CARGO_UTILITY_LIST_OPTIONS} -- -D warnings 2>&1) && printf "%s\n" "\$S" || { printf "%s\n" "\$S" ; printf "%s" "\$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*\$/::\${FAULT_TYPE} file=\2,line=\3,col=\4::\${FAULT_PREFIX}: \\\`cargo clippy\\\`: \1 (file:'\2', line:\3)/p;" -e '}' ; FAULT=true ; }
CLIPPY_ARGS="--features ${{ matrix.job.features }} --fault-type \${FAULT_TYPE}"
if [ -n "\${FAIL_ON_FAULT}" ]; then CLIPPY_ARGS="\${CLIPPY_ARGS} --fail-on-fault"; fi
python3 util/run-clippy.py \${CLIPPY_ARGS} || FAULT=true
fi
# Clean to avoid to rsync back the files
cargo clean
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/openbsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
prepare: |
# Clean up disk space before installing packages
df -h
pkg_add curl sudo-- jq coreutils bash rust rust-clippy rust-rustfmt llvm--
pkg_add curl sudo-- jq coreutils bash rust rust-clippy rust-rustfmt llvm-- python3
rm -rf /usr/share/relink/* /usr/X11R6/* /usr/share/doc/* /usr/share/man/* &
# Clean up package cache after installation
pkg_delete -a &
Expand Down Expand Up @@ -84,7 +84,6 @@ jobs:
FAULT_PREFIX=\$(echo "\${FAULT_TYPE}" | tr '[:lower:]' '[:upper:]')
# * determine sub-crate utility list
UTILITY_LIST="\$(./util/show-utils.sh --features ${{ matrix.job.features }})"
CARGO_UTILITY_LIST_OPTIONS="\$(for u in \${UTILITY_LIST}; do echo -n "-puu_\${u} "; done;)"
## Info
# environment
echo "## environment"
Expand All @@ -111,8 +110,9 @@ jobs:
## cargo clippy lint testing
if [ -z "\${FAULT}" ]; then
echo "## cargo clippy lint testing"
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
S=\$(cargo clippy --all-targets \${CARGO_UTILITY_LIST_OPTIONS} -- -D warnings 2>&1) && printf "%s\n" "\$S" || { printf "%s\n" "\$S" ; printf "%s" "\$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*\$/::\${FAULT_TYPE} file=\2,line=\3,col=\4::\${FAULT_PREFIX}: \\\`cargo clippy\\\`: \1 (file:'\2', line:\3)/p;" -e '}' ; FAULT=true ; }
CLIPPY_ARGS="--features ${{ matrix.job.features }} --fault-type \${FAULT_TYPE}"
if [ -n "\${FAIL_ON_FAULT}" ]; then CLIPPY_ARGS="\${CLIPPY_ARGS} --fail-on-fault"; fi
python3 util/run-clippy.py \${CLIPPY_ARGS} || FAULT=true
fi
# Clean to avoid to rsync back the files and free up disk space
cargo clean
Expand Down
28 changes: 27 additions & 1 deletion src/uu/wc/src/countable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ pub trait WordCountable: AsFd + AsRawFd + Read {
fn inner_file(&mut self) -> Option<&mut File>;
}

#[cfg(not(unix))]
#[cfg(all(not(unix), not(target_os = "wasi")))]
pub trait WordCountable: Read {
type Buffered: BufRead;
fn buffered(self) -> Self::Buffered;
fn inner_file(&mut self) -> Option<&mut File>;
}

#[cfg(target_os = "wasi")]
pub trait WordCountable: Read {
type Buffered: BufRead;
fn buffered(self) -> Self::Buffered;
}

#[cfg(not(target_os = "wasi"))]
impl WordCountable for StdinLock<'_> {
type Buffered = Self;

Expand All @@ -38,6 +45,16 @@ impl WordCountable for StdinLock<'_> {
}
}

#[cfg(target_os = "wasi")]
impl WordCountable for StdinLock<'_> {
type Buffered = Self;

fn buffered(self) -> Self::Buffered {
self
}
}

#[cfg(not(target_os = "wasi"))]
impl WordCountable for File {
type Buffered = BufReader<Self>;

Expand All @@ -49,3 +66,12 @@ impl WordCountable for File {
Some(self)
}
}

#[cfg(target_os = "wasi")]
impl WordCountable for File {
type Buffered = BufReader<Self>;

fn buffered(self) -> Self::Buffered {
BufReader::new(self)
}
}
6 changes: 3 additions & 3 deletions src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct FileInformation(
#[cfg(unix)] nix::sys::stat::FileStat,
#[cfg(windows)] winapi_util::file::Information,
// WASI does not have nix::sys::stat, so we store std::fs::Metadata instead.
#[cfg(target_os = "wasi")] std::fs::Metadata,
#[cfg(target_os = "wasi")] fs::Metadata,
);

impl FileInformation {
Expand Down Expand Up @@ -97,9 +97,9 @@ impl FileInformation {
#[cfg(target_os = "wasi")]
{
let metadata = if dereference {
std::fs::metadata(path.as_ref())
fs::metadata(path.as_ref())
} else {
std::fs::symlink_metadata(path.as_ref())
fs::symlink_metadata(path.as_ref())
};
Ok(Self(metadata?))
}
Expand Down
14 changes: 12 additions & 2 deletions src/uucore/src/lib/features/fsext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::os_str_from_bytes;
#[cfg(windows)]
use crate::show_warning;

#[cfg(not(target_os = "wasi"))]
use std::ffi::OsStr;
#[cfg(unix)]
use std::os::unix::ffi::OsStrExt;
Expand Down Expand Up @@ -64,13 +65,14 @@ use libc::{
};
#[cfg(unix)]
use std::ffi::{CStr, CString};
#[cfg(not(target_os = "wasi"))]
use std::io::Error as IOError;
#[cfg(unix)]
use std::mem;
#[cfg(windows)]
use std::path::Path;
use std::time::SystemTime;
#[cfg(not(windows))]
#[cfg(unix)]
use std::time::UNIX_EPOCH;
use std::{borrow::Cow, ffi::OsString};

Expand Down Expand Up @@ -426,6 +428,7 @@ fn mount_dev_id(mount_dir: &OsStr) -> String {
}
}

#[cfg(not(target_os = "wasi"))]
use crate::error::UResult;
#[cfg(any(
target_os = "freebsd",
Expand Down Expand Up @@ -456,6 +459,7 @@ use std::ptr;
use std::slice;

/// Read file system list.
#[cfg(not(target_os = "wasi"))]
pub fn read_fs_list() -> UResult<Vec<MountInfo>> {
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))]
{
Expand Down Expand Up @@ -536,14 +540,20 @@ pub fn read_fs_list() -> UResult<Vec<MountInfo>> {
target_os = "redox",
target_os = "illumos",
target_os = "solaris",
target_os = "wasi"
))]
{
// No method to read mounts on these platforms
Ok(Vec::new())
}
}

/// Read file system list.
#[cfg(target_os = "wasi")]
pub fn read_fs_list() -> Vec<MountInfo> {
// No method to read mounts on WASI
Vec::new()
}

#[derive(Debug, Clone)]
pub struct FsUsage {
pub blocksize: u64,
Expand Down
Loading
Loading