Skip to content
Open
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
49 changes: 0 additions & 49 deletions .github/workflows/build_binary.yml

This file was deleted.

6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build executable
run: bash ./build.sh
run: |
cmake -S . -B build
cmake --build build --parallel "$(nproc)"
- name: install dev dependencies
run: python3 -m pip install -r requirements_dev.txt
run: python3 -m pip install -r requirements_dev.txt --break-system-packages
- name: run tests
run: pytest
113 changes: 95 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,109 @@
cmake_minimum_required(VERSION 3.16.3)
set (CMAKE_CXX_STANDARD 14)
project(analysis_tools_ts C CXX)

project(analysis_tools_ts)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(JSONCODE include/json/include/)
include(FetchContent)

if(JSONDIR)
set(JSONCODE ${JSONDIR})
FetchContent_Declare(
tree-sitter
GIT_REPOSITORY https://github.com/tree-sitter/tree-sitter.git
GIT_TAG 0535b0ca378a3f13a2b469f6c090a0c1b90904b7
GIT_SHALLOW TRUE
)

FetchContent_GetProperties(tree-sitter)
if(NOT tree-sitter_POPULATED)
FetchContent_Populate(tree-sitter)

# Build the core library from the fetched source
add_library(tree-sitter STATIC ${tree-sitter_SOURCE_DIR}/lib/src/lib.c)
target_include_directories(tree-sitter PUBLIC ${tree-sitter_SOURCE_DIR}/lib/include)
endif()

add_library(tree-sitter-python include/tree-sitter-python/src/parser.c
include/tree-sitter-python/src/scanner.c)
function(fetch_and_build_ts_parser PARSER_NAME GIT_URL GIT_COMMIT)
FetchContent_Declare(
${PARSER_NAME}
GIT_REPOSITORY ${GIT_URL}
GIT_TAG ${GIT_COMMIT}
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(${PARSER_NAME})
if(NOT ${PARSER_NAME}_POPULATED)
FetchContent_Populate(${PARSER_NAME})

# Collect sources
set(SOURCES ${${PARSER_NAME}_SOURCE_DIR}/src/parser.c)
if(EXISTS ${${PARSER_NAME}_SOURCE_DIR}/src/scanner.c)
list(APPEND SOURCES ${${PARSER_NAME}_SOURCE_DIR}/src/scanner.c)
elseif(EXISTS ${${PARSER_NAME}_SOURCE_DIR}/src/scanner.cc)
list(APPEND SOURCES ${${PARSER_NAME}_SOURCE_DIR}/src/scanner.cc)
endif()

add_library(${PARSER_NAME} STATIC ${SOURCES})
target_include_directories(${PARSER_NAME} PRIVATE ${${PARSER_NAME}_SOURCE_DIR}/src)
target_link_libraries(${PARSER_NAME} PRIVATE tree-sitter)
endif()
endfunction()

# Fetch each language. Uses the latest commit as of 03-29-2026

add_library(tree-sitter-cpp include/tree-sitter-cpp/src/parser.c
include/tree-sitter-cpp/src/scanner.c)
fetch_and_build_ts_parser(
tree-sitter-python
https://github.com/tree-sitter/tree-sitter-python.git
26855eabccb19c6abf499fbc5b8dc7cc9ab8bc64
)

add_library(tree-sitter-c include/tree-sitter-c/src/parser.c)
fetch_and_build_ts_parser(
tree-sitter-c
https://github.com/tree-sitter/tree-sitter-c.git
ae19b676b13bdcc13b7665397e6d9b14975473dd
)

add_library(tree-sitter-java include/tree-sitter-java/src/parser.c)
fetch_and_build_ts_parser(
tree-sitter-cpp
https://github.com/tree-sitter/tree-sitter-cpp.git
8b5b49eb196bec7040441bee33b2c9a4838d696
)

link_libraries(tree-sitter-python tree-sitter-c tree-sitter-cpp tree-sitter-java
${PROJECT_SOURCE_DIR}/include/tree-sitter/libtree-sitter.a)
fetch_and_build_ts_parser(
tree-sitter-java
https://github.com/tree-sitter/tree-sitter-java.git
e10607b45ff745f5f876bfa3e94fbcc6b44bdc11
)

add_executable(submitty_count_ts src/count.cpp src/parser.cpp src/utils.cpp)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG 9a737481aed085fd289f82dff1fa8c3c66627a7e
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(nlohmann_json)

add_executable(submitty_diagnostics_ts src/diagnostics.cpp src/parser.cpp
src/utils.cpp)
set(COMMON_LIBS
tree-sitter
tree-sitter-python
tree-sitter-c
tree-sitter-cpp
tree-sitter-java
)

include_directories(include/tree-sitter/lib/include)
# Submitty Count
add_executable(submitty_count_ts
src/count.cpp
src/parser.cpp
src/utils.cpp
)
target_link_libraries(submitty_count_ts PRIVATE ${COMMON_LIBS})

target_include_directories(submitty_diagnostics_ts PUBLIC ${JSONCODE})
# Submitty Diagnostics
add_executable(submitty_diagnostics_ts
src/diagnostics.cpp
src/parser.cpp
src/utils.cpp
)
target_link_libraries(submitty_diagnostics_ts PRIVATE
${COMMON_LIBS}
nlohmann_json::nlohmann_json
)
82 changes: 0 additions & 82 deletions build.sh

This file was deleted.

79 changes: 5 additions & 74 deletions install_analysistoolsts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

set -e

########################################################################################################################
########################################################################################################################
# this script must be run by root or sudo
if [[ "$UID" -ne "0" ]] ; then
echo "ERROR: This script must be run by root or sudo"
echo "ERROR: This script must be run as root"
exit 1
fi

Expand All @@ -19,85 +16,19 @@ fi
source "${VARS}"

echo -e "Installing AnalysisToolsTS... "

mkdir -p "${INSTALLATION_DIR}"

# Copy cloned files to AnalysisToolsTS directory
if [ $# -eq 0 ]; then
rsync -rtz "${REPO_DIR}/src" "${REPO_DIR}/CMakeLists.txt" "${INSTALLATION_DIR}"
fi

mkdir -p "${INCLUDE_DIR}"

########################################################################

# Clone the tree-sitter repos
repos=( tree-sitter tree-sitter-python tree-sitter-c tree-sitter-cpp tree-sitter-java)

for repo in "${repos[@]}"
do
dir="${INCLUDE_DIR}"/"${repo}"

echo "clone or update ${repo}... "

# TEMPORARY - workaround due to problem with the git repository
# just delete the directory and start over
echo "removing ${dir}"
rm -rf "${dir}"
# TEMPORARY

if [ -d "${dir}" ]; then
echo "pulling changes ..."
# IF THE REPO ALREADY EXISTS...
pushd "${dir}"

CURRENT_BRANCH=$(git branch --show-current)

# PULL CHANGES
git fetch
git reset --hard HEAD
git merge origin/"${CURRENT_BRANCH}"
popd

else
# THE REPO DID NOT EXIST
echo "the repository did not previously exist cloning... "
pushd "${INCLUDE_DIR}"
git clone --depth 1 "https://github.com/tree-sitter/${repo}"
popd

fi
done

# CHECKOUT & INSTALL THE NLOHMANN C++ JSON LIBRARY
# If we don't already have a copy of this repository, check it out, only for local development
if [ $# -gt 0 ] && [ ! -d "${NLOHMANN_DIR}" ]; then
git clone --depth 1 "https://github.com/nlohmann/json.git" "${NLOHMANN_DIR}"
fi

########################################################################

# build tree sitter library
pushd "${INCLUDE_DIR}"/tree-sitter

make

popd

echo "building submitty_count_ts ..."

# Compile the project
mkdir -p "${INSTALLATION_DIR}/build"

cmake -S "${INSTALLATION_DIR}" -B "${INSTALLATION_DIR}/build" -DJSONDIR="${NLOHMANN_INCLUDE_DIR}"

pushd "${INSTALLATION_DIR}/build"

make
BUILD_DIR="${INSTALLATION_DIR}/build"
mkdir -p "${BUILD_DIR}"

popd
cmake -S "${INSTALLATION_DIR}" -B "${BUILD_DIR}"
cmake --build "${BUILD_DIR}" --parallel "$(nproc)"

# # change permissions
if [ $# -eq 0 ]; then
chown -R root:root "${INSTALLATION_DIR}"
chmod -R 755 "${INSTALLATION_DIR}"
Expand Down
Loading