Skip to content

Commit

Permalink
fix: rm the error 'conflict kcl.mod file path' (kcl-lang#819)
Browse files Browse the repository at this point in the history
* fix: rm the error 'conflict kcl.mod file path'

Signed-off-by: zongz <[email protected]>

* fix: make fmt

Signed-off-by: zongz <[email protected]>

---------

Signed-off-by: zongz <[email protected]>
  • Loading branch information
zong-zhe authored Oct 30, 2023
1 parent a36b79f commit 09b8ffe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
14 changes: 10 additions & 4 deletions kclvm/cmd/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn test_run_command() {
test_kcl_path_is_sym_link();
test_compile_two_kcl_mod();
test_main_pkg_not_found();
test_conflict_mod_file();
test_multi_mod_file();
test_instances_with_yaml();
test_plugin_not_found();
test_error_message_fuzz_matched();
Expand Down Expand Up @@ -531,7 +531,7 @@ fn test_main_pkg_not_found() {
}
}

fn test_conflict_mod_file() {
fn test_multi_mod_file() {
let test_case_path = PathBuf::from("./src/test_data/multimod");

let matches = app().arg_required_else_help(true).get_matches_from(&[
Expand All @@ -543,8 +543,14 @@ fn test_conflict_mod_file() {
let settings = must_build_settings(matches.subcommand_matches("run").unwrap());
let sess = Arc::new(ParseSession::default());
match exec_program(sess.clone(), &settings.try_into().unwrap()) {
Ok(_) => panic!("unreachable code."),
Err(msg) => assert!(msg.contains("conflict kcl.mod file paths")),
Ok(res) => {
assert_eq!(res.yaml_result, "kcl1: hello 1\nkcl2: hello 2");
assert_eq!(
res.json_result,
"[{\"kcl1\": \"hello 1\", \"kcl2\": \"hello 2\"}]"
);
}
Err(_) => panic!("unreachable code."),
}
}

Expand Down
4 changes: 2 additions & 2 deletions kclvm/config/src/modfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ pub fn get_pkg_root_from_paths(file_paths: &[String], workdir: String) -> Result
return Ok(last_root);
} else if !workdir.is_empty() {
return Ok(workdir);
} else {
return Ok("".to_string());
}

Err(format!("conflict kcl.mod file paths: {:?}", m))
}

pub fn get_pkg_root(k_file_path: &str) -> Option<String> {
Expand Down
7 changes: 1 addition & 6 deletions kclvm/parser/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,7 @@ pub fn get_compile_entries_from_paths(
"".to_string()
}
} else {
// If there are more than one main 'kcl.mod' files, return error.
// the root path of package '__main__' can only one.
return Err(format!(
"conflict kcl.mod file paths: {:?}",
result.get_unique_normal_paths_by_name(kclvm_ast::MAIN_PKG)
));
"".to_string()
};
result.root_path = pkg_root.clone();
// Replace the '${KCL_MOD}' of all the paths with package name '__main__'.
Expand Down

0 comments on commit 09b8ffe

Please sign in to comment.