From 392f6d4a3bfbb57a7acf4d41e3b7b87fdc8fe50e Mon Sep 17 00:00:00 2001 From: Robert Sipka Date: Mon, 2 Jan 2017 10:47:50 +0100 Subject: [PATCH] Modify the profile option to specify external compile definitions. (#1497) JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com --- jerry-core/CMakeLists.txt | 35 +++++++------------- jerry-core/profiles/README.md | 39 +++++++++++++++++++++++ jerry-core/profiles/es2015-subset.profile | 1 + jerry-core/profiles/es5.1.profile | 1 + jerry-core/profiles/minimal.profile | 11 +++++++ tests/unit/CMakeLists.txt | 6 +++- tools/build.py | 14 ++++++-- 7 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 jerry-core/profiles/README.md create mode 100644 jerry-core/profiles/es2015-subset.profile create mode 100644 jerry-core/profiles/es5.1.profile create mode 100644 jerry-core/profiles/minimal.profile diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt index 7094d18fe..e9f2380ce 100644 --- a/jerry-core/CMakeLists.txt +++ b/jerry-core/CMakeLists.txt @@ -23,7 +23,7 @@ set(FEATURE_JS_PARSER ON CACHE BOOL "Enable js-parser?") set(FEATURE_MEM_STATS OFF CACHE BOOL "Enable memory statistics?") set(FEATURE_MEM_STRESS_TEST OFF CACHE BOOL "Enable mem-stress test?") set(FEATURE_PARSER_DUMP OFF CACHE BOOL "Enable parser byte-code dumps?") -set(FEATURE_PROFILE "es5.1" CACHE STRING "Profile types: es5.1, minimal, es2015-subset") +set(FEATURE_PROFILE "es5.1" CACHE STRING "Use default or other profile?") set(FEATURE_REGEXP_DUMP OFF CACHE BOOL "Enable regexp byte-code dumps?") set(FEATURE_SNAPSHOT_EXEC OFF CACHE BOOL "Enable executing snapshot files?") set(FEATURE_SNAPSHOT_SAVE OFF CACHE BOOL "Enable saving snapshot files?") @@ -163,28 +163,17 @@ if(FEATURE_PARSER_DUMP) set(DEFINES_JERRY ${DEFINES_JERRY} PARSER_DUMP_BYTE_CODE) endif() -# Profile modes -set(CONFIG_DISABLE_ES2015 - CONFIG_DISABLE_ARRAYBUFFER_BUILTIN) -# Minimal profile -if(FEATURE_PROFILE STREQUAL "minimal") - set(DEFINES_JERRY ${DEFINES_JERRY} - ${CONFIG_DISABLE_ES2015} - CONFIG_DISABLE_ANNEXB_BUILTIN - CONFIG_DISABLE_ARRAY_BUILTIN - CONFIG_DISABLE_BOOLEAN_BUILTIN - CONFIG_DISABLE_DATE_BUILTIN - CONFIG_DISABLE_ERROR_BUILTINS - CONFIG_DISABLE_JSON_BUILTIN - CONFIG_DISABLE_MATH_BUILTIN - CONFIG_DISABLE_NUMBER_BUILTIN - CONFIG_DISABLE_REGEXP_BUILTIN - CONFIG_DISABLE_STRING_BUILTIN) -elseif(FEATURE_PROFILE STREQUAL "es5.1") - set(DEFINES_JERRY ${DEFINES_JERRY} - ${CONFIG_DISABLE_ES2015}) -elseif(NOT FEATURE_PROFILE STREQUAL "es2015-subset") - message(FATAL_ERROR "FEATURE_PROFILE='${FEATURE_PROFILE}' isn't supported") +if (NOT IS_ABSOLUTE ${FEATURE_PROFILE}) + set(FEATURE_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/profiles/${FEATURE_PROFILE}.profile") +endif() + +if(EXISTS ${FEATURE_PROFILE}) + FILE(READ "${FEATURE_PROFILE}" PROFILE_SETTINGS) + STRING(REGEX REPLACE "^#.*$" "" PROFILE_SETTINGS "${PROFILE_SETTINGS}") + STRING(REGEX REPLACE "[\r|\n]" ";" PROFILE_SETTINGS "${PROFILE_SETTINGS}") + set(DEFINES_JERRY ${DEFINES_JERRY} ${PROFILE_SETTINGS}) +else() + MESSAGE(FATAL_ERROR "Profile file: '${FEATURE_PROFILE}' doesn't exist!") endif() # RegExp byte-code dumps diff --git a/jerry-core/profiles/README.md b/jerry-core/profiles/README.md new file mode 100644 index 000000000..0924b6d62 --- /dev/null +++ b/jerry-core/profiles/README.md @@ -0,0 +1,39 @@ + +### About profile files + +Specify compile definitions in profile files to use when compiling the `jerry-core` target. + +The default profile is ``es5.1`` which disables the ArrayBuffer built-in. + +### Using profiles with the build system + +You can specify the profile for the build system in the following ways: + * with absolute path + * with a name (this options selects profiles/$(name).profile file) + +#### Restrictions +Only single line options are allowed in the profile file. Any line starting with hash-mark is ignored. Semicolon character is not allowed. + +### Example usage: + +#### 1. Using the build script + +``` +# assuming you are in jerryscript folder +./tools/build.py --profile=/absolute/path/to/my_profile.any_extension +``` + +or + +``` +# assuming you are in jerryscript folder +./tools/build.py --profile=minimal +``` + +This command selects the profile/minimal.profile file. + +#### 2. Using only CMake build system + +Set FEATURE_PROFILE option to one of the following values: +* the profile with absolute path +* name of the profile (which needs to exist in the `profiles` folder) diff --git a/jerry-core/profiles/es2015-subset.profile b/jerry-core/profiles/es2015-subset.profile new file mode 100644 index 000000000..93c0f3575 --- /dev/null +++ b/jerry-core/profiles/es2015-subset.profile @@ -0,0 +1 @@ +# Currently an empty profile. diff --git a/jerry-core/profiles/es5.1.profile b/jerry-core/profiles/es5.1.profile new file mode 100644 index 000000000..1bbf25213 --- /dev/null +++ b/jerry-core/profiles/es5.1.profile @@ -0,0 +1 @@ +CONFIG_DISABLE_ARRAYBUFFER_BUILTIN diff --git a/jerry-core/profiles/minimal.profile b/jerry-core/profiles/minimal.profile new file mode 100644 index 000000000..726eaafe7 --- /dev/null +++ b/jerry-core/profiles/minimal.profile @@ -0,0 +1,11 @@ +CONFIG_DISABLE_ARRAYBUFFER_BUILTIN +CONFIG_DISABLE_ANNEXB_BUILTIN +CONFIG_DISABLE_ARRAY_BUILTIN +CONFIG_DISABLE_BOOLEAN_BUILTIN +CONFIG_DISABLE_DATE_BUILTIN +CONFIG_DISABLE_ERROR_BUILTINS +CONFIG_DISABLE_JSON_BUILTIN +CONFIG_DISABLE_MATH_BUILTIN +CONFIG_DISABLE_NUMBER_BUILTIN +CONFIG_DISABLE_REGEXP_BUILTIN +CONFIG_DISABLE_STRING_BUILTIN diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 0b6e69f07..5da7ae051 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -15,7 +15,11 @@ cmake_minimum_required (VERSION 2.8.12) project (Unittest C) -if(NOT FEATURE_PROFILE STREQUAL "es5.1") +if (NOT IS_ABSOLUTE ${FEATURE_PROFILE}) + set(FEATURE_PROFILE "${CMAKE_SOURCE_DIR}/jerry-core/profiles/${FEATURE_PROFILE}.profile") +endif() + +if(NOT ${FEATURE_PROFILE} STREQUAL "${CMAKE_SOURCE_DIR}/jerry-core/profiles/es5.1.profile") message(FATAL_ERROR "FEATURE_PROFILE='${FEATURE_PROFILE}' isn't supported with UNITTESTS=ON") endif() diff --git a/tools/build.py b/tools/build.py index a7ca5b6a7..745c0731f 100755 --- a/tools/build.py +++ b/tools/build.py @@ -25,6 +25,9 @@ from settings import * BUILD_DIR = path.join(PROJECT_DIR, 'build') DEFAULT_PORT_DIR = path.join(PROJECT_DIR, 'targets/default') +PROFILE_DIR = path.join(PROJECT_DIR, 'jerry-core/profiles') +DEFAULT_PROFILE = 'es5.1' + def default_toolchain(): (sysname, _, _, _, machine) = uname() toolchain = path.join(PROJECT_DIR, 'cmake', 'toolchain_%s_%s.cmake' % (sysname.lower(), machine.lower())) @@ -61,7 +64,7 @@ def get_arguments(): parser.add_argument('--lto', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='enable link-time optimizations (%(choices)s; default: %(default)s)') parser.add_argument('--mem-heap', metavar='SIZE', action='store', type=int, default=512, help='size of memory heap, in kilobytes (default: %(default)s)') parser.add_argument('--port-dir', metavar='DIR', action='store', default=DEFAULT_PORT_DIR, help='add port directory (default: %(default)s)') - parser.add_argument('--profile', metavar='PROFILE', choices=['es5.1', 'minimal', 'es2015-subset'], default='es5.1', type=str.lower, help='specify the profile (%(choices)s; default: %(default)s)') + parser.add_argument('--profile', metavar='FILE', action='store', default=DEFAULT_PROFILE, help='specify profile file (default: %(default)s)') parser.add_argument('--snapshot-exec', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable executing snapshot files (%(choices)s; default: %(default)s)') parser.add_argument('--snapshot-save', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable saving snapshot files (%(choices)s; default: %(default)s)') parser.add_argument('--static-link', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='enable static linking of binaries (%(choices)s; default: %(default)s)') @@ -105,7 +108,14 @@ def generate_build_options(arguments): build_options.append('-DENABLE_LTO=%s' % arguments.lto) build_options.append('-DMEM_HEAP_SIZE_KB=%d' % arguments.mem_heap) build_options.append('-DPORT_DIR=%s' % arguments.port_dir) - build_options.append('-DFEATURE_PROFILE=%s' % arguments.profile) + + if path.isabs(arguments.profile): + PROFILE = arguments.profile + else: + PROFILE = path.join(PROFILE_DIR, arguments.profile + '.profile') + + build_options.append('-DFEATURE_PROFILE=%s' % PROFILE) + build_options.append('-DFEATURE_SNAPSHOT_EXEC=%s' % arguments.snapshot_exec) build_options.append('-DFEATURE_SNAPSHOT_SAVE=%s' % arguments.snapshot_save) build_options.append('-DENABLE_STATIC_LINK=%s' % arguments.static_link)