diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index f824235..687a0e8 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -15,90 +15,112 @@ jobs: test: name: "Tests" strategy: + fail-fast: false matrix: include: - name: "Linux GCC" os: ubuntu-latest - cc: gcc - cxx: g++ + compiler: gcc test: true - cmake: cmake - name: "Linux Clang" os: ubuntu-latest - cc: clang - cxx: clang++ + compiler: llvm test: true - cmake: cmake - - name: "Linux emscripten" - os: ubuntu-latest - cc: emcc - cxx: "em++" - test: false - cmake: "emcmake cmake" - - - name: "MacOS GCC" + - name: "MacOS clang" os: macos-latest - cc: /usr/local/opt/gcc/bin/gcc-11 - cxx: /usr/local/opt/gcc/bin/g++-11 test: true - cmake: cmake + compiler: llvm - #- name: "Windows MSVC" - #os: windows-latest - #cc: cl - #cxx: cl - #test: false - #cmake: cmake + - name: "Windows" + os: windows-latest + compiler: cl + + - name: "WebAssembly" + os: ubuntu-latest + emscripten: true runs-on: ${{ matrix.os }} steps: - name: "Checkout repository" uses: actions/checkout@v2 - - name: "Enable MSVC command prompt" - if: matrix.os == 'windows-latest' - uses: ilammy/msvc-dev-cmd@v1 + - name: "Setup Cpp" + uses: aminya/setup-cpp@v1 + with: + compiler: ${{ matrix.compiler }} + vcvarsall: ${{ contains(matrix.os, 'windows' )}} + cmake: true + ninja: true + clangtidy: false + cppcheck: false + gcovr: "5.0" + opencppcoverage: false - - name: "Install cmake" - uses: lukka/get-cmake@latest + - name: "Setup Java" + uses: actions/setup-java@v3 + with: + distribution: "temurin" + java-version: '17' + check-latest: true - name: "Install Linux Dependencies" - if: runner.os == 'Linux' + if: ${{ runner.os == 'Linux' }} run: sudo apt install libboost-graph-dev uuid-dev - name: "Install boost for windows" - if: runner.os == 'Windows' + if: ${{ runner.os == 'Windows' }} uses: MarkusJx/install-boost@v1.0.1 with: boost_version: 1.73.0 - name: "Install dependencies for macOS" - if: runner.os == 'macOS' + if: ${{ runner.os == 'macOS' }} run: | brew install gcc brew install boost - name: "Setup Emscripten" - if: ${{ matrix.cc == 'emcc' }} + if: ${{ matrix.emscripten }} uses: mymindstorm/setup-emsdk@v7 - - name: "Build debug mode" + - name: "Configure emscripten" + if: ${{ matrix.emscripten }} run: > - mkdir build; - cd build; - ${{ matrix.cmake }} .. - -DCMAKE_BUILD_TYPE=Debug - -DCMAKE_C_COMPILER=${{ matrix.cc }} - -DCMAKE_CXX_COMPILER=${{ matrix.cxx }}; - cmake --build . --config Release + emcmake cmake -S . + -B ./build + -DCMAKE_BUILD_TYPE:STRING=Debug + -DDIAGON_BUILD_TESTS:BOOL=OFF + -DDIAGON_BUILD_TESTS_FUZZER:BOOL=OFF; + + - name: "Configure build only" + if: ${{ !matrix.emscripten && !matrix.test}} + run: > + cmake -S . + -B ./build + -DCMAKE_BUILD_TYPE:STRING=Debug + -DDIAGON_BUILD_TESTS:BOOL=OFF + -DDIAGON_BUILD_TESTS_FUZZER:BOOL=OFF; + + - name: "Configure buil and tests" + if: ${{ !matrix.emscripten && matrix.test}} + run: > + cmake -S . + -B ./build + -DCMAKE_BUILD_TYPE:STRING=Debug + -DDIAGON_BUILD_TESTS:BOOL=ON + -DDIAGON_BUILD_TESTS_FUZZER:BOOL=OFF; + + - name: "Build" + run: > + cmake --build ./build; - name: "Run tests" - if: matrix.test + if: ${{ matrix.test}} run: > cd build; - ./input_output_test + ./input_output_test; # Create a release on new v* tags release: @@ -126,81 +148,102 @@ jobs: include: - name: "Linux Clang" os: ubuntu-latest - cc: clang - cxx: clang++ - cmake: cmake + compiler: llvm asset_path: build/diagon*Linux* - - name: "Linux emscripten" + - name: "WebAssembly" os: ubuntu-latest - cc: emcc - cxx: em++ - cmake: "emcmake cmake" + emscripten: true asset_path: build/diagon-Web.zip - #- name: "MacOS clang" - #os: macos-latest - #cc: clang - #cxx: clang++ - #test: true - #cmake: cmake - #asset_path: build/diagon*Darwin* - - #- name: "Windows MSVC" - #os: windows-latest - #cc: cl - #cxx: cl - #test: false - #cmake: cmake - #asset_path: build/diagon*Win64* + - name: "MacOS" + os: macos-latest + compiler: llvm + asset_path: build/ftxui*Darwin* + + - name: "Windows" + os: windows-latest + compiler: cl + asset_path: build/ftxui*Win64* runs-on: ${{ matrix.os }} steps: - name: "Checkout repository" uses: actions/checkout@v2 - - name: "Enable MSVC command prompt" - if: matrix.os == 'windows-latest' - uses: ilammy/msvc-dev-cmd@v1 + - name: "Setup Cpp" + uses: aminya/setup-cpp@v1 + with: + compiler: ${{ matrix.compiler }} + vcvarsall: ${{ contains(matrix.os, 'windows' )}} + cmake: true + ninja: true + clangtidy: false + cppcheck: false + gcovr: "5.0" + opencppcoverage: false - - name: "Install cmake" - uses: lukka/get-cmake@latest + - name: "Setup Java" + uses: actions/setup-java@v3 + with: + distribution: "temurin" + java-version: '17' + check-latest: true - name: "Install Linux Dependencies" - if: runner.os == 'Linux' - run: sudo apt install libboost-graph-dev uuid-dev zip + if: ${{ runner.os == 'Linux' }} + run: sudo apt install libboost-graph-dev uuid-dev - name: "Install boost for windows" - if: runner.os == 'Windows' + if: ${{ runner.os == 'Windows' }} uses: MarkusJx/install-boost@v1.0.1 with: boost_version: 1.73.0 + - name: "Install dependencies for macOS" + if: ${{ runner.os == 'macOS' }} + run: | + brew install gcc + brew install boost + - name: "Setup Emscripten" - if: ${{ matrix.cc == 'emcc' }} + if: ${{ matrix.emscripten }} uses: mymindstorm/setup-emsdk@v7 - - name: "Build release mode" + - name: "Configure cmake with emscripten" + if: ${{ matrix.emscripten }} run: > - mkdir build; - cd build; - ${{ matrix.cmake }} .. - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_C_COMPILER=${{ matrix.cc }} - -DCMAKE_CXX_COMPILER=${{ matrix.cxx }}; - cmake --build . --config Release; - make package; + emcmake cmake -S . + -B ./build + -DCMAKE_BUILD_TYPE:STRING=Release + -DDIAGON_BUILD_TESTS:BOOL=OFF + -DDIAGON_BUILD_TESTS_FUZZER:BOOL=OFF; + + - name: "Configure CMake" + if: ${{ !matrix.emscripten }} + run: > + cmake -S . + -B ./build + -DCMAKE_BUILD_TYPE:STRING=Release + -DDIAGON_BUILD_TESTS:BOOL=OFF + -DDIAGON_BUILD_TESTS_FUZZER:BOOL=OFF; + + - name: "Build" + run: > + cmake + --build ./build + --target package; - name: "Upload native binaries" uses: shogo82148/actions-upload-release-asset@v1 - if: ${{ matrix.cc != 'emcc'}} + if: ${{ !matrix.emscripten }} with: upload_url: ${{ needs.release.outputs.upload_url }} asset_path: ${{ matrix.asset_path }} overwrite: true - name: "Make webAssembly distribution" - if: ${{ matrix.cc == 'emcc' }} + if: ${{ matrix.emscripten }} run: > cd build; mkdir -p diagon-Web; @@ -213,7 +256,7 @@ jobs: zip -r diagon-Web.zip diagon-Web; - name: "Upload WebAssembly distribution" - if: ${{ matrix.cc == 'emcc' }} + if: ${{ matrix.emscripten }} uses: shogo82148/actions-upload-release-asset@v1 with: upload_url: ${{ needs.release.outputs.upload_url }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 565b124..0000000 --- a/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ -sudo: false - -language: - - cpp - -script: - - mkdir build - - cd build - - cmake .. - - cmake --build . - -notifications: - email: false - -addons: - apt: - sources: - - sourceline: "deb http://archive.ubuntu.com/ubuntu/ xenial multiverse" - - sourceline: "deb http://archive.ubuntu.com/ubuntu/ xenial-backports universe" - packages: - - libboost-graph-dev - -jobs: - include: - # Ubuntu - - os: linux - dist: bionic - compiler: gcc - - # Ubuntu - - os: linux - dist: bionic - compiler: clang - - # OS X - - os: osx - - # Windows - - os: windows diff --git a/CMakeLists.txt b/CMakeLists.txt index 3130487..208f4dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,12 @@ cmake_minimum_required (VERSION 3.11) +set(git_version 139) project(Diagon LANGUAGES C CXX - VERSION 1.0.127 + VERSION 1.0.${git_version} ) +option(DIAGON_BUILD_TESTS "Set to ON to build tests" OFF) option(DIAGON_BUILD_TESTS_FUZZER "Set to ON to enable fuzzing" OFF) include(FetchContent) @@ -28,7 +30,7 @@ endif() FetchContent_Declare(antlr GIT_REPOSITORY https://github.com/antlr/antlr4 - GIT_TAG 4.8 + GIT_TAG 4.11.1 GIT_PROGRESS TRUE ) @@ -79,8 +81,6 @@ set(test_directory ${CMAKE_CURRENT_SOURCE_DIR}/test) include_directories(${CMAKE_CURRENT_BINARY_DIR}/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) -set(test_directory ${CMAKE_CURRENT_SOURCE_DIR}/test) - #------------------------------------------------------------------------------- # Environment variable available in C++ source #------------------------------------------------------------------------------- @@ -178,10 +178,6 @@ if (EMSCRIPTEN) else() install(TARGETS diagon RUNTIME DESTINATION "bin") - - add_executable(input_output_test src/input_output_test.cpp) - target_link_libraries(input_output_test diagon_lib) - target_set_common(input_output_test) endif() if (UNIX AND NOT APPLE) @@ -215,6 +211,10 @@ set(CPACK_RPM_PACKAGE_LICENSE MIT) include(CPack) +if (DIAGON_BUILD_TESTS) + include(cmake/diagon_test.cmake) +endif() + if (DIAGON_BUILD_TESTS_FUZZER) include(cmake/diagon_fuzzer.cmake) endif() diff --git a/cmake/diagon_test.cmake b/cmake/diagon_test.cmake new file mode 100644 index 0000000..b87a329 --- /dev/null +++ b/cmake/diagon_test.cmake @@ -0,0 +1,3 @@ +add_executable(input_output_test src/input_output_test.cpp) +target_link_libraries(input_output_test diagon_lib) +target_set_common(input_output_test) diff --git a/src/api.cpp b/src/api.cpp index ef40f6c..5de97a3 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -20,6 +20,8 @@ std::string API(const Translator::Widget& type) { case Translator::Widget::Checkbox: return "checkbox"; } + // NOTREACHED + return "combobox"; } json API(const Translator::OptionDescription& option) { diff --git a/src/translator/flowchart/Flowchart.cpp b/src/translator/flowchart/Flowchart.cpp index 3313eb8..7b9c98c 100644 --- a/src/translator/flowchart/Flowchart.cpp +++ b/src/translator/flowchart/Flowchart.cpp @@ -282,7 +282,7 @@ std::vector Split(std::wstring_view str, std::vector Broke(std::wstring_view content, int size) { std::vector words = Split(content, L" "); std::vector lines; - int last_line_size = 0; + size_t last_line_size = 0; for (auto& word : words) { if (last_line_size == 0 && word.size() >= size) { lines.push_back(word); @@ -295,9 +295,10 @@ std::vector Broke(std::wstring_view content, int size) { lines.push_back(word); last_line_size = word.size(); } else { - int size = std::distance(lines.back().begin(), word.end()); - auto concat = std::wstring_view(lines.back().begin(), size); - lines.back() = concat; + std::wstring_view last_line = lines.back(); + size_t size = std::distance(last_line.begin(), word.end()); + std::wstring_view new_last_line(&last_line[0], size); + lines.back() = new_last_line; last_line_size = size; } continue; @@ -446,26 +447,26 @@ Draw Boxed(std::string content, bool is_final) { return draw; } -Draw Text(std::string content, bool is_final) { - Draw draw; - draw.screen.Resize(content.size() + 5, 3); - draw.screen.DrawText(2, 1, to_wstring(content)); +//Draw Text(std::string content, bool is_final) { + //Draw draw; + //draw.screen.Resize(content.size() + 5, 3); + //draw.screen.DrawText(2, 1, to_wstring(content)); - draw.up.x = draw.screen.width() / 2; - draw.up.y = 0; + //draw.up.x = draw.screen.width() / 2; + //draw.up.y = 0; - draw.down.x = draw.screen.width() / 2; - draw.down.y = draw.screen.height() - 1; + //draw.down.x = draw.screen.width() / 2; + //draw.down.y = draw.screen.height() - 1; - draw.left.x = 0; - draw.left.y = draw.screen.height() / 2; + //draw.left.x = 0; + //draw.left.y = draw.screen.height() / 2; - draw.right.x = draw.screen.width() - 1; - draw.right.y = draw.screen.height() / 2; + //draw.right.x = draw.screen.width() - 1; + //draw.right.y = draw.screen.height() / 2; - draw.returned = is_final; - return draw; -} + //draw.returned = is_final; + //return draw; +//} Draw Unimplemented(bool is_final) { return Boxed("Unimplemented", is_final); diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 6f50b4b..4724c28 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,12 +1,12 @@ -set(DIAGON_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "") - # ┌─────────────────────────────────────────────────┐ # │ ANTLR │ # └─────────────────────────────────────────────────┘ -execute_process( - COMMAND bash download_and_patch.sh - WORKING_DIRECTORY ${DIAGON_TOOLS_DIR} -) +if(NOT EXISTS "${CMAKE_BINARY_DIR}/antlr.jar") + execute_process( + COMMAND curl http://www.antlr.org/download/antlr-4.11.1-complete.jar -L -o antlr.jar + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) +endif() # Function # ANTLR() @@ -26,20 +26,20 @@ function(ANTLR source) get_filename_component(source_gen_dir ${CMAKE_CURRENT_BINARY_DIR}/${source} DIRECTORY) add_custom_command( OUTPUT - ${source_gen_dir}/${source_filename}Lexer.cpp - ${source_gen_dir}/${source_filename}Parser.cpp - ${source_gen_dir}/${source_filename}Lexer.h - ${source_gen_dir}/${source_filename}Parser.h + ${source_gen_dir}/${source_filename}Lexer.cpp + ${source_gen_dir}/${source_filename}Parser.cpp + ${source_gen_dir}/${source_filename}Lexer.h + ${source_gen_dir}/${source_filename}Parser.h COMMAND - java + java ARGS - -jar ${DIAGON_TOOLS_DIR}/antlr.jar - -Dlanguage=Cpp - -no-listener - -no-visitor - -o ${source_gen_dir} - ${source_src_dir}/${source_filename}.g4 + -jar ${CMAKE_BINARY_DIR}/antlr.jar + -Dlanguage=Cpp + -no-listener + -no-visitor + -o ${source_gen_dir} + ${source_src_dir}/${source_filename}.g4 MAIN_DEPENDENCY - ${source_src_dir}/${source_filename}.g4 - ) + ${source_src_dir}/${source_filename}.g4 + ) endfunction() diff --git a/tools/download_and_patch.sh b/tools/download_and_patch.sh deleted file mode 100755 index dbf989f..0000000 --- a/tools/download_and_patch.sh +++ /dev/null @@ -1,9 +0,0 @@ -cd "$(dirname "$0")" -top=$(pwd) - -if [[ -f "antlr.jar" ]] -then - exit -else - curl http://www.antlr.org/download/antlr-4.8-complete.jar -L -o antlr.jar -fi