Skip to content

Commit 7262b98

Browse files
authored
Add script to extract JerryScript version from headers (#4333)
This can be used at configuration time to - display version in diagnostics, and - to write proper version number in pkgconfig files. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent 65db835 commit 7262b98

File tree

6 files changed

+57
-4
lines changed

6 files changed

+57
-4
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
cmake_minimum_required (VERSION 2.8.12)
1616
project (Jerry C)
1717

18+
# Determining version
19+
execute_process(COMMAND python ${CMAKE_SOURCE_DIR}/tools/version.py
20+
OUTPUT_VARIABLE JERRY_VERSION
21+
OUTPUT_STRIP_TRAILING_WHITESPACE)
22+
1823
# Determining platform
1924
set(PLATFORM "${CMAKE_SYSTEM_NAME}")
2025
string(TOUPPER "${PLATFORM}" PLATFORM)
@@ -124,6 +129,7 @@ message(STATUS "CMAKE_SYSTEM_PROCESSOR " ${CMAKE_SYSTEM_PROCESSOR})
124129
message(STATUS "BUILD_SHARED_LIBS " ${BUILD_SHARED_LIBS})
125130
message(STATUS "ENABLE_LTO " ${ENABLE_LTO} ${ENABLE_LTO_MESSAGE})
126131
message(STATUS "ENABLE_STRIP " ${ENABLE_STRIP} ${ENABLE_STRIP_MESSAGE})
132+
message(STATUS "JERRY_VERSION " ${JERRY_VERSION})
127133
message(STATUS "JERRY_CMDLINE " ${JERRY_CMDLINE} ${JERRY_CMDLINE_MESSAGE})
128134
message(STATUS "JERRY_CMDLINE_TEST " ${JERRY_CMDLINE_TEST} ${JERRY_CMDLINE_TEST_MESSAGE})
129135
message(STATUS "JERRY_CMDLINE_SNAPSHOT " ${JERRY_CMDLINE_SNAPSHOT} ${JERRY_CMDLINE_SNAPSHOT_MESSAGE})

jerry-core/libjerry-core.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ includedir=${prefix}/include
55
Name: libjerry-core
66
Description: JerryScript: lightweight JavaScript engine (core engine library)
77
URL: https://github.com/jerryscript-project/jerryscript
8-
Version: 1.0
8+
Version: @JERRY_VERSION@
99
Requires.private: @JERRY_CORE_PKGCONFIG_REQUIRES@ # NOTE: libjerry-port-default is not added as a required package
1010
Libs: -L${libdir} -ljerry-core
1111
Libs.private: @JERRY_CORE_PKGCONFIG_LIBS@

jerry-ext/libjerry-ext.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ includedir=${prefix}/include
55
Name: libjerry-ext
66
Description: JerryScript: lightweight JavaScript engine (extensions library)
77
URL: https://github.com/jerryscript-project/jerryscript
8-
Version: 1.0
8+
Version: @JERRY_VERSION@
99
Requires.private: libjerry-core
1010
Libs: -L${libdir} -ljerry-ext
1111
Libs.private: @JERRY_EXT_PKGCONFIG_LIBS@

jerry-libm/libjerry-libm.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ includedir=${prefix}/include/jerry-libm
55
Name: libjerry-libm
66
Description: JerryScript: lightweight JavaScript engine (minimal math library)
77
URL: https://github.com/jerryscript-project/jerryscript
8-
Version: 1.0
8+
Version: @JERRY_VERSION@
99
Libs: -L${libdir} -ljerry-libm
1010
Cflags: -I${includedir}

jerry-port/default/libjerry-port-default.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ includedir=${prefix}/include
55
Name: libjerry-port-default
66
Description: JerryScript: lightweight JavaScript engine (default port library)
77
URL: https://github.com/jerryscript-project/jerryscript
8-
Version: 1.0
8+
Version: @JERRY_VERSION@
99
Libs: -L${libdir} -ljerry-port-default
1010
Cflags: -I${includedir}

tools/version.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright JS Foundation and other contributors, http://js.foundation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from __future__ import print_function
18+
19+
import argparse
20+
import os
21+
import re
22+
import settings
23+
24+
25+
def main():
26+
parser = argparse.ArgumentParser(
27+
description='Display version of JerryScript',
28+
epilog="""
29+
Extract version information from sources without relying on
30+
compiler or preprocessor features.
31+
"""
32+
)
33+
_ = parser.parse_args()
34+
35+
with open(os.path.join(settings.PROJECT_DIR, 'jerry-core', 'include', 'jerryscript-core.h'), 'r') as header:
36+
version = {}
37+
version_re = re.compile(r'\s*#define\s+JERRY_API_(?P<key>MAJOR|MINOR|PATCH)_VERSION\s+(?P<value>\S+)')
38+
for line in header:
39+
match = version_re.match(line)
40+
if match:
41+
version[match.group('key')] = match.group('value')
42+
43+
print('%(MAJOR)s.%(MINOR)s.%(PATCH)s' % version)
44+
45+
46+
if __name__ == "__main__":
47+
main()

0 commit comments

Comments
 (0)