From 8ef37bc00fe492a5cf78d145d1f4d498fc8af445 Mon Sep 17 00:00:00 2001 From: zoziha Date: Thu, 2 Sep 2021 01:22:10 +0800 Subject: [PATCH 1/5] initial add fpm support. --- .github/workflows/fpm-deployment.yml | 60 ++++++++++++++++++++++++++++ ci/fpm-deployment.sh | 35 ++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 .github/workflows/fpm-deployment.yml create mode 100644 ci/fpm-deployment.sh diff --git a/.github/workflows/fpm-deployment.yml b/.github/workflows/fpm-deployment.yml new file mode 100644 index 000000000..f548694a1 --- /dev/null +++ b/.github/workflows/fpm-deployment.yml @@ -0,0 +1,60 @@ +name: fpm-deployment + +# When a PR occurs, the fpm package of `stdlib` will be generated. +on: [push, pull_request] +env: + GCC_V: "10" + +jobs: + Build: + runs-on: ubuntu-latest + + steps: + - name: Git clone fpm branch (stdlib-fpm) + run: git clone -b stdlib-fpm https://github.com/fortran-lang/stdlib.git + + - name: Checkout stdlib code (master) + uses: actions/checkout@v2 + with: + path: "stdlib-master" + + - name: Set up Python 3.x + uses: actions/setup-python@v1 + with: + python-version: 3.x + + - name: Install fypp + run: pip install --upgrade fypp + + - name: Generate stdlib-fpm package + run: | + ls + sh ./stdlib-master/ci/fpm-deployment.sh + + - name: Install GFortran + run: | + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ env.GCC_V }} 100 \ + --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${{ env.GCC_V }} \ + --slave /usr/bingcov gcov /usr/bin/gcov-${{ env.GCC_V }} + - name: Install fpm latest release + uses: fortran-lang/setup-fpm@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run fpm test + run: | + cp -r stdlib stdlib-fpm-test + cd stdlib-fpm-test + fpm test + - name: Run fpm test (release) + run: | + cd stdlib-fpm-test + fpm test --profile release + # Update and deploy the f90 files generated by github-ci to the `stdlib-fpm` branch. + - name: Deploy + uses: JamesIves/github-pages-deploy-action@releases/v3 + if: github.event_name != 'pull_request' + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: stdlib-fpm + FOLDER: stdlib \ No newline at end of file diff --git a/ci/fpm-deployment.sh b/ci/fpm-deployment.sh new file mode 100644 index 000000000..bbd85c9c7 --- /dev/null +++ b/ci/fpm-deployment.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# +set -ex + +SRCDIR="stdlib-master" +DESTDIR="stdlib" + +FYFLAGS="-DMAXRANK=4" + +mkdir -p $DESTDIR/src +mkdir -p $DESTDIR/test + +# Clean destination +rm -rf $DESTDIR/src/* +rm -rf $DESTDIR/test/* + +# Preprocess stdlib sources +ls $SRCDIR/src/*.fypp | cut -f1 -d. | xargs -i{} fypp {}.fypp {}.f90 $FYFLAGS + +# Collect stdlib files +find $SRCDIR/src -maxdepth 1 -iname "*.f90" -exec cp {} $DESTDIR/src/ \; +find $SRCDIR/src/tests -name "test_*.f90" -exec cp {} $DESTDIR/test/ \; +find $SRCDIR/src/tests -name "*.dat" -exec cp {} $DESTDIR/ \; +cp $SRCDIR/LICENSE $DESTDIR/ + +# Source file workarounds for fpm +rm $DESTDIR/test/test_always_fail.f90 +rm $DESTDIR/test/test_always_skip.f90 +rm $DESTDIR/test/test_mean_f03.f90 +rm $DESTDIR/src/common.f90 +rm $DESTDIR/src/f18estop.f90 + +# List stdlib-fpm package contents +ls -R $DESTDIR \ No newline at end of file From b81199e62bed0341845084361789f18f2885010d Mon Sep 17 00:00:00 2001 From: zoziha Date: Mon, 13 Sep 2021 17:49:01 +0800 Subject: [PATCH 2/5] add ./ci/fpm.toml and update README.md . --- .github/workflows/fpm-deployment.yml | 31 ++++++++++------------------ README.md | 15 ++++++++++++++ ci/fpm-deployment.sh | 20 +++++++----------- ci/fpm.toml | 5 +++++ 4 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 ci/fpm.toml diff --git a/.github/workflows/fpm-deployment.yml b/.github/workflows/fpm-deployment.yml index f548694a1..081ae1c32 100644 --- a/.github/workflows/fpm-deployment.yml +++ b/.github/workflows/fpm-deployment.yml @@ -1,6 +1,5 @@ name: fpm-deployment -# When a PR occurs, the fpm package of `stdlib` will be generated. on: [push, pull_request] env: GCC_V: "10" @@ -10,13 +9,8 @@ jobs: runs-on: ubuntu-latest steps: - - name: Git clone fpm branch (stdlib-fpm) - run: git clone -b stdlib-fpm https://github.com/fortran-lang/stdlib.git - - - name: Checkout stdlib code (master) - uses: actions/checkout@v2 - with: - path: "stdlib-master" + - name: Checkout 🛎️ + uses: actions/checkout@v2.3.1 - name: Set up Python 3.x uses: actions/setup-python@v1 @@ -26,35 +20,32 @@ jobs: - name: Install fypp run: pip install --upgrade fypp - - name: Generate stdlib-fpm package + - name: Generate stdlib-fpm package 🔧 run: | - ls - sh ./stdlib-master/ci/fpm-deployment.sh + sh ./ci/fpm-deployment.sh - name: Install GFortran run: | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ env.GCC_V }} 100 \ --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${{ env.GCC_V }} \ --slave /usr/bingcov gcov /usr/bin/gcov-${{ env.GCC_V }} + - name: Install fpm latest release uses: fortran-lang/setup-fpm@v3 with: github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Run fpm test + - name: Run fpm test ⚙ run: | - cp -r stdlib stdlib-fpm-test + cp -r stdlib-fpm stdlib-fpm-test cd stdlib-fpm-test fpm test - - name: Run fpm test (release) - run: | - cd stdlib-fpm-test fpm test --profile release + # Update and deploy the f90 files generated by github-ci to the `stdlib-fpm` branch. - - name: Deploy - uses: JamesIves/github-pages-deploy-action@releases/v3 + - name: Deploy 🚀 + uses: JamesIves/github-pages-deploy-action@4.1.5 if: github.event_name != 'pull_request' with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH: stdlib-fpm - FOLDER: stdlib \ No newline at end of file + FOLDER: stdlib-fpm \ No newline at end of file diff --git a/README.md b/README.md index f75a2e24b..e2678e4bd 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ - [Supported compilers](#supported-compilers) - [Build with CMake](#build-with-cmake) - [Build with make](#build-with-make) + - [Build with fortran-lang/fpm](#build-with-fortran-langfpm) * [Using stdlib in your project](#using-stdlib-in-your-project) * [Documentation](#documentation) * [Contributing](#contributing) @@ -176,7 +177,21 @@ You can limit the maximum rank by setting ``-DMAXRANK=`` in the ``FYPPFLAGS make -f Makefile.manual FYPPFLAGS=-DMAXRANK=4 ``` +### Build with [fortran-lang/fpm](https://github.com/fortran-lang/fpm) +Fortran Package Manager (fpm) is a great package manager and build system for Fortran. +You can build using provided `fpm.toml`: + +```sh +git checkout stdlib-fpm +fpm build --profile release +``` + +To use `stdlib` within your `fpm` project, add the following to your `fpm.toml` file: +```toml +[dependencies] +stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm" } +``` ## Using stdlib in your project diff --git a/ci/fpm-deployment.sh b/ci/fpm-deployment.sh index bbd85c9c7..fa0e1a590 100644 --- a/ci/fpm-deployment.sh +++ b/ci/fpm-deployment.sh @@ -3,26 +3,22 @@ # set -ex -SRCDIR="stdlib-master" -DESTDIR="stdlib" +DESTDIR="stdlib-fpm" FYFLAGS="-DMAXRANK=4" mkdir -p $DESTDIR/src mkdir -p $DESTDIR/test -# Clean destination -rm -rf $DESTDIR/src/* -rm -rf $DESTDIR/test/* - # Preprocess stdlib sources -ls $SRCDIR/src/*.fypp | cut -f1 -d. | xargs -i{} fypp {}.fypp {}.f90 $FYFLAGS +ls src/*.fypp | cut -f1 -d. | xargs -i{} fypp {}.fypp {}.f90 $FYFLAGS # Collect stdlib files -find $SRCDIR/src -maxdepth 1 -iname "*.f90" -exec cp {} $DESTDIR/src/ \; -find $SRCDIR/src/tests -name "test_*.f90" -exec cp {} $DESTDIR/test/ \; -find $SRCDIR/src/tests -name "*.dat" -exec cp {} $DESTDIR/ \; -cp $SRCDIR/LICENSE $DESTDIR/ +find src -maxdepth 1 -iname "*.f90" -exec cp {} $DESTDIR/src/ \; +find src/tests -name "test_*.f90" -exec cp {} $DESTDIR/test/ \; +find src/tests -name "*.dat" -exec cp {} $DESTDIR/ \; +cp LICENSE $DESTDIR/ +cp ci/fpm.toml $DESTDIR/ # Source file workarounds for fpm rm $DESTDIR/test/test_always_fail.f90 @@ -32,4 +28,4 @@ rm $DESTDIR/src/common.f90 rm $DESTDIR/src/f18estop.f90 # List stdlib-fpm package contents -ls -R $DESTDIR \ No newline at end of file +ls -R $DESTDIR diff --git a/ci/fpm.toml b/ci/fpm.toml new file mode 100644 index 000000000..fc8cb8b7e --- /dev/null +++ b/ci/fpm.toml @@ -0,0 +1,5 @@ +name = "stdlib" +version = "0.0.0" +license = "MIT" +author = "stdlib contributors" +copyright = "2019-2021 stdlib contributors" \ No newline at end of file From af8b766e4a923d0364e8b03061456ac8f5ff1e1a Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Mon, 13 Sep 2021 21:11:14 +0200 Subject: [PATCH 3/5] Minor adjustments to script - fix all shellcheck warning - don't write into source directory - allow adjusting of destination directory --- .gitignore | 1 + ci/fpm-deployment.sh | 57 +++++++++++++++++++++++++++++--------------- ci/fpm.toml | 10 ++++---- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index d6e779c07..8d1cff52f 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ API-doc/ # Build directory for out-of-tree builds /build +/stdlib-fpm # Emacs backup files *~ diff --git a/ci/fpm-deployment.sh b/ci/fpm-deployment.sh index fa0e1a590..a784b3920 100644 --- a/ci/fpm-deployment.sh +++ b/ci/fpm-deployment.sh @@ -1,31 +1,50 @@ #!/usr/bin/env bash -# -# + set -ex -DESTDIR="stdlib-fpm" +# Target directory to deploy stdlib to +destdir="${DESTDIR:-stdlib-fpm}" + +# Get fypp preprocessor +fypp="${FYPP:-$(which fypp)}" + +# Arguments for the fypp preprocessor +fyflags="${FYFLAGS:--DMAXRANK=4}" -FYFLAGS="-DMAXRANK=4" +# Number of parallel jobs for preprocessing +njob="$(nproc)" -mkdir -p $DESTDIR/src -mkdir -p $DESTDIR/test +# Additional files to include +include=( + "ci/fpm.toml" + "LICENSE" +) + +# Files to remove from collection +prune=( + "$destdir/test/test_always_fail.f90" + "$destdir/test/test_always_skip.f90" + "$destdir/test/test_mean_f03.f90" + "$destdir/src/common.f90" + "$destdir/src/f18estop.f90" +) + +mkdir -p "$destdir/src" "$destdir/test" # Preprocess stdlib sources -ls src/*.fypp | cut -f1 -d. | xargs -i{} fypp {}.fypp {}.f90 $FYFLAGS +find src -maxdepth 1 -iname "*.fypp" \ + | cut -f1 -d. | xargs -P "$njob" -I{} "$fypp" "{}.fypp" "$destdir/{}.f90" $fyflags + +# Collect stdlib source files +find src -maxdepth 1 -iname "*.f90" -exec cp {} "$destdir/src/" \; +find src/tests -name "test_*.f90" -exec cp {} "$destdir/test/" \; +find src/tests -name "*.dat" -exec cp {} "$destdir/" \; -# Collect stdlib files -find src -maxdepth 1 -iname "*.f90" -exec cp {} $DESTDIR/src/ \; -find src/tests -name "test_*.f90" -exec cp {} $DESTDIR/test/ \; -find src/tests -name "*.dat" -exec cp {} $DESTDIR/ \; -cp LICENSE $DESTDIR/ -cp ci/fpm.toml $DESTDIR/ +# Include additional files +cp "${include[@]}" "$destdir/" # Source file workarounds for fpm -rm $DESTDIR/test/test_always_fail.f90 -rm $DESTDIR/test/test_always_skip.f90 -rm $DESTDIR/test/test_mean_f03.f90 -rm $DESTDIR/src/common.f90 -rm $DESTDIR/src/f18estop.f90 +rm "${prune[@]}" # List stdlib-fpm package contents -ls -R $DESTDIR +ls -R "$destdir" diff --git a/ci/fpm.toml b/ci/fpm.toml index fc8cb8b7e..eaa59c013 100644 --- a/ci/fpm.toml +++ b/ci/fpm.toml @@ -1,5 +1,5 @@ -name = "stdlib" -version = "0.0.0" -license = "MIT" -author = "stdlib contributors" -copyright = "2019-2021 stdlib contributors" \ No newline at end of file +name = "stdlib" +version = "0.0.0" +license = "MIT" +author = "stdlib contributors" +copyright = "2019-2021 stdlib contributors" From 64ec9f834f4590485acb4874152d45b58e55af2a Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Tue, 14 Sep 2021 08:26:22 +0200 Subject: [PATCH 4/5] Use bash instead of POSIX sh for deployment script --- .github/workflows/fpm-deployment.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fpm-deployment.yml b/.github/workflows/fpm-deployment.yml index 081ae1c32..e33afe764 100644 --- a/.github/workflows/fpm-deployment.yml +++ b/.github/workflows/fpm-deployment.yml @@ -22,7 +22,7 @@ jobs: - name: Generate stdlib-fpm package 🔧 run: | - sh ./ci/fpm-deployment.sh + bash ./ci/fpm-deployment.sh - name: Install GFortran run: | @@ -48,4 +48,4 @@ jobs: if: github.event_name != 'pull_request' with: BRANCH: stdlib-fpm - FOLDER: stdlib-fpm \ No newline at end of file + FOLDER: stdlib-fpm From 7abb41343161b3286dc8880c2b54af3910abc82c Mon Sep 17 00:00:00 2001 From: zoziha <1325686572@qq.com> Date: Wed, 15 Sep 2021 19:30:27 +0800 Subject: [PATCH 5/5] A minor fix. --- .github/workflows/fpm-deployment.yml | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/fpm-deployment.yml b/.github/workflows/fpm-deployment.yml index e33afe764..f01fec2b3 100644 --- a/.github/workflows/fpm-deployment.yml +++ b/.github/workflows/fpm-deployment.yml @@ -28,7 +28,7 @@ jobs: run: | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ env.GCC_V }} 100 \ --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${{ env.GCC_V }} \ - --slave /usr/bingcov gcov /usr/bin/gcov-${{ env.GCC_V }} + --slave /usr/bin/gcov gcov /usr/bin/gcov-${{ env.GCC_V }} - name: Install fpm latest release uses: fortran-lang/setup-fpm@v3 diff --git a/README.md b/README.md index e2678e4bd..acefeb61a 100644 --- a/README.md +++ b/README.md @@ -179,15 +179,15 @@ make -f Makefile.manual FYPPFLAGS=-DMAXRANK=4 ### Build with [fortran-lang/fpm](https://github.com/fortran-lang/fpm) -Fortran Package Manager (fpm) is a great package manager and build system for Fortran. -You can build using provided `fpm.toml`: +Fortran Package Manager (fpm) is a package manager and build system for Fortran. +You can build `stdlib` using provided `fpm.toml`: ```sh git checkout stdlib-fpm fpm build --profile release ``` -To use `stdlib` within your `fpm` project, add the following to your `fpm.toml` file: +To use `stdlib` within your `fpm` project, add the following lines to your `fpm.toml` file: ```toml [dependencies] stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm" }