Skip to content

Commit ac10b91

Browse files
authored
feat: 0.2.18 Improved -x flag, fixes (#182)
- Fix: avoid error on relative paths with no ./ for -x, -Lx - Fix: don't try parsing global conf when file doesn't exist - Bump EXPECTED_AMBOSO_API_LEVEL to 2.0.8
1 parent 4cf68d4 commit ac10b91

File tree

7 files changed

+106
-133
lines changed

7 files changed

+106
-133
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [0.2.18] - 2024-10-24
4+
5+
### Changed
6+
7+
- Fix: avoid error on relative paths with no `./` for `-x`, `-Lx`
8+
- Fix: don't try parsing global conf when file doesn't exist
9+
- Bump `EXPECTED_AMBOSO_API_LEVEL` to `2.0.8`
10+
311
## [0.2.17] - 2024-08-29
412

513
### Added

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "invil"
33
description = "A port of amboso to Rust"
4-
version = "0.2.17"
4+
version = "0.2.18"
55
edition = "2021"
66
license = "GPL-3.0-only"
77
homepage = "https://github.com/jgabaut/invil"
@@ -24,11 +24,11 @@ anvilPy = ["dep:flate2", "dep:tar", "dep:url"]
2424
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2525

2626
[dependencies]
27-
clap = { version = "4.5.16", features = ["derive"] }
27+
clap = { version = "4.5.18", features = ["derive"] }
2828
dirs = "5.0.1"
2929
flate2 = { version = "1.0.33", optional = true }
3030
git2 = "0.19.0"
31-
is_executable = "1.0.1"
31+
is_executable = "1.0.3"
3232
log = "0.4.22"
3333
regex = "1.10.6"
3434
simplelog = "0.12.2"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- Generate new projects supporting the build tool using `invil init <DIR>`
2424
- Generate a basic header+impl containing project info, such as time of current commit
2525

26-
It's (\*) on par with the original implementation, as of `amboso` `2.0.6`.
26+
It's (\*) on par with the original implementation, as of `amboso` `2.0.8`.
2727
Check the [next section](#supported_amboso) for more support info.
2828
Check [this section](#extended_amboso) for info about extensions to `amboso 2.0.4`.
2929

src/core.rs

Lines changed: 68 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub const ANVIL_BONEDIR_KEYNAME: &str = "testsdir";
4848
pub const ANVIL_KULPODIR_KEYNAME: &str = "errortestsdir";
4949
pub const ANVIL_VERSION_KEYNAME: &str = "version";
5050
pub const ANVIL_KERN_KEYNAME: &str = "kern";
51-
pub const EXPECTED_AMBOSO_API_LEVEL: &str = "2.0.7";
51+
pub const EXPECTED_AMBOSO_API_LEVEL: &str = "2.0.8";
5252
pub const MIN_AMBOSO_V_EXTENSIONS: &str = "2.0.1";
5353
pub const MIN_AMBOSO_V_STEGO_NOFORCE: &str = "2.0.3";
5454
pub const MIN_AMBOSO_V_STEGODIR: &str = "2.0.3";
@@ -966,8 +966,16 @@ pub fn check_amboso_dir(dir: &PathBuf, args: &Args) -> Result<AmbosoEnv,String>
966966
pub fn parse_invil_toml(invil_path: &PathBuf) -> Result<AmbosoConf, String> {
967967
let start_time = Instant::now();
968968
debug!("Checking global config file at {}", invil_path.display());
969-
let invil = fs::read_to_string(invil_path).expect("Could not read anvil_conf.toml contents");
970-
return parse_invil_tomlvalue(&invil, start_time);
969+
let invil = fs::read_to_string(invil_path);
970+
match invil {
971+
Ok(i) => {
972+
return parse_invil_tomlvalue(&i, start_time);
973+
},
974+
Err(e) => {
975+
error!("Could not read anvil_conf.toml contents");
976+
return Err(e.to_string());
977+
},
978+
}
971979
}
972980

973981
fn parse_invil_tomlvalue(invil_str: &str, start_time: Instant) -> Result<AmbosoConf, String> {
@@ -992,7 +1000,7 @@ fn parse_invil_tomlvalue(invil_str: &str, start_time: Instant) -> Result<AmbosoC
9921000
info!("Running as <2.0.4");
9931001
anvil_conf.anvil_kern = AnvilKern::AmbosoC;
9941002
}
995-
"2.0.4" | "2.0.5" | "2.0.6" | "2.0.7" => {
1003+
"2.0.4" | "2.0.5" | "2.0.6" | "2.0.7" | "2.0.8" => {
9961004
info!("Running as {{{}}}", anvil_v_str);
9971005
anvil_conf.anvil_kern = AnvilKern::AmbosoC;
9981006
}
@@ -1090,6 +1098,9 @@ pub fn parse_stego_toml(stego_path: &PathBuf, builds_path: &PathBuf) -> Result<A
10901098
error!("Failed pop for {{{}}}", stego_dir.display());
10911099
return Err(format!("Unexpected stego_dir value: {{{}}}", stego_dir.display()));
10921100
}
1101+
if stego_dir.to_str().expect("Could not stringify {stego_path}") == "" {
1102+
stego_dir = PathBuf::from(".");
1103+
}
10931104
if stego_dir.exists() {
10941105
trace!("Setting ANVIL_STEGODIR to {{{}}}", stego_dir.display());
10951106
} else {
@@ -1151,7 +1162,7 @@ fn parse_stego_tomlvalue(stego_str: &str, builds_path: &PathBuf, stego_dir: Path
11511162
info!("Running as <2.0.4");
11521163
anvil_env.anvil_kern = AnvilKern::AmbosoC;
11531164
}
1154-
"2.0.4" | "2.0.5" | "2.0.6" | "2.0.7" => {
1165+
"2.0.4" | "2.0.5" | "2.0.6" | "2.0.7" | "2.0.8" => {
11551166
info!("Running as {{{}}}", anvil_v_str);
11561167
anvil_env.anvil_kern = AnvilKern::AmbosoC;
11571168
}
@@ -1736,7 +1747,7 @@ pub fn check_passed_args(args: &mut Args) -> Result<AmbosoEnv,String> {
17361747
info!("Running as {}", x.as_str());
17371748
args.anvil_kern = Some(AnvilKern::AmbosoC.to_string());
17381749
}
1739-
"2.0.4" | "2.0.5" | "2.0.6" | "2.0.7" => {
1750+
"2.0.4" | "2.0.5" | "2.0.6" | "2.0.7" | "2.0.8" => {
17401751
info!("Running as {}", x.as_str());
17411752
}
17421753
_ => {
@@ -1854,22 +1865,26 @@ pub fn check_passed_args(args: &mut Args) -> Result<AmbosoEnv,String> {
18541865
}
18551866
let mut invil_conf_path = PathBuf::from(user_home_dir.expect("Failed getting user's home directory"));
18561867
invil_conf_path.push(ANVIL_DEFAULT_CONF_PATH);
1857-
let res = parse_invil_toml(&invil_conf_path);
1858-
match res {
1859-
Ok(c) => {
1860-
match args.anvil_version {
1861-
Some(_) => {},
1862-
None => { args.anvil_version = Some(c.anvil_version);},
1868+
if invil_conf_path.exists() {
1869+
let res = parse_invil_toml(&invil_conf_path);
1870+
match res {
1871+
Ok(c) => {
1872+
match args.anvil_version {
1873+
Some(_) => {},
1874+
None => { args.anvil_version = Some(c.anvil_version);},
1875+
}
1876+
match args.anvil_kern {
1877+
Some(_) => {},
1878+
None => { args.anvil_kern = Some(c.anvil_kern.to_string()); },
1879+
}
18631880
}
1864-
match args.anvil_kern {
1865-
Some(_) => {},
1866-
None => { args.anvil_kern = Some(c.anvil_kern.to_string()); },
1881+
Err(e) => {
1882+
error!("Failed parsing anvil config file.");
1883+
return Err(e.to_string());
18671884
}
18681885
}
1869-
Err(e) => {
1870-
error!("Failed parsing anvil config file.");
1871-
return Err(e.to_string());
1872-
}
1886+
} else {
1887+
debug!("Could not read global conf from {{{}}}", invil_conf_path.display());
18731888
}
18741889
}
18751890

@@ -2256,112 +2271,49 @@ pub fn lex_stego_toml(stego_path: &PathBuf) -> Result<String,String> {
22562271
let stego = fs::read_to_string(stego_path).expect("Could not read {stego_path} contents");
22572272
trace!("Stego contents: {{{}}}", stego);
22582273
let toml_value = stego.parse::<Table>();
2259-
let mut stego_dir = stego_path.clone();
2260-
if ! stego_dir.pop() {
2261-
error!("Failed pop for {{{}}}", stego_dir.display());
2262-
return Err("Unexpected stego_dir value: {{{stego_dir.display()}}}".to_string());
2263-
}
2264-
if stego_dir.exists() {
2265-
info!("ANVIL_BINDIR = {{{}}}", stego_dir.display());
2266-
} else {
2267-
error!("Failed reading ANVIL_BINDIR from passed stego_path: {{{}}}", stego_path.display());
2268-
return Err("Could not get stego_dir from {{{stego_path.display()}}}".to_string());
2269-
}
2274+
let allow_nonstr_values = false;
22702275
match toml_value {
22712276
Ok(y) => {
22722277
trace!("Toml value: {{{}}}", y);
2273-
if let Some(build_table) = y.get("build").and_then(|v| v.as_table()) {
2274-
if let Some(source_name) = build_table.get(ANVIL_SOURCE_KEYNAME) {
2275-
info!("ANVIL_SOURCE: {{{source_name}}}");
2276-
} else {
2277-
error!("Missing ANVIL_SOURCE definition.");
2278-
return Err("Missing ANVIL_SOURCE".to_string());
2279-
}
2280-
if let Some(binary_name) = build_table.get(ANVIL_BIN_KEYNAME) {
2281-
info!("ANVIL_BIN: {{{binary_name}}}");
2282-
} else {
2283-
error!("Missing ANVIL_BIN definition.");
2284-
return Err("Missing ANVIL_BIN".to_string());
2285-
}
2286-
if let Some(anvil_make_vers_tag) = build_table.get(ANVIL_MAKE_VERS_KEYNAME) {
2287-
info!("ANVIL_MAKE_VERS: {{{anvil_make_vers_tag}}}");
2288-
} else {
2289-
error!("Missing ANVIL_MAKE_VERS definition.");
2290-
return Err("Missing ANVIL_MAKE".to_string());
2291-
}
2292-
if let Some(anvil_automake_vers_tag) = build_table.get(ANVIL_AUTOMAKE_VERS_KEYNAME) {
2293-
info!("ANVIL_AUTOMAKE_VERS: {{{anvil_automake_vers_tag}}}");
2294-
} else {
2295-
error!("Missing ANVIL_AUTOMAKE_VERS definition.");
2296-
return Err("Missing ANVIL_AUTOMAKE_VERS".to_string());
2297-
}
2298-
if let Some(anvil_testsdir) = build_table.get(ANVIL_TESTSDIR_KEYNAME) {
2299-
info!("ANVIL_TESTDIR: {{{anvil_testsdir}}}");
2300-
} else {
2301-
error!("Missing ANVIL_TESTDIR definition.");
2302-
return Err("Missing ANVIL_TESTDIR".to_string());
2303-
}
2304-
} else {
2305-
error!("Missing ANVIL_BUILD section.");
2306-
return Err("Missing ANVIL_BUILD".to_string());
2307-
}
2308-
if let Some(tests_table) = y.get("tests").and_then(|v| v.as_table()) {
2309-
if let Some(anvil_bonetests_dir) = tests_table.get(ANVIL_BONEDIR_KEYNAME) {
2310-
info!("ANVIL_BONEDIR: {{{anvil_bonetests_dir}}}");
2311-
} else {
2312-
error!("Missing ANVIL_BONEDIR definition.");
2313-
return Err("Missing ANVIL_BONEDIR".to_string());
2314-
}
2315-
if let Some(anvil_kulpotests_dir) = tests_table.get(ANVIL_KULPODIR_KEYNAME) {
2316-
info!("ANVIL_KULPODIR: {{{anvil_kulpotests_dir}}}");
2317-
} else {
2318-
error!("Missing ANVIL_KULPODIR definition.");
2319-
return Err("Missing ANVIL_KULPODIR".to_string());
2320-
}
2321-
} else {
2322-
warn!("Missing ANVIL_TESTS section.");
2323-
}
2324-
if let Some(versions_tab) = y.get("versions").and_then(|v| v.as_table()) {
2325-
let mut basemode_versions_table = BTreeMap::new();
2326-
let mut gitmode_versions_table = BTreeMap::new();
2327-
let versions_table: BTreeMap<SemVerKey,String> = versions_tab.iter().map(|(key, value)| (SemVerKey(key.to_string()), value.as_str().unwrap().to_string()))
2328-
.collect();
2329-
if versions_table.len() == 0 {
2330-
warn!("versions_table is empty.");
2331-
} else {
2332-
for (key, value) in versions_table.iter() {
2333-
if key.to_string().starts_with('B') {
2334-
let trimmed_key = key.to_string().trim_start_matches('B').to_string();
2335-
if ! is_semver(&trimmed_key) {
2336-
error!("Invalid semver key: {{{}}}", trimmed_key);
2337-
return Err("Invalid semver key".to_string());
2338-
}
2339-
let ins_res = basemode_versions_table.insert(SemVerKey(trimmed_key.clone()), value.clone());
2340-
match ins_res {
2341-
None => {},
2342-
Some(old) => {
2343-
error!("lex_stego_toml(): A value was already present for key {{{}}} and was replaced. {{{} => {}}}", trimmed_key, old, value);
2344-
return Err("Basemode version conflict".to_string());
2278+
for t in y.iter() {
2279+
println!("Scope: {}", t.0);
2280+
if let Some(table) = y.get(t.0).and_then(|v| v.as_table()) {
2281+
for key in table.keys() {
2282+
if let Some(val) = table.get(key) {
2283+
if val.is_str() {
2284+
println!("Variable: {}_{}, Value: {}", t.0, key, val);
2285+
} else if allow_nonstr_values {
2286+
if val.is_array() {
2287+
println!("Array: {}_{}, Name: {}", t.0, key, key);
2288+
for (i, inner_v) in val.as_array().expect("Failed parsing array").iter().enumerate() {
2289+
if inner_v.is_str() {
2290+
println!("Arrvalue: {}_{}[{}], Value: {}", t.0, key, i, inner_v);
2291+
}
2292+
}
2293+
} else if val.is_table() {
2294+
println!("Struct: {}_{}, Name: {}", t.0, key, key);
2295+
let tab = val.as_table().expect("Failed parsing table");
2296+
for inner_k in tab.keys() {
2297+
if let Some(inner_v) = tab.get(inner_k) {
2298+
if inner_v.is_str() {
2299+
println!("Structvalue: {}_{}_{}, Value: {}", t.0, key, inner_k, inner_v);
2300+
}
2301+
} else {
2302+
error!("Could not parse inner key {inner_k} for table {key}")
2303+
}
2304+
}
23452305
}
2306+
} else {
2307+
debug!("Value was not a string and was skipped: {val}");
23462308
}
23472309
} else {
2348-
if ! is_semver(&key.to_string()) {
2349-
error!("Invalid semver key: {{{}}}", key);
2350-
return Err("Invalid semver key".to_string());
2351-
}
2352-
let ins_res = gitmode_versions_table.insert(SemVerKey(key.to_string()), value.clone());
2353-
match ins_res {
2354-
None => {},
2355-
Some(old) => {
2356-
error!("lex_stego_toml(): A value was already present for key {{{}}} and was replaced. {{{} => {}}}", key, old, value);
2357-
return Err("Gitmode version conflict".to_string());
2358-
}
2359-
}
2310+
error!("Could not parse {key}");
23602311
}
23612312
}
2313+
} else {
2314+
error!("Could not parse {}", t.0);
23622315
}
2363-
} else {
2364-
warn!("Missing ANVIL_VERSIONS section.");
2316+
println!("----------------------------");
23652317
}
23662318
let elapsed = start_time.elapsed();
23672319
debug!("Done lexing stego.toml. Elapsed: {:.2?}", elapsed);

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn main() -> ExitCode {
204204
debug!("{s}");
205205
}
206206
_ => {
207-
info!("{s}");
207+
debug!("{s}");
208208
}
209209
}
210210
return ExitCode::SUCCESS;

0 commit comments

Comments
 (0)