diff --git a/.circleci/config.yml b/.circleci/config.yml index 949338268d..285a00ddf0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ jobs: only: - develop docker: - - image: srcml/ubuntu_x86_64_base + - image: srcml/ubuntu:21.10 steps: - checkout - run: apt-get update diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index a14d44b0bf..c71ff3c605 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -57,10 +57,52 @@ jobs: cpack -G WIX -V - shell: bash +======= + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Setup Ubuntu + shell: bash + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + sudo apt install antlr libantlr-dev libantlr-java libarchive-dev \ + libcurl4-openssl-dev libxml2-utils libxslt1-dev \ + ninja-build + curl -L http://www.sdml.cs.kent.edu/build/srcML-1.0.0-Boost.tar.gz | \ + sudo tar xz -C /usr/local/include + + - name: Setup macOS + shell: bash + if: ${{ matrix.os == 'macos-latest' }} + run: | + brew install ninja antlr2 --display-times + curl -L http://www.sdml.cs.kent.edu/build/srcML-1.0.0-Boost.tar.gz | \ + sudo tar xz -C /usr/local/include + + - name: Setup Windows + uses: microsoft/setup-msbuild@v1 + if: ${{ matrix.os == 'windows-latest' }} + + - name: Create build directory + shell: bash + run: mkdir build + + - name: CMake Setup on Windows + shell: bash + if: ${{ matrix.os == 'windows-latest' }} + working-directory: build + run: | + export UseMultiToolTask=true + cmake .. + + - name: CMake Setup on Ubuntu/macOS + shell: bash +>>>>>>> upstream/issue1942 if: ${{ matrix.os != 'windows-latest' }} working-directory: build run: | cmake .. -G Ninja +<<<<<<< HEAD sudo cmake --build . --config Release --target install - working-directory: build/dist @@ -82,10 +124,51 @@ jobs: - shell: bash if: matrix.os == 'macos-latest' +======= + + - name: Build + shell: bash + working-directory: build + run: | + export UseMultiToolTask=true + cmake --build . --config Release + + - name: Install on Windows + shell: bash + if: ${{ matrix.os == 'windows-latest' }} + working-directory: build + run: | + cmake --build . --config Release --target install + + - name: Install on Ubuntu/macOS + shell: bash + if: ${{ matrix.os != 'windows-latest' }} + working-directory: build + run: | + sudo cmake --build . --config Release --target install + + - name: Finish install for Ubuntu + shell: bash + if: ${{ matrix.os == 'ubuntu-latest' }} + working-directory: build + run: | + sudo ldconfig + + - name: Set PATH for Windows + shell: bash + if: ${{ matrix.os == 'windows-latest' }} + working-directory: build + run: | + echo "/c/Program Files (x86)/srcML/bin" >> $GITHUB_PATH + + - name: Run Installed srcml + shell: bash +>>>>>>> upstream/issue1942 working-directory: build run: | srcml --version srcml --text="int a;" -l C++ +<<<<<<< HEAD - shell: bash if: matrix.os == 'windows-latest' @@ -93,3 +176,5 @@ jobs: run: | srcml.exe --version srcml.exe --text="int a;" -l C++ +======= +>>>>>>> upstream/issue1942 diff --git a/.github/workflows/BuildWindows.yml b/.github/workflows/BuildWindows.yml index 123172a51a..6379adc546 100644 --- a/.github/workflows/BuildWindows.yml +++ b/.github/workflows/BuildWindows.yml @@ -6,6 +6,7 @@ on: workflow_dispatch jobs: build: runs-on: windows-latest +<<<<<<< HEAD timeout-minutes: 10 steps: @@ -15,12 +16,343 @@ jobs: - shell: bash run: mkdir build +======= + env: + SCCACHE_GHA_ENABLED: "true" + timeout-minutes: 30 + steps: + + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Setup Windows + uses: microsoft/setup-msbuild@v1.3.1 + + - name: Restore artifacts, or run vcpkg, build (and cache artifacts as post step) + uses: lukka/run-vcpkg@v11 + id: runvcpkg + with: + vcpkgGitCommitId: 'acc3bcf76b84ae5041c86ab55fe138ae7b8255c7' + + - name: Fix vcpkg + shell: bash + run: | + mkdir "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/vcpkg/scripts/msys" + curl -L -O https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/cmake/compile_wrapper_consider_clang-cl.patch -o "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/vcpkg/scripts/msys/compile_wrapper_consider_clang-cl.patch" + + - name: Setup devcmd to use cl.exe + uses: ilammy/msvc-dev-cmd@v1.12.1 + + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.3 + + - name: Create build directory + shell: bash + run: | + cmake --version + mkdir build + echo $VCPKG_ROOT/vcpkg list + + - name: CMake Setup on Windows + shell: bash + working-directory: build + run: | + export UseMultiToolTask=true + cmake .. --preset msvc -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache +>>>>>>> upstream/issue1942 - name: Build shell: bash working-directory: build continue-on-error: true run: | +<<<<<<< HEAD export EXTERNAL_INCLUDE="C:\Program Files (x86)\Windows Kits\10\Include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\include" cmake .. -DBUILD_LIBSRCML_TESTS=OFF cmake --build . --verbose --config Release +======= + export UseMultiToolTask=true + cmake --build . --config Release + + - name: Package + working-directory: build + continue-on-error: true + run: | + cpack -V --preset msvc + # - uses: actions/upload-artifact@v3 + # with: + # name: wix.log + # # if: failure() + # path: build/dist/_CPack_Packages/win64/WIX/wix.log + - uses: actions/upload-artifact@v3 + with: + name: installers + path: | + build/dist/*.msi + build/dist/*.zip + build/dist/*.exe + build/dist/*.nupkg + + # - name: Install from build + # working-directory: build + # continue-on-error: true + # run: | + # cmake --build . --config Release --target install + + # # - name: Clean build + # # working-directory: build + # # continue-on-error: true + # # run: | + # # cmake --build . --config Release --target clean + # # cmake . -DSRCML_TEST_INSTALLED=ON + + # - name: Set PATH for Windows + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # echo "/c/Program Files/srcML/bin" >> $GITHUB_PATH + + # - name: Run Installed srcml + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # EOL="\r\n" + # export PATH=$PATH:"/c/Program Files/srcML/bin" + # SRCML_HOME="/c/Program Files/srcML/bin" + # ls -lh "$SRCML_HOME" + # SRCML="$SRCML_HOME/srcml.exe" + # ls -lh "$SRCML" + # export MSYS2_ARG_CONV_EXCL="*" + # diff='diff -Z ' + # "$SRCML" --version + # "$SRCML" --text="int a;" -l C++ + # touch "a.cpp" + # "$SRCML" a.cpp + # echo "a;" >> a.cpp + # "$SRCML" a.cpp + # echo "b;" >> b.cpp + # "$SRCML" a.cpp b.cpp + + # - name: Create build examples directory + # shell: bash + # continue-on-error: true + # run: | + # mkdir build2 + + # - name: Build examples + # shell: bash + # working-directory: build2 + # continue-on-error: true + # run: | + # cmake "/c/Program Files/srcML/share/srcml/examples" -DsrcML_DIR="C:/Program Files/srcML/cmake" -G Ninja + # ninja + + # - name: Run examples + # shell: bash + # working-directory: build2 + # continue-on-error: true + # run: | + # ls *.exe + # ./srcml_copy_archive.exe || echo $? + # ./srcml_create_archive_fd.exe || echo $? + # ./srcml_create_archive_file.exe || echo $? + # ./srcml_create_archive_filename.exe || echo $? + # ./srcml_create_archive_full.exe || echo $? + # ./srcml_direct_language.exe || echo $? + # ./srcml_direct_language_list.exe || echo $? + # ./srcml_direct_language_xml.exe || echo $? + # ./srcml_direct_src2srcml.exe || echo $? + # ./srcml_direct_srcml2src.exe || echo $? + # ./srcml_list.exe || echo $? + # ./srcml_read_archive_fd.exe || echo $? + # ./srcml_read_archive_file.exe || echo $? + # ./srcml_read_archive_filename.exe || echo $? + # ./srcml_read_archive_full.exe || echo $? + # ./srcml_read_archive_memory.exe || echo $? + # ./srcml_relaxng.exe || echo $? + # ./srcml_sort_archive.exe || echo $? + # ./srcml_split_archive.exe || echo $? + # ./srcml_transform.exe || echo $? + # ./srcml_xpath.exe || echo $? + # ./srcml_xslt.exe || echo $? + + + test: + needs: build + runs-on: windows-latest + steps: + # Download the installer artifact + - name: Download installer + uses: actions/download-artifact@v3 + with: + name: installers + + # - shell: bash + # continue-on-error: true + # run: | + # ls -lh + + - name: Install package + continue-on-error: true + run: msiexec /i srcml-1.0.0-windows-x86_64.msi /quiet /norestart /L*vx .\msi.log + - uses: actions/upload-artifact@v3 + with: + name: msi.log + path: ./msi.log + + - name: Set PATH for Windows + shell: bash + continue-on-error: true + run: | + echo "/c/Program Files/srcML/bin" >> $GITHUB_PATH + + - name: Run Installed srcml + shell: bash + continue-on-error: true + run: | + srcml --help + srcml --text="a;" -l C++ + + # - name: Create build examples directory + # shell: bash + # continue-on-error: true + # run: | + # mkdir build3 + + # - name: Build examples + # shell: bash + # working-directory: build3 + # continue-on-error: true + # run: | + # cmake "/c/Program Files/srcML/share/srcml/examples" -G Ninja + # ninja + + # - name: Run examples + # shell: bash + # working-directory: build3 + # continue-on-error: true + # run: | + # ./srcml_copy_archive.exe || echo $? + # ./srcml_create_archive_fd.exe || echo $? + # ./srcml_create_archive_file.exe || echo $? + # ./srcml_create_archive_filename.exe || echo $? + # ./srcml_create_archive_full.exe || echo $? + # ./srcml_direct_language.exe || echo $? + # ./srcml_direct_language_list.exe || echo $? + # ./srcml_direct_language_xml.exe || echo $? + # ./srcml_direct_src2srcml.exe || echo $? + # ./srcml_direct_srcml2src.exe || echo $? + # ./srcml_list.exe || echo $? + # ./srcml_read_archive_fd.exe || echo $? + # ./srcml_read_archive_file.exe || echo $? + # ./srcml_read_archive_filename.exe || echo $? + # ./srcml_read_archive_full.exe || echo $? + # ./srcml_read_archive_memory.exe || echo $? + # ./srcml_relaxng.exe || echo $? + # ./srcml_sort_archive.exe || echo $? + # ./srcml_split_archive.exe || echo $? + # ./srcml_transform.exe || echo $? + # ./srcml_xpath.exe || echo $? + # ./srcml_xslt.exe || echo $? + + - name: Setup msys2 with additional client-test packages for Windows + uses: msys2/setup-msys2@v2 + continue-on-error: true + with: + install: >- + zip + cpio + diffutils + util-linux + cmake + libxml2 + + - name: Create build directory + shell: bash + run: | + mkdir build + + - name: Build + shell: bash + working-directory: build + continue-on-error: true + run: | + export UseMultiToolTask=true + cmake .. --preset msvc + + - name: Windows Client Tests on Installed srcml + shell: msys2 {0} + working-directory: build + timeout-minutes: 10 + continue-on-error: true + run: | + # export SRCML_HOME="/c/Program Files/srcML/bin/" + ctest -C Release + + - uses: actions/upload-artifact@v3 + with: + name: ClientTest.windows-latest.log + path: build/Testing/Temporary/LastTest.log + + # - name: Build libsrcml Tests + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # export UseMultiToolTask=true + # export PATH=$PATH:"/c/Program Files/srcML/bin/" + # echo "C:\Program Files\srcML\bin" >> $GITHUB_PATH + # SRCML_HOME="/c/Program Files/srcML/bin/" + # cmake . -DBUILD_LIBSRCML_TESTS=ON + # cmake --build . --config Release --target build_libsrcml_tests + + # - name: Check dependents + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # dumpbin -dependents "/c/Program Files/srcML/bin/srcml.exe" || true + # dumpbin -dependents "/c/Program Files/srcML/bin/archive.dll" || true + # dumpbin -dependents "/c/Program Files/srcML/bin/libcurl.dll" || true + # dumpbin -dependents "/c/Program Files/srcML/bin/libsrcml.dll" || true + # dumpbin -dependents "/c/Program Files/srcML/bin/libxml2.dll" || true + # dumpbin -dependents "/c/Program Files/srcML/bin/libexslt.dll" || true + # dumpbin -dependents "/c/Program Files/srcML/bin/libxslt.dll" || true + # dumpbin -dependents "/c/Program Files/srcML/bin/iconv-2.dll" || true + # dumpbin -exports "/c/Program Files/srcML/bin/libsrcml.dll" || true + + # - name: Run libsrcml Tests on Installed libsrcml + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # ctest -C Release -R ^test_ + # - uses: actions/upload-artifact@v3 + # with: + # name: libsrcmlTest.windows-latest.log + # path: build/Testing/Temporary/LastTest.log + + # - name: Generate Parser Tests + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # export PATH=$PATH:"/c/Program Files/srcML/bin/" + # ls -lh "/c/Program Files/srcML/bin/" + # echo "C:\Program Files\srcML\bin" >> $GITHUB_PATH + # cmake . -DBUILD_PARSER_TESTS=ON + # cmake --build . --config Release --target gen_parser_tests + + # - name: Run Parser Tests + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # srcml --parser-test test/parser/testsuite | tee ParserTest.log + # - uses: actions/upload-artifact@v3 + # with: + # name: ParserTest.windows-latest.log + # path: build/ParserTest.log +>>>>>>> upstream/issue1942 diff --git a/.github/workflows/ClangBuildAnalysis.yml b/.github/workflows/ClangBuildAnalysis.yml index c64fa80d0e..874e0e4b12 100644 --- a/.github/workflows/ClangBuildAnalysis.yml +++ b/.github/workflows/ClangBuildAnalysis.yml @@ -34,8 +34,12 @@ jobs: cd build cmake -DCMAKE_BUILD_TYPE=Release .. -G Ninja ninja +<<<<<<< HEAD echo ":/Users/runner/work/srcML/srcML/analyzer/build" >> $GITHUB_PATH ls -lh /Users/runner/work/srcML/srcML/analyzer/build +======= + sudo cp ClangBuildAnalyzer /usr/local/bin +>>>>>>> upstream/issue1942 - name: Create build directory shell: bash @@ -60,7 +64,10 @@ jobs: shell: bash working-directory: build run: | +<<<<<<< HEAD export PATH="$PATH:/Users/runner/work/srcML/srcML/analyzer/build" +======= +>>>>>>> upstream/issue1942 ClangBuildAnalyzer --all src/parser capture_pch_parser ClangBuildAnalyzer --analyze capture_pch_parser > capture_pch_parser.txt ClangBuildAnalyzer --all src/libsrcml capture_pch_libsrcml @@ -87,7 +94,10 @@ jobs: shell: bash working-directory: build run: | +<<<<<<< HEAD export PATH="$PATH:/Users/runner/work/srcML/srcML/analyzer/build" +======= +>>>>>>> upstream/issue1942 ClangBuildAnalyzer --all src/parser capture_nopch_parser ClangBuildAnalyzer --analyze capture_nopch_parser > capture_nopch_parser.txt ClangBuildAnalyzer --all src/libsrcml capture_nopch_libsrcml diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 4fd74a6c0c..91f1270f7c 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -15,6 +15,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v2 +<<<<<<< HEAD - name: Cache Build id: cache uses: actions/cache@v2 @@ -22,15 +23,23 @@ jobs: path: build key: ${{ runner.os }}-client1 +======= +>>>>>>> upstream/issue1942 - name: Setup Ubuntu shell: bash if: ${{ matrix.os == 'ubuntu-latest' }} run: | +<<<<<<< HEAD sudo apt update sudo apt install curl zip g++ make ninja-build antlr libantlr-dev \ libxml2-dev libxml2-utils libxslt1-dev \ libarchive-dev libssl-dev libcurl4-openssl-dev \ cpio man file dpkg-dev +======= + sudo apt install antlr libantlr-dev libantlr-java libarchive-dev \ + libcurl4-openssl-dev libxml2-utils libxslt1-dev \ + ninja-build +>>>>>>> upstream/issue1942 curl -L http://www.sdml.cs.kent.edu/build/srcML-1.0.0-Boost.tar.gz | \ sudo tar xz -C /usr/local/include @@ -38,7 +47,11 @@ jobs: shell: bash if: ${{ matrix.os == 'macos-latest' }} run: | +<<<<<<< HEAD brew install ninja antlr2 +======= + brew install ninja antlr2 --display-times +>>>>>>> upstream/issue1942 curl -L http://www.sdml.cs.kent.edu/build/srcML-1.0.0-Boost.tar.gz | \ sudo tar xz -C /usr/local/include @@ -48,23 +61,37 @@ jobs: - name: Create build directory shell: bash +<<<<<<< HEAD if: ${{ !steps.cache.outputs.cache-hit }} run: mkdir build - name: Build on Windows +======= + run: mkdir build + + - name: CMake Setup on Windows +>>>>>>> upstream/issue1942 shell: bash if: ${{ matrix.os == 'windows-latest' }} working-directory: build run: | +<<<<<<< HEAD cmake .. cmake --build . --config Release --target install - name: Build on Ubuntu/macOS +======= + export UseMultiToolTask=true + cmake .. + + - name: CMake Setup on Ubuntu/macOS +>>>>>>> upstream/issue1942 shell: bash if: ${{ matrix.os != 'windows-latest' }} working-directory: build run: | cmake .. -G Ninja +<<<<<<< HEAD sudo cmake --build . --config Release --target install - name: Finish install for Ubuntu @@ -73,6 +100,43 @@ jobs: working-directory: build run: | sudo ldconfig +======= + + - name: Build + shell: bash + working-directory: build + run: | + export UseMultiToolTask=true + cmake --build . --config Release + + - name: Install on Windows + shell: bash + if: ${{ matrix.os == 'windows-latest' }} + working-directory: build + run: | + cmake --build . --config Release --target install + + - name: Install on Ubuntu/macOS + shell: bash + if: ${{ matrix.os != 'windows-latest' }} + working-directory: build + run: | + sudo cmake --build . --config Release --target install + + - name: Set PATH for Windows + shell: bash + if: ${{ matrix.os == 'windows-latest' }} + working-directory: build + run: | + echo "/c/Program Files (x86)/srcML/bin" >> $GITHUB_PATH + + - name: Run Installed srcml + shell: bash + working-directory: build + run: | + srcml --version + srcml --text="int a;" -l C++ +>>>>>>> upstream/issue1942 - name: Setup msys2 with additional client-test packages for Windows if: ${{ matrix.os == 'windows-latest' }} @@ -96,18 +160,30 @@ jobs: ctest -C Release -VV - uses: actions/upload-artifact@v2 with: +<<<<<<< HEAD name: ClientLastTest.${{ runner.os }}.log +======= + name: ClientTest.${{ runner.os }}.log +>>>>>>> upstream/issue1942 path: build/Testing/Temporary/LastTest.log - name: Ubuntu/macOS Client Tests on Installed srcml if: ${{ matrix.os != 'windows-latest' }} shell: bash working-directory: build +<<<<<<< HEAD +======= + continue-on-error: true +>>>>>>> upstream/issue1942 run: | ctest -VV - uses: actions/upload-artifact@v2 with: +<<<<<<< HEAD name: ClientLastTest.${{ runner.os }}.log +======= + name: ClientTest.${{ runner.os }}.log +>>>>>>> upstream/issue1942 path: build/Testing/Temporary/LastTest.log - name: Build libsrcml Tests @@ -115,6 +191,10 @@ jobs: working-directory: build continue-on-error: true run: | +<<<<<<< HEAD +======= + export UseMultiToolTask=true +>>>>>>> upstream/issue1942 cmake .. -DBUILD_LIBSRCML_TESTS=ON cmake --build . --config Release --target build_libsrcml_tests @@ -126,7 +206,11 @@ jobs: ctest -C Release -R ^test_ - uses: actions/upload-artifact@v2 with: +<<<<<<< HEAD name: libsrcmlLastTest.${{ runner.os }}.log +======= + name: libsrcmlTest.${{ runner.os }}.log +>>>>>>> upstream/issue1942 path: build/Testing/Temporary/LastTest.log - name: Generate Parser Tests diff --git a/.github/workflows/TestClient.yml b/.github/workflows/TestClient.yml index 8bb2ec8c48..52bf46bc95 100644 --- a/.github/workflows/TestClient.yml +++ b/.github/workflows/TestClient.yml @@ -56,6 +56,7 @@ jobs: if: ${{ matrix.os == 'windows-latest' }} working-directory: build run: | + export UseMultiToolTask=true cmake .. cmake --build . --config Release --target install @@ -86,3 +87,39 @@ jobs: working-directory: build run: | ctest + + - name: Setup msys2 with additional client-test packages for Windows + if: ${{ matrix.os == 'windows-latest' }} + uses: msys2/setup-msys2@v2 + with: + install: >- + zip + cpio + diffutils + cmake + util-linux + + - name: Windows Client Tests on Installed srcml + if: ${{ matrix.os == 'windows-latest' }} + shell: msys2 {0} + working-directory: build + timeout-minutes: 5 + continue-on-error: true + run: | + export SRCML_HOME="/c/Program Files (x86)/srcML/bin" + ctest -C Release -VV + - uses: actions/upload-artifact@v2 + with: + name: ClientLastTest.${{ runner.os }}.log + path: build/Testing/Temporary/LastTest.log + + - name: Ubuntu/macOS Client Tests on Installed srcml + if: ${{ matrix.os != 'windows-latest' }} + shell: bash + working-directory: build + run: | + ctest -VV + - uses: actions/upload-artifact@v2 + with: + name: ClientLastTest.${{ runner.os }}.log + path: build/Testing/Temporary/LastTest.log diff --git a/.github/workflows/TestFedora.yml b/.github/workflows/TestFedora.yml index dc52f69fb6..980801edca 100644 --- a/.github/workflows/TestFedora.yml +++ b/.github/workflows/TestFedora.yml @@ -4,10 +4,118 @@ name: Test Fedora on: workflow_dispatch jobs: - package: + build: runs-on: ubuntu-latest timeout-minutes: 10 steps: - name: Checkout Repository uses: actions/checkout@v2 + + - name: Run docker image + shell: bash + run: | + mkdir dist + + - name: Run docker image + working-directory: dist + shell: bash + run: | + echo "PWD: " "$(pwd)" + docker run -v "$(pwd)"/..:/Source -v "$(pwd)":/Dist srcml/fedora_x86_64_base:latest bash -c "mkdir /Build; cd /Build; cmake /Source -G Ninja;ninja install;ctest;cpack -G RPM; cp dist/*.rpm /Dist/." # - name: Setup Ubuntu + + - uses: actions/upload-artifact@v2 + with: + name: FedoraDist + path: dist/* + + # shell: bash + # run: | + # sudo apt install antlr libantlr-dev libantlr-java libarchive-dev \ + # libcurl4-openssl-dev libxml2-utils libxslt1-dev \ + # ninja-build + # curl -L http://www.sdml.cs.kent.edu/build/srcML-1.0.0-Boost.tar.gz | \ + # sudo tar xz -C /usr/local/include + + # - name: Create build directory + # shell: bash + # run: mkdir build + + # - name: CMake Setup on Ubuntu/macOS + # shell: bash + # if: ${{ matrix.os != 'windows-latest' }} + # working-directory: build + # run: | + # cmake .. -G Ninja + + # - name: Build + # shell: bash + # working-directory: build + # run: | + # export UseMultiToolTask=true + # cmake --build . --config Release + + # - name: Install on Ubuntu/macOS + # shell: bash + # if: ${{ matrix.os != 'windows-latest' }} + # working-directory: build + # run: | + # sudo cmake --build . --config Release --target install + + # - name: Run Installed srcml + # shell: bash + # working-directory: build + # run: | + # srcml --version + # srcml --text="int a;" -l C++ + + # - name: Ubuntu/macOS Client Tests on Installed srcml + # if: ${{ matrix.os != 'windows-latest' }} + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # ctest -VV + # - uses: actions/upload-artifact@v2 + # with: + # name: ClientTest.${{ runner.os }}.log + # path: build/Testing/Temporary/LastTest.log + + # - name: Build libsrcml Tests + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # export UseMultiToolTask=true + # cmake .. -DBUILD_LIBSRCML_TESTS=ON + # cmake --build . --config Release --target build_libsrcml_tests + + # - name: Run libsrcml Tests on Installed libsrcml + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # ctest -C Release -R ^test_ + # - uses: actions/upload-artifact@v2 + # with: + # name: libsrcmlTest.${{ runner.os }}.log + # path: build/Testing/Temporary/LastTest.log + + # - name: Generate Parser Tests + # shell: bash + # working-directory: build + # run: | + # cmake .. -DBUILD_PARSER_TESTS=ON + # cmake --build . --config Release --target gen_parser_tests + + # - name: Run Parser Tests + # shell: bash + # working-directory: build + # continue-on-error: true + # run: | + # srcml --parser-test test/parser/testsuite | tee ParserTest.log + + # - uses: actions/upload-artifact@v2 + # with: + # name: ParserTest.${{ runner.os }}.log + # path: build/ParserTest.log diff --git a/.github/workflows/TestLibsrcml.yml b/.github/workflows/TestLibsrcml.yml index d6b06dca97..9cca7b91fc 100644 --- a/.github/workflows/TestLibsrcml.yml +++ b/.github/workflows/TestLibsrcml.yml @@ -56,7 +56,8 @@ jobs: if: ${{ matrix.os == 'windows-latest' }} working-directory: build run: | - cmake .. -DBUILD_LIBSRCML_TESTS=ON + export UseMultiToolTask=true + cmake .. -DBUILD_LIBSRCML_TESTS=OFF cmake --build . --config Release --target install - name: Build on Ubuntu/macOS @@ -64,7 +65,7 @@ jobs: if: ${{ matrix.os != 'windows-latest' }} working-directory: build run: | - cmake .. -G Ninja -DBUILD_LIBSRCML_TESTS=ON + cmake .. -G Ninja -DBUILD_LIBSRCML_TESTS=OFF sudo cmake --build . --config Release --target install - name: Finish install for Ubuntu @@ -74,13 +75,21 @@ jobs: run: | sudo ldconfig - - name: Libsrcml Tests on Installed srcml + - name: Build libsrcml Tests + shell: bash + working-directory: build + continue-on-error: true + run: | + cmake .. -DBUILD_LIBSRCML_TESTS=ON + cmake --build . --config Release --target build_libsrcml_tests + + - name: Run libsrcml Tests on Installed libsrcml + shell: bash working-directory: build - timeout-minutes: 5 continue-on-error: true run: | - ctest -C Release -VV -R test_ + ctest -C Release -R ^test_ - uses: actions/upload-artifact@v2 with: - name: LibsrcmlLastTest.${{ runner.os }}.log + name: libsrcmlLastTest.${{ runner.os }}.log path: build/Testing/Temporary/LastTest.log diff --git a/.github/workflows/TestParser.yml b/.github/workflows/TestParser.yml index 2f6016817d..f24d6ea457 100644 --- a/.github/workflows/TestParser.yml +++ b/.github/workflows/TestParser.yml @@ -56,6 +56,7 @@ jobs: if: ${{ matrix.os == 'windows-latest' }} working-directory: build run: | + export UseMultiToolTask=true cmake .. cmake --build . --config Release --target install @@ -88,20 +89,13 @@ jobs: run: | echo "/c/Program Files (x86)/srcML/bin" >> $GITHUB_PATH - - name: Run Parser Tests on Windows + - name: Run Parser Tests shell: bash - if: ${{ matrix.os == 'windows-latest' }} - working-directory: build - continue-on-error: true - run: | - srcml --parser-test test/parser/testsuite | tee ParserTest.log - - name: Run Parser Tests on Ubuntu/macOS - shell: bash - if: ${{ matrix.os != 'windows-latest' }} working-directory: build continue-on-error: true run: | srcml --parser-test test/parser/testsuite | tee ParserTest.log + - uses: actions/upload-artifact@v2 with: name: ParserTest.${{ runner.os }}.log diff --git a/.github/workflows/docker-compose.yml b/.github/workflows/docker-compose.yml new file mode 100644 index 0000000000..b53d69e2b0 --- /dev/null +++ b/.github/workflows/docker-compose.yml @@ -0,0 +1,88 @@ +x-configuration: &CONFIGURATION + platform: ${PLATFORM:-linux/arm64} + volumes: + - ~/srcML:/srcML:ro + - ~/srcML-Data:/Data + - ~/Builds:/Builds + working_dir: /srcML-build + command: bash -c "${COMPOSE_COMMAND- + cmake -G Ninja -DCMAKE_UNITY_BUILD=ON /srcML; + ninja; + cpack; + cp dist/* /Builds/. + } + ${COMPOSE_APPEND- }" + +services: + + # ubuntu_latest: + # image: srcml/ubuntu:latest + # <<: *CONFIGURATION + + # ubuntu_rolling: + # image: srcml/ubuntu:rolling + # <<: *CONFIGURATION + + ubuntu_23.04: + image: srcml/ubuntu:23.04 + <<: *CONFIGURATION + + # ubuntu_22.10: + # image: srcml/ubuntu:22.10 + # <<: *CONFIGURATION + + # ubuntu_22.04: + # image: srcml/ubuntu:22.04 + # <<: *CONFIGURATION + + # ubuntu_20.04: + # image: srcml/ubuntu:20.04 + # <<: *CONFIGURATION + + ubuntu_18.04: + image: srcml/ubuntu:18.04 + <<: *CONFIGURATION + + # fedora_latest: + # image: srcml/fedora:latest + # <<: *CONFIGURATION + + # fedora_rawhide: + # image: srcml/fedora:rawhide + # <<: *CONFIGURATION + + fedora_39: + image: srcml/fedora:39 + <<: *CONFIGURATION + + # fedora_38: + # image: srcml/fedora:38 + # <<: *CONFIGURATION + + # fedora_37: + # image: srcml/fedora:37 + # <<: *CONFIGURATION + + fedora_36: + image: srcml/fedora:36 + <<: *CONFIGURATION + + opensuse_15.5: + image: srcml/opensuse:15.5 + <<: *CONFIGURATION + + # opensuse_15.4: + # image: srcml/opensuse:15.4 + # <<: *CONFIGURATION + + # opensuse_15.3: + # image: srcml/opensuse:15.3 + # <<: *CONFIGURATION + + # opensuse_15.2: + # image: srcml/opensuse:15.2 + # <<: *CONFIGURATION + + opensuse_15.1: + image: srcml/opensuse:15.1 + <<: *CONFIGURATION diff --git a/BUILD.md b/BUILD.md index d0aafe4788..c251b9fd2d 100644 --- a/BUILD.md +++ b/BUILD.md @@ -1,6 +1,6 @@ # Building srcML -srcML is built using cmake, www.cmake.org, (version 2.8.12 or above) and currently supports builds for +srcML is built using cmake, www.cmake.org, (version 3.24 or above) and currently supports builds for macOS, Fedora, Ubuntu, CentOS, OpenSUSE, and Windows Visual Studio. Out of source builds (builds outside the source directory) are required. In source builds are not supported. @@ -31,15 +31,11 @@ The main packages required may be installed via brew: brew install antlr2 boost cmake -The srcML client requires at least LibArchive 3. macOS includes version 2.8. Because of this, LibArchive is -statically linked into the client. There are two options - -* Use brew to install a more recent version: +Libarchive greater than 3.0.0 is required. For macOS previous to Catalina (19.*.*), libarchive.a 3.3.* must be +statically included. Use brew to install a more recent version: `brew install libarchive` -* Download and build LibArchive in a directory `libarchive` parallel to the source directory, typically \~/libarchive - To generate srcML documentation: brew install man2html doxygen diff --git a/CMakeLists.txt b/CMakeLists.txt index a9a0f0cbe3..ba698135ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,28 +1,30 @@ +# SPDX-License-Identifier: GPL-3.0-only ## # @file CMakeLists.txt # -# @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) -# -# The srcML Toolkit is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcML Toolkit is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcML Toolkit; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# @copyright Copyright (C) 2013-2023 srcML, LLC. (www.srcML.org) # # The master CMake project file for srcML -cmake_minimum_required(VERSION 3.14) +if(DEFINED ENV{VCPKG_ROOT} OR DEFINED CMAKE_TOOLCHAIN_FILE) + set(VCPKG_BUILD_TYPE "release") +endif() + +cmake_minimum_required(VERSION 3.24) + +# If performed here, before project(), then this prefix becomes part of the CMAKE_SYSTEM_PREFIX_PATH +# and then the installed version of srcML can be found by the tests without building srcml. +# Note that the default for the install prefix is "C:/Program Files (x86)/srcML", which contradicts +# the CMake documentation (https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html) +# Also note that without this, the install target places the files in "C:/Program Files (x86)/srcML", +# while the package installer places it in "C:/Program Files/srcML" +# Note that this overwrites any changes to the CMAKE_INSTALL_PREFIX from the command line cmake options. +if(WIN32 AND NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "C:/Program Files/srcML" CACHE PATH "Set Windows install dir" FORCE) +endif() # Set libsrcml version from src/libsrcml/srcml.h -# Extract this first because manually setting major, minor, and patch leads to bugs +# Extract this before project() because manually setting major, minor, and patch leads to bugs file(STRINGS "${CMAKE_SOURCE_DIR}/src/libsrcml/srcml.h" SRCML_HEADER REGEX "SRCML_VERSION_STRING") string(REGEX MATCH "\"([0-9.]+)\"" _ "${SRCML_HEADER}") @@ -30,65 +32,17 @@ project(srcML VERSION "${CMAKE_MATCH_1}" HOMEPAGE_URL "https://www.srcML.org") message(STATUS "Project version: ${PROJECT_VERSION}") -# Turn ON/OFF tests -option(BUILD_CLIENT_TESTS "Build srcml client tests" ON) -option(BUILD_LIBSRCML_TESTS "Build unit tests for libsrcml" OFF) -option(BUILD_PARSER_TESTS "Include tests for parser" OFF) - -# Turn ON building all tests -option(BUILD_ALL_TESTS "Build all tests" OFF) -if(BUILD_ALL_TESTS) - set(BUILD_CLIENT_TESTS ON) - set(BUILD_LIBSRCML_TESTS ON) - set(BUILD_PARSER_TESTS ON) -endif() - -# Turn ON/OFF building examples -option(BUILD_EXAMPLES "Build examples usage files for libsrcml" OFF) - -# Turn ON/OFF building documentation -option(BUILD_CLIENT_DOC "Build client documentation" OFF) -option(INSTALL_CLIENT_DOC "Install (but do not build) client documentation" OFF) -option(BUILD_LIBSRCML_DOC "Build libsrcml documentation" OFF) -if(NOT BUILD_CLIENT_DOC) - set(INSTALL_CLIENT_DOC ON) -endif() - -# Turn ON building all documentation -option(BUILD_ALL_DOCS "Build all documentation" OFF) -if(BUILD_ALL_DOCS) - set(BUILD_CLIENT_DOC ON) - set(BUILD_LIBSRCML_DOC ON) -endif() - # Turn ON everything option(BUILD_ALL "Build all test, documentation, and examples" OFF) -if(BUILD_ALL) - set(BUILD_ALL_TESTS ON) - set(BUILD_EXAMPLES ON) - set(BUILD_ALL_DOCS ON) -endif() - -# Build options -option(BUILD_LIBSRCML_STATIC "Build a static version of libsrcml" ON) -option(LINK_LIBSRCML_STATIC "Link srcml client, tests, and examples with static version of libsrcml" OFF) # The default configuration is to compile in Release mode if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) endif() -# Dynamic Load libraries (Unix only) -if(NOT WIN32) - option(DYNAMIC_LOAD_ENABLED "Dynamically load some libraries such as libxslt and libexslt" ON) -endif() - -enable_testing() -include(CTest) - # Determine distribution # Does not work for all distributions, but does work for supported Linux distributions -if(EXISTS /etc/os-release) +if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux") file(STRINGS /etc/os-release DISTRO REGEX "^NAME=") endif() @@ -101,6 +55,9 @@ endif() # used as defaults for installation and packaging include(GNUInstallDirs) +# Call at root so testing can be run at root +enable_testing() + add_subdirectory(src) add_subdirectory(test) add_subdirectory(doc) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000000..f952fbaf32 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,266 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 24, + "patch": 0 + }, + "configurePresets": [ + { + "name": "ubuntu-release", + "displayName": "Ubuntu Release", + "description": "Default build options for Ubuntu release", + "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Linux" }, + "inherits": ["gcc-release"] + }, + { + "name": "rpm-release", + "displayName": "GCC Release", + "description": "Default build options for GCC release", + "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Linux" }, + "inherits": ["gcc-release"] + }, + { + "name": "macos-release", + "inherits": ["clang-release"], + "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Darwin" }, + "displayName": "macOS Release", + "description": "Default build options for macOS release", + "cacheVariables": { + // "CPACK_GENERATOR": "productbuild;TGZ;TBZ2", + // Making the exported_symbols_list an empty file reduces size of executable, as strip does not work + "SRCML_CLIENT_LINK_FLAGS": "-exported_symbols_list /dev/null", + "CMAKE_BUILD_TYPE": "Release", + // Build for both x86 and arm64 + "CMAKE_OSX_ARCHITECTURES": "x86_64;arm64", + "CMAKE_OSX_DEPLOYMENT_TARGET": "10.15" + } + }, + { + "name": "msvc", + "displayName": "MSVC", + "description": "Default build options for MSVC", + "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" }, + "toolchainFile": "toolchain-msvc.cmake", + "cacheVariables": { + "CMAKE_CXX_COMPILER": "cl", + "CMAKE_C_COMPILER": "cl", + // /Wall + // /D_CRT_SECURE_NO_WARNINGS # disable strcpy() warnings + // /D_CRT_NONSTDC_NO_WARNINGS # disable read() warnings + // /wd4068 # unknown pragma + // # /wd4101 # unreferenced local variable + // # /wd4519 # unmarked inlining notification warning + // /wd4514 # removed inline function not called (in one context) + // # /wd4668 # preprocessor symbol not defined but used in an #if + // /wd4710 # unmarked inlining notification warning + // /wd4820 # byte padding + // /wd5039 # pointer or reference to potentially throwing function passed to 'extern "C"' function under -EHc + // /wd4711 # selected for automatic inline expansion + // /wd4706 # assigment within conditional expression + // /wd4625 # copy constructor was implicitly defined as deleted + // /wd4626 # assignment operator was implicitly defined as deleted + // /wd5026 # move constructor was implicitly defined as deleted + // /wd5027 # move assignment operator was implicitly defined as deleted + // /wd4668 # is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' + // /wd4868 # compiler may not enforce left-to-right evaluation order in braced initializer list + // /wd4371 # layout of class may have changed from a previous version of the compiler due to better packing of member + // /wd4623 # default constructor was implicitly defined as deleted + // /wd5045 # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified + "CMAKE_CXX_FLAGS": "/Wall /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS /wd4068 /wd4514 /wd4710 /wd4820 /wd5039 /wd4711 /wd4706 /wd4625 /wd4626 /wd5026 /wd5027 /wd4668 /wd4868 /wd4371 /wd4623 /wd5045 ", + // With MSVC, interprocedural optimization leads to a 10x static library, with only a slight reduction in size for the dynamic library + // /wd4355 # 'this' used in base member initializer list + // /wd4866 # compiler may not enforce left-to-right evaluation order for call to 'operator<<' + // /wd5204 # 'Concurrency::details::_DefaultPPLTaskScheduler': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly + // /wd5264 # 'int const `void __cdecl srcml_display_metadata(srcml_request_t const &,std::vector > const &,srcml_input_src const &)'::`2'::display_commands': 'const' variable is not used + // /wd4577 # 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc + "SRCML_GLOBAL_COMPILE_OPTIONS": "/wd4355;/wd4866;/wd5204;/wd5264;/wd4577", + "SRCML_GLOBAL_LINK_OPTIONS": "", + // /wd4242 # 'argument': conversion from 'T' to '_Elem', possible loss of data + // /wd4244 # 'argument': conversion from '' to '', possible loss of data + // /wd4267 # 'return': conversion from 'size_t' to 'unsigned int', possible loss of data + // /wd4355 # this': used in base member initializer list + // /wd4365 # 'argument': conversion from 'size_t' to 'const __int64', signed/unsigned mismatch + // # conversion from 'int' to 'unsigned int', + // /wd4477 # 'sprintf' : format string '%u' requires an argument of type 'unsigned int', but variadic argument 1 has type 'size_t' + // /wd4530 # C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc + // /wd4577 # 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc + "SRCML_ANTLR_DISABLED_WARNINGS": "/wd4242;/wd4244;/wd4267;/wd4355;/wd4365;/wd4477;/wd4530;/wd4577", + // /wd4267 # 'return': conversion from 'size_t' to 'unsigned int', possible loss of data + // /wd4365 # 'argument': conversion from 'size_t' to 'const __int64', signed/unsigned mismatch + // # conversion from 'int' to 'unsigned int', + // /wd4459 # declaration of 'context' hides global declaration + // /wd4530 # C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc + // /wd4577 # 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc + // /wd4701 # potentially uninitialized local variable '...' used + // /wd5262 # implicit fall-through occurs here; are you missing a break statement? Use [[fallthrough]] when a break statement is intentionally omitted between cases + // /wd5264 # 'int const `char const * __cdecl `anonymous namespace'::positoa(int)'::`2'::SIZE': 'const' variable is not used + "SRCML_PARSER_DISABLED_WARNINGS": "/wd4267;/wd4365;/wd4459;/wd4530;/wd4577;/wd4701;/wd5262;/wd5264", + "SRCML_LIBSRCML_COMPILE_FLAGS": "/Zi", + "SRCML_LIBSRCML_SHARED_LINK_FLAGS_RELEASE": "/DEBUG /OPT:REF /OPT:ICF", + "SRCML_LIBSRCML_STATIC_LINK_FLAGS_RELEASE": "/LTCG:OFF", + // wd4355 # this': used in base member initializer list + // wd5204 # class has virtual functions, but its trivial destructor is not virtual + "SRCML_CLIENT_COMPILE_FLAGS": "/wd4355;/wd5204", + "SRCML_CLIENT_LINK_FLAGS": "" + } + }, + { + "name": "ccache", + "hidden": true, + "description": "ccache setup", + "cacheVariables": { + "CMAKE_CXX_COMPILER_LAUNCHER": "ON" + } + }, + { + "name": "linux", + "description": "Default build options for Linux", + "hidden": true, + "generator": "Ninja", + "cacheVariables": { + "CMAKE_CXX_FLAGS": "-Wall -Wextra -pedantic", + // "CMAKE_INTERPROCEDURAL_OPTIMIZATION": "ON", + "SRCML_ANTLR_DISABLED_WARNINGS": "-Wno-format;-Wno-misleading-indentation;-Wno-deprecated-declarations", + "SRCML_PARSER_DISABLED_WARNINGS": "-Wno-unused-but-set-variable" + } + }, + { + "name": "pch", + "description": "Use PCH", + "hidden": true, + "cacheVariables": { + // Determined via clang-trace + "SRCML_CLIENT_PCH": ";;;;;;;;;", + "SRCML_LIBSRCML_PCH": ";;;;", + "SRCML_PARSER_PCH": " " + } + }, + { + "name": "gcc", + "inherits": ["linux"], + "displayName": "GCC", + "description": "Default build options for GCC", + "toolchainFile": "toolchain-gcc.cmake", + "cacheVariables": { + "SRCML_LIBSRCML_LINK_FLAGS": "-Wl,--version-script=${sourceDir}/src/libsrcml/libsrcml.version" + } + }, + { + "name": "gcc-release", + "inherits": ["gcc"], + "displayName": "GCC Release", + "description": "Default build options for GCC release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "clang", + "inherits": ["linux"], + "displayName": "Clang", + "description": "Default build options for Clang", + "cacheVariables": { + "SRCML_LIBSRCML_LINK_FLAGS": "-Wl,-exported_symbols_list ${sourceDir}/src/libsrcml/export_list" + } + }, + { + "name": "clang-trace", + "inherits": ["clang"], + "displayName": "Clang Trace", + "description": "Default build options for Clang trace", + "cacheVariables": { + "CMAKE_C_FLAGS": "-ftime-trace", + "CMAKE_CXX_FLAGS": "-ftime-trace" + } + }, + { + "name": "macos-universal", + "displayName": "macOS Universal Binary", + "description": "Universal binary for macOS", + "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Darwin" }, + "hidden": true, + "cacheVariables": { + // Build for both x86 and arm64 + "CMAKE_OSX_ARCHITECTURES": "x86_64;arm64" + } + }, + { + "name": "clang-release", + "inherits": ["clang"], + "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Darwin" }, + "displayName": "Clang Release", + "description": "Default build options for Clang release", + "cacheVariables": { + "CPACK_GENERATOR": "productbuild;TGZ;TBZ2", + // Making the exported_symbols_list an empty file reduces size of executable, as strip does not work + "SRCML_CLIENT_LINK_FLAGS": "-exported_symbols_list /dev/null", + "CMAKE_BUILD_TYPE": "Release", + "SRCML_GLOBAL_COMPILE_OPTIONS": "-flto", + "SRCML_GLOBAL_LINK_OPTIONS": "-flto;-dead_strip" + } + }, + { + "name": "clang-release-ccache", + "inherits": ["clang-release", "ccache"], + "displayName": "Clang Release ccache", + "description": "Default build options for Clang release with ccache" + }, + { + "name": "vcpkg", + "hidden": true, + "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + }, + { + "name": "macos-vcpkg", + "inherits": ["clang-release", "vcpkg"], + "cacheVariables": { + // "PKG_CONFIG_EXECUTABLE": "/usr/bin/true" + } + } + ], + "packagePresets": [ + { + "name": "rpm", + "configurePreset": "rpm-release", + "generators": [ "RPM", "TGZ", "TBZ2" ], + "configurations": [ "Release" ] + }, + { + "name": "deb", + "configurePreset": "ubuntu-release", + "generators": [ "DEB", "TGZ", "TBZ2" ], + "configurations": [ "Release" ] + }, + { + "name": "macos", + "configurePreset": "macos-release", + "generators": [ "productbuild", "TGZ", "TBZ2" ], + "configurations": [ "Release" ] + }, + { + "name": "msvc", + "configurePreset": "msvc", + "generators": [ "WIX", "INNOSETUP", "NuGet", "ZIP" ], + "configurations": [ "Release" ] + }, + { + "name": "msvc-wix", + "configurePreset": "msvc", + "generators": [ "WIX", "ZIP" ], + "configurations": [ "Release" ] + }, + { + "name": "msvc-inno", + "configurePreset": "msvc", + "generators": [ "INNOSETUP", "ZIP" ], + "configurations": [ "Release" ] + }, + { + "name": "msvc-nuget", + "configurePreset": "msvc", + "generators": [ "NuGet", "ZIP" ], + "configurations": [ "Release" ] + } + ] +} diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 684342d6da..b58cdebfe9 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1,24 +1,26 @@ +# SPDX-License-Identifier: GPL-3.0-only ## # @file CMakeLists.txt # # @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) # -# The srcML Toolkit is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcML Toolkit is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcML Toolkit; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# # CMake files for documentation +# Turn ON/OFF building documentation +option(BUILD_CLIENT_DOC "Build client documentation" OFF) +option(INSTALL_CLIENT_DOC "Install (but do not build) client documentation" OFF) +option(BUILD_LIBSRCML_DOC "Build libsrcml documentation" OFF) +if(NOT BUILD_CLIENT_DOC) + set(INSTALL_CLIENT_DOC ON) +endif() + +# Turn ON building all documentation +option(BUILD_ALL_DOCS "Build all documentation" OFF) +if(BUILD_ALL OR BUILD_ALL_DOCS) + set(BUILD_CLIENT_DOC ON) + set(BUILD_LIBSRCML_DOC ON) +endif() + if(BUILD_CLIENT_DOC OR INSTALL_CLIENT_DOC) add_subdirectory(manpage) endif() diff --git a/doc/doxygen/CMakeLists.txt b/doc/doxygen/CMakeLists.txt index caa8da95f2..2237d36739 100644 --- a/doc/doxygen/CMakeLists.txt +++ b/doc/doxygen/CMakeLists.txt @@ -1,22 +1,9 @@ +# SPDX-License-Identifier: GPL-3.0-only ## # @file CMakeLists.txt # # @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) # -# The srcML Toolkit is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcML Toolkit is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcML Toolkit; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# # CMake files for doxygen documentation find_package(Doxygen REQUIRED) diff --git a/doc/manpage/CMakeLists.txt b/doc/manpage/CMakeLists.txt index bf339f70c3..144957ff2b 100644 --- a/doc/manpage/CMakeLists.txt +++ b/doc/manpage/CMakeLists.txt @@ -1,22 +1,9 @@ +# SPDX-License-Identifier: GPL-3.0-only ## # @file CMakeLists.txt # # @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) # -# The srcML Toolkit is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcML Toolkit is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcML Toolkit; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# # CMake files for the client manpage add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/srcml.1.gz @@ -40,9 +27,10 @@ endif() # Requires permission by default user add_custom_target(publish_manpage COMMAND rsync --inplace ${CMAKE_BINARY_DIR}/srcml.1.gz gehry.sdml.cs.kent.edu:/var/www/html/sdml/build/${REMOTE_MANPAGE_NAME}) -find_program(RONN_EXE REQUIRED NAMES ronn ronn.exe PATHS /bin /usr/bin ~/gems/bin/ronn ${WINDOWS_DEP_PATH}/bin) +find_program(PANDOC_EXE REQUIRED NAMES pandoc pandoc.exe) # Configure file properties used to configure the file srcml.cfg +set(CLIENT_VERSION "1.0.0") set(HELP_FLAG_LONG "help") set(HELP_FLAG_SHORT "h") set(VERSION_FLAG_LONG "version") @@ -134,17 +122,22 @@ set(STATUS_ERROR "1") set(STATUS_INTERNAL_ERROR "2") set(PRETTY_FLAG_LONG "pretty") -# Custom commands for creating things using the ronn executable +set(NULL_SEPARATOR_LONG "print0") +set(NULL_SEPARATOR_SHORT "Z") + +# Custom commands for creating things using pandoc configure_file(${CMAKE_SOURCE_DIR}/doc/manpage/srcml.cfg ${CMAKE_BINARY_DIR}/srcml.md) add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/srcml.1 - COMMAND ${RONN_EXE} ${CMAKE_BINARY_DIR}/srcml.1.md --manual=srcml + COMMAND ${PANDOC_EXE} -s -t man ${CMAKE_BINARY_DIR}/srcml.1.md --output ${CMAKE_BINARY_DIR}/srcml.1 + COMMENT Generating ${CMAKE_BINARY_DIR}/srcml.1 DEPENDS ${CMAKE_BINARY_DIR}/srcml.1.md ) configure_file(${CMAKE_SOURCE_DIR}/doc/manpage/srcml.cfg ${CMAKE_BINARY_DIR}/srcml.1.md) add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/srcml.html - COMMAND ${RONN_EXE} ${CMAKE_BINARY_DIR}/srcml.md --manual=srcml - DEPENDS ${CMAKE_BINARY_DIR}/srcml.md + COMMAND ${PANDOC_EXE} -s -t html ${CMAKE_BINARY_DIR}/srcml.1.md --output ${CMAKE_BINARY_DIR}/srcml.html + COMMENT Generating ${CMAKE_BINARY_DIR}/srcml.html + DEPENDS ${CMAKE_BINARY_DIR}/srcml.1.md ) add_custom_target(doc_manpage ALL DEPENDS ${CMAKE_BINARY_DIR}/srcml.1.gz ${CMAKE_BINARY_DIR}/srcml.html) diff --git a/doc/manpage/srcml.cfg b/doc/manpage/srcml.cfg index 76af9730cd..b9660a9f53 100644 --- a/doc/manpage/srcml.cfg +++ b/doc/manpage/srcml.cfg @@ -1,14 +1,15 @@ -## NAME +% SRCML(1) srcml ${CLIENT_VERSION} | srcml -**srcml** - Conversion of source code to/from the srcML format, querying and manipulation of srcML +# NAME +**srcml** - Conversion of source code to/from the srcML format, querying and manipulation of srcML -## SYNOPSIS +# SYNOPSIS `srcml` \[[general-options\]][GENERAL OPTIONS] \[[srcML-options\]][CREATING SRCML] \[[transformations\]][TRANSFORMATIONS] \[[output-src-options\]][EXTRACTING SOURCE CODE] \[input\] \[output\] -## DESCRIPTION +# DESCRIPTION The program `srcml` supports the srcML format. The srcML format presents an XML view of source code for addressing, querying, and transformation. @@ -29,7 +30,7 @@ Use of the character '-' in the place of an input file, or providing no input file, implies reading from standard input. A source-code language must be specified when source-code input is from standard input. -## GENERAL OPTIONS +# GENERAL OPTIONS `-${HELP_FLAG_SHORT}`, `--${HELP_FLAG_LONG}` : Output the help and exit. @@ -45,13 +46,13 @@ a directory, or source-code archive (e.g., tar.gz). `-${QUIET_FLAG_SHORT}`, `--${QUIET_FLAG_LONG}` : Suppresses status messages. -`-${OUTPUT_FLAG_SHORT}` , `--${OUTPUT_FLAG_LONG}`= -: Write the output to . By default, it writes to standard output. +`-${OUTPUT_FLAG_SHORT}` _file_, `--${OUTPUT_FLAG_LONG}`=_file_ +: Write the output to _file_. By default, it writes to standard output. -`-${JOBS_FLAG_SHORT}` , `--${JOBS_FLAG_LONG}`= -: Allow up to threads for source parsing. Default is 4. +`-${JOBS_FLAG_SHORT}` _num_, `--${JOBS_FLAG_LONG}`=_num_ +: Allow up to _num_ threads for source parsing. Default is 4. -## CREATING SRCML +# CREATING SRCML The following options are to create srcML. The format of the input affects the format of the output unless otherwise specified. @@ -59,21 +60,21 @@ If the input is source-code files, then the output is expected to be in srcML format. If the input is in srcML format, then the output is in source-code format. -`-${TEXT_FLAG_SHORT}` , `--${TEXT_FLAG_LONG}`= -: Input the string as source code. +`-${TEXT_FLAG_SHORT}` _text_, `--${TEXT_FLAG_LONG}`=_text_ +: Input the _text_ string as source code. Useful for short text input. Common escape sequences in C and echo are expanded, including \n, \t, \a, \b, \v, \e \xHH where H is 1 to 2 hex values, and \NNN and \0NNN where N is 1 to 3 octal digits. -`--${FILES_FROM_LONG}`= -: Treat the input as a list of source files. +`--${FILES_FROM_LONG}`=_file_ +: Treat the input _file_ as a list of source files. Each file is separately translated and collectively stored into a single srcML archive. The list has a single filename on each line. Ignored lines include blank lines and lines that begin with the character '\#'. As with input and output files, using the character '-' in place of a file name takes the input list from standard input. -`-${LANGUAGE_FLAG_SHORT}` , `--${LANGUAGE_FLAG_LONG}`= +`-${LANGUAGE_FLAG_SHORT}` _language_, `--${LANGUAGE_FLAG_LONG}`=_language_ : Set the programming language of the input source code. Allowable values are C, C++, C\#, and Java. The language affects parsing, the allowed markup, and what is considered a keyword. The value is also stored @@ -88,22 +89,22 @@ program will skip that file. This allows you to run `srcml` on a project directory with source and non-source files, where `srcml` only parses files with supported extensions. -`--${REGISTER_EXTENSION_FLAG_LONG}` = -: Set the file map to a given . Note +`--${REGISTER_EXTENSION_FLAG_LONG}` _extension_=_language_ +: Set the file _extension_ map to a given _language_. Note that the extensions do not contain the period character '.', e.g., `--register-ext "h=C++"` A common use is C++ files that use the .h extension for header files. By default, these are processed as C source-code files. This option can be used to override this behavior. -`--${SRC_ENCODING_FLAG_LONG}`= -: Use the when processing the input source-code file. The +`--${SRC_ENCODING_FLAG_LONG}`=_encoding_ +: Use the _encoding_ when processing the input source-code file. The default is to try to automatically determine this when possible, i.e., ISO-8859-1 is assumed unless a non-character is detected. Encodings include "UTF-16", "ISO-10646-UCS-2", and "ISO-8859-1". On UNIX platforms, a full list of encodings can be obtained by using the command `iconv -l`. -`--${EOL_FLAG_LONG}`= -: Use the for output of source code. Allowable values are the default `auto`, 'UNIX' or linefeed `lf`, +`--${EOL_FLAG_LONG}`=_eol_ +: Use the _eol_ for output of source code. Allowable values are the default `auto`, 'UNIX' or linefeed `lf`, carriage return `cr`, and 'Windows' or carriage return, linefeed `crlf`. In most cases the default `auto` is sufficient. @@ -127,7 +128,7 @@ any namespaces or attributes on the archive root element, and is technically not : Output the XML inside of the srcML unit element. This is not valid XML as it contains no namespace declarations and does not necessarily have a single root element. -### Examples +## Examples srcml --text="a;" -l C++ --output-srcml-outer @@ -150,7 +151,7 @@ ${TABS_FLAG}. "${SRCML_EXT_POSITION_NS_PREFIX_DEFAULT}" in the namespace "${SRCML_EXT_POSITION_NS_URL}", e.g., `` -`--${TABS_FLAG}`= +`--${TABS_FLAG}`=_tabsize_ : Set the tab size. Default is 8. Use of this option automatically turns on the position attributes. @@ -176,7 +177,7 @@ The default is to markup these regions. The following options control the format of the XML. -`--${XML_ENCODING_FLAG_LONG}`= +`--${XML_ENCODING_FLAG_LONG}`=_encoding_ : Use the encoding for the output srcML file. The default is UTF-8. Possible encodings can be obtained by using the command `iconv -l` on UNIX platforms. The encoding is stored on the XML declaration. @@ -191,12 +192,12 @@ indicated in the srcML document by the declaration of the specific extension namespace. These flags make it easier to declare, and are an alternative way to turn on options by declaring the URL for an option. -`--${XMLNS_FLAG}`= -: Set the for the default namespace. The predefined URL is: +`--${XMLNS_FLAG}`=_url_ +: Set the _url_ for the default namespace. The predefined URL is: `--${XMLNS_FLAG}=${SRCML_SRC_NS_URL}` -`--${XMLNS_FLAG}:`= +`--${XMLNS_FLAG}:`_prefix_=_url_ : Set the namespace prefix PREFIX for the namespace URL. There is a set of standard URLs for the elements in srcML, each with a predefined prefix. The predefined URLs and prefixes are: @@ -247,22 +248,22 @@ then exit. `--${SHOW_UNIT_COUNT_FLAG_LONG}` : Display the unit count and exit. -`--${PREFIX_FLAG_LONG}`= -: Display a prefix given by a and exit. +`--${PREFIX_FLAG_LONG}`=_url_ +: Display a prefix given by a _url_ and exit. The following options allow the user to control the attributes: -`-${FILENAME_FLAG_SHORT}` , `--${FILENAME_FLAG_LONG}`= +`-${FILENAME_FLAG_SHORT}` _filename_, `--${FILENAME_FLAG_LONG}`=_filename_ : The value of the filename attribute is typically obtained from the input filename. This option allows you to specify a different filename for standard input or where the filename is not contained in the input path. -`--${URL_FLAG_LONG}`= +`--${URL_FLAG_LONG}`=_url_ : The url attribute on the root element can be defined. This is purely descriptive and has no interpretation by `srcml`. It is useful for specifying a directory or defining the source protocol. -`-${SRCVERSION_FLAG_SHORT}` , `--${SRCVERSION_FLAG_LONG}`= +`-${SRCVERSION_FLAG_SHORT}` _version_, `--${SRCVERSION_FLAG_LONG}`=_version_ : Set the value of the attribute version to version. This is a purely-descriptive attribute, where the value has no interpretation by `srcml`. The attribute is applied to the root element, and in the case @@ -278,7 +279,7 @@ working with srcML archives. time of the input source-code archive. This is the last modified time based on the archive files. -### EXAMPLES +## EXAMPLES srcml input.cpp : Create a srcML unit from input.cpp, using C++ parsing rules, @@ -306,18 +307,21 @@ rules as well as C++ parsing rules for preprocessor directives. The following describe options that are only applicable for when the output is in source-code format. -`-${UNIT_OPTION_SHORT}` , `--${UNIT_OPTION_LONG}` -: Extract individual th unit from srcML archive. +`-${UNIT_OPTION_SHORT}` _n_, `--${UNIT_OPTION_LONG}` _n_ +: Extract individual _n_-th unit from srcML archive. `-${OUTPUT_SRC_FLAG_SHORT}`, `--${OUTPUT_SRC_FLAG_LONG}` : Output source code. This is the default when the input is in srcML. -`--${TO_DIR_FLAG_LONG}`= +`--${TO_DIR_FLAG_LONG}`=_directory_ : Extract all files from srcML and create them in the file system at -. +_directory>_ + +`-${NULL_SEPARATOR_SHORT}`, `--${NULL_SEPARATOR_LONG}` +: Separates each source code unit with an ASCII NULL ('\0') -### EXAMPLES +## EXAMPLES srcml dir/ -${OUTPUT_FLAG_SHORT} dir.xml : Create a srcML archive from all files contained in the dir directory, using @@ -330,10 +334,10 @@ directory as the root directory. ## TRANSFORMATIONS -`--${XPATH_OPTION_LONG}=` -: Query each individual unit using the Xpath . +`--${XPATH_OPTION_LONG}=`_expression_ +: Query each individual unit using the XPath _expression_. Multiple XPath expression options allowed. -The default prefix cannot be used in Xpath expressions. Element names must have a prefix, e.g., `src`, `cpp`, etc. If path from the root is not given, i.e., '//...' or '/src:unit/..', context is assumed to the '//', e.g., 'src:name' is the same as '//src:name', and 'count(src:name)' is the same as 'count(//src:name)'. +The default prefix cannot be used in XPath expressions. Element names must have a prefix, e.g., `src`, `cpp`, etc. Path from the root is required. By default, the result is a srcML archive where each unit is a query result, marked with the original filename. As an alternative, the original srcML can be preserved with the query results marked with an attribute, wrapped with an element, or both. Note that the prefix and url used for the namespace must be declared with the option `--${XMLNS_FLAG}:`. @@ -344,17 +348,17 @@ must be declared with the option `--${XMLNS_FLAG}:`. `--${ELEMENT_LONG}` _prefix:name_ : Wrap every Xpath expression result with an element of the form _prefix:name_. May be mixed with `--${ATTRIBUTE_LONG}`. -`--${XSLT_LONG}` -: Apply a transformation from an XSLT or to each individual unit. +`--${XSLT_LONG}` _file_|_url_ +: Apply a transformation from an XSLT _file_ or _url_ to each individual unit. -`--${XSLT_PARAM}` _name_="" -: Pass the string parameter _name_ with UTF-8 encoded string to the XSLT program +`--${XSLT_PARAM}` _name_="_value_" +: Pass the string parameter _name_ with UTF-8 encoded string _value_ to the XSLT program -`--${RELAXNG_OPTION_LONG}`= -: Output individual units that match the RELAXNG or . +`--${RELAXNG_OPTION_LONG}`=_file_|_url_ +: Output individual units that match the RELAXNG _file_ or _url_. -### EXAMPLES +## EXAMPLES srcml a.cpp --${XPATH_OPTION_LONG}="//src:name" --${ATTRIBUTE_LONG}="q:foo=test" --${XMLNS_FLAG}:q=mysite.net @@ -367,9 +371,11 @@ of each unit in the archive to standard out. ## RETURN STATUS -* ${STATUS_SUCCESS}: Normal -* ${STATUS_ERROR}: General error -* ${STATUS_INTERNAL_ERROR}: Internal error +${STATUS_SUCCESS}: Normal + +${STATUS_ERROR}: General error + +${STATUS_INTERNAL_ERROR}: Internal error ## CAVEATS @@ -396,7 +402,7 @@ and Heather Michaud. ## COPYRIGHT -Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) +Copyright (C) 2013-2023 srcML, LLC. (www.srcML.org) The srcML Toolkit is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b441b97dff..425dc0bda8 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,22 +1,15 @@ +# SPDX-License-Identifier: GPL-3.0-only ## # @file CMakeLists.txt # # @copyright Copyright (C) 2014-2019 srcML, LLC. (www.srcML.org) # -# The srcML Toolkit is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcML Toolkit is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcML Toolkit; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# # CMake files for examples +# Turn ON/OFF building examples +option(BUILD_EXAMPLES "Build examples usage files for libsrcml" OFF) +if(BUILD_ALL) + set(BUILD_EXAMPLES ON) +endif() + add_subdirectory(libsrcml) diff --git a/examples/libsrcml/CMakeLists.root.txt.in b/examples/libsrcml/CMakeLists.root.txt.in new file mode 100644 index 0000000000..93e0224697 --- /dev/null +++ b/examples/libsrcml/CMakeLists.root.txt.in @@ -0,0 +1,23 @@ +## +# @file CMakeLists.txt +# + +# Any more recent cmake can be specified +cmake_minimum_required(VERSION 3.11) + +project(srcML-Examples) + +# Produces the target srcML::LibsrcML +# Can also specify components. The default component is shared +# find_package(srcml COMPONENT shared REQUIRED) +# find_package(srcml COMPONENT static REQUIRED) +find_package(srcML REQUIRED) + +set(CMAKE_CXX_STANDARD 11) + +# Copy data files for examples +file(COPY decl_stmt.cpp expr.cpp define.cpp project.xml schema.rng copy.xsl DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") + +# Add each executable as a separate program +# For each target, add the srcML::LibsrcML library +add_custom_target(run) diff --git a/examples/libsrcml/CMakeLists.txt b/examples/libsrcml/CMakeLists.txt index c0402ee553..d9b9b0c147 100644 --- a/examples/libsrcml/CMakeLists.txt +++ b/examples/libsrcml/CMakeLists.txt @@ -1,40 +1,93 @@ +# SPDX-License-Identifier: GPL-3.0-only ## # @file CMakeLists.txt # -# @copyright Copyright (C) 2014-2019 srcML, LLC. (www.srcML.org) -# -# The srcML Toolkit is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcML Toolkit is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcML Toolkit; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# @copyright Copyright (C) 2014-2023 srcML, LLC. (www.srcML.org) # # CMake files for libsrcml examples -# add examples -file(GLOB EXAMPLES "srcml_*.c") +cmake_minimum_required(VERSION 3.24) + +project(srcML-Examples-libsrcml) + +if(SRCML_TEST_INSTALLED OR NOT TARGET srcML::LibsrcML) + find_package(srcml REQUIRED) +endif() + +# Install directory for libsrcml examples +set(LIBSRCML_EXAMPLES_DIRECTORY share/srcml/examples/libsrcml) + +# Build examples directory +set(EXAMPLE_ROOT "${CMAKE_BINARY_DIR}/examples/libsrcml/") + +# Example files +set(TEST_FILES "decl_stmt.cpp;expr.cpp;define.cpp;project.xml;schema.rng;copy.xsl") + +# Setup the examples +# * Create directory with example +# * Generate CMakeLists.txt customized for that example +# * Copy any test files used by the example +# * Append to the CMakeLists.txt commands to copy test files to the binary +file(GLOB EXAMPLES "srcml_*.cpp") +foreach(EXAMPLE IN ITEMS ${EXAMPLES}) + get_filename_component(EXAMPLE_NAME "${EXAMPLE}" NAME_WE) -install(FILES ${EXAMPLES} DESTINATION share/srcml/examples COMPONENT EXAMPLES) + set(EXAMPLE_DIR "${EXAMPLE_ROOT}/${EXAMPLE_NAME}") -if(BUILD_EXAMPLES) + # Create a directory for each example + file(MAKE_DIRECTORY "${EXAMPLE_DIR}") - set(CMAKE_C_STANDARD 99) + # Copy the example source file into its directory + file(COPY ${EXAMPLE} DESTINATION "${EXAMPLE_DIR}") - foreach(EXAMPLE ${EXAMPLES}) - get_filename_component(EXAMPLE_NAME ${EXAMPLE} NAME_WE) - add_executable(${EXAMPLE_NAME} ${EXAMPLE}) - target_include_directories(${EXAMPLE_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/libsrcml) - target_link_libraries(${EXAMPLE_NAME} libsrcml_link) - set_target_properties(${EXAMPLE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + # Customize a CMakeLists.txt for each example + configure_file(CMakeLists.txt.in "${EXAMPLE_DIR}/CMakeLists.txt") + + get_filename_component(EXAMPLE_NAME "${EXAMPLE_DIR}" NAME) + + # Copy test files if they are used + set(ADD_COPY_TESTFILES "") + foreach(TESTFILE IN ITEMS ${TEST_FILES}) + # Copy file if used + file(STRINGS "${EXAMPLE}" TESTFILE_FOUND REGEX "${TESTFILE}") + if(TESTFILE_FOUND) + file(COPY ${TESTFILE} DESTINATION "${EXAMPLE_DIR}") + string(APPEND ADD_COPY_TESTFILES "file(COPY ${TESTFILE} DESTINATION \${CMAKE_BINARY_DIR})\n") + endif() endforeach() + if(NOT ADD_COPY_TESTFILES STREQUAL "") + file(APPEND "${EXAMPLE_DIR}/CMakeLists.txt" + "\n# Copy data files\n" + "${ADD_COPY_TESTFILES}\n" ) + endif() -endif() + # Install this example subdirectory + install(DIRECTORY "${EXAMPLE_DIR}" DESTINATION "${LIBSRCML_EXAMPLES_DIRECTORY}" COMPONENT DEVLIBS) + +endforeach() + +# Create an overall CMake project in the example root directory +file(COPY_FILE "CMakeLists.root.txt.in" "${EXAMPLE_ROOT}/CMakeLists.txt") + +# Copy/install the example files +file(COPY ${TEST_FILES} DESTINATION "${EXAMPLE_ROOT}") +install(FILES ${TEST_FILES} DESTINATION "${LIBSRCML_EXAMPLES_DIRECTORY}" COMPONENT DEVLIBS) + +# Append to the build file for each example +foreach(EXAMPLE IN ITEMS ${EXAMPLES}) + + # Base filename + get_filename_component(EXAMPLE_NAME "${EXAMPLE}" NAME_WE) + + # Add test to overall build + file(APPEND "${EXAMPLE_ROOT}/CMakeLists.txt" + "# Example ${EXAMPLE_NAME}\n" + "add_executable(${EXAMPLE_NAME} ${EXAMPLE_NAME}/${EXAMPLE_NAME}.cpp)\n" + "target_link_libraries(${EXAMPLE_NAME} PRIVATE srcML::LibsrcML)\n" + "add_custom_target(run_${EXAMPLE_NAME} COMMAND $ DEPENDS ${EXAMPLE_NAME} USES_TERMINAL)\n" + "add_dependencies(run run_${EXAMPLE_NAME})\n\n") + +endforeach() +# Install the CMake build file for all of the examples +install(FILES "${EXAMPLE_ROOT}/CMakeLists.txt" DESTINATION "${LIBSRCML_EXAMPLES_DIRECTORY}" COMPONENT DEVLIBS) diff --git a/examples/libsrcml/CMakeLists.txt.in b/examples/libsrcml/CMakeLists.txt.in new file mode 100644 index 0000000000..eed1671866 --- /dev/null +++ b/examples/libsrcml/CMakeLists.txt.in @@ -0,0 +1,23 @@ +## +# @file CMakeLists.txt + +# Any more-recent cmake can be specified +cmake_minimum_required(VERSION 3.11) + +project(${EXAMPLE_NAME}) + +# Produces the target srcML::LibsrcML +# Can also specify a component for shared (default) or static +# find_package(srcML COMPONENTS shared REQUIRED) +# find_package(srcML COMPONENTS static REQUIRED) +find_package(srcML REQUIRED) + +# Create the executable ${EXAMPLE_NAME} +add_executable(${EXAMPLE_NAME} ${EXAMPLE_NAME}.cpp) + +# Add the srcML::LibsrcML library +# This gives access to srcml.h and either the shared or static libsrcml library +target_link_libraries(${EXAMPLE_NAME} PRIVATE srcML::LibsrcML) + +# Add run command +add_custom_target(run COMMAND $ DEPENDS ${EXAMPLE_NAME} USES_TERMINAL) diff --git a/examples/libsrcml/README.md b/examples/libsrcml/README.md new file mode 100644 index 0000000000..1a9fff2d24 --- /dev/null +++ b/examples/libsrcml/README.md @@ -0,0 +1,6 @@ +# Libsrcml Examples + +This directory contains a set of examples of using libsrcml. + +You can build all of the examples using the CMakeLists.txt in the root directory, +or you can build a specific examples using the CMakeLists.txt in the example subdirectory. diff --git a/examples/libsrcml/copy.xsl b/examples/libsrcml/copy.xsl old mode 100755 new mode 100644 diff --git a/examples/libsrcml/decl_stmt.cpp b/examples/libsrcml/decl_stmt.cpp new file mode 100644 index 0000000000..9f489d86a7 --- /dev/null +++ b/examples/libsrcml/decl_stmt.cpp @@ -0,0 +1 @@ +int n = 0; diff --git a/examples/libsrcml/define.cpp b/examples/libsrcml/define.cpp new file mode 100644 index 0000000000..f41c9697a8 --- /dev/null +++ b/examples/libsrcml/define.cpp @@ -0,0 +1 @@ +#define MAX 10 diff --git a/examples/libsrcml/expr.cpp b/examples/libsrcml/expr.cpp new file mode 100644 index 0000000000..b45b1b7162 --- /dev/null +++ b/examples/libsrcml/expr.cpp @@ -0,0 +1 @@ +n = 0; diff --git a/examples/libsrcml/project.xml b/examples/libsrcml/project.xml new file mode 100644 index 0000000000..e1a54397fb --- /dev/null +++ b/examples/libsrcml/project.xml @@ -0,0 +1,13 @@ + + + +int n = 0; + + +#define MAX 10 + + +n = 0; + + + diff --git a/examples/libsrcml/srcml_convenient.c b/examples/libsrcml/srcml_convenient.c deleted file mode 100644 index 6a220c73c0..0000000000 --- a/examples/libsrcml/srcml_convenient.c +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @file srcml_convenient.cpp - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the convenience funcion C API for srcML. -*/ - -#include - -int main(int argc, char* argv[]) { - - /* setup options and attributes */ - srcml_set_version("211"); - srcml_set_tabstop(4); - - /* treat "*.h" as C++ */ - srcml_register_file_extension("h", SRCML_LANGUAGE_CXX); - - /* change prefix of standard namespace */ - srcml_register_namespace("s", "http://www.sdml.info/srcML/src"); - - /* default prefix is now for cpp namespace */ - srcml_register_namespace("", "http://www.sdml.info/srcML/cpp"); - - /* new prefix for further processing */ - srcml_register_namespace("doc", "http://www.sdml.info/srcML/doc"); - - /* - Translates source code file "main.cpp" to srcML file "main.cpp.xml". - - Translate using the above global options - - The language will be automatically based on the extension of the input (first) filename - - Since there is only a single input file, the output file will be a non-archive by default. - Convenience function can also convert to archive - */ - srcml("main.cpp", "main.cpp.xml"); - - return 0; -} diff --git a/examples/libsrcml/srcml_convenient.cpp b/examples/libsrcml/srcml_convenient.cpp new file mode 100644 index 0000000000..9868e5b3f5 --- /dev/null +++ b/examples/libsrcml/srcml_convenient.cpp @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_convenient.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the convenience funcion C API for srcML. +*/ + +#include + +int main(int argc, char* argv[]) { + + // setup options and attributes + srcml_set_version("211"); + srcml_set_tabstop(4); + + // treat "*.h" as C++ + srcml_register_file_extension("h", SRCML_LANGUAGE_CXX); + + // change prefix of standard namespace + srcml_register_namespace("s", "http://www.sdml.info/srcML/src"); + + // default prefix is now for cpp namespace + srcml_register_namespace("", "http://www.sdml.info/srcML/cpp"); + + // new prefix for further processing + srcml_register_namespace("doc", "http://www.sdml.info/srcML/doc"); + + /* + Translates source code file "main.cpp" to srcML file "main.cpp.xml". + - Translate using the above global options + - The language is automatica and based on the extension of the input (first) filename + - Since there is only a single input file, the output file will be a non-archive by default. + Convenience function can also convert to archive + */ + srcml("main.cpp", "main.cpp.xml"); + + return 0; +} diff --git a/examples/libsrcml/srcml_copy_archive.c b/examples/libsrcml/srcml_copy_archive.c deleted file mode 100644 index d0b04e1a3f..0000000000 --- a/examples/libsrcml/srcml_copy_archive.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * @file srcml_copy_archive.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Copy an archive. -*/ - -#include - -int main(int argc, char* argv[]) { - - /* open up an existing archive */ - struct srcml_archive* iarchive = srcml_archive_create(); - srcml_archive_read_open_filename(iarchive, "project.xml"); - - /* create a new srcml archive structure */ - /* options and attributes of cloned archive start the same as - the original archive */ - struct srcml_archive* oarchive = srcml_archive_clone(iarchive); - - /* open a srcML archive for output */ - srcml_archive_write_open_filename(oarchive, "project2.xml"); - - /* copy the files from the input archive to the output archive */ - struct srcml_unit* unit = 0; - while ((unit = srcml_archive_read_unit(iarchive))) { - - /* Translate to srcml and append to the archive */ - srcml_archive_write_unit(oarchive, unit); - - srcml_unit_free(unit); - } - - /* close the archives */ - srcml_archive_close(oarchive); - srcml_archive_close(iarchive); - - /* free the srcML archive data */ - srcml_archive_free(oarchive); - srcml_archive_free(iarchive); - - return 0; -} diff --git a/examples/libsrcml/srcml_copy_archive.cpp b/examples/libsrcml/srcml_copy_archive.cpp new file mode 100644 index 0000000000..d2e62d62fb --- /dev/null +++ b/examples/libsrcml/srcml_copy_archive.cpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_copy_archive.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Copy an archive. +*/ + +#include + +int main(int argc, char* argv[]) { + + // open up an existing archive + srcml_archive* inputArchive = srcml_archive_create(); + srcml_archive_read_open_filename(inputArchive, "project.xml"); + + // create a new srcml archive structure + // options and attributes of cloned archive start the same + // original archive + srcml_archive* outputArchive = srcml_archive_clone(inputArchive); + + // open a srcML archive for output + srcml_archive_write_open_filename(outputArchive, "projectCopy.xml"); + + // copy the files from the input archive to the output archive + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(inputArchive))) { + + // append to the output archive + srcml_archive_write_unit(outputArchive, unit); + + srcml_unit_free(unit); + } + + // close the archives + srcml_archive_close(outputArchive); + srcml_archive_close(inputArchive); + + // free the archives + srcml_archive_free(outputArchive); + srcml_archive_free(inputArchive); + + return 0; +} diff --git a/examples/libsrcml/srcml_create_archive_fd.c b/examples/libsrcml/srcml_create_archive_fd.c deleted file mode 100644 index 7b4972b6e3..0000000000 --- a/examples/libsrcml/srcml_create_archive_fd.c +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @file srcml_archive_create_fd.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Create an archive, file by file, with an output file descriptor -*/ - -#include -#include -#include -#ifdef _MSC_BUILD -#include -#else -#include -#endif - -int main(int argc, char* argv[]) { - - /* create a new srcml archive structure */ - struct srcml_archive* archive = srcml_archive_create(); - - /* setup our output file using a file descriptor */ - int srcml_output = open("project.xml", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); - - /* open a srcML archive for output */ - srcml_archive_write_open_fd(archive, srcml_output); - - /* add all the files to the archive */ - for (int i = 1; i < argc; ++i) { - - struct srcml_unit* unit = srcml_unit_create(archive); - - srcml_unit_set_language(unit, srcml_archive_check_extension(archive, argv[i])); - - /* Translate to srcml */ - int srcml_input = open(argv[i], O_RDONLY, 0); - srcml_unit_parse_fd(unit, srcml_input); - - /* Append to the archive */ - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - close(srcml_input); - } - - /* close the srcML archive */ - srcml_archive_close(archive); - - /* file can now be closed also */ - close(srcml_output); - - /* free the srcML archive data */ - srcml_archive_free(archive); - - return 0; -} diff --git a/examples/libsrcml/srcml_create_archive_fd.cpp b/examples/libsrcml/srcml_create_archive_fd.cpp new file mode 100644 index 0000000000..14610ec82a --- /dev/null +++ b/examples/libsrcml/srcml_create_archive_fd.cpp @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_archive_create_fd.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Create an archive, file by file, with an output file descriptor +*/ + +#include +#include +#include +#ifdef _MSC_BUILD +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif +#pragma warning(disable : 4996) +#include +#else +#include +#endif + +int main(int argc, char* argv[]) { + + // create a new srcml archive structure + srcml_archive* archive = srcml_archive_create(); + + // setup our output file using a file descriptor + int srcml_output = open("newProject.xml", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); + + // open a srcML archive for output + srcml_archive_write_open_fd(archive, srcml_output); + + // add all the files to the archive + for (int i = 1; i < argc; ++i) { + + srcml_unit* unit = srcml_unit_create(archive); + + srcml_unit_set_language(unit, srcml_archive_check_extension(archive, argv[i])); + + // Translate to srcml + int srcml_input = open(argv[i], O_RDONLY, 0); + srcml_unit_parse_fd(unit, srcml_input); + close(srcml_input); + + // Append to the archive + srcml_archive_write_unit(archive, unit); + + srcml_unit_free(unit); + } + + // close the srcML archive + srcml_archive_close(archive); + + // free the archives + srcml_archive_free(archive); + + return 0; +} diff --git a/examples/libsrcml/srcml_create_archive_file.c b/examples/libsrcml/srcml_create_archive_file.c deleted file mode 100644 index 56f9f988de..0000000000 --- a/examples/libsrcml/srcml_create_archive_file.c +++ /dev/null @@ -1,67 +0,0 @@ -/** - * @file srcml_archive_create_file.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Create an archive, file by file, with an output FILE* -*/ - -#include -#include - -int main(int argc, char* argv[]) { - - /* create a new srcml archive structure */ - struct srcml_archive* archive = srcml_archive_create(); - - /* setup our output file using a FILE* */ - FILE* srcml_output = fopen("project.xml", "w"); - - /* open a srcML archive for output */ - srcml_archive_write_open_FILE(archive, srcml_output); - - /* add all the files to the archive */ - for (int i = 1; i < argc; ++i) { - - struct srcml_unit* unit = srcml_unit_create(archive); - - srcml_unit_set_language(unit, srcml_archive_check_extension(archive, argv[i])); - - FILE* srcml_input = fopen(argv[i], "r"); - srcml_unit_parse_FILE(unit, srcml_input); - - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - fclose(srcml_input); - } - - /* close the srcML archive */ - srcml_archive_close(archive); - - /* file can now be closed also */ - fclose(srcml_output); - - /* free the srcML archive data */ - srcml_archive_free(archive); - - return 0; -} diff --git a/examples/libsrcml/srcml_create_archive_file.cpp b/examples/libsrcml/srcml_create_archive_file.cpp new file mode 100644 index 0000000000..85a55621b8 --- /dev/null +++ b/examples/libsrcml/srcml_create_archive_file.cpp @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_archive_create_file.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Create an archive, file by file, with an output FILE* +*/ + +#include +#include + +#ifdef _MSC_BUILD +#pragma warning(disable : 4996) +#endif + +int main(int argc, char* argv[]) { + + // create a new srcml archive structure + srcml_archive* archive = srcml_archive_create(); + + // setup our output file using a FILE* + FILE* srcml_output = fopen("newProject.xml", "w"); + + // open a srcML archive for output + srcml_archive_write_open_FILE(archive, srcml_output); + + // add all the files to the archive + for (int i = 1; i < argc; ++i) { + + // creae a new unit + srcml_unit* unit = srcml_unit_create(archive); + + // base the language on the source filename extension + srcml_unit_set_language(unit, srcml_archive_check_extension(archive, argv[i])); + + // parse the source file + FILE* srcml_input = fopen(argv[i], "r"); + srcml_unit_parse_FILE(unit, srcml_input); + fclose(srcml_input); + + // add the srcML of the source file to the archive + srcml_archive_write_unit(archive, unit); + + // free + srcml_unit_free(unit); + } + + // close the srcML archive + srcml_archive_close(archive); + + // file can now be closed also + fclose(srcml_output); + + // free the archives + srcml_archive_free(archive); + + return 0; +} diff --git a/examples/libsrcml/srcml_create_archive_filename.c b/examples/libsrcml/srcml_create_archive_filename.c deleted file mode 100644 index 7fd2449627..0000000000 --- a/examples/libsrcml/srcml_create_archive_filename.c +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file srcml_archive_create_filename.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Create an archive, file by file, with an output filename. -*/ - -#include - -int main(int argc, char* argv[]) { - - /* create a new srcml archive structure */ - struct srcml_archive* archive = srcml_archive_create(); - - /* open a srcML archive for output */ - srcml_archive_write_open_filename(archive, "project.xml"); - - /* add all the files to the archive */ - for (int i = 1; i < argc; ++i) { - - struct srcml_unit* unit = srcml_unit_create(archive); - - srcml_unit_set_filename(unit, argv[i]); - - /* Translate to srcml and append to the archive */ - srcml_unit_parse_filename(unit, argv[i]); - - /* Translate to srcml and append to the archive */ - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - } - - /* close the srcML archive */ - srcml_archive_close(archive); - - /* free the srcML archive data */ - srcml_archive_free(archive); - - return 0; -} diff --git a/examples/libsrcml/srcml_create_archive_filename.cpp b/examples/libsrcml/srcml_create_archive_filename.cpp new file mode 100644 index 0000000000..58bd721607 --- /dev/null +++ b/examples/libsrcml/srcml_create_archive_filename.cpp @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_archive_create_filename.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Create an archive, file by file, with an output filename. +*/ + +#include + +int main(int argc, char* argv[]) { + + // create a new srcml archive structure + srcml_archive* archive = srcml_archive_create(); + + // open a srcML archive for output + srcml_archive_write_open_filename(archive, "newProject.xml"); + + // add all the files to the archive + for (int i = 1; i < argc; ++i) { + + srcml_unit* unit = srcml_unit_create(archive); + + // set the filename + srcml_unit_set_filename(unit, argv[i]); + + // translate to srcml + srcml_unit_parse_filename(unit, argv[i]); + + // append to the archive + srcml_archive_write_unit(archive, unit); + + srcml_unit_free(unit); + } + + // close the srcML archive + srcml_archive_close(archive); + + // free the archives + srcml_archive_free(archive); + + return 0; +} diff --git a/examples/libsrcml/srcml_create_archive_full.c b/examples/libsrcml/srcml_create_archive_full.c deleted file mode 100644 index aa53b811e6..0000000000 --- a/examples/libsrcml/srcml_create_archive_full.c +++ /dev/null @@ -1,91 +0,0 @@ -/** - * @file srcml_archive_create_full.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Create an archive, file by file, with an output filename, showing - most of the option features -*/ - -#include - -int main(int argc, char* argv[]) { - - /* - Setup archive - */ - - /* create a new srcml archive structure */ - struct srcml_archive* archive = srcml_archive_create(); - - /* setup options and attributes */ - srcml_archive_set_version(archive, "211"); - srcml_archive_set_tabstop(archive, 4); - - /* treat "*.h" as C++ */ - srcml_archive_register_file_extension(archive, "h", SRCML_LANGUAGE_CXX); - - /* change prefix of standard namespace */ - srcml_archive_register_namespace(archive, "s", "http://www.sdml.info/srcML/src"); - - /* default prefix is now for cpp namespace */ - srcml_archive_register_namespace(archive, "", "http://www.sdml.info/srcML/cpp"); - - /* new prefix for further processing */ - srcml_archive_register_namespace(archive, "doc", "http://www.sdml.info/srcML/doc"); - - /* - Open and write to the archive - */ - - /* open a srcML archive for output */ - srcml_archive_write_open_filename(archive, "project.xml"); - - /* add all files on the command line to the archive */ - for (int i = 1; i < argc; ++i) { - - /* Setup this entry */ - struct srcml_unit* unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_C); - srcml_unit_set_filename(unit, argv[i]); - - /* Translate the entry to srcML */ - srcml_unit_parse_filename(unit, argv[i]); - - /* Append unit to the archive */ - srcml_archive_write_unit(archive, unit); - - /* Done with the entry for now */ - srcml_unit_free(unit); - } - - /* - Finish up - */ - - /* close the srcML archive */ - srcml_archive_close(archive); - - /* free the srcML archive data */ - srcml_archive_free(archive); - - return 0; -} diff --git a/examples/libsrcml/srcml_create_archive_full.cpp b/examples/libsrcml/srcml_create_archive_full.cpp new file mode 100644 index 0000000000..d56cab0db1 --- /dev/null +++ b/examples/libsrcml/srcml_create_archive_full.cpp @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_archive_create_full.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Create an archive, file by file, with an output filename, showing + * most of the option features +*/ + +#include + +int main(int argc, char* argv[]) { + + // create a new srcml archive + srcml_archive* archive = srcml_archive_create(); + + // setup options and attributes + srcml_archive_set_version(archive, "211"); + srcml_archive_set_tabstop(archive, 4); + + // treat "*.h" as C++ + srcml_archive_register_file_extension(archive, "h", SRCML_LANGUAGE_CXX); + + // change prefix of standard namespace + srcml_archive_register_namespace(archive, "s", "http://www.sdml.info/srcML/src"); + + // default prefix is now for cpp namespace + srcml_archive_register_namespace(archive, "", "http://www.sdml.info/srcML/cpp"); + + // new prefix for further processing + srcml_archive_register_namespace(archive, "doc", "http://www.sdml.info/srcML/doc"); + + // open a srcML archive for output + srcml_archive_write_open_filename(archive, "newProject.xml"); + + // add all files on the command line to the archive + for (int i = 1; i < argc; ++i) { + + // setup this entry + srcml_unit* unit = srcml_unit_create(archive); + srcml_unit_set_filename(unit, argv[i]); + + // translate the entry to srcML + srcml_unit_parse_filename(unit, argv[i]); + + // append unit to the archive + srcml_archive_write_unit(archive, unit); + + // done with the entry + srcml_unit_free(unit); + } + + // close the srcML archive + srcml_archive_close(archive); + + // free the archives + srcml_archive_free(archive); + + return 0; +} diff --git a/examples/libsrcml/srcml_create_archive_memory.c b/examples/libsrcml/srcml_create_archive_memory.c deleted file mode 100644 index 0871cec8c8..0000000000 --- a/examples/libsrcml/srcml_create_archive_memory.c +++ /dev/null @@ -1,79 +0,0 @@ -/** - * @file srcml_archive_create_memory.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Create an archive, file by file, with an output memory. -*/ - -#include -#include -#include -#include -#include -#ifdef _MSC_BUILD -#include -#else -#include -#endif - -int main(int argc, char* argv[]) { - - /* create a new srcml archive structure */ - struct srcml_archive* archive = srcml_archive_create(); - - /* open a srcML archive for output */ - char* s = 0; - size_t size; - srcml_archive_write_open_memory(archive, &s, &size); - - /* add all the files to the archive */ - for (int i = 1; i < argc; ++i) { - - struct srcml_unit* unit = srcml_unit_create(archive); - - /* Translate to srcml and append to the archive */ - char buffer[256]; - int srcml_input = open(argv[i], O_RDONLY, 0); - int num_read = read(srcml_input, buffer, 256); - close(srcml_input); - srcml_unit_set_language(unit, srcml_archive_check_extension(archive, argv[i])); - - srcml_unit_parse_memory(unit, buffer, num_read); - - /* Translate to srcml and append to the archive */ - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - } - - /* close the srcML archive */ - srcml_archive_close(archive); - - /* free the srcML archive data */ - srcml_archive_free(archive); - - /* now dump the contents of the archive */ - puts(s); - free(s); - - return 0; -} diff --git a/examples/libsrcml/srcml_create_archive_memory.cpp b/examples/libsrcml/srcml_create_archive_memory.cpp new file mode 100644 index 0000000000..245eb0c55b --- /dev/null +++ b/examples/libsrcml/srcml_create_archive_memory.cpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_archive_create_memory.cpp + * + * @copyright Copyright (C) 2013-2023 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Create an archive, file by file, with an output memory. +*/ + +#include +#include +#include + +int main(int argc, char* argv[]) { + + // open a srcML archive for memory output + srcml_archive* archive = srcml_archive_create(); + char* s = nullptr; + size_t size; + srcml_archive_write_open_memory(archive, &s, &size); + + // translate to the code to srcml and append to the archive + const char* code = "int n = 0;"; + srcml_unit* unit = srcml_unit_create(archive); + srcml_unit_set_language(unit, "C++"); + srcml_unit_parse_memory(unit, code, strlen(code)); + srcml_archive_write_unit(archive, unit); + + // free the unit + srcml_unit_free(unit); + + // close the srcML archive + srcml_archive_close(archive); + + // free the archive + srcml_archive_free(archive); + + // output the contents of the archive + std::cout << s; + + // free the generated archive + free(s); + + return 0; +} diff --git a/examples/libsrcml/srcml_direct_language.c b/examples/libsrcml/srcml_direct_language.c deleted file mode 100644 index d2f478afb4..0000000000 --- a/examples/libsrcml/srcml_direct_language.c +++ /dev/null @@ -1,42 +0,0 @@ -/** - * @file test_srcml_direct_language.cpp - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - A straightforward translation of source code to the srcML format. - Translates the file "a.cpp" to the srcML format in "a.cpp.xml", however - in this case the language is specified: - - * This creates a single-unit srcML file, i.e., a non-archive srcML - * The srcML attribute filename will be the name of the file passed as the first - parameter. -*/ - -#include - -int main(int argc, char* argv[]) { - - /* Translate from a source-code file to a srcML file */ - srcml_set_language(SRCML_LANGUAGE_CXX); - srcml("a.cpp", "a.cpp.xml"); - - return 0; -} diff --git a/examples/libsrcml/srcml_direct_language.cpp b/examples/libsrcml/srcml_direct_language.cpp new file mode 100644 index 0000000000..a7ee2e85f8 --- /dev/null +++ b/examples/libsrcml/srcml_direct_language.cpp @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file test_srcml_direct_language.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * A straightforward translation of source code to the srcML format. + * Translates the file "decl_stmt.cpp" to the srcML format in "decl_stmt.cpp.xml", however + * in this case the language is specified: + * + * * This creates a single-unit srcML file, i.e., a non-archive srcML + * * The srcML attribute filename is the name of the file passed as the first + * parameter. +*/ + +#include + +int main(int argc, char* argv[]) { + + // translate from a source-code file to a srcML file + srcml_set_language(SRCML_LANGUAGE_CXX); + srcml("decl_stmt.cpp", "decl_stmt.cpp.xml"); + + return 0; +} diff --git a/examples/libsrcml/srcml_direct_language_list.c b/examples/libsrcml/srcml_direct_language_list.c deleted file mode 100644 index 1e5d559486..0000000000 --- a/examples/libsrcml/srcml_direct_language_list.c +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file srcml_direct_language_list.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - A null-terminated list of the supported srcML source-code language. -*/ - -#include -#include - -int main(int argc, char* argv[]) { - - for (int i = 0; i < srcml_get_language_list_size(); ++i) - puts(srcml_get_language_list(i)); - - return 0; -} diff --git a/examples/libsrcml/srcml_direct_language_list.cpp b/examples/libsrcml/srcml_direct_language_list.cpp new file mode 100644 index 0000000000..abf2fc33de --- /dev/null +++ b/examples/libsrcml/srcml_direct_language_list.cpp @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_direct_language_list.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * A null-terminated list of the supported srcML source-code language. +*/ + +#include +#include + +int main(int argc, char* argv[]) { + + // output the supported srcML source-code languages + for (int i = 0; i < srcml_get_language_list_size(); ++i) + std::cout << srcml_get_language_list(i) << '\n'; + + return 0; +} diff --git a/examples/libsrcml/srcml_direct_language_xml.c b/examples/libsrcml/srcml_direct_language_xml.c deleted file mode 100644 index 2facc951f7..0000000000 --- a/examples/libsrcml/srcml_direct_language_xml.c +++ /dev/null @@ -1,42 +0,0 @@ -/** - * @file srcml_direct_language_xml.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - A straightforward translation from the srcML format back to source code. - Translates the srcML file "a.cpp.xml" to the source-code file "a.cpp", however - in this case the language is specified: - - * This creates a single-unit srcML file, i.e., a non-archive srcML - * The srcML attribute filename will be the name of the file passed as the first - parameter. -*/ - -#include - -int main(int argc, char* argv[]) { - - /* Translate from a source-code file to a srcML file */ - srcml_set_language(SRCML_LANGUAGE_XML); - srcml("a.cpp.xml", "a.cpp"); - - return 0; -} diff --git a/examples/libsrcml/srcml_direct_language_xml.cpp b/examples/libsrcml/srcml_direct_language_xml.cpp new file mode 100644 index 0000000000..efe4dc884c --- /dev/null +++ b/examples/libsrcml/srcml_direct_language_xml.cpp @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_direct_language_xml.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * A straightforward translation from the srcML format back to source code. + * Translates the srcML file "decl_stmt.cpp.xml" to the source-code file "decl_stmt.cpp", however + * in this case the language is specified: + * + * * This creates a single-unit srcML file, i.e., a non-archive srcML + * * The srcML attribute filename is the name of the file passed as the first + * parameter. +*/ + +#include + +int main(int argc, char* argv[]) { + + // translate from a source-code file to a srcML file + srcml_set_language(SRCML_LANGUAGE_XML); + srcml("decl_stmt.cpp.xml", "decl_stmt.cpp"); + + return 0; +} diff --git a/examples/libsrcml/srcml_direct_src2srcml.c b/examples/libsrcml/srcml_direct_src2srcml.c deleted file mode 100644 index 6b697f3dfc..0000000000 --- a/examples/libsrcml/srcml_direct_src2srcml.c +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @file srcml_direct_src2srcml.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - A straightforward translation of source code to the srcML format. - Translates the file "a.cpp" to the srcML format in "a.cpp.xml": - - * The language is determined automatically from the source file extension - * This creates a single-unit srcML file, i.e., a non-archive srcML - * The srcML attribute filename will be the name of the file passed as the first - parameter. -*/ - -#include -#include - -int main(int argc, char* argv[]) { - - /* Translate from a source-code file to a srcML file */ - int error = srcml("a.cpp", "a.cpp.xml"); - - if (error) - puts(srcml_error_string()); - - return 0; -} diff --git a/examples/libsrcml/srcml_direct_src2srcml.cpp b/examples/libsrcml/srcml_direct_src2srcml.cpp new file mode 100644 index 0000000000..b202ad5ce5 --- /dev/null +++ b/examples/libsrcml/srcml_direct_src2srcml.cpp @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_direct_src2srcml.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * A straightforward translation of source code to the srcML format. + * Translates the file "decl_stmt.cpp" to the srcML format in "decl_stmt.cpp.xml": + * + * * The language is determined automatically from the source file extension + * * This creates a single-unit srcML file, i.e., a non-archive srcML + * * The srcML attribute filename will be the name of the file passed as the first + * parameter. +*/ + +#include +#include + +int main(int argc, char* argv[]) { + + // translate from a source-code file to a srcML file + int error = srcml("decl_stmt.cpp", "decl_stmt.cpp.xml"); + + // output the error + if (error) + std::cerr << srcml_error_string(); + + return 0; +} diff --git a/examples/libsrcml/srcml_direct_srcml2src.c b/examples/libsrcml/srcml_direct_srcml2src.c deleted file mode 100644 index d8e773086b..0000000000 --- a/examples/libsrcml/srcml_direct_srcml2src.c +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file srcml_direct_srcml2src.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - A straightforward translation from the srcML format back to source code. - Translates the srcML file "a.cpp.xml" to the source-code file "a.cpp": - - * This creates a single-unit srcML file, i.e., a non-archive srcML - * The srcML attribute filename will be the name of the file passed as the first - parameter. -*/ - -#include - -int main(int argc, char* argv[]) { - - /* Translate from a srcML file to a source-code file */ - srcml("a.cpp.xml", "a.cpp"); - - return 0; -} diff --git a/examples/libsrcml/srcml_direct_srcml2src.cpp b/examples/libsrcml/srcml_direct_srcml2src.cpp new file mode 100644 index 0000000000..762153543c --- /dev/null +++ b/examples/libsrcml/srcml_direct_srcml2src.cpp @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_direct_srcml2src.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * A straightforward translation from the srcML format back to source code. + * Translates the srcML file "decl_stmt.cpp.xml" to the source-code file "decl_stmt.cpp": + * + * * This creates a single-unit srcML file, i.e., a non-archive srcML + * * The srcML attribute filename will be the name of the file passed as the first + * parameter. +*/ + +#include + +int main(int argc, char* argv[]) { + + // translate from a srcML file to a source-code file + srcml("decl_stmt.cpp.xml", "decl_stmt.cpp"); + + return 0; +} diff --git a/examples/libsrcml/srcml_list.c b/examples/libsrcml/srcml_list.c deleted file mode 100644 index c4dbdc9575..0000000000 --- a/examples/libsrcml/srcml_list.c +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @file srcml_list.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Gather info from an archive from a given unit. -*/ - -#include - -int main(int argc, char* argv[]) { - - struct srcml_archive* archive = srcml_archive_create(); - srcml_archive_read_open_filename(archive, "project.xml"); - - struct srcml_unit* unit = 0; - while ((unit = srcml_archive_read_unit(archive))) { - puts(srcml_unit_get_filename(unit)); - srcml_unit_free(unit); - } - - srcml_archive_close(archive); - srcml_archive_free(archive); - - return 0; -} diff --git a/examples/libsrcml/srcml_list.cpp b/examples/libsrcml/srcml_list.cpp new file mode 100644 index 0000000000..ac02e83c5e --- /dev/null +++ b/examples/libsrcml/srcml_list.cpp @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_list.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Gather info from an archive from a given unit. + */ + +#include +#include +#include + +int main(int argc, char* argv[]) { + + srcml_archive* archive = srcml_archive_create(); + srcml_archive_read_open_filename(archive, "project.xml"); + + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(archive))) { + const char* filename = srcml_unit_get_filename(unit); + if (filename) + std::cout << filename << '\n'; + + srcml_unit_free(unit); + } + + srcml_archive_close(archive); + srcml_archive_free(archive); + + return 0; +} diff --git a/examples/libsrcml/srcml_read_archive_fd.c b/examples/libsrcml/srcml_read_archive_fd.c deleted file mode 100644 index 871c19120a..0000000000 --- a/examples/libsrcml/srcml_read_archive_fd.c +++ /dev/null @@ -1,69 +0,0 @@ -/** - * @file srcml_read_archive_fd.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Take an archive and extract the invidual units and write to a filesystem. -*/ - -#include -#include -#include -#ifdef _MSC_BUILD -#include -#else -#include -#endif - -int main(int argc, char* argv[]) { - - /* create a new srcml archive structure */ - struct srcml_archive* archive = srcml_archive_create(); - - /* open a srcML archive for input */ - int srcml_input = open("project.xml", O_RDONLY, 0); - srcml_archive_read_open_fd(archive, srcml_input); - - /* add all the files to the archive */ - struct srcml_unit* unit = 0; - while ((unit = srcml_archive_read_unit(archive))) { - - /* can inquire about the current unit */ - const char* language = srcml_unit_get_language(unit); - const char* filename = srcml_unit_get_filename(unit); - - /* uparse and write to a file */ - int srcml_output = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); - srcml_unit_unparse_fd(unit, srcml_output); - - srcml_unit_free(unit); - close(srcml_output); - } - - /* close the srcML archive */ - srcml_archive_close(archive); - close(srcml_input); - - /* free the srcML archive data */ - srcml_archive_free(archive); - - return 0; -} diff --git a/examples/libsrcml/srcml_read_archive_fd.cpp b/examples/libsrcml/srcml_read_archive_fd.cpp new file mode 100644 index 0000000000..6e386118e6 --- /dev/null +++ b/examples/libsrcml/srcml_read_archive_fd.cpp @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_read_archive_fd.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Take an archive and extract the invidual units and write to a filesystem. +*/ + +#include +#include +#include +#include +#ifdef _MSC_BUILD +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif +#pragma warning(disable : 4996) +#include +#else +#include +#endif + +int main(int argc, char* argv[]) { + + // create a new srcml archive structure + srcml_archive* archive = srcml_archive_create(); + + // open a srcML archive for input + int srcml_input = open("project.xml", O_RDONLY, 0); + srcml_archive_read_open_fd(archive, srcml_input); + + // add all the files to the archive + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(archive))) { + + // inquire about the current unit + std::string language = srcml_unit_get_language(unit); + std::string filename = srcml_unit_get_filename(unit); + + // uparse and write to a file + int srcml_output = open(filename.data(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); + srcml_unit_unparse_fd(unit, srcml_output); + close(srcml_output); + + srcml_unit_free(unit); + } + + // close the srcML archive + srcml_archive_close(archive); + + // free the archive + srcml_archive_free(archive); + + return 0; +} diff --git a/examples/libsrcml/srcml_read_archive_file.c b/examples/libsrcml/srcml_read_archive_file.c deleted file mode 100644 index 07f6f6841d..0000000000 --- a/examples/libsrcml/srcml_read_archive_file.c +++ /dev/null @@ -1,63 +0,0 @@ -/** - * @file srcml_read_archive_file.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Take an archive and extract the invidual units and write to a filesystem. -*/ - -#include -#include - -int main(int argc, char* argv[]) { - - /* create a new srcml archive structure */ - struct srcml_archive* archive = srcml_archive_create(); - - /* open a srcML archive for input */ - FILE* srcml_input = fopen("project.xml", "r"); - srcml_archive_read_open_FILE(archive, srcml_input); - - /* add all the files to the archive */ - struct srcml_unit* unit = 0; - while ((unit = srcml_archive_read_unit(archive))) { - - /* can inquire about the current unit */ - const char* language = srcml_unit_get_language(unit); - const char* filename = srcml_unit_get_filename(unit); - - /* uparse and write to a file */ - FILE* srcml_output = fopen(filename, "w"); - srcml_unit_unparse_FILE(unit, srcml_output); - - srcml_unit_free(unit); - fclose(srcml_output); - } - - /* close the srcML archive */ - srcml_archive_close(archive); - fclose(srcml_input); - - /* free the srcML archive data */ - srcml_archive_free(archive); - - return 0; -} diff --git a/examples/libsrcml/srcml_read_archive_file.cpp b/examples/libsrcml/srcml_read_archive_file.cpp new file mode 100644 index 0000000000..7daf47be81 --- /dev/null +++ b/examples/libsrcml/srcml_read_archive_file.cpp @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_read_archive_file.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Extract the archive to the filesystem. +*/ + +#include +#include +#include + +#ifdef _MSC_BUILD +#pragma warning(disable : 4996) +#endif + +int main(int argc, char* argv[]) { + + // create a new srcml archive structure + srcml_archive* inputArchive = srcml_archive_create(); + + // open a srcML archive for input + FILE* srcml_input = fopen("project.xml", "r"); + srcml_archive_read_open_FILE(inputArchive, srcml_input); + + // add all the files to the archive + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(inputArchive))) { + + // filename of the unit + std::string filename = srcml_unit_get_filename(unit); + + // uparse and write to a file + FILE* srcml_output = fopen(filename.data(), "w"); + srcml_unit_unparse_FILE(unit, srcml_output); + fclose(srcml_output); + + // free the unit + srcml_unit_free(unit); + } + + // close the srcML archive + srcml_archive_close(inputArchive); + + // close the srcML archive file + fclose(srcml_input); + + // free the archive + srcml_archive_free(inputArchive); + + return 0; +} diff --git a/examples/libsrcml/srcml_read_archive_filename.c b/examples/libsrcml/srcml_read_archive_filename.c deleted file mode 100644 index 10be34495a..0000000000 --- a/examples/libsrcml/srcml_read_archive_filename.c +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file srcml_read_archive_filename.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Take an archive and extract the invidual units and write to a filesystem. -*/ - -#include - -int main(int argc, char* argv[]) { - - /* create a new srcml archive structure */ - struct srcml_archive* archive = srcml_archive_create(); - - /* open a srcML archive for input */ - srcml_archive_read_open_filename(archive, "project.xml"); - - /* add all the files to the archive */ - struct srcml_unit* unit = 0; - while ((unit = srcml_archive_read_unit(archive))) { - - /* can inquire about the current unit */ - const char* language = srcml_unit_get_language(unit); - const char* filename = srcml_unit_get_filename(unit); - - /* uparse and write to a file */ - srcml_unit_unparse_filename(unit, filename); - - srcml_unit_free(unit); - } - - /* close the srcML archive */ - srcml_archive_close(archive); - - /* free the srcML archive data */ - srcml_archive_free(archive); - - return 0; -} diff --git a/examples/libsrcml/srcml_read_archive_filename.cpp b/examples/libsrcml/srcml_read_archive_filename.cpp new file mode 100644 index 0000000000..ceb9a68c45 --- /dev/null +++ b/examples/libsrcml/srcml_read_archive_filename.cpp @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_read_archive_filename.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Take an archive and extract the invidual units and write to a filesystem. +*/ + +#include + +int main(int argc, char* argv[]) { + + // open a srcML archive for input + srcml_archive* archive = srcml_archive_create(); + srcml_archive_read_open_filename(archive, "project.xml"); + + // add all the files to the archive + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(archive))) { + + // can inquire about the current unit + const char* language = srcml_unit_get_language(unit); + const char* filename = srcml_unit_get_filename(unit); + + // uparse and write to a file + srcml_unit_unparse_filename(unit, filename); + + srcml_unit_free(unit); + } + + // close the srcML archive + srcml_archive_close(archive); + + // free the archives + srcml_archive_free(archive); + + return 0; +} diff --git a/examples/libsrcml/srcml_read_archive_full.c b/examples/libsrcml/srcml_read_archive_full.c deleted file mode 100644 index 55c1be7c2d..0000000000 --- a/examples/libsrcml/srcml_read_archive_full.c +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file srcml_read_archive_full.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Take an archive and extract the invidual units and write to a filesystem. -*/ - -#include - -int main(int argc, char* argv[]) { - - /* create a new srcml archive structure */ - struct srcml_archive* archive = srcml_archive_create(); - - /* open a srcML archive for input */ - srcml_archive_read_open_filename(archive, "project.xml"); - - /* add all the files to the archive */ - struct srcml_unit* unit = 0; - while ((unit = srcml_archive_read_unit(archive))) { - - /* can inquire about the current unit */ - const char* language = srcml_unit_get_language(unit); - const char* filename = srcml_unit_get_filename(unit); - - /* uparse and write to a file */ - srcml_unit_unparse_filename(unit, filename); - - srcml_unit_free(unit); - } - - /* close the srcML archive */ - srcml_archive_close(archive); - - /* free the srcML archive data */ - srcml_archive_free(archive); - - return 0; -} diff --git a/examples/libsrcml/srcml_read_archive_full.cpp b/examples/libsrcml/srcml_read_archive_full.cpp new file mode 100644 index 0000000000..c83a7f88c8 --- /dev/null +++ b/examples/libsrcml/srcml_read_archive_full.cpp @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_read_archive_full.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Take an archive and extract the invidual units and write to a filesystem. +*/ + +#include +#include + +int main(int argc, char* argv[]) { + + // open a srcML archive for input + srcml_archive* archive = srcml_archive_create(); + srcml_archive_read_open_filename(archive, "project.xml"); + + // create source files from all the code in the project + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(archive))) { + + // inquire about the current unit + std::string filename = srcml_unit_get_filename(unit); + + // uparse and write to a file + srcml_unit_unparse_filename(unit, filename.data()); + + srcml_unit_free(unit); + } + + // close the srcML archive + srcml_archive_close(archive); + + // free the archives + srcml_archive_free(archive); + + return 0; +} diff --git a/examples/libsrcml/srcml_read_archive_memory.c b/examples/libsrcml/srcml_read_archive_memory.c deleted file mode 100644 index 8ef9ef92ee..0000000000 --- a/examples/libsrcml/srcml_read_archive_memory.c +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @file srcml_read_archive_memory.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Take an archive and extract the invidual units and write to a filesystem. -*/ - -#include -#include -#include -#include - -int main(int argc, char* argv[]) { - - const char* s = - "" - "" - "" - "int a;" - "" - "" - "int b;" - "" - "" - ""; - - /* create a new srcml archive structure */ - struct srcml_archive* archive = srcml_archive_create(); - - srcml_archive_read_open_memory(archive, s, strlen(s)); - - /* add all the files to the archive */ - struct srcml_unit* unit = 0; - while ((unit = srcml_archive_read_unit(archive))) { - - /* can inquire about the current unit */ - const char* language = srcml_unit_get_language(unit); - const char* filename = srcml_unit_get_filename(unit); - - /* uparse and write to a file */ - char* buffer = 0;; - size_t size = 0; - srcml_unit_unparse_memory(unit, &buffer, &size); - - printf("%s", buffer); - free((void *)buffer); - srcml_unit_free(unit); - } - - /* close the srcML archive */ - srcml_archive_close(archive); - - /* free the srcML archive data */ - srcml_archive_free(archive); - - return 0; -} diff --git a/examples/libsrcml/srcml_read_archive_memory.cpp b/examples/libsrcml/srcml_read_archive_memory.cpp new file mode 100644 index 0000000000..4ff02d1819 --- /dev/null +++ b/examples/libsrcml/srcml_read_archive_memory.cpp @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_read_archive_memory.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Take an archive and extract the invidual units and write to a filesystem. +*/ + +#include +#include +#include + +int main(int argc, char* argv[]) { + + // input archive contents + std::string input = R"( + + +int n = 0; + + +#define MAX 10 + + +n = 0; + + + +)"; + + // create a new archive from the string + srcml_archive* archive = srcml_archive_create(); + srcml_archive_read_open_memory(archive, input.data(), input.size()); + + // add all the files to the archive + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(archive))) { + + // output the current filename + std::cout << srcml_unit_get_filename(unit) << '\n'; + + // uparse into a buffer + char* buffer = nullptr; + size_t size = 0; + srcml_unit_unparse_memory(unit, &buffer, &size); + + // output the source in the buffer + std::cout << buffer; + + // free the buffer + free((void *)buffer); + + // free the unit + srcml_unit_free(unit); + } + + // close the archive + srcml_archive_close(archive); + + // free the archive + srcml_archive_free(archive); + + return 0; +} diff --git a/examples/libsrcml/srcml_relaxng.c b/examples/libsrcml/srcml_relaxng.c deleted file mode 100644 index 09f2c3b579..0000000000 --- a/examples/libsrcml/srcml_relaxng.c +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @file srcml_relaxng.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - RelaxNG usage. -*/ - -#include - -int main(int argc, char * argv[]) { - - struct srcml_archive* iarchive = srcml_archive_create(); - srcml_archive_read_open_filename(iarchive, "project.xml"); - struct srcml_archive* oarchive = srcml_archive_clone(iarchive); - srcml_archive_write_open_filename(oarchive, "relaxng.xml"); - - srcml_append_transform_relaxng_filename(iarchive, "schema.rng"); -/* - srcml_apply_transforms(iarchive, oarchive); -*/ - srcml_archive_close(iarchive); - srcml_archive_close(oarchive); - - srcml_archive_free(iarchive); - srcml_archive_free(oarchive); - - return 0; -} diff --git a/examples/libsrcml/srcml_relaxng.cpp b/examples/libsrcml/srcml_relaxng.cpp new file mode 100644 index 0000000000..ed5d91e4f7 --- /dev/null +++ b/examples/libsrcml/srcml_relaxng.cpp @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_relaxng.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * RelaxNG usage. +*/ + +#include + +int main(int argc, char * argv[]) { + + // open the input archive + srcml_archive* inputArchive = srcml_archive_create(); + srcml_archive_read_open_filename(inputArchive, "project.xml"); + + // add the RelaxNG validation + srcml_append_transform_relaxng_filename(inputArchive, "schema.rng"); + + // open the output archive + srcml_archive* outputArchive = srcml_archive_clone(inputArchive); + srcml_archive_write_open_filename(outputArchive, "relaxng.xml"); + + // apply the RelaxNG validation to the archive + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(inputArchive))) { + + // apply the transform + // since the RelaxNG is just a validiation, convert the unit in-place + srcml_unit_apply_transforms(inputArchive, unit, nullptr); + + // write the transformed unit + srcml_archive_write_unit(outputArchive, unit); + + // free the input unit + srcml_unit_free(unit); + } + + // close the archives + srcml_archive_close(inputArchive); + srcml_archive_close(outputArchive); + + // free the archives + srcml_archive_free(inputArchive); + srcml_archive_free(outputArchive); + + return 0; +} diff --git a/examples/libsrcml/srcml_sort_archive.c b/examples/libsrcml/srcml_sort_archive.c deleted file mode 100644 index 70d03f7b1b..0000000000 --- a/examples/libsrcml/srcml_sort_archive.c +++ /dev/null @@ -1,94 +0,0 @@ -/** - * @file srcml_sort_archive.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Sorts an archive in alphabetical filename order. - Not especially useful, but does show how units can be rearranged. -*/ - -#include -#include - -int main(int argc, char* argv[]) { - - int num_units = 0; - struct srcml_unit* units[10]; - const char* inputfile = "project.xml"; - const char* outputfile = "project_tmp.xml"; - - /* open up an existing archive */ - struct srcml_archive* iarchive = srcml_archive_create(); - - /* create a new srcml archive structure */ - /* options and attributes of cloned archive start the same as - the original archive */ - struct srcml_archive* oarchive = srcml_archive_clone(iarchive); - srcml_archive_read_open_filename(iarchive, inputfile); - while (1) { - - units[num_units] = srcml_archive_read_unit(iarchive); - if (units[num_units] == 0) - break; - ++num_units; - } - int i; - for(i = 1; i < num_units; ++i) { - - int j; - for(j = i; j > 0; --j) { - - if(strcmp(srcml_unit_get_filename(units[j]), srcml_unit_get_filename(units[j - 1])) < 0) { - - struct srcml_unit* tmp_unit = units[j]; - units[j] = units[j - 1]; - units[j - 1] = tmp_unit; - - } else - break; - - } - - } - - /* open a srcML archive for output */ - srcml_archive_write_open_filename(oarchive, outputfile); - - for(i = 0; i < num_units; ++i) { - - /* copy the files from the input archive to the output archive */ - /* Translate to srcml and append to the archive */ - srcml_archive_write_unit(oarchive, units[i]); - - srcml_unit_free(units[i]); - - } - - /* close the archives */ - srcml_archive_close(oarchive); - srcml_archive_close(iarchive); - - /* free the srcML archive data */ - srcml_archive_free(oarchive); - srcml_archive_free(iarchive); - - return 0; -} diff --git a/examples/libsrcml/srcml_sort_archive.cpp b/examples/libsrcml/srcml_sort_archive.cpp new file mode 100644 index 0000000000..fe84652479 --- /dev/null +++ b/examples/libsrcml/srcml_sort_archive.cpp @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_sort_archive.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Converts an input archive into an output archive sorted by the unit filename. +*/ + +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + + // open an existing archive + srcml_archive* inputArchive = srcml_archive_create(); + srcml_archive_read_open_filename(inputArchive, "project.xml"); + + // create a new output archive with the same + // options and attributes of the input archive + srcml_archive* sortedArchive = srcml_archive_clone(inputArchive); + + // read all the units in the archive into a container + std::vector units; + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(inputArchive))) { + units.push_back(unit); + } + + // sort the units in the container by filename + std::sort(units.begin(), units.end(), [](const srcml_unit* a, const srcml_unit* b) { + return std::string(srcml_unit_get_filename(a)) < std::string(srcml_unit_get_filename(b)); + }); + + // open a srcML archive for output + srcml_archive_write_open_filename(sortedArchive, "sortedProject.xml"); + + // copy the files from the container to the output archive + // free them now since we did not before + for (auto unit : units) { + srcml_archive_write_unit(sortedArchive, unit); + srcml_unit_free(unit); + } + + // close the archives + srcml_archive_close(inputArchive); + srcml_archive_close(sortedArchive); + + // free the archives + srcml_archive_free(inputArchive); + srcml_archive_free(sortedArchive); + + return 0; +} diff --git a/examples/libsrcml/srcml_split_archive.c b/examples/libsrcml/srcml_split_archive.c deleted file mode 100644 index 125f4cdaac..0000000000 --- a/examples/libsrcml/srcml_split_archive.c +++ /dev/null @@ -1,71 +0,0 @@ -/** - * @file srcml_split_archive.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Split an archive into two, one for .h files and one for other extensions -*/ - -#include -#include - -int main(int argc, char* argv[]) { - - /* open up an existing archive */ - struct srcml_archive* iarchive = srcml_archive_create(); - srcml_archive_read_open_filename(iarchive, "project.xml"); - - /* create a new srcml archive structure */ - /* options and attributes of cloned archive start the same as - the original archive */ - struct srcml_archive* includearchive = srcml_archive_clone(iarchive); - struct srcml_archive* otherarchive = srcml_archive_clone(iarchive); - - /* open a srcML archive for output */ - srcml_archive_write_open_filename(includearchive, "project_include.xml"); - srcml_archive_write_open_filename(otherarchive, "project_other.xml"); - - /* copy the files from the input archive to the output archive */ - struct srcml_unit* unit = 0; - while ((unit = srcml_archive_read_unit(iarchive))) { - - /* Get the filename */ - const char* filename = srcml_unit_get_filename(unit); - if (strcmp(".h", filename + strlen(filename) - 2) == 0) - srcml_archive_write_unit(includearchive, unit); - else - srcml_archive_write_unit(otherarchive, unit); - - srcml_unit_free(unit); - } - - /* close the archives */ - srcml_archive_close(includearchive); - srcml_archive_close(otherarchive); - srcml_archive_close(iarchive); - - /* free the srcML archive data */ - srcml_archive_free(includearchive); - srcml_archive_free(otherarchive); - srcml_archive_free(iarchive); - - return 0; -} diff --git a/examples/libsrcml/srcml_split_archive.cpp b/examples/libsrcml/srcml_split_archive.cpp new file mode 100644 index 0000000000..88d7e15c0e --- /dev/null +++ b/examples/libsrcml/srcml_split_archive.cpp @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_split_archive.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Split an archive into two archives, one for include files and one for non-include files. +*/ + +#include +#include +#include + +int main(int argc, char* argv[]) { + + // open an existing archive in the file "project.xml" + srcml_archive* inputArchive = srcml_archive_create(); + srcml_archive_read_open_filename(inputArchive, "project.xml"); + + // create two new output srcML archives where the options and attributes + // start the same as the original archive + srcml_archive* includeArchive = srcml_archive_clone(inputArchive); + srcml_archive* nonIncludeArchive = srcml_archive_clone(inputArchive); + srcml_archive_write_open_filename(includeArchive, "projectInclude.xml"); + srcml_archive_write_open_filename(nonIncludeArchive, "projectNonInclude.xml"); + + // copy the files from the input archive to the output archives + // where the include files are written to the includeArchive + // and the rest are written to the nonIncludeArchive + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(inputArchive))) { + + // split the input archive into an include archive and a non-include archive + const char* rawFilename = srcml_unit_get_filename(unit); + if (!rawFilename) { + std::cerr << "Unit missing filename\n"; + srcml_unit_free(unit); + continue; + } + std::string filename = rawFilename; + + std::string extension; + const auto extensionPosition = filename.rfind('.'); + if (extensionPosition != std::string::npos) { + extension = filename.substr(extensionPosition); + } + if (extension == ".h" || extension == ".hpp" || extension == ".hxx" || + extension == ".H" || extension == ".h++" || extension == ".hh") + srcml_archive_write_unit(includeArchive, unit); + else + srcml_archive_write_unit(nonIncludeArchive, unit); + + // free the input unit + srcml_unit_free(unit); + } + + // close the archives + srcml_archive_close(includeArchive); + srcml_archive_close(nonIncludeArchive); + srcml_archive_close(inputArchive); + + // free the archives + srcml_archive_free(includeArchive); + srcml_archive_free(nonIncludeArchive); + srcml_archive_free(inputArchive); + + return 0; +} diff --git a/examples/libsrcml/srcml_transform.c b/examples/libsrcml/srcml_transform.c deleted file mode 100644 index 16998203fb..0000000000 --- a/examples/libsrcml/srcml_transform.c +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file srcml_transform.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - Use XPath, XSLT, and RelaxNG. -*/ - -#include - -int main(int argc, char * argv[]) { - - struct srcml_archive* iarchive = srcml_archive_create(); - srcml_archive_read_open_filename(iarchive, "project.xml"); - struct srcml_archive* oarchive = srcml_archive_clone(iarchive); - srcml_archive_write_open_filename(oarchive, "transform.xml"); - - srcml_append_transform_xpath(iarchive, "//src:unit"); - srcml_append_transform_xslt_filename(iarchive, "copy.xsl"); - srcml_append_transform_relaxng_filename(iarchive, "schema.rng"); -/* - srcml_apply_transforms(iarchive, oarchive); -*/ - srcml_archive_close(iarchive); - srcml_archive_close(oarchive); - - srcml_archive_free(iarchive); - srcml_archive_free(oarchive); - - return 0; -} diff --git a/examples/libsrcml/srcml_transform.cpp b/examples/libsrcml/srcml_transform.cpp new file mode 100644 index 0000000000..ab9e8febd0 --- /dev/null +++ b/examples/libsrcml/srcml_transform.cpp @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_transform.cpp + * + * @copyright Copyright (C) 2013-2022 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Applies XPath, XSLT, and RelaxNG in order. The provided copy.xls and schema.rng are + * identity transformations. Along with the identity XPath "//src:unit", + * the entire transformation change produces an output identical to the input. + * + * Equivalent to the srcml command line: + * + * srcml -j 1 --xpath="//src:unit" --xslt="copy.xsl" --relaxng="schema.rng" project.xml -o transform.xml +*/ + +#include + +int main(int argc, char * argv[]) { + + // open the input archive + srcml_archive* inputArchive = srcml_archive_create(); + srcml_archive_read_open_filename(inputArchive, "project.xml"); + + // set the transforms in order + srcml_append_transform_xpath(inputArchive, "//src:unit"); + srcml_append_transform_xslt_filename(inputArchive, "copy.xsl"); + srcml_append_transform_relaxng_filename(inputArchive, "schema.rng"); + + // open the output archive + srcml_archive* outputArchive = srcml_archive_clone(inputArchive); + srcml_archive_write_open_filename(outputArchive, "transform.xml"); + + // apply the transformations to the archive + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(inputArchive))) { + + // apply the transforms + srcml_transform_result* result = nullptr; + srcml_unit_apply_transforms(inputArchive, unit, &result); + + // write the transform results + for (int i = 0; i < srcml_transform_get_unit_size(result); ++i) { + srcml_archive_write_unit(outputArchive, srcml_transform_get_unit(result, 0)); + } + + // free the tansformation result + srcml_transform_free(result); + + // free the input unit + srcml_unit_free(unit); + } + + // close the archives + srcml_archive_close(inputArchive); + srcml_archive_close(outputArchive); + + // free the archives + srcml_archive_free(inputArchive); + srcml_archive_free(outputArchive); + + return 0; +} diff --git a/examples/libsrcml/srcml_xpath.c b/examples/libsrcml/srcml_xpath.c deleted file mode 100644 index 78671d4ad6..0000000000 --- a/examples/libsrcml/srcml_xpath.c +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @file srcml_xpath.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - XPath usage. -*/ - -#include - -int main(int argc, char * argv[]) { - - struct srcml_archive* iarchive = srcml_archive_create(); - srcml_archive_read_open_filename(iarchive, "project.xml"); - struct srcml_archive* oarchive = srcml_archive_clone(iarchive); - srcml_archive_write_open_filename(oarchive, "xpath.xml"); - - srcml_append_transform_xpath(iarchive, "//src:unit"); -/* - srcml_unit_apply_transforms(iarchive, oarchive); -*/ - srcml_archive_close(iarchive); - srcml_archive_close(oarchive); - - srcml_archive_free(iarchive); - srcml_archive_free(oarchive); - - return 0; -} diff --git a/examples/libsrcml/srcml_xpath.cpp b/examples/libsrcml/srcml_xpath.cpp new file mode 100644 index 0000000000..373e0f2d47 --- /dev/null +++ b/examples/libsrcml/srcml_xpath.cpp @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_xpath.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Applies an XPath query. The query is an identity transformation, + * the entire transformation change produces an output identical to the input. + * + * Equivalent to the srcml command line: + * + * srcml -j 1 --xpath="//src:unit" project.xml -o xpath.xml +*/ + +#include + +int main(int argc, char * argv[]) { + + // open the input archive + srcml_archive* inputArchive = srcml_archive_create(); + srcml_archive_read_open_filename(inputArchive, "project.xml"); + + // add the xpath transformation + srcml_append_transform_xpath(inputArchive, "//src:unit"); + + // open the output archive + srcml_archive* outputArchive = srcml_archive_clone(inputArchive); + srcml_archive_write_open_filename(outputArchive, "xpath.xml"); + + // apply the transformation to the archive + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(inputArchive))) { + + // apply the transforms + // since an XPath transformation can produce multiple units + // from a single input unit, this requires using the srcml_transform_result + srcml_transform_result* result = nullptr; + srcml_unit_apply_transforms(inputArchive, unit, &result); + + // write the transform result + for (int i = 0; i < srcml_transform_get_unit_size(result); ++i) { + srcml_archive_write_unit(outputArchive, srcml_transform_get_unit(result, i)); + } + + // free the transformation result + srcml_transform_free(result); + + // free the input unit + srcml_unit_free(unit); + } + + // close the archives + srcml_archive_close(inputArchive); + srcml_archive_close(outputArchive); + + // free the archives + srcml_archive_free(inputArchive); + srcml_archive_free(outputArchive); + + return 0; +} diff --git a/examples/libsrcml/srcml_xslt.c b/examples/libsrcml/srcml_xslt.c deleted file mode 100644 index 44e3ac0eb9..0000000000 --- a/examples/libsrcml/srcml_xslt.c +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @file srcml_xslt.c - * - * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - Example program of the use of the C API for srcML. - - XSLT usage. -*/ - -#include - -int main(int argc, char * argv[]) { - - struct srcml_archive* iarchive = srcml_archive_create(); - srcml_archive_read_open_filename(iarchive, "project.xml"); - struct srcml_archive* oarchive = srcml_archive_clone(iarchive); - srcml_archive_write_open_filename(oarchive, "xslt.xml"); - - srcml_append_transform_xslt_filename(iarchive, "copy.xsl"); -/* - srcml_apply_transforms(iarchive, oarchive); -*/ - srcml_archive_close(iarchive); - srcml_archive_close(oarchive); - - srcml_archive_free(iarchive); - srcml_archive_free(oarchive); - - return 0; -} diff --git a/examples/libsrcml/srcml_xslt.cpp b/examples/libsrcml/srcml_xslt.cpp new file mode 100644 index 0000000000..bbcca1de50 --- /dev/null +++ b/examples/libsrcml/srcml_xslt.cpp @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcml_xslt.cpp + * + * @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) + * + * Example program of the use of the libsrcml C API. + * + * Applies XSLT to the archive. The provided copy.xsl is an + * identity transformation. The entire transformation change + * produces an output identical to the input. + * + * Equivalent to the srcml command line: + * + * srcml -j 1 --xslt="copy.xsl" project.xml -o xslt.xml +*/ + +#include + +int main(int argc, char * argv[]) { + + // open the input archive + srcml_archive* inputArchive = srcml_archive_create(); + srcml_archive_read_open_filename(inputArchive, "project.xml"); + + // open the output archive + srcml_archive* outputArchive = srcml_archive_clone(inputArchive); + srcml_archive_write_open_filename(outputArchive, "xslt.xml"); + + // add the XSLT transformation + srcml_append_transform_xslt_filename(inputArchive, "copy.xsl"); + + // apply the transformation to the archive + srcml_unit* unit = nullptr; + while ((unit = srcml_archive_read_unit(inputArchive))) { + + // apply the transform + srcml_transform_result* result = nullptr; + srcml_unit_apply_transforms(inputArchive, unit, &result); + + // write the transform result + for (int i = 0; i < srcml_transform_get_unit_size(result); ++i) { + srcml_archive_write_unit(outputArchive, srcml_transform_get_unit(result, 0)); + } + + // free the tansformation result + srcml_transform_free(result); + + // free the input unit + srcml_unit_free(unit); + } + + // close the archives + srcml_archive_close(inputArchive); + srcml_archive_close(outputArchive); + + // free the archives + srcml_archive_free(inputArchive); + srcml_archive_free(outputArchive); + + return 0; +} diff --git a/package/CMakeLists.txt b/package/CMakeLists.txt index 796c913242..dd66496a75 100644 --- a/package/CMakeLists.txt +++ b/package/CMakeLists.txt @@ -1,87 +1,29 @@ -## +# SPDX-License-Identifier: GPL-3.0-only +# # @file package.cmake -# +# # @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) -# -# The srcML Toolkit is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcML Toolkit is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcML Toolkit; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# -# CMake files for packages +# +# CPack configuration for all installers -# Client component, SRCML, is just one component so it appears as on item -# for installers that let you pick what to install -# Development group, SRCMLDEV, is composed of multiple components -include(CPackComponent) -cpack_add_component(SRCML - DISPLAY_NAME "srcml" - DESCRIPTION "srcml cli program with required library" - REQUIRED) - -cpack_add_component_group(SRCMLDEV - DISPLAY_NAME "Development" - DESCRIPTION "Include file, static library, and examples for developing C++ programs with libsrcml") +# Copy preset file to build directory +configure_file(${CMAKE_SOURCE_DIR}/CMakePresets.json ${CMAKE_BINARY_DIR} COPYONLY) -cpack_add_component(INCLUDE - DISPLAY_NAME "srcml.h" - DESCRIPTION "Include file, srcml.h" - DISABLED - GROUP SRCMLDEV) - -cpack_add_component(DEVLIBS - DISPLAY_NAME "libsrcml.a" - DESCRIPTION "Development libraries, i.e.., static library" - DISABLED - GROUP SRCMLDEV) - -cpack_add_component(EXAMPLES - DISPLAY_NAME "libsrcml examples" - DESCRIPTION "Include file, srcml.h" - DISABLED - GROUP SRCMLDEV) +# Copy user preset file to the build directory if it exists +if(EXISTS ${CMAKE_SOURCE_DIR}/CMakeUserPresets.json) + configure_file(${CMAKE_SOURCE_DIR}/CMakeUserPresets.json ${CMAKE_BINARY_DIR} COPYONLY) +endif() # especially for archives set(CPACK_COMPONENTS_GROUPING "ONE_PER_GROUP") # Package name -set(CPACK_PACKAGE_NAME "srcml") +set(CPACK_PACKAGE_NAME "srcml") # Package release number (NOT srcml or libsrcml release) # Note: Update when package is updated, but not contents set(SRCML_PACKAGE_RELEASE 1) -# executables and text label -set(CPACK_PACKAGE_EXECUTABLES srcml;srcML) - -# desktop links -set(CPACK_CREATE_DESKTOP_LINKS "${CPACK_PACKAGE_NAME}") - -# Generator settings -if(CMAKE_SYSTEM_NAME MATCHES "Windows") - set(CPACK_PACKAGE_FILE_NAME "srcML-Win") -elseif(APPLE) - set(CPACK_GENERATOR "productbuild;TGZ;TBZ2") -else() - if(CMAKE_SYSTEM_NAME MATCHES "Darwin") - set(CPACK_GENERATOR "TGZ;TBZ2") - elseif(DISTRO MATCHES "Ubuntu") - set(CPACK_GENERATOR "DEB;TGZ;TBZ2") - else() - set(CPACK_GENERATOR "RPM;TGZ;TBZ2") - endif() -endif() -message(STATUS "CPack generators: ${CPACK_GENERATOR}") - # summary set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "srcML Toolkit") @@ -92,8 +34,8 @@ set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_SOURCE_DIR}/package/welcome.html) set(CPACK_PACKAGE_VENDOR "srcML, LLC.") # contact -set(CPACK_PACKAGE_CONTACT "Software Development Laboratories srcML.org>") - +set(CPACK_PACKAGE_CONTACT "Software Development Laboratories ") + # package version # set as part of project() @@ -107,33 +49,48 @@ set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md) set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_SOURCE_DIR}/package/welcome.html) # strip executables -#set(CPACK_STRIP_FILES ON) - +set(CPACK_STRIP_FILES ON) + # output directory set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/dist) # Generate user and development tar.gz's set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) -# specific configurations -if (CPACK_GENERATOR MATCHES "RPM") - include(rpm.cmake) -elseif (CPACK_GENERATOR MATCHES "DEB") - include(debian.cmake) -elseif (WIN32) - include(nsis.cmake) -elseif (APPLE) - include(macos.cmake) -endif() +# Client component, SRCML, is just one component so it appears as on item +# for installers that let you pick what to install +# Development group, SRCMLDEV, is composed of multiple components +include(CPackComponent) +cpack_add_install_type(CLIENT DISPLAY_NAME "srcml cli") +cpack_add_install_type(DEVELOPER DISPLAY_NAME "development") -# Perform any platform-specific fixes or updating of the installer -# THis noop version basically just runs the normal packaging, e.g., cpack -if(NOT TARGET gen_package) - add_custom_target(gen_package - COMMAND ${CMAKE_COMMAND} --build . --target package - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - VERBATIM) -endif() +cpack_add_component(SRCML + DISPLAY_NAME "srcml client" + DESCRIPTION "srcml cli program with required libraries" + REQUIRED + INSTALL_TYPES CLIENT DEVELOPER) + +cpack_add_component(DEVLIBS + DISPLAY_NAME "libsrcml development" + DESCRIPTION "Include file, development libraries, i.e.., static library, and CMake configuration" + INSTALL_TYPES DEVELOPER) + +# Copy and rename the README file for the proper extension +configure_file(${CMAKE_SOURCE_DIR}/README.md ${CMAKE_BINARY_DIR}/README.txt COPYONLY) +set(CPACK_RESOURCE_FILE_README ${CMAKE_BINARY_DIR}/README.txt) + +# Generators are defined in the *.cpack files +set(CPACK_GENERATOR) +file(GLOB INSTALLERS "*.cpack") +foreach(INSTALLER IN ITEMS ${INSTALLERS}) + include(${INSTALLER}) +endforeach() + +message(STATUS "CPack generators: ${CPACK_GENERATOR}") + +# Hide the LOCAL components +get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS) +list(REMOVE_ITEM CPACK_COMPONENTS_ALL "LOCAL") # needs to be last so not overwritten include(CPack) diff --git a/package/CPack.distribution.dist.in b/package/CPack.distribution.dist.in index 5648abc591..eb5a02c2cb 100644 --- a/package/CPack.distribution.dist.in +++ b/package/CPack.distribution.dist.in @@ -3,8 +3,8 @@ @CPACK_PACKAGE_NAME@ - + - @CPACK_PACKAGEMAKER_CHOICES@ - \ No newline at end of file +@CPACK_APPLE_PKG_INSTALLER_CONTENT@ + diff --git a/package/WIX.template.in b/package/WIX.template.in new file mode 100644 index 0000000000..094999f1d0 --- /dev/null +++ b/package/WIX.template.in @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + ProductIcon.ico + + + + + + + + + + + + + + + + + + + diff --git a/package/background.png b/package/background.png index c594debf54..3a73967391 100644 Binary files a/package/background.png and b/package/background.png differ diff --git a/package/background_new.bmp b/package/background_new.bmp new file mode 100644 index 0000000000..b2c84eddd8 Binary files /dev/null and b/package/background_new.bmp differ diff --git a/package/banner.png b/package/banner.png new file mode 100644 index 0000000000..b04f1a3f5f Binary files /dev/null and b/package/banner.png differ diff --git a/package/debian.cmake b/package/debian.cpack similarity index 81% rename from package/debian.cmake rename to package/debian.cpack index 76c60fa4b8..4b86dcc42d 100644 --- a/package/debian.cmake +++ b/package/debian.cpack @@ -1,28 +1,23 @@ -## +# SPDX-License-Identifier: GPL-3.0-only +# # @file debian.cmake # # @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) -# -# The srcML Toolkit is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcML Toolkit is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcML Toolkit; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# CPack configuration for Debian installers + +# Exclude other platforms +if(NOT UNIX OR NOT DISTRO OR NOT DISTRO MATCHES "Ubuntu") + return() +endif() + +# Update the generator list +list(APPEND CPACK_GENERATOR "DEB;TGZ;TBZ2") +list(REMOVE_DUPLICATES CPACK_GENERATOR) # Turn ON/OFF internal CPackDeb debugging set(CPACK_DEBIAN_PACKAGE_DEBUG OFF) -# icon -set(CPACK_PACKAGE_ICON ${CMAKE_SOURCE_DIR}/package/srcml_icon.ico) - # Generate user and SRCMLDEV rpms # Note: Yes, this is CPACK_DEB_, not CPACK_DEBIAN set(CPACK_DEB_COMPONENT_INSTALL ON) @@ -44,9 +39,16 @@ string(REGEX MATCH "ID=\([a-z]+\)" _ "${OS_RELEASE}") set(OS_RELEASE_ID "${CMAKE_MATCH_1}") set(DEBIAN_VERSION "${OS_RELEASE_ID}${OS_RELEASE_VERSION_ID}") +# Architecture +if(CMAKE_SYSTEM_PROCESSOR EQUAL "aarch64") + set(SRCML_SYSTEM_ARCHITECTURE "arm64") +else() + set(SRCML_SYSTEM_ARCHITECTURE "amd64") +endif() + # Package filenames -set(BASE_SRCML_FILE_NAME "${CPACK_DEBIAN_SRCML_PACKAGE_NAME}_${PROJECT_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}_${DEBIAN_VERSION}") -set(BASE_SRCMLDEV_FILE_NAME "${CPACK_DEBIAN_SRCMLDEV_PACKAGE_NAME}_${PROJECT_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}_${DEBIAN_VERSION}") +set(BASE_SRCML_FILE_NAME "${CPACK_DEBIAN_SRCML_PACKAGE_NAME}_${PROJECT_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}_${DEBIAN_VERSION}_${CMAKE_SYSTEM_PROCESSOR}") +set(BASE_SRCMLDEV_FILE_NAME "${CPACK_DEBIAN_SRCMLDEV_PACKAGE_NAME}_${PROJECT_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}_${DEBIAN_VERSION}_${CMAKE_SYSTEM_PROCESSOR}") set(CPACK_DEBIAN_SRCML_FILE_NAME "${BASE_SRCML_FILE_NAME}.deb") set(CPACK_DEBIAN_SRCMLDEV_FILE_NAME "${BASE_SRCMLDEV_FILE_NAME}.deb") set(CPACK_ARCHIVE_SRCML_FILE_NAME "${BASE_SRCML_FILE_NAME}") diff --git a/package/inno.cpack b/package/inno.cpack new file mode 100644 index 0000000000..fca0d0c038 --- /dev/null +++ b/package/inno.cpack @@ -0,0 +1,147 @@ +# SPDX-License-Identifier: GPL-3.0-only +# +# @file inno.cpack +# +# @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org) +# +# CPack configuration for Inno Setup installers + +# Exclude other platforms +if(NOT WIN32) + return() +endif() + +# Update the generator list +list(APPEND CPACK_GENERATOR "INNOSETUP") +list(REMOVE_DUPLICATES CPACK_GENERATOR) + +# Package naming +set(CPACK_SYSTEM_NAME "windows-x86_64") + +# Use modern wizard +set(CPACK_INNOSETUP_USE_MODERN_WIZARD ON) + +# Enable welcome page +set(CPACK_INNOSETUP_SETUP_DisableWelcomePage OFF) + +# The path to a custom installer .ico file. This is displayed in the file explorer +set(CPACK_INNOSETUP_ICON_FILE ${CMAKE_SOURCE_DIR}/package/srcml_icon.ico) + +# A branding image that will be displayed inside the installer (used by GUI installers). +# This is displayed in the upper right-hand corner of each page +set(CPACK_PACKAGE_ICON ${CMAKE_SOURCE_DIR}/package/srcml_icon_inno.bmp) + +# The welcome page display image +set(CPACK_INNOSETUP_SETUP_WizardImageFile ${CMAKE_SOURCE_DIR}/package/background_new.bmp) + +# Make the client required +set(CPACK_COMPONENT_SRCML_REQUIRED TRUE) + +# Setup will always show the selected directory in the list of settings on the Ready to Install wizard page +set(CPACK_INNOSETUP_SETUP_AlwaysShowDirOnReadyPage ON) + +# Specify a particular icon file (either an executable or an .ico file) to display for the Uninstall entry in the +# Add/Remove Programs Control Panel applet +set(CPACK_INNOSETUP_SETUP_UninstallDisplayIcon ${CMAKE_SOURCE_DIR}/package/srcml_icon.ico) + +# Extend functionality with custom script, inno_extension_script.iss +set(CPACK_INNOSETUP_EXTRA_SCRIPTS ${CMAKE_BINARY_DIR}/inno_extension_script.iss) + +# Generate inno_extension_script.iss +file(WRITE ${CMAKE_BINARY_DIR}/inno_extension_script.iss +[=[ +[Setup] +ChangesEnvironment=yes + +[Tasks] +Name: "addtosystempath"; Description: "Add srcML to the system PATH for all users"; Flags: exclusive +Name: "addtouserpath"; Description: "Add srcML to the system PATH for the current user"; Flags: exclusive +Name: "dontaddtopath"; Description: "Do not add srcML to the system PATH"; Flags: exclusive + +[Registry] +// Adding to system path +Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}\bin"; Check: ShouldAddToSystemPath +// Adding to current user path +Root: HKCU; Subkey: "Environment"; ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}\bin"; Check: ShouldAddToUserPath +// Adding CMake Registry Key +Root: HKLM; Subkey: "Software\Kitware\CMake\Packages\srcML"; ValueType: string; ValueName: "InstalledDir"; ValueData: ExpandConstant('{app}'); Check: WizardIsComponentSelected('DEVLIBS'); Flags: uninsdeletekey; + +[Code] +function ShouldAddToSystemPath: Boolean; +var + RegPath: String; + RegValue: String; + ResultStr: String; +begin + RegPath := 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'; + RegValue := 'Path'; + + // Check if the value already exists in the registry + Result := WizardIsTaskSelected('addtosystempath') and (RegQueryStringValue(HKLM, RegPath, RegValue, ResultStr) and (Pos(ExpandConstant('{app}\bin'), ResultStr) = 0)); + +end; + +function ShouldAddToUserPath: Boolean; +var + RegPath: String; + RegValue: String; + ResultStr: String; +begin + RegPath := 'Environment'; + RegValue := 'Path'; + + // Check if the value already exists in the registry + Result := WizardIsTaskSelected('addtouserpath') and (RegQueryStringValue(HKCU, RegPath, RegValue, ResultStr) and (Pos(ExpandConstant('{app}\bin'), ResultStr) = 0)); +end; + +var +InfoLabel: TLabel; + +procedure InitializeWizard; +begin + + // Select All Components For Install + WizardSelectComponents('SRCML,SRCMLDEV\DEVLIBS,SRCMLDEV\EXAMPLES'); + + InfoLabel := TLabel.Create(WizardForm); + InfoLabel.Parent := WizardForm.FinishedPage; + InfoLabel.Left := WizardForm.FinishedLabel.Left; + InfoLabel.Top := WizardForm.FinishedLabel.Top + WizardForm.FinishedLabel.Height; + InfoLabel.WordWrap := True; +end; + +procedure CurPageChanged(CurPageID: Integer); +begin + if CurPageID = wpFinished then + begin + InfoLabel.Caption := + 'The srcml command-line program is at ' + ExpandConstant('{app}') + '\bin\srcml.exe'#13#10#13#10 + + '# Convert from a source file to srcML'#13#10 + + 'srcml main.cpp -o main.cpp.xml'#13#10 + + '# Convert from srcML back to source code'#13#10 + + 'srcml main.cpp.xml -o main.cpp'#13#10 + + '# Convert a code fragment to srcML'#13#10 + + 'srcml --text="int a = b;" -l C++ -o fragment.cpp.xml'#13#10 + + '# Convert entire project to srcML'#13#10 + + 'srcml --verbose project -o project.xml'#13#10#13#10; + + if WizardIsComponentSelected('DEVLIBS') then + begin + InfoLabel.Caption := InfoLabel.Caption + + 'The libsrcml development package installed:'#13#10#13#10 + + '* The include file srcml.h in ' + ExpandConstant('{app}') + '\include'#13#10 + + '* The static library libsrcml_static.lib in ' + ExpandConstant('{app}') + '\lib'#13#10 + + '* The debug file libsrcml.pdb in ' + ExpandConstant('{app}') + '\bin'#13#10 + + '* The libsrcml examples in ' + ExpandConstant('{app}') + '\share\srcml'#13#10 + + '* CMake configuration files registered enabling the use of find_package(srcML REQUIRED)'; + end + + else + begin + InfoLabel.Caption := InfoLabel.Caption + + 'The libsrcml development package was not installed. To install, rerun the installer and select the libsrcml development package.'; + end; + + end; +end; +]=]) diff --git a/package/install_dir.wxs b/package/install_dir.wxs new file mode 100644 index 0000000000..bb29fca4e9 --- /dev/null +++ b/package/install_dir.wxs @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + 1 + "1"]]> + + 1 + + NOT Installed + Installed AND PATCH + + 1 + LicenseAccepted = "1" + + 1 + 1 + NOT WIXUI_DONTVALIDATEPATH + "1"]]> + 1]]> + 1 + 1 + + 1 + 1 + + NOT Installed + Installed AND NOT PATCH + Installed AND PATCH + + 1 + + 1 + 1 + 1 + + + + + diff --git a/package/installed.html b/package/installed.html index 7ad0ea8e2f..8228092ff7 100644 --- a/package/installed.html +++ b/package/installed.html @@ -3,8 +3,8 @@