Skip to content

[fix] fix godel script test #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions example/xml/GetBean.gdl
Original file line number Diff line number Diff line change
@@ -1,62 +1,6 @@
// script
use coref::xml::*

schema BeanXmlElement extends XmlElement {}

impl BeanXmlElement {
@data_constraint
pub fn __all__(db: XmlDB) -> *BeanXmlElement {
for (e in XmlElement(db)) {
let (path = e.getLocation().getFile().getRelativePath()) {
if (!path.contains("target") && e.getName() = "bean") {
yield BeanXmlElement {
id: e.id,
location_id: e.location_id,
parent_id: e.parent_id,
index_order: e.index_order
}
}
}
}
}
}

schema EntryXmlElement extends XmlElement {}

impl EntryXmlElement {
@data_constraint
fn __all__(db: XmlDB) -> *EntryXmlElement {
for (e in XmlElement(db)) {
if (e.getName() = "entry") {
yield EntryXmlElement {
id: e.id,
location_id: e.location_id,
parent_id: e.parent_id,
index_order: e.index_order
}
}
}
}
}

schema PropertyXmlElement extends XmlElement {}

impl PropertyXmlElement {
@data_constraint
fn __all__(db: XmlDB) -> *PropertyXmlElement {
for (e in XmlElement(db)) {
if (e.getName() = "property") {
yield PropertyXmlElement {
id: e.id,
location_id: e.location_id,
parent_id: e.parent_id,
index_order: e.index_order
}
}
}
}
}

fn default_db() -> XmlDB {
return XmlDB::load("coref_xml_src.db")
}
Expand Down
17 changes: 0 additions & 17 deletions example/xml/POM.gdl
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,6 @@ impl ArtifactElement {
}
}

schema PomFile extends XmlFile {}

impl PomFile {
@data_constraint
pub fn __all__(db: XmlDB) -> *PomFile {
for(f in XmlFile(db)) {
if (f.getFileName() = "pom.xml") {
yield PomFile {
id: f.id,
file_name: f.file_name,
relative_path: f.relative_path
}
}
}
}
}

// output relative path of the file, referenced jar name and version
fn out(fileName: string, m1: string, m2: string, m3: string) -> bool {
let (db = XmlDB::load("coref_xml_src.db")) {
Expand Down
76 changes: 9 additions & 67 deletions tool/aci/check_gdl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,72 +44,13 @@ fi
cd "$1" || exit 1

sparrow_godel_script="$HOME/sparrow-cli/sparrow-cli/godel-script/usr/bin/godel"
sparrow_lib_1_0="$HOME/sparrow-cli/sparrow-cli/lib-1.0"
sparrow_lib="$HOME/sparrow-cli/sparrow-cli/lib"

# Define get_files function
get_files() {
find "$1" -type f \( -name "*$2" \) -print
}

# Define rebuild_lib function
rebuild_lib() {
local lib_path="$1"
local lib="$2"
local gdl_list=()
local output_file
local tmp_out
local start_time
local end_time
local elapsed_time

gdl_list+=($(get_files "$lib_path" ".gs"))
gdl_list+=($(get_files "$lib_path" ".gdl"))

output_file=$(mktemp "tempfile.XXXXXX.gdl")
trap 'rm -f "$output_file"' EXIT

echo "// script" > "$output_file"
for file_name in "${gdl_list[@]}"; do
cat "$file_name" >> "$output_file"
done

tmp_out=$(mktemp "tempfile.XXXXXX.gdl")
trap 'rm -f "$tmp_out"' EXIT

start_time=$(date +%s%3N)
if ! "$sparrow_godel_script" "$output_file" -o "$tmp_out"; then
echo "$lib_path lib compile error, please check it yourself" >&2
exit 1
fi

mv "$tmp_out" "$sparrow_lib_1_0/coref.$lib.gdl"

end_time=$(date +%s%3N)
elapsed_time=$((end_time - start_time))
echo "$lib_path lib compile success time: ${elapsed_time} milliseconds" >&2
}

# Define get_language function
get_language() {
local dir="$1"
local dirname
local language

dirname=$(dirname "$dir")
language=$(basename "$dirname")
echo "$language"
}

# Get libs directories
directories=($(find "$PWD" -type d \( -path "$PWD/language/*/lib" -o -path "$PWD/language/*/libs" \) -print))

# Get libs
for dir in "${directories[@]}"; do
lang=$(get_language "$dir")
echo "Building lib for $lang ..."
rebuild_lib "$dir" "$lang"
done

# Define get_target_files function
get_target_files() {
find "$1" -type f \( -name "*.gs" -o -name "*.gdl" \) -not -name "tempfile.*.gdl" -not -path "$1/language/*/lib/*"
Expand All @@ -119,20 +60,21 @@ files=$(get_target_files "$PWD")

# Iterate over the files
for file in $files; do
output=$(("$sparrow_godel_script" "$file" -p "$sparrow_lib_1_0" -o "${file%.*}_tmp.gdl") 2>&1)
output=$(("$sparrow_godel_script" "$file" -p "$sparrow_lib" --semantic-only) 2>&1)
result=$?

# Check if the output is not empty
if [ -n "$output" ]; then
echo "The file $file produced the following output:"
echo "File $file produced the following output:"
echo "$output"
echo "Please check if this file is a godel script (.gs) or a godel 1.0 script (.gdl)"
fi

# Check if the output is not empty
if [ $result -ne 0 ]; then
echo "Build failed, please check this file"
exit 1
else
echo "$file build successful"
fi

# Remove temporary file
rm -f "${file%.*}_tmp.gdl"
done

exit 0