Skip to content

Commit

Permalink
feat: 0.2.19 Rough support for AnvilCustom, improve anvilPy, use HEAD…
Browse files Browse the repository at this point in the history
… again when -G receives invalid tag, add -Z, backcomp -C refactor (#195)

### Added

- Add `-Z` to pass `CFLAGS` to single file build mode
  - Avoids reading `CFLAGS` from env
- Basic optional support for `AnvilCustom` kern

### Changed

- Fix: avoid error on wrong tag for `-G`, mimicking amboso
- Try reading `AMBOSO_CONFIG_ARG_ISFILE` to use `-C` with flags directly
  - Setting it to `0` enables the new, backwards incompatible behaviour
- Fix `anvilPy` build op not replacing dashes as expected
- Fix `anvilPy` build op going to `autotools` prep when query `>=
ANVIL_AUTOMAKE_VERS`
- Fix `anvilPy` build op going to single-file C mode when query `<=
ANVIL_MAKE_VERS`
- Bump expected amboso version to `2.0.9`
  • Loading branch information
jgabaut authored Nov 26, 2024
1 parent ac10b91 commit 092e1d9
Show file tree
Hide file tree
Showing 8 changed files with 802 additions and 322 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
# Changelog

## [0.2.19] - 2024-11-26

### Added

- Add -Z to pass CFLAGS to single file build mode
- Avoids reading CFLAGS from env
- Basic optional support for AnvilCustom kern

### Changed

- Fix: avoid error on wrong tag for -G, mimicking amboso
- BaseMode cd is now done through env::set_current_dir()
- Refactored BaseMode do_build() to also use build_step() for queries above anvil_env.makevers
- Fix: anvilPy does not try to call gcc when query >= makevers
- Fix: anvilPy does not try to do autotools prep when query >= automakevers
- Try reading AMBOSO_CONFIG_ARG_ISFILE to use -C with flags directly
- Setting it to 0 enables the new, backwards incompatible behaviour
- Bump expected amboso version to 2.0.9

## [0.2.18] - 2024-10-24

### Changed

- 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`
- Bump expected amboso version to 2.0.8

## [0.2.17] - 2024-08-29

Expand Down
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "invil"
description = "A port of amboso to Rust"
version = "0.2.18"
version = "0.2.19"
edition = "2021"
license = "GPL-3.0-only"
homepage = "https://github.com/jgabaut/invil"
Expand All @@ -21,17 +21,18 @@ exclude = [
[features]

anvilPy = ["dep:flate2", "dep:tar", "dep:url"]
anvilCustom = []
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.18", features = ["derive"] }
clap = { version = "4.5.21", features = ["derive"] }
dirs = "5.0.1"
flate2 = { version = "1.0.33", optional = true }
flate2 = { version = "1.0.35", optional = true }
git2 = "0.19.0"
is_executable = "1.0.3"
is_executable = "1.0.4"
log = "0.4.22"
regex = "1.10.6"
regex = "1.11.1"
simplelog = "0.12.2"
tar = { version = "0.4.41", optional = true }
tar = { version = "0.4.43", optional = true }
toml = "0.8.19"
url = { version = "2.5.2", optional = true }
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- Generate new projects supporting the build tool using `invil init <DIR>`
- Generate a basic header+impl containing project info, such as time of current commit

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

Expand Down Expand Up @@ -100,6 +100,7 @@
- [x] No color: `-P`
- [x] Force build: `-F`
- [x] Turn off extensions: `-e` (Only relative to 2.0.0)
- [x] Pass CFLAGS to single file build mode: `-Z`
- [x] Run make when no arguments are provided


Expand All @@ -123,8 +124,9 @@
- [x] `-k` to set project type
- [x] `-O` to set stego.lock dir (defaults to working directory)
- [x] Retrocompatible `stego.lock` parsing, up to `1.7.x`
- [x] Init subcommand uses passed directory's basename for flags
- [x] Init subcommand uses passed directory's basename for generated flags
- [x] Read global config file from `$HOME/.anvil/anvil.toml`
- [x] `-Z` to pass CFLAGS to single file build mode

## Extended amboso features <a name = "extended_amboso"></a>

Expand Down
91 changes: 91 additions & 0 deletions src/anvil_custom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: GPL-3.0-only
/* Build tool with support for git tags, wrapping make.
* Copyright (C) 2023-2024 jgabaut
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::path::PathBuf;
use std::time::Instant;
use std::fs;
use toml::Table;
use regex::Regex;

pub const ANVILCUST_CUSTOM_BUILDER_KEYNAME: &str = "custombuilder";

#[derive(Debug)]
pub struct AnvilCustomEnv {
/// Custom builder command string
pub custom_builder: String,
}

pub fn parse_anvilcustom_toml(stego_path: &PathBuf) -> Result<AnvilCustomEnv,String> {
let start_time = Instant::now();
let stego = fs::read_to_string(stego_path).expect("Could not read {stego_path} contents");
//trace!("Pyproject contents: {{{}}}", pyproj);
let mut stego_dir = stego_path.clone();
if ! stego_dir.pop() {
error!("Failed pop for {{{}}}", stego_dir.display());
return Err(format!("Unexpected stego_dir value: {{{}}}", stego_dir.display()));
}
return parse_anvilcustom_tomlvalue(&stego, stego_path, start_time);
}

fn has_reserved_char(input: &str) -> bool {
// Use a delimited raw string to handle backslashes correctly
let re = Regex::new(r#"[\$\`\";\|\&><\*\(\)\#\{\}\[\]]"#).unwrap();

// Check if any forbidden character is found
if re.is_match(input) {
return true;
}

false
}

fn parse_anvilcustom_tomlvalue(stego_str: &str, stego_path: &PathBuf, start_time: Instant) -> Result<AnvilCustomEnv,String> {
let toml_value = stego_str.parse::<Table>();
match toml_value {
Ok(y) => {
let mut anvilcustom_env: AnvilCustomEnv = AnvilCustomEnv {
custom_builder : "".to_string(),
};
trace!("Toml value: {{{}}}", y);
if let Some(anvil_table) = y.get("anvil").and_then(|v| v.as_table()) {
if let Some(custom_builder) = anvil_table.get(ANVILCUST_CUSTOM_BUILDER_KEYNAME) {
let anvilcust_builder_str = custom_builder.as_str().expect("toml conversion failed");
if has_reserved_char(anvilcust_builder_str) {
//TODO: warning about the reserved chars?
error!("anvil_custombuilder: --> {{{anvilcust_builder_str}}}");
return Err("Invalid custombuilder arg".to_string());
}
debug!("anvil_custombuilder: {{{anvilcust_builder_str}}}");
anvilcustom_env.custom_builder = anvilcust_builder_str.to_string();
} else {
error!("Missing ANVILCUST_CUSTOM_BUILDER definition.");
return Err(format!("Missing anvil_custombuilder in {{{}}}", stego_path.display()));
}
} else {
error!("Missing anvil section.");
return Err(format!("Missing anvil section in {{{}}}", stego_path.display()));
}

let elapsed = start_time.elapsed();
debug!("Done parsing pyproject.toml. Elapsed: {:.2?}", elapsed);
return Ok(anvilcustom_env);
}
Err(e) => {
let elapsed = start_time.elapsed();
debug!("Done parsing stego.toml. Elapsed: {:.2?}", elapsed);
error!("Failed parsing {{{}}} as TOML. Err: [{}]", stego_str, e);
return Err("Failed parsing TOML".to_string());
}
}
}

Loading

0 comments on commit 092e1d9

Please sign in to comment.