From d7a20319e863c9d8def47199ee04dd0908808fe2 Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Wed, 31 Jul 2024 09:32:26 +0000 Subject: [PATCH] makes installs easy to manage and debug, downloads more updated tools, first make of a parse tree --- ...GQL_standard_2024-07-27.g4 => GQL_2024.g4} | 2 +- developer/ANTLR/{GQL.g4 => GQL_test.g4} | 2 +- developer/makefile | 70 ++++++++++++------- executor/clean.sh | 17 ++--- executor/clean_ANTLR.sh | 22 ++++++ executor/clean_Java.sh | 22 ++++++ executor/clean_upstream.sh | 22 ++++++ executor/install.sh | 64 ++--------------- executor/install_ANTLR.sh | 40 +++++++++++ executor/install_Java.sh | 50 +++++++++++++ 10 files changed, 216 insertions(+), 95 deletions(-) rename developer/ANTLR/{GQL_standard_2024-07-27.g4 => GQL_2024.g4} (99%) rename developer/ANTLR/{GQL.g4 => GQL_test.g4} (92%) create mode 100755 executor/clean_ANTLR.sh create mode 100755 executor/clean_Java.sh create mode 100755 executor/clean_upstream.sh create mode 100755 executor/install_ANTLR.sh create mode 100755 executor/install_Java.sh diff --git a/developer/ANTLR/GQL_standard_2024-07-27.g4 b/developer/ANTLR/GQL_2024.g4 similarity index 99% rename from developer/ANTLR/GQL_standard_2024-07-27.g4 rename to developer/ANTLR/GQL_2024.g4 index 46e0daf..4a2f4e6 100644 --- a/developer/ANTLR/GQL_standard_2024-07-27.g4 +++ b/developer/ANTLR/GQL_2024.g4 @@ -1,4 +1,4 @@ -grammar GQL; +grammar GQL_2024; options { caseInsensitive = true; } diff --git a/developer/ANTLR/GQL.g4 b/developer/ANTLR/GQL_test.g4 similarity index 92% rename from developer/ANTLR/GQL.g4 rename to developer/ANTLR/GQL_test.g4 index 2e34fad..19cc208 100644 --- a/developer/ANTLR/GQL.g4 +++ b/developer/ANTLR/GQL_test.g4 @@ -1,4 +1,4 @@ -grammar GQL; +grammar GQL_test; root: query+ EOF; diff --git a/developer/makefile b/developer/makefile index 45334b8..a03082d 100644 --- a/developer/makefile +++ b/developer/makefile @@ -1,28 +1,38 @@ -# FL = File List -ISLAND = land island # value has embedded and trailing spaces +# Use `make variable` to print the value assigned to the variable ISLAND. +# Spaces in and after non-white characters are part of the value. +# This includes trailing spaces on the line, and space leading to a comment marker. +# Note the next line has 4 trailing spaces after 'island': +ISLAND = land island -ANTLR_JAR = ../tool/executor/antlr-4.9.2-complete.jar +ANTLR_JAR = ../tool/executor/antlr-4.9.2-complete.jar +JAVA_COMP = $(JAVA_HOME)/bin/javac +JAVA_INTERP = $(JAVA_HOME)/bin/java +JAR = $(JAVA_HOME)/bin/jar +# FL = File List ANTLR_IN_DIR = ANTLR ANTLR_OUT_DIR = javac/antlr -ANTLR_IN_FL = $(wildcard $(ANTLR_IN_DIR)/*.g4) -ANTLR_OUT_FL = $(patsubst %.g4,$(ANTLR_OUT_DIR)/%.java,$(ANTLR_IN_FL)) +ANTLR_IN_FL = $(wildcard $(ANTLR_IN_DIR)/*.g4) +ANTLR_OUT_FL = $(patsubst $(ANTLR_IN_DIR)/%.g4,$(ANTLR_OUT_DIR)/%.java,$(ANTLR_IN_FL)) -JAR = $(JAVA_HOME)/bin/jar -JAVAC = $(JAVA_HOME)/bin/javac JAVA_IN_DIR = javac -JAVA_IN_FL = $(wildcard $(JAVA_IN_DIR)/*.java) $(ANTLR_OUT_FL) JVM_IN_DIR = jvm +JAVA_IN_FL0 = $(wildcard $(JAVA_IN_DIR)/*.java) +JAVA_IN_FL1 = $(ANTLR_OUT_FL) +JAVA_IN_FL = $(JAVA_IN_FL0) $(JAVA_IN_FL1) + +JAVA_OUT_FL0 = $(patsubst $(JAVA_IN_DIR)/%.java,$(JVM_IN_DIR)/%.class,$(JAVA_IN_FL0)) +JAVA_OUT_FL1 = $(patsubst $(ANTLR_OUT_DIR)/%.java,$(JVM_IN_DIR)/%.class,$(JAVA_IN_FL1)) +JAVA_OUT_FL = $(JAVA_OUT_FL0) $(JAVA_OUT_FL1) + # programs we are creating GQL_SYNTAX_TREE = GQL_syntax_tree #... OUT_FL = $(JVM_IN_DIR)/$(GQL_SYNTAX_TREE).jar - - .PHONY: all all: grammar program @@ -35,43 +45,51 @@ grammar: setup $(ANTLR_OUT_FL) .PHONY: variable variable: $(info ISLAND is '$(ISLAND)') - $(info JAVAC is '$(JAVAC)') - $(info JAR is '$(JAR)') $(info ANTLR_JAR is '$(ANTLR_JAR)') - $(info JAVA_IN_DIR is '$(JAVA_IN_DIR)') - $(info JVM_IN_DIR is '$(JVM_IN_DIR)') $(info ANTLR_IN_DIR is '$(ANTLR_IN_DIR)') $(info ANTLR_OUT_DIR is '$(ANTLR_OUT_DIR)') - $(info JAVA_IN_FL is '$(JAVA_IN_FL)') $(info ANTLR_IN_FL is '$(ANTLR_IN_FL)') $(info ANTLR_OUT_FL is '$(ANTLR_OUT_FL)') + $(info JAVA_COMP is '$(JAVA_COMP)') + $(info JAVA_IN_DIR is '$(JAVA_IN_DIR)') + $(info JVM_IN_DIR is '$(JVM_IN_DIR)') + + $(info JAVA_IN_FL0 is '$(JAVA_IN_FL0)') + $(info JAVA_IN_FL1 is '$(JAVA_IN_FL1)') + $(info JAVA_IN_FL is '$(JAVA_IN_FL)') + + $(info JAVA_OUT_FL0 is '$(JAVA_OUT_FL0)') + $(info JAVA_OUT_FL1 is '$(JAVA_OUT_FL1)') + $(info JAVA_OUT_FL is '$(JAVA_OUT_FL)') + $(info JAR is '$(JAR)') .PHONY: version version: - @ $(JAVAC) --version + @ $(JAVA_COMP) --version @ $(JAR) --version $(info ANTLR_JAR is '$(ANTLR_JAR)') @ make -v | head -n 1 .PHONY: setup setup: - mkdir -p $(JAVA_IN_DIR) - mkdir -p $(JVM_IN_DIR) - mkdir -p $(ANTLR_OUT_DIR) + mkdir -p $(ANTLR_IN_DIR) $(ANTLR_OUT_DIR) $(JAVA_IN_DIR) $(JVM_IN_DIR) + mkdir -p deprecated experiment lector temporary test .PHONY: clean clean: rm -rf $(JVM_IN_DIR)/* rm -rf $(ANTLR_OUT_DIR)/*.java -# Compile ANTLR grammars +# recipes $(ANTLR_OUT_DIR)/%.java: $(ANTLR_IN_DIR)/%.g4 - java -jar $(ANTLR_JAR) -Dlanguage=Java -o $(ANTLR_OUT_DIR) $< + $(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -o $(ANTLR_OUT_DIR) $< -# Compile Java sources -$(JVM_IN_DIR)/%.class: $(JAVA_IN_DIR)/gql/%.java $(ANTLR_OUT_FL) - $(JAVAC) -d $(JVM_IN_DIR) -cp $(ANTLR_JAR) $< +$(JAVA_OUT_FL0): $(JVM_IN_DIR)/%.class: $(JAVA_IN_DIR)/%.java + $(JAVA_COMP) -d $(JVM_IN_DIR) -cp $(ANTLR_JAR) $< -# Create jar file -$(JVM_IN_DIR)/$(GQL_SYNTAX_TREE).jar: $(patsubst $(JAVA_IN_DIR)/gql/%.java,$(JVM_IN_DIR)/%.class,$(JAVA_IN_FL)) +$(JAVA_OUT_FL1): $(JVM_IN_DIR)/%.class: $(ANTLR_OUT_DIR)/%.java + $(JAVA_COMP) -d $(JVM_IN_DIR) -cp $(ANTLR_JAR) $< + +$(JVM_IN_DIR)/$(GQL_SYNTAX_TREE).jar: $(JAVA_OUT_FL) $(JAR) cvf $@ -C $(JVM_IN_DIR) . + diff --git a/executor/clean.sh b/executor/clean.sh index d86ecc6..8be044c 100755 --- a/executor/clean.sh +++ b/executor/clean.sh @@ -6,15 +6,16 @@ project_root="${script_path%/*}" # Function to handle errors handle_error() { - echo "Error occurred during cleaning. Exiting." - exit 1 + echo "Error occurred during cleaning. Exiting." + exit 1 } -# Remove the contents of the tool directory while preserving the directory itself and .gitignore -find "$project_root/tool" -mindepth 1 ! -name ".gitignore" -exec rm -rf {} + || handle_error +# Call specific clean scripts +./clean_Java.sh || { echo "Java cleanup failed."; } +./clean_ANTLR.sh || { echo "ANTLR cleanup failed."; } -# Unset environment variables if they are set -[ -n "$JAVA_HOME" ] && unset JAVA_HOME -[ -n "$CLASSPATH" ] && unset CLASSPATH +# Remove the contents of the tool directory while preserving the directory itself and .gitignore +find "$project_root/tool" -mindepth 1 -maxdepth 1 -not -name ".gitignore" -not -name "upstream" -not -type l -exec rm -rf {} + || handle_error +find "$project_root/tool" -maxdepth 1 -type l -exec rm -f {} + || handle_error -echo "Project clean complete. All tools have been removed." +echo 'Tool directory cleanup complete. Run `clean_upstream.sh` to remove cached upstream files.' diff --git a/executor/clean_ANTLR.sh b/executor/clean_ANTLR.sh new file mode 100755 index 0000000..4c77844 --- /dev/null +++ b/executor/clean_ANTLR.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# Get the project root path by removing 'executor' from the script path +script_path="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +project_root="${script_path%/*}" + +# Function to handle errors +handle_error() { + echo "Error occurred during ANTLR cleanup. Exiting." + exit 1 +} + +# Clean the ANTLR directory +antlr_dir="$project_root/tool/upstream/antlr4-*" +if [ -d "$antlr_dir" ]; then + find "$antlr_dir" -mindepth 1 -maxdepth 1 -not -type l -exec rm -rf {} + || handle_error + find "$antlr_dir" -maxdepth 1 -type l -exec rm -f {} + || handle_error +else + echo "ANTLR directory does not exist." +fi + +echo "ANTLR cleanup complete." diff --git a/executor/clean_Java.sh b/executor/clean_Java.sh new file mode 100755 index 0000000..922d3a9 --- /dev/null +++ b/executor/clean_Java.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# Get the project root path by removing 'executor' from the script path +script_path="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +project_root="${script_path%/*}" + +# Function to handle errors +handle_error() { + echo "Error occurred during Java cleanup. Exiting." + exit 1 +} + +# Clean the JDK directory +jdk_dir="$project_root/tool/upstream/jdk-*" +if [ -d "$jdk_dir" ]; then + find "$jdk_dir" -mindepth 1 -maxdepth 1 -not -type l -exec rm -rf {} + || handle_error + find "$jdk_dir" -maxdepth 1 -type l -exec rm -f {} + || handle_error +else + echo "JDK directory does not exist." +fi + +echo "Java cleanup complete." diff --git a/executor/clean_upstream.sh b/executor/clean_upstream.sh new file mode 100755 index 0000000..567cde4 --- /dev/null +++ b/executor/clean_upstream.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# Get the project root path by removing 'executor' from the script path +script_path="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +project_root="${script_path%/*}" + +# Function to handle errors +handle_error() { + echo "Error occurred during upstream cleanup. Exiting." + exit 1 +} + +# Check if the upstream directory exists +if [ -d "$project_root/tool/upstream" ]; then + echo "Cleaning up upstream directory..." + find "$project_root/tool/upstream" -mindepth 1 -maxdepth 1 -not -type l -exec rm -rf {} + || handle_error + find "$project_root/tool/upstream" -maxdepth 1 -type l -exec rm -f {} + || handle_error +else + echo "Upstream directory does not exist." +fi + +echo "Upstream cleanup complete." diff --git a/executor/install.sh b/executor/install.sh index 8267eff..5a4e453 100755 --- a/executor/install.sh +++ b/executor/install.sh @@ -1,67 +1,13 @@ #!/usr/bin/env bash -# Exit on first error -set -e +# Call install scripts and handle errors +./install_Java.sh || { echo "Java installation failed. "; } +./install_ANTLR.sh || { echo "ANTLR installation failed."; exit 1; } -# Set the platform type: currently "Debian" or "Fedora" -PLATFORM="Fedora" - -# Define the versions and URLs for the JDK and ANTLR -JDK_VERSION="17.0.2" -JDK_URL="https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2+8/OpenJDK17U-jdk_x64_linux_hotspot_17.0.2_8.tar.gz" -ANTLR_VERSION="4.9.2" -ANTLR_URL="https://www.antlr.org/download/antlr-$ANTLR_VERSION-complete.jar" - -# Get the project root path by removing 'executor' from the script path +# Create symbolic link script_path="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" project_root="${script_path%/*}" -# Create the tool/executor directory if it doesn't exist -mkdir -p "$project_root/tool/executor" - -# Create a symbolic link tool/bin pointing to tool/executor ln -sfn "$project_root/tool/executor" "$project_root/tool/bin" -# Function to handle errors -handle_error() { - echo "Error occurred during installation. Exiting." - exit 1 -} - -# Download and extract JDK to the tool directory -curl -L -o "$project_root/tool/jdk-$JDK_VERSION.tar.gz" "$JDK_URL" || handle_error - -# Check if the download was successful -if [ ! -s "$project_root/tool/jdk-$JDK_VERSION.tar.gz" ]; then - echo "JDK download failed. Exiting." - exit 1 -fi - -tar -xzf "$project_root/tool/jdk-$JDK_VERSION.tar.gz" -C "$project_root/tool" || handle_error -rm "$project_root/tool/jdk-$JDK_VERSION.tar.gz" - -# Find the extracted JDK directory -jdk_dir=$(find "$project_root/tool" -maxdepth 1 -type d -name "jdk-*" | head -n 1) -if [ -z "$jdk_dir" ]; then - echo "JDK extraction failed. Exiting." - exit 1 -fi - -# Set JAVA_HOME and update PATH to use the local JDK -export JAVA_HOME="$jdk_dir" -export PATH="$JAVA_HOME/bin:$project_root/tool/executor:$PATH" - -# Download ANTLR jar file and place it in the tool/executor directory -curl -o "$project_root/tool/executor/antlr-$ANTLR_VERSION-complete.jar" "$ANTLR_URL" || handle_error - -# Check if the download was successful -if [ ! -s "$project_root/tool/executor/antlr-$ANTLR_VERSION-complete.jar" ]; then - echo "ANTLR download failed. Exiting." - exit 1 -fi - -# Set environment variables for ANTLR -export CLASSPATH=".:$project_root/tool/executor/antlr-$ANTLR_VERSION-complete.jar:$CLASSPATH" -export PATH="$PATH:$project_root/tool/executor" - -echo "Installation complete. Java and ANTLR have been installed successfully." +echo "All installations complete. Java and ANTLR have been installed successfully." diff --git a/executor/install_ANTLR.sh b/executor/install_ANTLR.sh new file mode 100755 index 0000000..6d899ba --- /dev/null +++ b/executor/install_ANTLR.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# Define the version and URL for ANTLR +ANTLR_VERSION="4.11.1" +ANTLR_URL="https://github.com/antlr/antlr4/archive/refs/tags/4.11.1.tar.gz" + +# Get the project root path by removing 'executor' from the script path +script_path="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +project_root="${script_path%/*}" + +# Create the upstream directory if it doesn't exist +mkdir -p "$project_root/tool/upstream" + +# Download ANTLR tarball and extract to the upstream directory +antlr_tar="$project_root/tool/upstream/antlr-$ANTLR_VERSION.tar.gz" +if [ ! -f "$antlr_tar" ]; then + echo "Downloading ANTLR..." + curl -L -o "$antlr_tar" "$ANTLR_URL" +fi + +if [ ! -s "$antlr_tar" ]; then + echo "ANTLR download failed. Exiting." + exit 1 +fi + +echo "Extracting ANTLR..." +tar -xzf "$antlr_tar" -C "$project_root/tool/upstream" || { echo "ANTLR extraction failed. Exiting."; exit 1; } +rm "$antlr_tar" + +# Move the ANTLR jar to the executor directory +antlr_jar="$project_root/tool/upstream/antlr-$ANTLR_VERSION-complete.jar" +if [ ! -f "$antlr_jar" ]; then + echo "ANTLR JAR file not found after extraction. Exiting." + exit 1 +fi + +mkdir -p "$project_root/tool/executor" +mv "$antlr_jar" "$project_root/tool/executor/" + +echo "ANTLR installation complete." diff --git a/executor/install_Java.sh b/executor/install_Java.sh new file mode 100755 index 0000000..7f8dc48 --- /dev/null +++ b/executor/install_Java.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Set the platform type: currently "Debian" or "Fedora" +PLATFORM="Fedora" + +# Define the version and URL for the JDK +JDK_VERSION="22.0.1" +JDK_URL="https://github.com/adoptium/temurin22-binaries/releases/download/jdk-22.0.1%2B8/OpenJDK22U-jdk_x64_linux_hotspot_22.0.1_8.tar.gz" + +# Get the project root path by removing 'executor' from the script path +script_path="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +project_root="${script_path%/*}" + +# Create the upstream directory if it doesn't exist +mkdir -p "$project_root/tool/upstream" + +# Download and extract JDK to the upstream directory +jdk_tar="$project_root/tool/upstream/jdk-$JDK_VERSION.tar.gz" +if [ ! -f "$jdk_tar" ]; then + echo "Downloading JDK..." + curl -L -o "$jdk_tar" "$JDK_URL" +fi + +if [ ! -s "$jdk_tar" ]; then + echo "JDK download failed. Exiting." + exit 1 +fi + +echo "Extracting JDK..." +tar -xzf "$jdk_tar" -C "$project_root/tool/upstream" || { echo "JDK extraction failed. Exiting."; exit 1; } +rm "$jdk_tar" + +# Find the extracted JDK directory +jdk_dir=$(find "$project_root/tool/upstream" -maxdepth 1 -type d -name "jdk-*" | head -n 1) +if [ -z "$jdk_dir" ]; then + echo "JDK extraction failed. Exiting." + exit 1 +fi + +# Set JAVA_HOME and update PATH to use the local JDK +export JAVA_HOME="$jdk_dir" +export PATH="$JAVA_HOME/bin:$PATH" + +# Test Java installation +if ! java -version > /dev/null 2>&1; then + echo "Java version check failed." + exit 1 +fi + +echo "Java installation complete." -- 2.20.1