Skip to content

Commit 65e4335

Browse files
committed
Embedded stm_rules, removed --rules #29
1 parent 795fd8b commit 65e4335

39 files changed

+95
-293
lines changed

stackmuncher/src/app_args.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub(crate) struct AppArgs {
3535
/// E.g. `fb8fc0f87ee78231f064131022c8154a`
3636
pub gh_validation_id: Option<String>,
3737
pub project: Option<PathBuf>,
38-
pub rules: Option<PathBuf>,
3938
pub reports: Option<PathBuf>,
4039
pub config: Option<PathBuf>,
4140
pub log: Option<tracing::Level>,
@@ -75,7 +74,6 @@ impl AppArgs {
7574
emails: None,
7675
gh_validation_id: None,
7776
project: None,
78-
rules: None,
7977
reports: None,
8078
config: None,
8179
log: None,
@@ -184,38 +182,14 @@ impl AppArgs {
184182
}
185183
};
186184

187-
// rules folder
188-
if let Some(rules) = find_arg_value(&mut pargs, vec!["--rules"]) {
189-
// en empty value doesn't make sense in this context
190-
if rules.trim().is_empty() {
191-
eprintln!(
192-
"STACKMUNCHER CONFIG ERROR: param `--rules` has no value. Omit it to use the default set or provide a valid path to where the rules files are located (absolute or relative).",
193-
);
194-
help::emit_usage_msg();
195-
exit(1);
196-
}
197-
198-
match PathBuf::from_str(&rules) {
199-
Ok(v) => app_args.rules = Some(v),
200-
Err(_) => {
201-
eprintln!(
202-
"STACKMUNCHER CONFIG ERROR: `{}` is not a valid path for `--rules`. Omit it to use the default set or provide a valid path to where the rules files are located (absolute or relative).",
203-
rules
204-
);
205-
help::emit_report_dir_msg();
206-
exit(1);
207-
}
208-
}
209-
};
210-
211185
// report folder
212186
if let Some(reports) = find_arg_value(&mut pargs, vec!["--reports"]) {
213187
// en empty value doesn't make sense in this context
214188
if reports.trim().is_empty() {
215189
eprintln!(
216190
"STACKMUNCHER CONFIG ERROR: param `--reports` has no value. Omit it to use the default location or provide a valid path to where report files should be placed (absolute or relative).",
217191
);
218-
help::emit_usage_msg();
192+
help::emit_report_dir_msg();
219193
exit(1);
220194
}
221195

@@ -226,7 +200,7 @@ impl AppArgs {
226200
"STACKMUNCHER CONFIG ERROR: `{}` is not a valid path for `--reports`. Omit it to use the default location or provide a valid path to where report files should be placed (absolute or relative).",
227201
reports
228202
);
229-
help::emit_usage_msg();
203+
help::emit_report_dir_msg();
230204
exit(1);
231205
}
232206
}

stackmuncher/src/cmd_config.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ pub(crate) async fn view_config(config: AppConfig) {
6363
.expect("Cannot convert config.report_dir to absolute path. It's a bug.")
6464
.to_string_lossy()
6565
.to_string();
66-
let rules = config
67-
.lib_config
68-
.code_rules_dir
69-
.absolutize()
70-
.expect("Cannot convert config.code_rules_dir to absolute path. It's a bug.")
71-
.to_string_lossy()
72-
.to_string();
7366
let config_file = config
7467
.config_file_path
7568
.absolutize()
@@ -99,8 +92,7 @@ pub(crate) async fn view_config(config: AppConfig) {
9992
println!(" GitHub validation: {}", github_validation);
10093
println!();
10194
println!(" Local stack reports: {}", reports);
102-
println!(" Code analysis rules: {}", rules);
103-
println!(" Config file: {}", config_file);
95+
println!(" Config folder: {}", config_file);
10496
println!();
10597
}
10698

stackmuncher/src/cmd_munch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) async fn run(config: AppConfig) -> Result<(), ()> {
1212
let instant = std::time::Instant::now();
1313

1414
// load code rules
15-
let mut code_rules = CodeRules::new(&config.lib_config.code_rules_dir);
15+
let mut code_rules = CodeRules::new();
1616

1717
// Reports are grouped per project with a canonical project name as the last subfolder
1818
let report_dir = Path::new(

stackmuncher/src/config.rs

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,8 @@ impl AppConfig {
114114
// only validate project, rules and report if code analysis is to be done
115115
// config should be validated regardless because nothing functions without it
116116
if app_args.command == AppArgCommands::Munch {
117-
// rules and project folders are being validated only - not much difference if it's done now or later
117+
// only `project` folder is being validated - not much difference if it's done now or later
118118
// replace default config with user values from the CLI
119-
if let Some(rules) = app_args.rules {
120-
validate_rules_dir(&rules);
121-
config.code_rules_dir = rules;
122-
} else {
123-
// validate the default value
124-
validate_rules_dir(&config.code_rules_dir);
125-
};
126119

127120
// check the project folder for existence and if it has .git in it
128121
config.project_dir = match app_args.project {
@@ -294,29 +287,26 @@ pub(crate) async fn new_config_with_defaults(current_dir: PathBuf) -> (Config, P
294287
// look for the rules in the current working dir if in debug mode
295288
// otherwise default to a platform-specific location
296289
// this can be overridden by `--rules` CLI param
297-
let (code_rules_dir, report_dir, config_dir, log_level) = if is_local_release {
290+
let (report_dir, config_dir, log_level) = if is_local_release {
298291
// this branch activates when the app is called directly from `stm_app/target/release` folder, but all the config files are 2 levels up
299292
// go 2 steps up in the hierarchy to get to the root of stm_app project
300293
let mut exec_dir = exec_dir;
301294
exec_dir.pop();
302295
exec_dir.pop();
303296
(
304-
exec_dir.join(Config::RULES_FOLDER_NAME_DEBUG),
305297
exec_dir.join(Config::REPORT_FOLDER_NAME_DEBUG),
306298
exec_dir.join(CONFIG_FOLDER_NAME_DEBUG),
307299
tracing::Level::ERROR,
308300
)
309301
} else if cfg!(debug_assertions) {
310302
// this branch activates when run as `cargo run`
311303
(
312-
Path::new(Config::RULES_FOLDER_NAME_DEBUG).to_path_buf(),
313304
Path::new(Config::REPORT_FOLDER_NAME_DEBUG).to_path_buf(),
314305
Path::new(CONFIG_FOLDER_NAME_DEBUG).to_path_buf(),
315306
tracing::Level::INFO,
316307
)
317308
} else if cfg!(target_os = "linux") {
318309
(
319-
Path::new(Config::RULES_FOLDER_NAME_LINUX).to_path_buf(),
320310
Path::new(Config::REPORT_FOLDER_NAME_LINUX).to_path_buf(),
321311
Path::new(CONFIG_FOLDER_NAME_LINUX).to_path_buf(),
322312
tracing::Level::ERROR,
@@ -326,7 +316,6 @@ pub(crate) async fn new_config_with_defaults(current_dir: PathBuf) -> (Config, P
326316
let local_appdata_dir = std::env::var("LOCALAPPDATA").expect("%LOCALAPPDATA% env variable not found");
327317
let local_appdata_dir = Path::new(&local_appdata_dir);
328318
(
329-
exec_dir.join(Config::RULES_FOLDER_NAME_WIN),
330319
local_appdata_dir.join(Config::REPORT_FOLDER_NAME_WIN),
331320
local_appdata_dir.join(CONFIG_FOLDER_NAME_WIN),
332321
tracing::Level::ERROR,
@@ -343,7 +332,6 @@ pub(crate) async fn new_config_with_defaults(current_dir: PathBuf) -> (Config, P
343332

344333
let config = Config {
345334
log_level,
346-
code_rules_dir,
347335
report_dir: Some(report_dir),
348336
project_dir: current_dir,
349337
user_name: String::new(),
@@ -380,50 +368,6 @@ fn trim_canonical_project_name(name: String) -> String {
380368
name
381369
}
382370

383-
/// Validates the value for config.code_rules_dir and does process::exit(1) on error.
384-
/// Prints error messages.
385-
fn validate_rules_dir(rules: &PathBuf) {
386-
// this checks if the rules dir is present, but not its contents
387-
// incomplete, may fall over later
388-
if !rules.exists() {
389-
eprintln!("STACKMUNCHER CONFIG ERROR: Cannot find StackMuncher code parsing rules.");
390-
help::emit_code_rules_msg();
391-
exit(1);
392-
}
393-
394-
// check if the sub-folders of stm_rules are present
395-
let file_type_dir = rules.join(Config::RULES_SUBFOLDER_FILE_TYPES);
396-
if !file_type_dir.exists() {
397-
let file_type_dir = file_type_dir
398-
.absolutize()
399-
.expect("Cannot convert rules / file_types dir path to absolute. It's a bug.")
400-
.to_path_buf();
401-
402-
eprintln!(
403-
"STACKMUNCHER CONFIG ERROR: Cannot find file type rules folder {}",
404-
file_type_dir.to_string_lossy()
405-
);
406-
help::emit_code_rules_msg();
407-
std::process::exit(1);
408-
}
409-
410-
// check if the munchers sub-folder is present
411-
let muncher_dir = rules.join(Config::RULES_SUBFOLDER_MUNCHERS);
412-
if !muncher_dir.exists() {
413-
let muncher_dir = muncher_dir
414-
.absolutize()
415-
.expect("Cannot convert rules / munchers dir path to absolute. It's a bug.")
416-
.to_path_buf();
417-
418-
eprintln!(
419-
"STACKMUNCHER CONFIG ERROR: Cannot find rules directory for munchers in {}",
420-
muncher_dir.to_string_lossy()
421-
);
422-
help::emit_code_rules_msg();
423-
std::process::exit(1);
424-
}
425-
}
426-
427371
/// Returns a validated config.project_dir or exits with an error message
428372
fn validate_project_dir(project: PathBuf) -> PathBuf {
429373
// the project dir at this point is either a tested param from the CLI or the current dir

stackmuncher/src/help.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,6 @@ pub(crate) fn emit_support_msg() {
2020
println!("Support: https://github.com/stackmuncher/stm/issues or [email protected]");
2121
}
2222

23-
/// Prints out info on where the rules are expected
24-
pub(crate) fn emit_code_rules_msg() {
25-
println!("");
26-
if cfg!(debug_assertions) {
27-
println!("The default location for StackMuncher code rules in DEBUGGING MODE is `{}` sub-folder of the current working directory.", Config::RULES_FOLDER_NAME_DEBUG);
28-
} else if cfg!(target_os = "linux") {
29-
println!(
30-
"The default location for StackMuncher code rules on Linux is `{}` folder.",
31-
Config::RULES_FOLDER_NAME_LINUX
32-
);
33-
} else if cfg!(target_os = "windows") {
34-
println!(
35-
"The default location for StackMuncher code rules on Windows is `{}` folder placed next stackmuncher.exe.",
36-
Config::RULES_FOLDER_NAME_WIN
37-
);
38-
}
39-
println!();
40-
println!(" To specify a different location use `--rules` param followed by a relative or absolute path to the rules folder.");
41-
println!(" The latest copy of the rules can be downloaded from https://github.com/stackmuncher/stm repo or https://distro.stackmuncher.com/stm_rules.zip");
42-
println!();
43-
emit_support_msg();
44-
}
45-
4623
/// Prints out info on where the reports can be saved
4724
pub(crate) fn emit_report_dir_msg() {
4825
println!("");

stackmuncher/src/main.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ async fn main() -> Result<(), ()> {
3636
.to_string_lossy()
3737
);
3838

39-
info!(
40-
"Code rules folder: {}",
41-
config
42-
.lib_config
43-
.code_rules_dir
44-
.absolutize()
45-
.expect("Cannot convert config.code_rules_dir to absolute path. It's a bug.")
46-
.to_string_lossy()
47-
);
48-
4939
#[cfg(debug_assertions)]
5040
info!("Running in debug mode");
5141

stackmuncher_lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ sha2 = "0.9.5"
2323
bs58 = "0.4.0"
2424
path-absolutize = "3.0.10"
2525
flate2 = "1.0"
26+
rust-embed = { version = "6", features = ["compression"] }
2627

2728
[dev-dependencies]
2829
tracing-subscriber = "0.2"

0 commit comments

Comments
 (0)