diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index adb91138..89f7f336 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -36,10 +36,10 @@ jobs: sudo apt-get install valgrind - name: Install missing software on ubuntu (clang++) - if: matrix.os == 'ubuntu-24.04' && matrix.compiler == 'clang++' + if: contains(matrix.os, 'ubuntu') && matrix.compiler == 'clang++' run: | sudo apt-get update - sudo apt-get install libc++-18-dev + sudo apt-get install libc++-dev # coreutils contains "nproc" - name: Install missing software on macos diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml deleted file mode 100644 index 767bba6c..00000000 --- a/.github/workflows/CI-windows.yml +++ /dev/null @@ -1,66 +0,0 @@ -# Some convenient links: -# - https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md -# - -name: CI-windows - -on: [push,pull_request] - -permissions: - contents: read - -defaults: - run: - shell: cmd - -jobs: - - build: - strategy: - matrix: - os: [windows-2022, windows-2025] - config: [Release, Debug] - fail-fast: false - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Setup msbuild.exe - uses: microsoft/setup-msbuild@v2 - - - name: Set up Python 3.13 - uses: actions/setup-python@v5 - with: - python-version: '3.13' - check-latest: true - - - name: Install missing Python packages - run: | - python -m pip install pip --upgrade || exit /b !errorlevel! - python -m pip install pytest || exit /b !errorlevel! - - - name: Run CMake - run: | - cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_COMPILE_WARNING_AS_ERROR=On . || exit /b !errorlevel! - - - name: Build - run: | - msbuild -m simplecpp.sln /p:Configuration=${{ matrix.config }} /p:Platform=x64 || exit /b !errorlevel! - - - name: Test - run: | - .\${{ matrix.config }}\testrunner.exe || exit /b !errorlevel! - - - name: Selfcheck - run: | - .\${{ matrix.config }}\simplecpp.exe simplecpp.cpp -e || exit /b !errorlevel! - - - name: integration test - run: | - set SIMPLECPP_EXE_PATH=.\${{ matrix.config }}\simplecpp.exe - python -m pytest integration_test.py -vv || exit /b !errorlevel! - diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml deleted file mode 100644 index fd71bdfe..00000000 --- a/.github/workflows/clang-tidy.yml +++ /dev/null @@ -1,44 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: clang-tidy - -on: [push, pull_request] - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install missing software - run: | - sudo apt-get update - sudo apt-get install -y cmake make - - - name: Install clang - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 20 - sudo apt-get install clang-tidy-20 - - - name: Verify clang-tidy configuration - run: | - clang-tidy-20 --verify-config - - - name: Prepare CMake - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - env: - CXX: clang-20 - - - name: Clang-Tidy - run: | - run-clang-tidy-20 -q -j $(nproc) -p=cmake.output diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index 4d5657f8..00000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,62 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: format - -on: - push: - branches: - - 'master' - - 'releases/**' - - '1.*' - tags: - - '1.*' - pull_request: - -permissions: - contents: read - -jobs: - format: - - runs-on: ubuntu-22.04 - - defaults: - run: - shell: bash -euo pipefail {0} - - env: - UNCRUSTIFY_INSTALL_DIR: ${{ github.workspace }}/runformat-uncrustify - - steps: - - uses: actions/checkout@v5 - with: - persist-credentials: false - - - name: Determine uncrustify version - id: get-uncrustify-version - run: | - version="$(./runformat --expected-uncrustify-version)" - echo "Expected uncrustify version: $version" - echo "version=$version" >> "$GITHUB_OUTPUT" - - - name: Set UNCRUSTIFY_VERSION env variable - run: | - version=$(./runformat --expected-uncrustify-version) - echo "version [$version]" - echo "UNCRUSTIFY_VERSION=${version}" >> "$GITHUB_ENV" - - - name: Cache uncrustify - uses: actions/cache@v4 - id: cache-uncrustify - with: - path: ${{ env.UNCRUSTIFY_INSTALL_DIR }} - key: ${{ runner.os }}-uncrustify-${{ steps.get-uncrustify-version.outputs.version }} - - - name: Install uncrustify - if: steps.cache-uncrustify.outputs.cache-hit != 'true' - run: | - ./runformat --install --install-dir "${UNCRUSTIFY_INSTALL_DIR}" - - - name: Uncrustify check - run: | - ./runformat diff --git a/Makefile b/Makefile index 7489ec83..b6bc26da 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ test: testrunner simplecpp python3 -m pytest integration_test.py -vv selfcheck: simplecpp - ./selfcheck.sh + CXX=$(CXX) ./selfcheck.sh simplecpp: main.o simplecpp.o $(CXX) $(LDFLAGS) main.o simplecpp.o -o simplecpp diff --git a/main.cpp b/main.cpp index a6d14386..747f041b 100644 --- a/main.cpp +++ b/main.cpp @@ -43,6 +43,11 @@ int main(int argc, char **argv) } case 'I': { // include path const char * const value = arg[2] ? (argv[i] + 2) : argv[++i]; + std::ifstream f(value); + if (!f.is_open()) { + std::cout << "error: include path '" << value << "' does not exist" << std::endl; + std::exit(1); + } dui.includePaths.push_back(value); found = true; break; diff --git a/selfcheck.sh b/selfcheck.sh index a43ef8c5..c6fbc906 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -4,8 +4,104 @@ output=$(./simplecpp simplecpp.cpp -e -f 2>&1) ec=$? errors=$(echo "$output" | grep -v 'Header not found: <') if [ $ec -ne 0 ]; then - # only fail if got errors which do not refer to missing system includes + # only fail if we got errors which do not refer to missing system includes if [ ! -z "$errors" ]; then exit $ec fi -fi \ No newline at end of file +fi + +if [ -z "$CXX" ]; then + exit 0 +fi + +cxx_type=$($CXX --version | head -1 | cut -d' ' -f1) +if [ "$cxx_type" = "Ubuntu" ]; then + cxx_type=$($CXX --version | head -1 | cut -d' ' -f2) +fi +# TODO: how to get built-in include paths from compiler? +if [ "$cxx_type" = "g++" ]; then + gcc_ver=$($CXX -dumpversion) + defs= + defs="$defs -D__GNUC__" + defs="$defs -D__STDC__" + defs="$defs -D__STDC_HOSTED__" + defs="$defs -D__CHAR_BIT__=8" + defs="$defs -D__x86_64__" + defs="$defs -D__has_builtin(x)=(1)" + defs="$defs -D__has_cpp_attribute(x)=(1)" + defs="$defs -D__has_attribute(x)=(1)" + # some required include paths might differ per distro + inc= + inc="$inc -I/usr/include" + inc="$inc -I/usr/include/linux" + inc="$inc -I/usr/include/c++/$gcc_ver" + if [ -d "/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu" ]; then + inc="$inc -I/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu" + fi + if [ -d "/usr/lib/gcc/x86_64-pc-linux-gnu/$gcc_ver/include" ]; then + inc="$inc -I/usr/lib/gcc/x86_64-pc-linux-gnu/$gcc_ver/include" + fi + if [ -d "/usr/lib/gcc/x86_64-linux-gnu/$gcc_ver/include" ]; then + inc="$inc -I/usr/lib/gcc/x86_64-linux-gnu/$gcc_ver/include" + fi + if [ -d "/usr/include/x86_64-linux-gnu" ]; then + inc="$inc -I/usr/include/x86_64-linux-gnu" + inc="$inc -I/usr/include/x86_64-linux-gnu/c++/$gcc_ver" + fi +elif [ "$cxx_type" = "clang" ]; then + clang_ver=$($CXX -dumpversion) + clang_ver=${clang_ver%%.*} + defs= + defs="$defs -D__BYTE_ORDER__" + defs="$defs -D__linux__" + defs="$defs -D__x86_64__" + defs="$defs -D__SIZEOF_SIZE_T__=8" + defs="$defs -D__has_feature(x)=(1)" + defs="$defs -D__has_extension(x)=(1)" + defs="$defs -D__has_attribute(x)=(0)" + defs="$defs -D__has_cpp_attribute(x)=(0)" + defs="$defs -D__has_include_next(x)=(0)" + defs="$defs -D__has_builtin(x)=(1)" + # some required include paths might differ per distro + inc= + if [ -d "/usr/include/c++/v1" ]; then + inc="$inc -I/usr/include/c++/v1" + fi + if [ -d "/usr/lib/llvm-$clang_ver/include/c++/v1" ]; then + inc="$inc -I/usr/lib/llvm-$clang_ver/include/c++/v1" + fi + inc="$inc -I/usr/include" + inc="$inc -I/usr/lib/clang/$clang_ver/include" + if [ -d "/usr/include/x86_64-linux-gnu" ]; then + inc="$inc -I/usr/include/x86_64-linux-gnu" + fi +elif [ "$cxx_type" = "Apple" ]; then + xcode_path="/Applications/Xcode_16.4.app" + if [ ! -d "$xcode_path" ]; then + xcode_path="/Applications/Xcode_15.2.app" + fi + sdk_path="$xcode_path/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" + defs= + defs="$defs -D__BYTE_ORDER__" + defs="$defs -D__APPLE__" + defs="$defs -D__GNUC__=15" + defs="$defs -D__x86_64__" + defs="$defs -D__has_feature(x)=(1)" + defs="$defs -D__has_extension(x)=(1)" + defs="$defs -D__has_attribute(x)=(0)" + defs="$defs -D__has_cpp_attribute(x)=(0)" + defs="$defs -D__has_include_next(x)=(0)" + inc= + inc="$inc -I$sdk_path/usr/include/c++/v1" + inc="$inc -I$sdk_path/usr/include" + inc="$inc -I$sdk_path/usr/include/i386" +else + echo "unknown compiler '$cxx_type'" + exit 1 +fi + +./simplecpp simplecpp.cpp -e -f -std=gnu++11 $defs $inc +ec=$? +if [ $ec -ne 0 ]; then + exit $ec +fi