Skip to content

Commit

Permalink
[Feature:Autograding] tree-sitter c-api (#2)
Browse files Browse the repository at this point in the history
* Initial C-API

* Update readme

* Initial class implementation

* Add function call counting

* Refactor header

* Add c counting

* Fix function counting

* Fix requested changes

* Update source sh scripts

* Add cpp shell static checks

* Add function counting

* File glob handling and format

* Update cmakelists

* Fix function changes

* Update actions

* Remove test.yml

* Initial diagnostics

* Refactor diagnostics

* Add nlohmann json

* Fix shell-check

* Format json output

* Add fixes

* Add identifier counting

* Add c++

* Update counting

* Add tests for executable

* Update test.yml

* check

* Fix file name

* Switch user

* Change to sudo

* FIx format

* Spaces for tabs
  • Loading branch information
poorna2152 authored Aug 2, 2022
1 parent 046c660 commit a04e1a5
Show file tree
Hide file tree
Showing 46 changed files with 667 additions and 10,891 deletions.
59 changes: 0 additions & 59 deletions .eslintrc.json

This file was deleted.

Empty file modified .gitattributes
100644 → 100755
Empty file.
Empty file modified .github/PULL_REQUEST_TEMPLATE.md
100644 → 100755
Empty file.
Empty file modified .github/workflows/pr_title.yml
100644 → 100755
Empty file.
24 changes: 24 additions & 0 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Static analysis
on: [push]

jobs:
cppcheck:
name: Cppcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: install cpp-check
run: sudo apt-get install -y cppcheck
- name: run cpp-check
run: cppcheck src/

shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: install shellcheck
run: sudo apt-get install -y shellcheck
- name: run shell-check
run: shellcheck *.sh -e SC1090

35 changes: 10 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
name: Test

on: ['push', 'pull_request']
on: [push]

jobs:
build:
test:
name: Test
runs-on: ubuntu-latest

strategy:
matrix:
# Disable 17.x for now, see https://github.com/tree-sitter/node-tree-sitter/issues/102
node-version: [16.x]

steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: npm

- run: npm install

- run: npm run lint

- run: npm run build

- run: npm run test

- uses: codecov/codecov-action@v2
- uses: actions/checkout@v2
- name: Change permission
run: chmod +x install_analysistoolsts.sh
- name: Build executable
run: sudo ./install_analysistoolsts.sh local
- name: run tests
run: python testRunner.py
11 changes: 2 additions & 9 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
node_modules/
.DS_Store

# build artifacts
dist/

# test artifacts
.nyc_output/
coverage/
include/
build/
5 changes: 0 additions & 5 deletions .husky/pre-commit

This file was deleted.

9 changes: 0 additions & 9 deletions .prettierrc.json

This file was deleted.

29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.16.3)

project(analysis_tools_ts)

set(JSONCODE include/json/include/)

if(JSONDIR)
set(JSONCODE ${JSONDIR})
endif()

add_library(tree-sitter-python include/tree-sitter-python/src/parser.c
include/tree-sitter-python/src/scanner.cc)

add_library(tree-sitter-cpp include/tree-sitter-cpp/src/parser.c
include/tree-sitter-cpp/src/scanner.cc)

add_library(tree-sitter-c include/tree-sitter-c/src/parser.c)

link_libraries(tree-sitter-python tree-sitter-c tree-sitter-cpp
${PROJECT_SOURCE_DIR}/include/tree-sitter/libtree-sitter.a)

add_executable(submitty_count_ts src/count.cpp src/parser.cpp src/utils.cpp)

add_executable(submitty_diagnostics_ts src/diagnostics.cpp src/parser.cpp
src/utils.cpp)

include_directories(include/tree-sitter/lib/include)

target_include_directories(submitty_diagnostics_ts PUBLIC ${JSONCODE})
Empty file modified LICENSE.md
100644 → 100755
Empty file.
10 changes: 7 additions & 3 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ This is intended to be a successor to the `count` and `diagnostics` applications
To work with this repo, you will need [Node.js](https://nodejs.org/).

```bash
git clone https://github.com/Submitty/tree-analyzer
cd tree-analyzer
npm install
git clone https://github.com/Submitty/AnalysisToolsTS
cd AnalysisToolsTS
```

To run locally setup with command
```
./install_analysistoolsts.sh local
```
94 changes: 94 additions & 0 deletions install_analysistoolsts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env bash

########################################################################################################################
########################################################################################################################
# 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"
exit 1
fi

VARS="$(dirname "$0")"/submitty.sh

if [ $# -gt 0 ] && [ "$1" == "local" ]; then
VARS="$(dirname "$0")"/local.sh
fi

source "${VARS}"

echo -e "Installing AnalysisToolsTS... "

mkdir -p "${INSTALLATION_DIR}"

# Copy cloned files to AnalysisToolsTS directory
rsync -rtz "${REPO_DIR}" "${INSTALLATION_DIR}"

mkdir -p "${INCLUDE_DIR}"

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

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

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

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

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

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

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

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 || exit

make

popd || exit

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" || exit

make

popd || exit

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

echo "Done setting up AnalysisToolsTS"
7 changes: 7 additions & 0 deletions local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
REPO_DIR=$(pwd)
export REPO_DIR=.
export INSTALLATION_DIR=.
export INCLUDE_DIR=include
export NLOHMANN_DIR=include/json
export NLOHMANN_INCLUDE_DIR=include/json/include/
Loading

0 comments on commit a04e1a5

Please sign in to comment.