Compare commits

...

47 commits

Author SHA1 Message Date
David Tolnay
eb505d1f24
Release 1.0.104 2025-03-24 15:13:21 -07:00
David Tolnay
8bc261eb41
Revert "Disregard outdated deranged crate"
This reverts commit 12a0d5320e.
2025-03-24 15:12:57 -07:00
David Tolnay
af09ebdaec
Merge pull request #243 from dtolnay/deranged
Unpin deranged
2025-03-24 15:12:16 -07:00
David Tolnay
c45e3a6b80
Unpin deranged 2025-03-24 15:08:03 -07:00
David Tolnay
da15a2f9c1
Release 1.0.103 2025-03-24 10:46:02 -07:00
David Tolnay
9b0e804d02
Lockfile update 2025-03-24 10:45:43 -07:00
David Tolnay
e8a31d38cb
Merge pull request #242 from dtolnay/deranged
Disallow deranged 0.4.1 until either deranged or plist is fixed
2025-03-24 10:45:28 -07:00
David Tolnay
12a0d5320e
Disregard outdated deranged crate 2025-03-24 10:42:01 -07:00
David Tolnay
c8b37ee49d
Disallow deranged 0.4.1 until either deranged or plist is fixed 2025-03-24 10:40:12 -07:00
David Tolnay
4e42ee6d65
Update time to pull in deranged 0.4
Generated by `cargo update -p time`
2025-03-24 10:39:50 -07:00
David Tolnay
fde85f1d46
Release 1.0.102 2025-03-13 10:55:39 -07:00
David Tolnay
ff4c109d20
Lockfile update 2025-03-13 10:54:13 -07:00
David Tolnay
56244a2bc4
Pull in prettyplease array wrapping improvement 2025-03-13 10:54:00 -07:00
David Tolnay
9804ddf1c4
Release 1.0.101 2025-03-02 23:23:38 -08:00
David Tolnay
95df5c388a
Lockfile update 2025-03-02 23:19:35 -08:00
David Tolnay
89d75db8e2
Merge pull request #241 from dtolnay/etcetera
Vendor cache_dir logic from etcetera
2025-03-03 02:19:12 -05:00
David Tolnay
5f32c30ad1
Acknowledge provenance of cache_dir code 2025-03-02 23:12:56 -08:00
David Tolnay
4317adcaf1
Touch up etcetera cache dir code 2025-03-02 23:12:56 -08:00
David Tolnay
36dbffb78c
Conditionally compile OS-specific cache dir logic 2025-03-02 22:41:39 -08:00
David Tolnay
d46967c745
Inline cache_dir into assets module 2025-03-02 22:38:14 -08:00
David Tolnay
a58bd1a6ca
Simplify interface to obtaining cache_dir 2025-03-02 22:34:57 -08:00
David Tolnay
69f8fad695
Inline etcetera modules into a single file 2025-03-02 22:26:23 -08:00
David Tolnay
b1a731c5f7
Combine error types 2025-03-02 22:20:41 -08:00
David Tolnay
d876f6e238
Strip unused code from etcetera 2025-03-02 22:16:12 -08:00
David Tolnay
6a2b06f3be
Make etcetera buildable as module 2025-03-02 22:01:22 -08:00
David Tolnay
0d6c07747b
Vendor etcetera 0.9.0 2025-03-02 21:57:19 -08:00
David Tolnay
38a2228409
Fix -Zrandomize-layout setting in Windows jobs
This didn't take effect when run by the default pwsh shell.
2025-01-25 19:13:18 -08:00
David Tolnay
8ad3fc774a
Ignore Windows linker warning
error: linker stderr: Warning: corrupt .drectve at end of def file␍
           Warning: corrupt .drectve at end of def file␍
      |
      = note: `-D linker-messages` implied by `-D warnings`
      = help: to override `-D warnings` add `#[allow(linker_messages)]`
2025-01-25 19:05:09 -08:00
David Tolnay
030e3ea9cd
More precise gitignore patterns 2025-01-22 20:19:46 -08:00
David Tolnay
dfdf458dbd
Release 1.0.100 2025-01-12 08:05:20 -08:00
David Tolnay
987474b814
Pull in prettyplease statement-position macro semicolon fix 2025-01-12 08:04:57 -08:00
David Tolnay
a7409f2506
Release 1.0.99 2025-01-11 20:32:36 -08:00
David Tolnay
88a5f85d72
Lockfile update 2025-01-11 20:32:13 -08:00
David Tolnay
7184ec551a
Pull in prettyplease precedence improvements 2025-01-11 20:31:49 -08:00
David Tolnay
e32ff18a18
Release 1.0.98 2025-01-07 11:24:37 -08:00
David Tolnay
2c1629df42
Lockfile update 2025-01-07 11:24:18 -08:00
David Tolnay
259b88dd45
Merge pull request #240 from dtolnay/bat
Update bat to 0.25
2025-01-07 11:23:59 -08:00
David Tolnay
e6d3b96355
Update bat to 0.25 2025-01-07 11:17:39 -08:00
David Tolnay
311791e2a7
Release 1.0.97 2025-01-05 14:01:53 -08:00
David Tolnay
fdf357c292
Lockfile update 2025-01-05 14:01:34 -08:00
David Tolnay
e0d03c58ae
Pull in prettyplease precedence improvements 2025-01-05 14:01:24 -08:00
David Tolnay
6f85020e4b
Release 1.0.96 2025-01-02 18:55:33 -08:00
David Tolnay
a55dbd98ac
Lockfile update 2025-01-02 18:49:34 -08:00
David Tolnay
a175e9b16f
Update clap-cargo to 0.15 2025-01-02 18:47:47 -08:00
David Tolnay
786dd97fc5
Raise required compiler to 1.81
Required by `home` since 0.5.11.

    error: package `home v0.5.11` cannot be built because it requires rustc 1.81 or newer, while the currently active rustc version is 1.74.1
    Either upgrade to rustc 1.81 or newer, or use
    cargo update home@0.5.11 --precise ver
    where `ver` is the latest version of `home` supporting rustc 1.74.1
2024-12-16 20:23:48 -08:00
David Tolnay
a42d9253e8
Resolve unnecessary_map_or clippy lint
warning: this `map_or` is redundant
       --> src/main.rs:676:22
        |
    676 |       let compatible = metadata
        |  ______________________^
    677 | |         .as_ref()
    678 | |         .map_or(false, |m| m.is_compatible_with(assets::BAT_VERSION));
        | |_____________________________________________________________________^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or
        = note: `-W clippy::unnecessary-map-or` implied by `-W clippy::all`
        = help: to override `-W clippy::all` add `#[allow(clippy::unnecessary_map_or)]`
    help: use is_some_and instead
        |
    676 ~     let compatible = metadata
    677 ~         .as_ref().is_some_and(|m| m.is_compatible_with(assets::BAT_VERSION));
        |
2024-11-15 19:20:31 -08:00
David Tolnay
850c0550a0
Prevent upload-artifact step from causing CI failure
This step has been failing way more than reasonable across my various repos.

    With the provided path, there will be 1 file uploaded
    Artifact name is valid!
    Root directory input is valid!
    Attempt 1 of 5 failed with error: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact. Retrying request in 3000 ms...
    Attempt 2 of 5 failed with error: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact. Retrying request in 6029 ms...
    Attempt 3 of 5 failed with error: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact. Retrying request in 8270 ms...
    Attempt 4 of 5 failed with error: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact. Retrying request in 12577 ms...
    Error: Failed to CreateArtifact: Failed to make request after 5 attempts: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact
2024-11-08 21:45:37 -05:00
8 changed files with 462 additions and 249 deletions

View file

@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rust: [nightly, beta, stable, 1.74.0]
rust: [nightly, beta, stable, 1.81.0]
os: [ubuntu]
include:
- name: macOS
@ -45,6 +45,11 @@ jobs:
- name: Enable type layout randomization
run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV
if: matrix.rust == 'nightly'
shell: bash
- name: Ignore Windows linker warning
run: echo RUSTFLAGS=${RUSTFLAGS}\ -Alinker_messages >> $GITHUB_ENV
if: matrix.rust == 'nightly-x86_64-pc-windows-gnu'
shell: bash
- run: cargo check --locked
- run: cargo update
- run: cargo check
@ -57,6 +62,7 @@ jobs:
with:
name: Cargo.lock
path: Cargo.lock
continue-on-error: true
clippy:
name: Clippy

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
/target/
expand.rs
target

584
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
[package]
name = "cargo-expand"
version = "1.0.95"
version = "1.0.104"
authors = ["David Tolnay <dtolnay@gmail.com>"]
autotests = false
categories = ["development-tools::cargo-plugins", "development-tools::debugging"]
@ -10,22 +10,21 @@ edition = "2021"
keywords = ["cargo", "subcommand", "macros"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/cargo-expand"
rust-version = "1.70"
rust-version = "1.81"
[features]
default = ["prettyplease"]
prettyplease = []
[dependencies]
bat = { version = "0.24", default-features = false, features = ["paging", "regex-fancy"] }
bat = { version = "0.25", default-features = false, features = ["paging", "regex-fancy"] }
cargo-subcommand-metadata = "0.1"
clap = { version = "4", features = ["deprecated", "derive"] }
clap-cargo = "0.14"
clap-cargo = "0.15"
console = "0.15"
etcetera = "0.8"
fs-err = "3"
home = "0.5"
prettyplease = { version = "0.2.25", features = ["verbatim"] }
prettyplease = { version = "0.2.31", features = ["verbatim"] }
proc-macro2 = "1.0.80"
quote = { version = "1.0.35", default-features = false }
semver = "1"
@ -38,6 +37,9 @@ termcolor = "1.0"
toml = "0.8"
toolchain_find = "0.4"
[target.'cfg(all(windows, not(target_vendor = "uwp")))'.dependencies]
windows-sys = { version = "0.59", features = ["Win32_Foundation", "Win32_System_Com", "Win32_UI_Shell"] }
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

View file

@ -1,5 +1,4 @@
use crate::error::Result;
use etcetera::BaseStrategy as _;
use crate::error::{Error, Result};
use std::env;
use std::path::PathBuf;
use std::str;
@ -21,6 +20,84 @@ pub fn cache_dir() -> Result<PathBuf> {
return Ok(PathBuf::from(cache_dir));
}
let basedirs = etcetera::choose_base_strategy()?;
Ok(basedirs.cache_dir().join("bat"))
let home_dir = home::home_dir().ok_or(Error::HomeDir)?;
#[cfg(windows)]
let cache_dir = windows::cache_dir(&home_dir);
#[cfg(not(windows))]
let cache_dir = xdg::cache_dir(&home_dir);
Ok(cache_dir.join("bat"))
}
// Based on etcetera v0.9.0
#[cfg(windows)]
mod windows {
use std::env;
use std::path::{Path, PathBuf};
pub fn cache_dir(home_dir: &Path) -> PathBuf {
env::var_os("LOCALAPPDATA")
.filter(|s| !s.is_empty())
.map(PathBuf::from)
.or_else(dir_crt)
.unwrap_or_else(|| home_dir.join("AppData").join("Local"))
}
// Ref: https://github.com/rust-lang/cargo/blob/home-0.5.11/crates/home/src/windows.rs
// We should keep this code in sync with the above.
#[cfg(not(target_vendor = "uwp"))]
fn dir_crt() -> Option<PathBuf> {
use std::ffi::OsString;
use std::os::windows::ffi::OsStringExt;
use std::ptr;
use std::slice;
use windows_sys::Win32::Foundation::S_OK;
use windows_sys::Win32::System::Com::CoTaskMemFree;
use windows_sys::Win32::UI::Shell::{
FOLDERID_LocalAppData, SHGetKnownFolderPath, KF_FLAG_DONT_VERIFY,
};
extern "C" {
fn wcslen(buf: *const u16) -> usize;
}
let mut path = ptr::null_mut();
let S_OK = (unsafe {
SHGetKnownFolderPath(
&FOLDERID_LocalAppData,
KF_FLAG_DONT_VERIFY as u32,
ptr::null_mut(),
&mut path,
)
}) else {
// Free any allocated memory even on failure. A null ptr is a no-op for `CoTaskMemFree`.
unsafe { CoTaskMemFree(path.cast()) };
return None;
};
let path_slice = unsafe { slice::from_raw_parts(path, wcslen(path)) };
let s = OsString::from_wide(path_slice);
unsafe { CoTaskMemFree(path.cast()) };
Some(PathBuf::from(s))
}
#[cfg(target_vendor = "uwp")]
fn dir_crt() -> Option<PathBuf> {
None
}
}
// Based on etcetera v0.9.0
#[cfg(not(windows))]
mod xdg {
use std::env;
use std::path::{Path, PathBuf};
pub fn cache_dir(home_dir: &Path) -> PathBuf {
env::var_os("XDG_CACHE_HOME")
.map(PathBuf::from)
.filter(|path| path.is_absolute())
.unwrap_or_else(|| home_dir.join(".cache/"))
}
}

View file

@ -1 +1 @@
0.24.0
0.25.0

View file

@ -8,7 +8,7 @@ pub enum Error {
TomlSer(toml::ser::Error),
TomlDe(toml::de::Error),
Quote(shlex::QuoteError),
HomeDir(etcetera::HomeDirError),
HomeDir,
Bat(bat::error::Error),
}
@ -38,12 +38,6 @@ impl From<shlex::QuoteError> for Error {
}
}
impl From<etcetera::HomeDirError> for Error {
fn from(error: etcetera::HomeDirError) -> Self {
Error::HomeDir(error)
}
}
impl From<bat::error::Error> for Error {
fn from(error: bat::error::Error) -> Self {
Error::Bat(error)
@ -57,7 +51,7 @@ impl Display for Error {
Error::TomlSer(e) => e.fmt(formatter),
Error::TomlDe(e) => e.fmt(formatter),
Error::Quote(e) => e.fmt(formatter),
Error::HomeDir(e) => e.fmt(formatter),
Error::HomeDir => formatter.write_str("could not locate home directory"),
Error::Bat(e) => e.fmt(formatter),
}
}
@ -70,7 +64,7 @@ impl StdError for Error {
Error::TomlSer(e) => e.source(),
Error::TomlDe(e) => e.source(),
Error::Quote(e) => e.source(),
Error::HomeDir(e) => e.source(),
Error::HomeDir => None,
Error::Bat(e) => e.source(),
}
}

View file

@ -320,7 +320,7 @@ fn do_cargo_expand() -> Result<i32> {
},
visible_lines: VisibleLines::Ranges(LineRanges::all()),
theme: theme.unwrap_or_else(String::new),
syntax_mapping: SyntaxMapping::empty(),
syntax_mapping: SyntaxMapping::new(),
pager: None,
use_italic_text: false,
highlighted_lines: HighlightedLineRanges(LineRanges::none()),
@ -675,7 +675,7 @@ fn print_themes() -> Result<()> {
let metadata = AssetsMetadata::load_from_folder(&cache_dir)?;
let compatible = metadata
.as_ref()
.map_or(false, |m| m.is_compatible_with(assets::BAT_VERSION));
.is_some_and(|m| m.is_compatible_with(assets::BAT_VERSION));
let assets = if compatible {
HighlightingAssets::from_cache(&cache_dir)?
} else {