Skip to content

Commit 7ebc14e

Browse files
authored
refactor(kclvm-tools): move 'query' out of 'kclvm-tools'. (#229)
* refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'. move 'printer' from 'kclvm-tools' to 'kclvm-ast' issue #67 * fmt * mv query to ast_pretty * remove useless dependencies * add pretty_assertions * refactor(kclvm-tools): move 'query' out of 'kclvm-tools'. move 'query' from 'kclvm-tools' to 'kclvm-query'. issue #67. * fix rebase conflicts * remove useless imports * fmt * fix failed test cases
1 parent 5f7a002 commit 7ebc14e

23 files changed

+345
-2149
lines changed

kclvm/Cargo.lock

+289-182
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kclvm/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ kclvm-sema = {path = "./sema", version = "0.1.0"}
3737
kclvm-tools = {path = "./tools", version = "0.1.0"}
3838
kclvm-version = {path = "./version", version = "0.1.0"}
3939
kclvm-error = {path = "./error", version = "0.1.0"}
40+
kclvm-query = {path = "./query", version = "0.1.0"}
4041

4142
[profile.release]
4243
rpath = true
@@ -60,5 +61,6 @@ members = [
6061
"sema",
6162
"span",
6263
"tools",
63-
"version"
64+
"version",
65+
"query"
6466
]

kclvm/ast_pretty/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ kclvm-error = {path = "../error", version = "0.1.0"}
1111
kclvm-ast = {path = "../ast", version = "0.1.0"}
1212
indexmap = "1.0"
1313
fancy-regex = "0.7.1"
14-
pretty_assertions = "1.3.0"
14+
pretty_assertions = "1.3.0"

kclvm/ast_pretty/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use kclvm_ast::{
55
walker::MutSelfTypedResultWalker,
66
};
77
use std::collections::VecDeque;
8-
98
mod node;
109

1110
#[cfg(test)]

kclvm/capi/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ kclvm-runner = {path = "../runner", version = "0.1.0"}
1919
kclvm-parser = {path = "../parser", version = "0.1.0"}
2020
kclvm-ast = {path = "../ast", version = "0.1.0"}
2121
kclvm-runtime = {path = "../runtime", version = "0.1.0"}
22-
kclvm-tools = {path = "../tools", version= "0.1.0" }
22+
kclvm-tools = {path = "../tools", version = "0.1.0" }
23+
kclvm-query = {path = "../query", version = "0.1.0"}
2324

2425
[dev-dependencies]
2526
criterion = "0.3"

kclvm/capi/src/model/gpyrpc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file is generated by rust-protobuf 3.1.0. Do not edit
1+
// This file is generated by rust-protobuf 3.2.0. Do not edit
22
// .proto file is parsed by protoc 3.19.4
33
// @generated
44

@@ -23,7 +23,7 @@
2323
2424
/// Generated files are compatible only with the same version
2525
/// of protobuf runtime.
26-
const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_3_1_0;
26+
const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_3_2_0;
2727

2828
#[derive(PartialEq,Clone,Default,Debug)]
2929
// @@protoc_insertion_point(message:gpyrpc.CmdArgSpec)

kclvm/capi/src/service/service.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::model::gpyrpc::*;
44

55
use kclvm::ValueRef;
66
use kclvm_parser::load_program;
7-
use kclvm_tools::query::apply_overrides;
8-
use kclvm_tools::query::override_file;
7+
use kclvm_query::apply_overrides;
8+
use kclvm_query::override_file;
99
use protobuf_json_mapping::print_to_string_with_options;
1010
use protobuf_json_mapping::PrintOptions;
1111

kclvm/query/Cargo.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "kclvm-query"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
anyhow = "1.0"
10+
kclvm-ast = {path = "../ast", version = "0.1.0"}
11+
kclvm-ast-pretty = {path = "../ast_pretty", version = "0.1.0"}
12+
kclvm-parser = {path = "../parser", version = "0.1.0"}
13+
kclvm-sema = {path = "../sema", version = "0.1.0"}
14+
kclvm-error = {path = "../error", version = "0.1.0"}
15+
16+
[dev-dependencies]
17+
pretty_assertions = "1.2.1"

kclvm/tools/src/query/mod.rs kclvm/query/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use self::r#override::parse_override_spec;
4242
/// # Examples
4343
///
4444
/// ```no_run
45-
/// use kclvm_tools::query::override_file;
45+
/// use kclvm_query::override_file;
4646
///
4747
/// let result = override_file(
4848
/// "test.k",

kclvm/tools/src/query/override.rs kclvm/query/src/override.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use kclvm_ast::path::{get_attr_paths_from_config_expr, get_key_path};
77
use kclvm_ast::walker::MutSelfMutWalker;
88
use kclvm_ast::{ast, walk_if_mut};
99
use kclvm_ast_pretty::print_ast_module;
10+
use kclvm_error::bug;
1011
use kclvm_parser::parse_expr;
1112
use kclvm_sema::pre_process::{fix_config_expr_nest_attr, transform_multi_assign};
1213

File renamed without changes.
File renamed without changes.
File renamed without changes.

kclvm/tools/src/query/tests.rs kclvm/query/src/tests.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
use std::path::PathBuf;
2+
13
use super::{r#override::apply_override_on_module, *};
24
use kclvm_ast::ast;
35
use kclvm_parser::parse_file;
46
use pretty_assertions::assert_eq;
57

8+
const CARGO_FILE_PATH: &str = env!("CARGO_MANIFEST_DIR");
9+
610
/// Test override_file result.
711
#[test]
812
fn test_override_file_simple() {
@@ -11,9 +15,14 @@ fn test_override_file_simple() {
1115
":config.image=\"image/image:v1\"".to_string(),
1216
":config.data={id=1,value=\"override_value\"}".to_string(),
1317
];
18+
19+
let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH);
20+
cargo_file_path.push("src/test_data/simple.k");
21+
let abs_path = cargo_file_path.to_str().unwrap();
22+
1423
let import_paths = vec![];
1524
assert_eq!(
16-
override_file("./src/query/test_data/simple.k", &specs, &import_paths).unwrap(),
25+
override_file(abs_path, &specs, &import_paths).unwrap(),
1726
true
1827
)
1928
}
@@ -27,13 +36,13 @@ fn test_override_file_import_paths() {
2736
"pkg.pkg as alias_pkg1".to_string(),
2837
"pkg.pkg as alias_pkg2".to_string(),
2938
];
39+
40+
let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH);
41+
cargo_file_path.push("src/test_data/import_paths.k");
42+
let abs_path = cargo_file_path.to_str().unwrap();
43+
3044
assert_eq!(
31-
override_file(
32-
"./src/query/test_data/import_paths.k",
33-
&specs,
34-
&import_paths
35-
)
36-
.unwrap(),
45+
override_file(abs_path, &specs, &import_paths).unwrap(),
3746
true
3847
)
3948
}
@@ -60,7 +69,12 @@ fn test_override_file_config() {
6069
.filter_map(Result::ok)
6170
.collect::<Vec<ast::OverrideSpec>>();
6271
let import_paths = vec![];
63-
let mut module = parse_file("./src/query/test_data/config.k", None).unwrap();
72+
73+
let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH);
74+
cargo_file_path.push("src/test_data/config.k");
75+
let abs_path = cargo_file_path.to_str().unwrap();
76+
77+
let mut module = parse_file(abs_path, None).unwrap();
6478
for o in &overrides {
6579
apply_override_on_module(&mut module, o, &import_paths).unwrap();
6680
}
File renamed without changes.

0 commit comments

Comments
 (0)