Skip to content

Commit

Permalink
refactor(kclvm-tools): move 'query' out of 'kclvm-tools'. (#229)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zong-zhe committed Oct 9, 2022
1 parent 5f7a002 commit 7ebc14e
Show file tree
Hide file tree
Showing 23 changed files with 345 additions and 2,149 deletions.
471 changes: 289 additions & 182 deletions kclvm/Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion kclvm/Cargo.toml
Expand Up @@ -37,6 +37,7 @@ kclvm-sema = {path = "./sema", version = "0.1.0"}
kclvm-tools = {path = "./tools", version = "0.1.0"}
kclvm-version = {path = "./version", version = "0.1.0"}
kclvm-error = {path = "./error", version = "0.1.0"}
kclvm-query = {path = "./query", version = "0.1.0"}

[profile.release]
rpath = true
Expand All @@ -60,5 +61,6 @@ members = [
"sema",
"span",
"tools",
"version"
"version",
"query"
]
2 changes: 1 addition & 1 deletion kclvm/ast_pretty/Cargo.toml
Expand Up @@ -11,4 +11,4 @@ kclvm-error = {path = "../error", version = "0.1.0"}
kclvm-ast = {path = "../ast", version = "0.1.0"}
indexmap = "1.0"
fancy-regex = "0.7.1"
pretty_assertions = "1.3.0"
pretty_assertions = "1.3.0"
1 change: 0 additions & 1 deletion kclvm/ast_pretty/src/lib.rs
Expand Up @@ -5,7 +5,6 @@ use kclvm_ast::{
walker::MutSelfTypedResultWalker,
};
use std::collections::VecDeque;

mod node;

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion kclvm/capi/Cargo.toml
Expand Up @@ -19,7 +19,8 @@ kclvm-runner = {path = "../runner", version = "0.1.0"}
kclvm-parser = {path = "../parser", version = "0.1.0"}
kclvm-ast = {path = "../ast", version = "0.1.0"}
kclvm-runtime = {path = "../runtime", version = "0.1.0"}
kclvm-tools = {path = "../tools", version= "0.1.0" }
kclvm-tools = {path = "../tools", version = "0.1.0" }
kclvm-query = {path = "../query", version = "0.1.0"}

[dev-dependencies]
criterion = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions kclvm/capi/src/model/gpyrpc.rs
@@ -1,4 +1,4 @@
// This file is generated by rust-protobuf 3.1.0. Do not edit
// This file is generated by rust-protobuf 3.2.0. Do not edit
// .proto file is parsed by protoc 3.19.4
// @generated

Expand All @@ -23,7 +23,7 @@

/// Generated files are compatible only with the same version
/// of protobuf runtime.
const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_3_1_0;
const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_3_2_0;

#[derive(PartialEq,Clone,Default,Debug)]
// @@protoc_insertion_point(message:gpyrpc.CmdArgSpec)
Expand Down
4 changes: 2 additions & 2 deletions kclvm/capi/src/service/service.rs
Expand Up @@ -4,8 +4,8 @@ use crate::model::gpyrpc::*;

use kclvm::ValueRef;
use kclvm_parser::load_program;
use kclvm_tools::query::apply_overrides;
use kclvm_tools::query::override_file;
use kclvm_query::apply_overrides;
use kclvm_query::override_file;
use protobuf_json_mapping::print_to_string_with_options;
use protobuf_json_mapping::PrintOptions;

Expand Down
17 changes: 17 additions & 0 deletions kclvm/query/Cargo.toml
@@ -0,0 +1,17 @@
[package]
name = "kclvm-query"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
kclvm-ast = {path = "../ast", version = "0.1.0"}
kclvm-ast-pretty = {path = "../ast_pretty", version = "0.1.0"}
kclvm-parser = {path = "../parser", version = "0.1.0"}
kclvm-sema = {path = "../sema", version = "0.1.0"}
kclvm-error = {path = "../error", version = "0.1.0"}

[dev-dependencies]
pretty_assertions = "1.2.1"
2 changes: 1 addition & 1 deletion kclvm/tools/src/query/mod.rs → kclvm/query/src/lib.rs
Expand Up @@ -42,7 +42,7 @@ use self::r#override::parse_override_spec;
/// # Examples
///
/// ```no_run
/// use kclvm_tools::query::override_file;
/// use kclvm_query::override_file;
///
/// let result = override_file(
/// "test.k",
Expand Down
Expand Up @@ -7,6 +7,7 @@ use kclvm_ast::path::{get_attr_paths_from_config_expr, get_key_path};
use kclvm_ast::walker::MutSelfMutWalker;
use kclvm_ast::{ast, walk_if_mut};
use kclvm_ast_pretty::print_ast_module;
use kclvm_error::bug;
use kclvm_parser::parse_expr;
use kclvm_sema::pre_process::{fix_config_expr_nest_attr, transform_multi_assign};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 22 additions & 8 deletions kclvm/tools/src/query/tests.rs → kclvm/query/src/tests.rs
@@ -1,8 +1,12 @@
use std::path::PathBuf;

use super::{r#override::apply_override_on_module, *};
use kclvm_ast::ast;
use kclvm_parser::parse_file;
use pretty_assertions::assert_eq;

const CARGO_FILE_PATH: &str = env!("CARGO_MANIFEST_DIR");

/// Test override_file result.
#[test]
fn test_override_file_simple() {
Expand All @@ -11,9 +15,14 @@ fn test_override_file_simple() {
":config.image=\"image/image:v1\"".to_string(),
":config.data={id=1,value=\"override_value\"}".to_string(),
];

let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH);
cargo_file_path.push("src/test_data/simple.k");
let abs_path = cargo_file_path.to_str().unwrap();

let import_paths = vec![];
assert_eq!(
override_file("./src/query/test_data/simple.k", &specs, &import_paths).unwrap(),
override_file(abs_path, &specs, &import_paths).unwrap(),
true
)
}
Expand All @@ -27,13 +36,13 @@ fn test_override_file_import_paths() {
"pkg.pkg as alias_pkg1".to_string(),
"pkg.pkg as alias_pkg2".to_string(),
];

let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH);
cargo_file_path.push("src/test_data/import_paths.k");
let abs_path = cargo_file_path.to_str().unwrap();

assert_eq!(
override_file(
"./src/query/test_data/import_paths.k",
&specs,
&import_paths
)
.unwrap(),
override_file(abs_path, &specs, &import_paths).unwrap(),
true
)
}
Expand All @@ -60,7 +69,12 @@ fn test_override_file_config() {
.filter_map(Result::ok)
.collect::<Vec<ast::OverrideSpec>>();
let import_paths = vec![];
let mut module = parse_file("./src/query/test_data/config.k", None).unwrap();

let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH);
cargo_file_path.push("src/test_data/config.k");
let abs_path = cargo_file_path.to_str().unwrap();

let mut module = parse_file(abs_path, None).unwrap();
for o in &overrides {
apply_override_on_module(&mut module, o, &import_paths).unwrap();
}
Expand Down
File renamed without changes.

0 comments on commit 7ebc14e

Please sign in to comment.