Skip to content

Commit 395b6fd

Browse files
committed
[make] basic implementation
1 parent ef4d6ef commit 395b6fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1850
-0
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"display",
99
"file",
1010
"fs",
11+
"make",
1112
"misc",
1213
"pathnames",
1314
"plib",

make/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "posixutils-make"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["Jeff Garzik"]
6+
license = "MIT"
7+
repository = "https://github.com/rustcoreutils/posixutils-rs.git"
8+
9+
[dependencies]
10+
plib = { path = "../plib" }
11+
clap.workspace = true
12+
gettext-rs.workspace = true
13+
14+
const_format = "0.2"
15+
makefile-lossless = "0.1"
16+
17+
[[bin]]
18+
name = "make"
19+
path = "src/main.rs"

make/src/config.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Copyright (c) 2024 Hemi Labs, Inc.
3+
//
4+
// This file is part of the posixutils-rs project covered under
5+
// the MIT License. For the full license text, please see the LICENSE
6+
// file in the root directory of this project.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
10+
/// Represents the configuration of the make utility
11+
#[derive(Debug, Clone, PartialEq, Eq)]
12+
pub struct Config {
13+
/// Whether to ignore the errors in the rule
14+
pub ignore: bool,
15+
/// Whether to execute commands or print to stdout
16+
pub dry_run: bool,
17+
/// Whether to print recipe lines
18+
pub silent: bool,
19+
/// Whether to touch targets on execution
20+
pub touch: bool,
21+
}
22+
23+
#[allow(clippy::derivable_impls)]
24+
impl Default for Config {
25+
fn default() -> Self {
26+
Self {
27+
ignore: false,
28+
dry_run: false,
29+
silent: false,
30+
touch: false,
31+
}
32+
}
33+
}

make/src/error_code.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//
2+
// Copyright (c) 2024 Hemi Labs, Inc.
3+
//
4+
// This file is part of the posixutils-rs project covered under
5+
// the MIT License. For the full license text, please see the LICENSE
6+
// file in the root directory of this project.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
10+
use core::fmt;
11+
use std::io;
12+
13+
use gettextrs::gettext;
14+
15+
use crate::special_target::Error;
16+
17+
/// Represents the error codes that can be returned by the make utility
18+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
19+
pub enum ErrorCode {
20+
// Transparent
21+
ExecutionError { exit_code: Option<i32> },
22+
IoError(io::ErrorKind),
23+
// for now just a string, in future `makefile_lossless::parse::ParseError` must be used (now it
24+
// is private)
25+
ParseError(String),
26+
27+
// Specific
28+
NoMakefile,
29+
NoTarget { target: Option<String> },
30+
NoRule { rule: String },
31+
RecursivePrerequisite { origin: String },
32+
SpecialTargetConstraintNotFulfilled { target: String, constraint: Error },
33+
}
34+
35+
impl From<ErrorCode> for i32 {
36+
fn from(err: ErrorCode) -> i32 {
37+
(&err).into()
38+
}
39+
}
40+
41+
impl From<&ErrorCode> for i32 {
42+
fn from(err: &ErrorCode) -> i32 {
43+
use ErrorCode::*;
44+
45+
match err {
46+
ExecutionError { .. } => 1,
47+
IoError(_) => 2,
48+
ParseError(_) => 3,
49+
NoMakefile => 4,
50+
NoTarget { .. } => 5,
51+
NoRule { .. } => 6,
52+
RecursivePrerequisite { .. } => 7,
53+
SpecialTargetConstraintNotFulfilled { .. } => 8,
54+
}
55+
}
56+
}
57+
58+
impl fmt::Display for ErrorCode {
59+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
60+
use ErrorCode::*;
61+
62+
match self {
63+
ExecutionError { exit_code } => match exit_code {
64+
Some(exit_code) => {
65+
write!(f, "{}: {}", gettext("execution error"), exit_code)
66+
}
67+
None => {
68+
write!(
69+
f,
70+
"{}: {}",
71+
gettext("execution error"),
72+
gettext("terminated by signal"),
73+
)
74+
}
75+
},
76+
IoError(err) => write!(f, "{}: {}", gettext("io error"), err),
77+
NoMakefile => write!(f, "{}", gettext("no makefile")),
78+
ParseError(err) => write!(f, "{}: {}", gettext("parse error"), err),
79+
NoTarget { target } => match target {
80+
Some(target) => write!(f, "{} '{}'", gettext("no target"), target),
81+
None => write!(f, "{}", gettext("no targets to execute")),
82+
},
83+
NoRule { rule } => write!(f, "{} '{}'", gettext("no rule"), rule),
84+
RecursivePrerequisite { origin } => {
85+
write!(
86+
f,
87+
"{} '{}'",
88+
gettext("recursive prerequisite found trying to build"),
89+
origin,
90+
)
91+
}
92+
SpecialTargetConstraintNotFulfilled { target, constraint } => {
93+
write!(
94+
f,
95+
"'{}' {}: {}",
96+
target,
97+
gettext("special target constraint is not fulfilled"),
98+
constraint,
99+
)
100+
}
101+
}
102+
}
103+
}
104+
105+
impl std::error::Error for ErrorCode {}
106+
107+
impl From<io::Error> for ErrorCode {
108+
fn from(err: io::Error) -> Self {
109+
Self::IoError(err.kind())
110+
}
111+
}

0 commit comments

Comments
 (0)