Skip to content

Commit 3af3259

Browse files
awvwgkivan-piCarlos Unejvdp1
authored
Add module for handling version information of stdlib (#579)
Co-authored-by: Ivan Pribec <[email protected]> Co-authored-by: Carlos Une <[email protected]> Co-authored-by: Jeremie Vandenplas <[email protected]>
1 parent 57c41f9 commit 3af3259

13 files changed

+168
-4
lines changed

.github/workflows/CI.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ jobs:
9494
- name: Test manual makefiles
9595
if: ${{ matrix.build == 'make' }}
9696
run: |
97-
make -f Makefile.manual FYPPFLAGS="-DMAXRANK=4" -j
97+
make -f Makefile.manual -j
9898
make -f Makefile.manual test
9999
make -f Makefile.manual clean
100+
env:
101+
FYPPFLAGS: "-DMAXRANK=4"
100102

101103
intel-build:
102104
runs-on: ${{ matrix.os }}

API-doc-FORD-file.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ media_dir: doc/media
99
fpp_extensions: fypp
1010
preprocess: true
1111
macro: MAXRANK=3
12+
PROJECT_VERSION_MAJOR=0
13+
PROJECT_VERSION_MINOR=0
14+
PROJECT_VERSION_PATCH=0
1215
preprocessor: fypp
1316
display: public
1417
protected

CMakeLists.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
cmake_minimum_required(VERSION 3.14.0)
22
project(fortran_stdlib
33
LANGUAGES Fortran
4-
VERSION 0.1.0
54
DESCRIPTION "Community driven and agreed upon de facto standard library for Fortran"
65
)
6+
7+
# Read version from file
8+
file(STRINGS "${PROJECT_SOURCE_DIR}/VERSION" PROJECT_VERSION)
9+
string(REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION})
10+
list(GET VERSION_LIST 0 PROJECT_VERSION_MAJOR)
11+
list(GET VERSION_LIST 1 PROJECT_VERSION_MINOR)
12+
list(GET VERSION_LIST 2 PROJECT_VERSION_PATCH)
13+
unset(VERSION_LIST)
14+
715
enable_testing()
816

917
# Follow GNU conventions for installation directories

Makefile.manual

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ FC ?= gfortran
44
FFLAGS ?= -Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all
55
FYPPFLAGS ?=
66

7+
VERSION := $(subst ., ,$(file < VERSION))
8+
FYPPFLAGS += \
9+
-DPROJECT_VERSION_MAJOR=$(word 1,$(VERSION)) \
10+
-DPROJECT_VERSION_MINOR=$(word 2,$(VERSION)) \
11+
-DPROJECT_VERSION_PATCH=$(word 3,$(VERSION))
12+
713
export FC
814
export FFLAGS
915
export FYPPFLAGS

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

ci/fpm-deployment.sh

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fi
2222
include=(
2323
"ci/fpm.toml"
2424
"LICENSE"
25+
"VERSION"
2526
)
2627

2728
# Files to remove from collection
@@ -32,6 +33,11 @@ prune=(
3233
"$destdir/src/f18estop.f90"
3334
)
3435

36+
major=$(cut -d. -f1 VERSION)
37+
minor=$(cut -d. -f2 VERSION)
38+
patch=$(cut -d. -f3 VERSION)
39+
fyflags="${fyflags} -DPROJECT_VERSION_MAJOR=${major} -DPROJECT_VERSION_MINOR=${minor} -DPROJECT_VERSION_PATCH=${patch}"
40+
3541
mkdir -p "$destdir/src" "$destdir/test"
3642

3743
# Preprocess stdlib sources

ci/fpm.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "stdlib"
2-
version = "0.1.0"
2+
version = "VERSION"
33
license = "MIT"
44
author = "stdlib contributors"
55
maintainer = "@fortran-lang/stdlib"

doc/specs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This is and index/directory of the specifications (specs) for each new module/fe
2828
- [string\_type](./stdlib_string_type.html) - Basic string support
2929
- [strings](./stdlib_strings.html) - String handling and manipulation routines
3030
- [stringlist_type](./stdlib_stringlist_type.html) - 1-Dimensional list of strings
31+
- [version](./stdlib_version.html) - Version information
3132

3233
## Released/Stable Features & Modules
3334

doc/specs/stdlib_version.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Version information
3+
---
4+
5+
# The `stdlib_version` module
6+
7+
[TOC]
8+
9+
## Introduction
10+
11+
The `stdlib_version` module contains the version of the standard library.
12+
The version information can be used as a compile time constant or retrieved from a getter function at runtime.
13+
In case the standard library is dynamically linked, the version number retrieved from the getter might mismatch the compile time constants provided from the version built against.
14+
Therefore, it is recommended to retrieve the version information always at runtime.
15+
16+
17+
## Constants provided by `stdlib_version`
18+
19+
### `stdlib_version_string`
20+
21+
String constant representing the version number.
22+
23+
### `stdlib_version_compact`
24+
25+
Compact representation of the version string following the scheme:
26+
major * 10000 + minor * 100 + patch.
27+
28+
29+
### `get_stdlib_version`
30+
31+
#### Status
32+
33+
Experimental
34+
35+
#### Description
36+
37+
Getter function to retrieve version information
38+
39+
#### Syntax
40+
41+
`res = [[stdlib_version(module):get_stdlib_version(function)]] ([major], [minor], [patch], [string])`
42+
43+
#### Class
44+
45+
Pure subroutine.
46+
47+
#### Argument
48+
49+
`major`: shall be an intrinsic integer type. It is an optional, `intent(out)` argument.
50+
`minor`: shall be an intrinsic integer type. It is an optional, `intent(out)` argument.
51+
`patch`: shall be an intrinsic integer type. It is an optional, `intent(out)` argument.
52+
`string`: shall be a deferred length character type. It is an optional, `intent(out)` argument.
53+
54+
#### Example
55+
56+
```fortran
57+
program demo_version
58+
use stdlib_version, only : get_stdlib_version
59+
implicit none
60+
character(len=:), allocatable :: version
61+
call get_stdlib_version(string=version)
62+
print '(a)', version
63+
end program demo_version
64+
```

src/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set(fppFiles
3939
stdlib_string_type_constructor.fypp
4040
stdlib_strings_to_string.fypp
4141
stdlib_strings.fypp
42+
stdlib_version.fypp
4243
)
4344

4445

@@ -55,6 +56,9 @@ list(
5556
APPEND fyppFlags
5657
"-DWITH_QP=$<BOOL:${WITH_QP}>"
5758
"-DWITH_XDP=$<BOOL:${WITH_XDP}>"
59+
"-DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}"
60+
"-DPROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}"
61+
"-DPROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}"
5862
)
5963

6064
fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)

src/Makefile.manual

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ SRCFYPP = \
3535
stdlib_string_type.fypp \
3636
stdlib_string_type_constructor.fypp \
3737
stdlib_strings.fypp \
38-
stdlib_strings_to_string.fypp
38+
stdlib_strings_to_string.fypp \
39+
stdlib_version.fypp
3940

4041
SRC = f18estop.f90 \
4142
stdlib_error.f90 \

src/common.fypp

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#:mute
22

3+
#! Project version number
4+
#:set PROJECT_VERSION = "{}.{}.{}".format(PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, PROJECT_VERSION_PATCH)
5+
36
#! Support for quadruple precision floating point numbers
47
#:if not defined("WITH_QP")
58
#:set WITH_QP = False

src/stdlib_version.fypp

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
! SPDX-Identifier: MIT
2+
3+
#:include "common.fypp"
4+
5+
!> Version information on stdlib
6+
module stdlib_version
7+
implicit none
8+
private
9+
10+
public :: get_stdlib_version
11+
public :: stdlib_version_string, stdlib_version_compact
12+
13+
14+
!> String representation of the standard library version
15+
character(len=*), parameter :: stdlib_version_string = "${PROJECT_VERSION}$"
16+
17+
!> Major version number of the above standard library version
18+
integer, parameter :: stdlib_major = ${PROJECT_VERSION_MAJOR}$
19+
20+
!> Minor version number of the above standard library version
21+
integer, parameter :: stdlib_minor = ${PROJECT_VERSION_MINOR}$
22+
23+
!> Patch version number of the above standard library version
24+
integer, parameter :: stdlib_patch = ${PROJECT_VERSION_PATCH}$
25+
26+
!> Compact numeric representation of the standard library version
27+
integer, parameter :: stdlib_version_compact = &
28+
& stdlib_major*10000 + stdlib_minor*100 + stdlib_patch
29+
30+
31+
contains
32+
33+
34+
!> Getter function to retrieve standard library version
35+
pure subroutine get_stdlib_version(major, minor, patch, string)
36+
37+
!> Major version number of the standard library version
38+
integer, intent(out), optional :: major
39+
40+
!> Minor version number of the standard library version
41+
integer, intent(out), optional :: minor
42+
43+
!> Patch version number of the standard library version
44+
integer, intent(out), optional :: patch
45+
46+
!> String representation of the standard library version
47+
character(len=:), allocatable, intent(out), optional :: string
48+
49+
if (present(major)) then
50+
major = stdlib_major
51+
end if
52+
if (present(minor)) then
53+
minor = stdlib_minor
54+
end if
55+
if (present(patch)) then
56+
patch = stdlib_patch
57+
end if
58+
if (present(string)) then
59+
string = stdlib_version_string
60+
end if
61+
62+
end subroutine get_stdlib_version
63+
64+
65+
end module stdlib_version

0 commit comments

Comments
 (0)