diff --git a/.github/workflows/build_binary.yml b/.github/workflows/build_binary.yml deleted file mode 100644 index 6fcbe85..0000000 --- a/.github/workflows/build_binary.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Build binaries on release - -on: - push: - tags: - - '*' - -jobs: - build: - name: build - runs-on: ubuntu-latest - strategy: - matrix: - arch: [x86_64, aarch64] - defaults: - run: - shell: bash - steps: - - uses: actions/checkout@v2 - - name: Install dependencies (aarch64) - if: matrix.arch == 'aarch64' - run: sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu - - name: Set CC / CXX (aarch64) - if: matrix.arch == 'aarch64' - run: | - echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV - echo "CXX=aarch64-linux-gnu-g++" >> $GITHUB_ENV - - name: Build executable - run: bash build.sh - - name: Duplicate executables (x86_64) - if: matrix.arch == 'x86_64' - run: | - cp build/submitty_count_ts build/submitty_count_ts-x86_64 - cp build/submitty_diagnostics_ts build/submitty_diagnostics_ts-x86_64 - - name: Move executables (aarch64) - if: matrix.arch == 'aarch64' - run: | - mv build/submitty_count_ts build/submitty_count_ts-aarch64 - mv build/submitty_diagnostics_ts build/submitty_diagnostics_ts-aarch64 - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: executables - path: build/submitty_* - - name: Release - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - with: - files: build/submitty_* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9eb2e7e..ee86a9d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8684544..711c826 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 +) \ No newline at end of file diff --git a/build.sh b/build.sh deleted file mode 100755 index 490ba68..0000000 --- a/build.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env bash - -set -e - -echo "Building AnalysisToolsTS... " - -CUR_DIR=$(dirname "${0}") -BUILD_DIR=${CUR_DIR}/build -INCLUDE_DIR=${CUR_DIR}/include - -mkdir -p "${BUILD_DIR}" -mkdir -p "${INCLUDE_DIR}" - -######################################################################## -# These variables specify the minimum version necessary for -# dependencies between versions. -source "${CUR_DIR}"/versions.sh - -######################################################################## -# 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}... " - LOCKED_BRANCH="${repo//-/_}"_hash - cd "${CUR_DIR}" - if [ -d "${dir}" ]; then - echo "pulling changes ..." - # IF THE REPO ALREADY EXISTS... - pushd "${dir}" - - # PULL CHANGES - git fetch - git reset --hard "${!LOCKED_BRANCH}" - - popd - else - # THE REPO DID NOT EXIST - echo "the repository did not previously exist cloning... " - git clone "https://github.com/tree-sitter/${repo}" "${INCLUDE_DIR}/${repo}" - pushd "${dir}" - git reset --hard "${!LOCKED_BRANCH}" - popd - fi -done - -# CHECKOUT & INSTALL THE NLOHMANN C++ JSON LIBRARY -echo "clone or update nlohmann" -if [ -d "${INCLUDE_DIR}/json" ]; then - echo "pulling changes ..." - pushd "${INCLUDE_DIR}/json" - - CURRENT_BRANCH=$(git branch --show-current) - git fetch - git reset --hard HEAD - git merge "origin/${CURRENT_BRANCH}" - popd -else - git clone --depth 1 "https://github.com/nlohmann/json.git" "${INCLUDE_DIR}/json" -fi - - -######################################################################## - -# build tree sitter library -pushd "${INCLUDE_DIR}/tree-sitter" -make -popd - -echo "building submitty_count_ts ..." - -# Compile the project -cmake -S "${CUR_DIR}" -B "${BUILD_DIR}" -DJSONDIR="${INCLUDE_DIR}/json/include" - -pushd "${BUILD_DIR}" -make -popd - -echo "Done building AnalysisToolsTS" diff --git a/install_analysistoolsts.sh b/install_analysistoolsts.sh index e07c582..fbcce45 100755 --- a/install_analysistoolsts.sh +++ b/install_analysistoolsts.sh @@ -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 @@ -19,7 +16,6 @@ fi source "${VARS}" echo -e "Installing AnalysisToolsTS... " - mkdir -p "${INSTALLATION_DIR}" # Copy cloned files to AnalysisToolsTS directory @@ -27,77 +23,12 @@ 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}"