Skip to content

Commit bceb39c

Browse files
committed
fs/make: Use compile-time macro env!
1 parent a0228ab commit bceb39c

File tree

4 files changed

+56
-60
lines changed

4 files changed

+56
-60
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fs/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ edition.workspace = true
88
rust-version.workspace = true
99

1010
[dependencies]
11-
plib = { path = "../plib" }
1211
clap.workspace = true
1312
gettext-rs.workspace = true
1413
libc.workspace = true

fs/df.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::mntent::MountTable;
1515

1616
use clap::Parser;
1717
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
18-
use plib::PROJECT_NAME;
1918
#[cfg(target_os = "macos")]
2019
use std::ffi::CStr;
2120
use std::{cmp, ffi::CString, fmt::Display, io};
@@ -364,12 +363,11 @@ fn mask_fs_by_file(info: &mut MountList, filename: &str) -> io::Result<()> {
364363
}
365364

366365
fn main() -> Result<(), Box<dyn std::error::Error>> {
367-
// parse command line arguments
368-
let args = Args::parse();
369-
370366
setlocale(LocaleCategory::LcAll, "");
371-
textdomain(PROJECT_NAME)?;
372-
bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?;
367+
textdomain(env!("PROJECT_NAME"))?;
368+
bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?;
369+
370+
let args = Args::parse();
373371

374372
let mut info = read_mount_info()?;
375373

make/src/main.rs

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,58 @@ struct Args {
107107
targets: Vec<OsString>,
108108
}
109109

110+
fn print_rules(rules: &BTreeMap<String, BTreeSet<String>>) {
111+
print!("{:?}", rules);
112+
}
113+
114+
/// Parse the makefile at the given path, or the first default makefile found.
115+
/// If no makefile is found, print an error message and exit.
116+
fn parse_makefile(path: Option<impl AsRef<Path>>) -> Result<Makefile, ErrorCode> {
117+
let path = path.as_ref().map(|p| p.as_ref());
118+
119+
let path = match path {
120+
Some(path) => path,
121+
None => {
122+
let mut makefile = None;
123+
for m in MAKEFILE_PATH.iter() {
124+
let path = Path::new(m);
125+
if path.exists() {
126+
makefile = Some(path);
127+
break;
128+
}
129+
}
130+
if let Some(makefile) = makefile {
131+
makefile
132+
} else {
133+
return Err(NoMakefile);
134+
}
135+
}
136+
};
137+
138+
let contents = if path == Path::new("-") {
139+
read_stdin()?
140+
} else {
141+
match fs::read_to_string(path) {
142+
Ok(contents) => contents,
143+
Err(err) => {
144+
return Err(IoError(err.kind()));
145+
}
146+
}
147+
};
148+
149+
match Makefile::from_str(&contents) {
150+
Ok(makefile) => Ok(makefile),
151+
Err(err) => Err(ErrorCode::ParserError { constraint: err }),
152+
}
153+
}
154+
155+
/// Reads the makefile from `stdin` until EOF (Ctrl + D)
156+
fn read_stdin() -> Result<String, ErrorCode> {
157+
let mut buffer = String::new();
158+
io::stdin().read_to_string(&mut buffer)?;
159+
Ok(buffer)
160+
}
161+
110162
fn main() -> Result<(), Box<dyn std::error::Error>> {
111163
setlocale(LocaleCategory::LcAll, "");
112164
textdomain(env!("PROJECT_NAME"))?;
@@ -229,55 +281,3 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
229281
}
230282
process::exit(status_code);
231283
}
232-
233-
fn print_rules(rules: &BTreeMap<String, BTreeSet<String>>) {
234-
print!("{:?}", rules);
235-
}
236-
237-
/// Parse the makefile at the given path, or the first default makefile found.
238-
/// If no makefile is found, print an error message and exit.
239-
fn parse_makefile(path: Option<impl AsRef<Path>>) -> Result<Makefile, ErrorCode> {
240-
let path = path.as_ref().map(|p| p.as_ref());
241-
242-
let path = match path {
243-
Some(path) => path,
244-
None => {
245-
let mut makefile = None;
246-
for m in MAKEFILE_PATH.iter() {
247-
let path = Path::new(m);
248-
if path.exists() {
249-
makefile = Some(path);
250-
break;
251-
}
252-
}
253-
if let Some(makefile) = makefile {
254-
makefile
255-
} else {
256-
return Err(NoMakefile);
257-
}
258-
}
259-
};
260-
261-
let contents = if path == Path::new("-") {
262-
read_stdin()?
263-
} else {
264-
match fs::read_to_string(path) {
265-
Ok(contents) => contents,
266-
Err(err) => {
267-
return Err(IoError(err.kind()));
268-
}
269-
}
270-
};
271-
272-
match Makefile::from_str(&contents) {
273-
Ok(makefile) => Ok(makefile),
274-
Err(err) => Err(ErrorCode::ParserError { constraint: err }),
275-
}
276-
}
277-
278-
/// Reads the makefile from `stdin` until EOF (Ctrl + D)
279-
fn read_stdin() -> Result<String, ErrorCode> {
280-
let mut buffer = String::new();
281-
io::stdin().read_to_string(&mut buffer)?;
282-
Ok(buffer)
283-
}

0 commit comments

Comments
 (0)