def adjust_options(options): # First fix some option inconsistencies. if options.target_os in ['nuttx', 'tizenrt']: options.buildlib = True if not options.sysroot: ex.fail('--sysroot needed for nuttx target') options.sysroot = fs.abspath(options.sysroot) if not fs.exists(options.sysroot): ex.fail('NuttX sysroot %s does not exist' % options.sysroot) if options.target_arch == 'x86': options.target_arch = 'i686' if options.target_arch == 'x64': options.target_arch = 'x86_64' if options.target_os == 'darwin': options.no_check_valgrind = True if options.target_board in ['rpi2', 'artik10', 'artik05x']: options.no_check_valgrind = True # Then add calculated options. options.host_tuple = '%s-%s' % (platform.arch(), platform.os()) options.target_tuple = '%s-%s' % (options.target_arch, options.target_os) options.build_root = fs.join(path.PROJECT_ROOT, options.builddir, options.target_tuple, options.buildtype) cmake_path = fs.join(path.PROJECT_ROOT, 'cmake', 'config', '%s.cmake') options.cmake_toolchain_file = cmake_path % options.target_tuple # Specify the file of JerryScript profile. options.jerry_profile = fs.join(path.JERRY_PROFILE_ROOT, options.jerry_profile + '.profile')
def build_libhttpparser(options): print_progress('Build libhttpparser') # Check if JerryScript submodule exists. if not fs.exists(path.HTTPPARSER_ROOT): ex.fail('libhttpparser submodule does not exists!') # Move working directory to JerryScript build directory. build_home = fs.join(options.build_root, 'deps', 'httpparser') # Set JerryScript cmake options. cmake_opt = [ '-B%s' % build_home, '-H%s' % path.HTTPPARSER_ROOT, "-DCMAKE_TOOLCHAIN_FILE='%s'" % options.cmake_toolchain_file, '-DBUILDTYPE=%s' % options.buildtype.capitalize(), ] if options.target_os == 'nuttx': cmake_opt.append("-DNUTTX_HOME='%s'" % options.sysroot) cmake_opt.append('-DOS=NUTTX') if options.target_os in ['linux', 'tizen']: cmake_opt.append('-DOS=LINUX') # Add common cmake options. cmake_opt.extend(build_cmake_args(options)) # Run cmake. ex.check_run_cmd('cmake', cmake_opt) run_make(options, build_home) copy_build_target('libhttpparser.a', build_home, options.build_libs)
def adjust_option(option): if option.target_os.lower() == 'nuttx': option.buildlib = True if option.nuttx_home == '': ex.fail('--nuttx-home needed for nuttx target') else: option.nuttx_home = fs.abspath(option.nuttx_home) if not fs.exists(option.nuttx_home): ex.fail('--nuttx-home %s not exists' % option.nuttx_home) if option.target_arch == 'x86': option.target_arch = 'i686' if option.target_arch == 'x64': option.target_arch = 'x86_64' if option.cmake_param is None: option.cmake_param = [] if option.compile_flag is None: option.compile_flag = [] if option.link_flag is None: option.link_flag = [] if option.external_include_dir is None: option.external_include_dir = [] if option.external_static_lib is None: option.external_static_lib = [] if option.external_shared_lib is None: option.external_shared_lib = [] if option.iotjs_include_module is None: option.iotjs_include_module = [] if option.iotjs_exclude_module is None: option.iotjs_exclude_module = [] if option.jerry_cmake_param is None: option.jerry_cmake_param = [] if option.jerry_compile_flag is None: option.jerry_compile_flag = [] if option.jerry_link_flag is None: option.jerry_link_flag = []
def build_host_jerry(options): print_progress('Build JerryScript for host') # Check if JerryScript submodule exists. if not fs.exists(path.JERRY_ROOT): ex.fail('JerryScript submodule does not exists!') # Move working directory to JerryScript build directory. build_home = fs.join(options.host_build_root, 'deps', 'jerry') # Set JerryScript cmake options. cmake_opt = [ '-B%s' % build_home, '-H%s' % path.JERRY_ROOT, "-DCMAKE_TOOLCHAIN_FILE='%s'" % options.host_cmake_toolchain_file, # Turn off LTO for jerry bin to save build time. '-DENABLE_LTO=OFF', ] if options.buildtype == 'debug': cmake_opt.append('-DCMAKE_BUILD_TYPE=Debug') # Turn on snapshot if not options.no_snapshot: cmake_opt.append('-DFEATURE_SNAPSHOT_SAVE=ON') # Run cmake. ex.check_run_cmd('cmake', cmake_opt) run_make(options, build_home) copy_build_target('jerry', fs.join(build_home, 'bin'), options.host_build_bins)
def run_checktest(options): checktest_quiet = 'yes' if os.getenv('TRAVIS') == "true": checktest_quiet = 'no' # IoT.js executable iotjs = fs.join(options.build_root, 'bin', 'iotjs') cmd = fs.join(path.TOOLS_ROOT, 'testrunner.py') args = [iotjs] # testsets if options.testsets: args.append('--testsets=' + options.testsets); if options.run_test == "quiet": args.append('--quiet') fs.chdir(path.PROJECT_ROOT) # run unit tests code = ex.run_cmd(cmd, args) if code != 0: ex.fail('Failed to pass unit tests') if not options.no_check_valgrind: code = ex.run_cmd(cmd, ['--valgrind'] + args) if code != 0: ex.fail('Failed to pass unit tests in valgrind environment')
def resolve_modules(options): """ Resolve include/exclude module lists based on command line arguments and build config. """ # Load all the supported modules supported = options.config['module']['supported'] core_modules = set(supported['core']) basic_modules = set(supported['basic']) # By default the target included modules are: # - 'core' module set from the build config # - modules specified by the command line argument include_modules = set() | core_modules include_modules |= options.iotjs_include_module if not options.iotjs_minimal_profile: # Add 'basic' module to the target include modules include_modules |= basic_modules # Start to check exclude modules exclude_modules = options.iotjs_exclude_module # Check if there are any modules which are not allowed to be excluded impossible_to_exclude = exclude_modules & core_modules if impossible_to_exclude: ex.fail('Can not exclude modules which are in `core` modules: %s' % ', '.join(impossible_to_exclude)) # Finally remove the excluded modules from the included modules set include_modules -= exclude_modules return include_modules, exclude_modules
def resolve_modules(options): """ Resolve include/exclude module lists based on command line arguments and build config. """ # Load the modules which are always enabled and the include/exclude sets build_modules_always = set(options.config['module']['always']) build_modules_includes = set(options.config['module']['include']) build_modules_excludes = set(options.config['module']['exclude']['all']) if options.target_os: system_os = options.target_os if system_os == 'tizen': system_os = 'linux' build_modules_excludes |= set( options.config['module']['exclude'][system_os]) # By default the target included modules are: # - always module set from the build config # - modules specified by the command line argument include_modules = set() include_modules |= build_modules_always include_modules |= options.iotjs_include_module if not options.iotjs_minimal_profile: # In case of normal build (not minimal profile): # Check if there is any overlap between the included and excluded # module sets which are from the build config problem_modules = build_modules_includes & build_modules_excludes if problem_modules: print('Detected module(s) both in include and exclude list.', end=' ') print('Module name(s): %s' % ', '.join(problem_modules)) ex.fail('Inconsistency in build config file!') # Add the include set from the build config to # the target include modules set include_modules |= build_modules_includes # Check if there is any modules which are not allowed to be excluded impossible_to_exclude = options.iotjs_exclude_module & build_modules_always if impossible_to_exclude: ex.fail('Cannot exclude modules which are always enabled: %s' % ', '.join(impossible_to_exclude)) # Remove any excluded modules (defined by the command line argument) from # the target include set include_modules -= options.iotjs_exclude_module # Finally build up the excluded module set: # - use the command line exclude set # - use the exclude set from the build config exclude_modules = options.iotjs_exclude_module | build_modules_excludes # Remove the included modules set from the excluded modules exclude_modules -= include_modules assert len(include_modules & exclude_modules) == 0, \ 'Module can NOT be both in include and exclude list' return include_modules, exclude_modules
def check_tidy(src_dir, options=None): allowed_exts = ['.c', '.h', '.js', '.py', '.sh', '.cmake'] allowed_files = ['CMakeLists.txt'] clang_format_exts = ['.c', '.h'] skip_dirs = [ 'deps', 'build', '.git', 'node_modules', 'coverage', 'iotjs_modules', 'IoTjsApp' ] skip_files = [ 'check_signed_off.sh', '__init__.py', 'iotjs_js.c', 'iotjs_js.h', 'iotjs_string_ext.inl.h', "iotjs_module_inl.h", 'ble.js', 'ble_hci_socket_acl_stream.js', 'ble_hci_socket_smp.js', 'ble_hci_socket_hci.js', 'ble_hci_socket_gap.js', 'ble_hci_socket_gatt.js', 'ble_hci_socket_mgmt.js', 'ble_hci_socket_bindings.js', 'ble_characteristic.js', 'test_ble_setservices.js', '.eslintrc.js', 'c_source_templates.py', 'cpp_source_templates.py' ] style = StyleChecker() style.set_rules() clang = ClangFormat(clang_format_exts, skip_files, options) eslint = EslintChecker(options) file_filter = FileFilter(allowed_exts, allowed_files, skip_files) files = fs.files_under(src_dir, skip_dirs, file_filter) clang.check(files) style.check(files) eslint.check() if clang.error_count: print("Detected clang-format problems:") print("".join(clang.diffs)) print() if style.error_count: print("Detected style problems:") print("\n".join(style.errors)) print() if eslint.error_count: print("Detected eslint problems:") print("\n".join(eslint.errors)) print() total_errors = style.error_count + clang.error_count + eslint.error_count print("* total lines of code: %d" % style.count_lines) print("* total non-blank lines of code: %d" % style.count_valid_lines) print("* style errors: %d" % style.error_count) print("* clang-format errors: %d" % clang.error_count) print("* eslint errors: %d" % eslint.error_count) msg_color = Terminal.red if total_errors > 0 else Terminal.green Terminal.pprint("* total errors: %d" % (total_errors), msg_color) print() if total_errors: ex.fail("Failed tidy check")
def adjust_options(options): # First fix some option inconsistencies if options.target_os == 'nuttx': options.buildlib = True if not options.sysroot: ex.fail('--sysroot needed for nuttx target') options.sysroot = fs.abspath(options.sysroot) if not fs.exists(options.sysroot): ex.fail('Nuttx sysroot %s does not exist' % options.sysroot) if options.target_arch == 'x86': options.target_arch = 'i686' if options.target_arch == 'x64': options.target_arch = 'x86_64' if options.target_os == 'darwin': options.no_check_valgrind = True if options.target_board in ['rpi2', 'artik10']: options.no_check_valgrind = True elif options.target_board == 'none': options.target_board = None if options.iotjs_minimal_profile: options.no_check_test = True # Then add calculated options options.host_tuple = '%s-%s' % (platform.arch(), platform.os()) options.target_tuple = '%s-%s' % (options.target_arch, options.target_os) arch_for_iotjs = 'arm' if options.target_arch[0:3] == 'arm' else \ options.target_arch os_for_iotjs = 'linux' if options.target_os == 'tizen' else \ options.target_os options.target_tuple_for_iotjs = '%s-%s' % (arch_for_iotjs, os_for_iotjs) options.host_build_root = fs.join(path.PROJECT_ROOT, options.builddir, 'host', options.host_tuple, options.buildtype) options.host_build_bins = fs.join(options.host_build_root, 'bin') options.build_root = fs.join(path.PROJECT_ROOT, options.builddir, options.target_tuple, options.buildtype) options.build_bins = fs.join(options.build_root, 'bin') options.build_libs = fs.join(options.build_root, 'lib') cmake_path = fs.join(path.PROJECT_ROOT, 'cmake', 'config', '%s.cmake') options.cmake_toolchain_file = cmake_path % options.target_tuple options.host_cmake_toolchain_file = cmake_path % options.host_tuple
def copy_build_target(target_name, src_dir, dst_dir, new_target_name=None): build_output = fs.join(src_dir, target_name) if not fs.exists(build_output): ex.fail('%s build failed - target not produced.' % target_name) if new_target_name: copy_target_name = new_target_name else: copy_target_name = target_name copy_target_path = fs.join(dst_dir, copy_target_name) fs.copy(build_output, copy_target_path)
def adjust_options(options): # First fix some option inconsistencies if options.target_os in ['nuttx', 'tizenrt']: options.buildlib = True if not options.sysroot: ex.fail('--sysroot needed for nuttx target') options.sysroot = fs.abspath(options.sysroot) if not fs.exists(options.sysroot): ex.fail('Nuttx sysroot %s does not exist' % options.sysroot) if options.target_arch == 'x86': options.target_arch = 'i686' if options.target_arch == 'x64': options.target_arch = 'x86_64' if options.target_os == 'darwin': options.no_check_valgrind = True if options.target_board in ['rpi2', 'artik10', 'artik05x']: options.no_check_valgrind = True elif options.target_board == 'none': options.target_board = None if options.iotjs_minimal_profile: options.no_check_test = True # Then add calculated options options.host_tuple = '%s-%s' % (platform.arch(), platform.os()) options.target_tuple = '%s-%s' % (options.target_arch, options.target_os) options.host_build_root = fs.join(path.PROJECT_ROOT, options.builddir, 'host', options.host_tuple, options.buildtype) options.host_build_bins = fs.join(options.host_build_root, 'bin') options.build_root = fs.join(path.PROJECT_ROOT, options.builddir, options.target_tuple, options.buildtype) options.build_bins = fs.join(options.build_root, 'bin') options.build_libs = fs.join(options.build_root, 'lib') cmake_path = fs.join(path.PROJECT_ROOT, 'cmake', 'config', '%s.cmake') options.cmake_toolchain_file = cmake_path % options.target_tuple options.host_cmake_toolchain_file = cmake_path % options.host_tuple # Specify the file of JerryScript profile options.jerry_profile = fs.join(path.JERRY_PROFILE_ROOT, options.jerry_profile + '.profile')
def build_tuv(option): # Check if libtuv submodule exists. if not fs.exists(path.TUV_ROOT): ex.fail('libtuv submodule not exists!') # Move working directory to libtuv build directory. build_home = fs.join(build_root, 'deps', 'libtuv') fs.maybe_make_directory(build_home) fs.chdir(build_home) # Set tuv cmake option. cmake_opt = [path.TUV_ROOT] cmake_opt.append('-DCMAKE_TOOLCHAIN_FILE=' + fs.join(path.TUV_ROOT, 'cmake', 'config', 'config_' + target_tuple + '.cmake')) cmake_opt.append('-DCMAKE_BUILD_TYPE=' + option.buildtype) cmake_opt.append('-DTARGET_PLATFORM=' + target_tuple) cmake_opt.append('-DLIBTUV_CUSTOM_LIB_OUT=' + build_home) cmake_opt.append('-DBUILDTESTER=no') cmake_opt.append('-DBUILDAPIEMULTESTER=no') if option.target_os == 'nuttx': cmake_opt.append('-DTARGET_SYSTEMROOT=' + option.nuttx_home) if option.target_board: cmake_opt.append('-DTARGET_BOARD=' + option.target_board) # inflate cmake option. inflate_cmake_option(cmake_opt, option) # Run cmake ex.check_run_cmd('cmake', cmake_opt) # Run make make_opt = [] if not option.no_parallel_build: make_opt.append('-j') ex.check_run_cmd('make', make_opt) # libtuv output output = fs.join(build_home, 'libtuv.a') if not fs.exists(output): ex.fail('libtuv build failed - target not produced.') # copy output to libs directory fs.maybe_make_directory(build_libs) fs.copy(output, libtuv_output_path) return True
def build_jerry(option): # Check if JerryScript submodule exists. if not fs.exists(path.JERRY_ROOT): ex.fail('JerryScript submodule not exists!') # Move working directory to JerryScript build directory. build_home = fs.join(host_build_root, 'deps', 'jerry') fs.maybe_make_directory(build_home) fs.chdir(build_home) # Set JerryScript cmake option. cmake_opt = [path.JERRY_ROOT] cmake_opt.append('-DCMAKE_TOOLCHAIN_FILE=' + host_cmake_toolchain_file) if option.buildtype == 'debug': cmake_opt.append('-DCMAKE_BUILD_TYPE=Debug') # Turn off LTO for jerry bin to save build time. cmake_opt.append('-DENABLE_LTO=OFF') # Turn on snapshot if not option.no_snapshot: cmake_opt.append('-DFEATURE_SNAPSHOT_SAVE=ON') # Run cmake. ex.check_run_cmd('cmake', cmake_opt) target_jerry = { 'target_name': 'jerry', 'output_path': fs.join(build_home, 'bin/jerry') } # Make option. make_opt = ['-C', build_home] if not option.no_parallel_build: make_opt.append('-j') # Run make for a target. ex.check_run_cmd('make', make_opt) # Check output output = target_jerry['output_path'] if not fs.exists(output): print output ex.fail('JerryScript build failed - target not produced.') # copy fs.copy(output, jerry_output_path) return True
def run_checktest(options): checktest_quiet = 'yes' if os.getenv('TRAVIS') == "true": checktest_quiet = 'no' # IoT.js executable iotjs = fs.join(options.build_root, 'bin', 'iotjs') build_args = ['quiet=' + checktest_quiet] # experimental if options.experimental: build_args.append('experimental=' + 'yes'); fs.chdir(path.PROJECT_ROOT) # Crash tests code = ex.run_cmd('tools/check_crash.sh', [iotjs]) if code != 0: ex.fail('Failed to pass crash tests') # run unit tests code = ex.run_cmd(iotjs, [path.CHECKTEST_PATH] + build_args) if code != 0: ex.fail('Failed to pass unit tests') if not options.no_check_valgrind: code = ex.run_cmd('valgrind', ['--leak-check=full', '--error-exitcode=5', '--undef-value-errors=no', iotjs, path.CHECKTEST_PATH] + build_args) if code == 5: ex.fail('Failed to pass valgrind test') if code != 0: ex.fail('Failed to pass unit tests in valgrind environment')
def adjust_options(options): # First fix some option inconsistencies. if options.target_os in ['nuttx', 'tizenrt']: options.buildlib = True if not options.sysroot: ex.fail('--sysroot needed for nuttx target') options.sysroot = fs.abspath(options.sysroot) if not fs.exists(options.sysroot): ex.fail('NuttX sysroot %s does not exist' % options.sysroot) if options.target_arch == 'x86': options.target_arch = 'i686' if options.target_arch == 'x64': options.target_arch = 'x86_64' if options.target_os == 'darwin': options.no_check_valgrind = True # Switch to no-snapshot mode on windows for now. # TODO: After Jerry update this could be removed. if options.target_os == 'windows': options.no_snapshot = True if options.target_board in ['rpi2', 'rpi3', 'artik10', 'artik05x']: options.no_check_valgrind = True # Then add calculated options. options.host_tuple = '%s-%s' % (platform.arch(), platform.os()) options.target_tuple = '%s-%s' % (options.target_arch, options.target_os) # Normalize the path of build directory. options.builddir = fs.normpath(options.builddir) options.build_root = fs.join(path.PROJECT_ROOT, options.builddir, options.target_tuple, options.buildtype) cmake_path = fs.join(path.PROJECT_ROOT, 'cmake', 'config', '%s.cmake') options.cmake_toolchain_file = cmake_path % options.target_tuple # Set the default value of '--js-backtrace' if it is not defined. if not options.js_backtrace: if options.buildtype == 'debug': options.js_backtrace = "ON" else: options.js_backtrace = "OFF"
def build_libhttpparser(option): # Check if JerryScript submodule exists. if not fs.exists(path.HTTPPARSER_ROOT): ex.fail('libhttpparser submodule not exists!') return False # Move working directory to JerryScript build directory. build_home = fs.join(build_root, 'deps', 'httpparser') fs.maybe_make_directory(build_home) fs.chdir(build_home) # Set JerryScript cmake option. cmake_opt = [path.HTTPPARSER_ROOT] cmake_opt.append('-DCMAKE_TOOLCHAIN_FILE=' + cmake_toolchain_file) cmake_opt.append('-DBUILDTYPE=' + option.buildtype.capitalize()) if option.target_os == 'nuttx': cmake_opt.append('-DNUTTX_HOME=' + option.nuttx_home) cmake_opt.append('-DOS=NUTTX') if option.target_os == 'linux': cmake_opt.append('-DOS=LINUX') # inflate cmake option. inflate_cmake_option(cmake_opt, option) # Run cmake. ex.check_run_cmd('cmake', cmake_opt) # Set make option. make_opt = [] if not option.no_parallel_build: make_opt.append('-j') # Run make ex.check_run_cmd('make', make_opt) # Output output = fs.join(build_home, 'libhttpparser.a') if not fs.exists(output): ex.fail('libhttpparser build failed - target not produced.') # copy fs.copy(output, libhttpparser_output_path) return True
def resolve_modules(options): """ Resolve include/exclude module lists based on command line arguments and build config. """ # Load the modules which are always enabled and the include/exclude sets build_modules_always = set(options.config['module']['always']) build_modules_includes = set(options.config['module']['include']) build_modules_excludes = set(options.config['module']['exclude']['all']) if options.target_os: system_os = options.target_os if system_os == 'tizen': system_os = 'linux' build_modules_excludes |= set( options.config['module']['exclude'][system_os]) # Build options has higher priority than defaults build_modules_excludes -= options.iotjs_include_module # By default the target included modules are: # - always module set from the build config # - modules specified by the command line argument include_modules = set() | build_modules_always include_modules |= options.iotjs_include_module if not options.iotjs_minimal_profile: # Add the include set from the build config to # the target include modules set include_modules |= build_modules_includes # Check if there are any modules which are not allowed to be excluded impossible_to_exclude = options.iotjs_exclude_module & build_modules_always if impossible_to_exclude: ex.fail('Cannot exclude modules which are always enabled: %s' % ', '.join(impossible_to_exclude)) # Finally build up the excluded module set: # - use the command line exclude set # - use the exclude set from the build config exclude_modules = options.iotjs_exclude_module | build_modules_excludes # Remove the excluded modules from the included modules set include_modules -= exclude_modules return include_modules, exclude_modules
def adjust_options(options): # First fix some option inconsistencies. if options.target_os in ['nuttx', 'tizenrt']: options.buildlib = True if not options.sysroot: ex.fail('--sysroot needed for %s target' % options.target_os) options.sysroot = fs.abspath(options.sysroot) if not fs.exists(options.sysroot): ex.fail('NuttX sysroot %s does not exist' % options.sysroot) if options.target_arch == 'x86': options.target_arch = 'i686' if options.target_arch == 'x64': options.target_arch = 'x86_64' if options.target_os == 'darwin': options.no_check_valgrind = True if options.target_board in ['rpi2', 'rpi3', 'artik10', 'artik05x']: options.no_check_valgrind = True # Then add calculated options. options.host_tuple = '%s-%s' % (platform.arch(), platform.os()) options.target_tuple = '%s-%s' % (options.target_arch, options.target_os) # Normalize the path of build directory. options.builddir = fs.normpath(options.builddir) options.build_root = fs.join(path.PROJECT_ROOT, options.builddir, options.target_tuple, options.buildtype) cmake_path = fs.join(path.PROJECT_ROOT, 'cmake', 'config', '%s.cmake') options.cmake_toolchain_file = cmake_path % options.target_tuple # Set the default value of '--js-backtrace' if it is not defined. if not options.js_backtrace: if options.buildtype == 'debug': options.js_backtrace = "ON" else: options.js_backtrace = "OFF"
def run_checktest(options): # IoT.js executable iotjs = fs.join(options.build_root, 'bin', 'iotjs') cmd = fs.join(path.TOOLS_ROOT, 'testrunner.py') args = [iotjs, "--platform=%s" % options.target_os] if options.run_test == "quiet": args.append('--quiet') fs.chdir(path.PROJECT_ROOT) code = ex.run_cmd(cmd, args) if code != 0: ex.fail('Failed to pass unit tests') if not options.no_check_valgrind: code = ex.run_cmd(cmd, ['--valgrind'] + args) if code != 0: ex.fail('Failed to pass unit tests in valgrind environment')
def build_tuv(options): print_progress('Build libtuv') # Check if libtuv submodule exists. if not fs.exists(path.TUV_ROOT): ex.fail('libtuv submodule does not exists!') # Move working directory to libtuv build directory. build_home = fs.join(options.build_root, 'deps', 'libtuv') # Set tuv cmake options. cmake_opt = [ '-B%s' % build_home, '-H%s' % path.TUV_ROOT, "-DCMAKE_TOOLCHAIN_FILE='%s'" % fs.join(path.TUV_ROOT, 'cmake', 'config', 'config_%s.cmake' % options.target_tuple), "-DCMAKE_BUILD_TYPE='%s'" % options.buildtype, "-DTARGET_PLATFORM='%s'" % options.target_tuple, "-DLIBTUV_CUSTOM_LIB_OUT='%s'" % build_home, '-DBUILDTESTER=NO', '-DBUILDAPIEMULTESTER=NO', ] if options.cross_compile: cmake_opt.append("-DCROSS_COMPILE='%s'" % options.cross_compile) if options.sysroot: cmake_opt.append("-DTARGET_SYSTEMROOT='%s'" % options.sysroot) cmake_opt.append("-DSYSROOT='%s'" % options.sysroot) if options.target_board: cmake_opt.append("-DTARGET_BOARD='%s'" % options.target_board) # Add common cmake options. cmake_opt.extend(build_cmake_args(options)) # Run cmake. ex.check_run_cmd('cmake', cmake_opt) run_make(options, build_home) copy_build_target('libtuv.a', build_home, options.build_libs)
def run_checktest(options): # IoT.js executable iotjs = fs.join(options.build_root, 'bin', 'iotjs') cmd = [] args = [] if options.test_driver == "js": cmd = iotjs args = [path.CHECKTEST_PATH] # quiet if options.run_test == "quiet": args.append('quiet=yes') # testsets if options.testsets: args.append('testsets=' + options.testsets) # experimental if options.experimental: args.append('experimental=yes') else: cmd = fs.join(path.TOOLS_ROOT, 'testrunner.py') args = [iotjs] # testsets if options.testsets: args.append('--testsets=' + options.testsets) if options.run_test == "quiet": args.append('--quiet') fs.chdir(path.PROJECT_ROOT) code = ex.run_cmd(cmd, args) if code != 0: ex.fail('Failed to pass unit tests') if not options.no_check_valgrind: if options.test_driver == "js": code = ex.run_cmd('valgrind', [ '--leak-check=full', '--error-exitcode=5', '--undef-value-errors=no', cmd ] + args) if code == 5: ex.fail('Failed to pass valgrind test') if code != 0: ex.fail('Failed to pass unit tests in valgrind environment') else: code = ex.run_cmd(cmd, ['--valgrind'] + args) if code != 0: ex.fail('Failed to pass unit tests in valgrind environment')
def adjust_options(options): # First fix some option inconsistencies if options.target_os == 'nuttx': options.buildlib = True if not options.nuttx_home: ex.fail('--nuttx-home needed for nuttx target') options.nuttx_home = fs.abspath(options.nuttx_home) if not fs.exists(options.nuttx_home): ex.fail('--nuttx-home %s does not exists' % options.nuttx_home) if options.target_arch == 'x86': options.target_arch = 'i686' if options.target_arch == 'x64': options.target_arch = 'x86_64' if options.target_board == 'rpi2': options.no_check_valgrind = True elif options.target_board == 'none': options.target_board = None if options.iotjs_minimal_profile: options.no_check_test = True # Then add calculated options options.host_tuple = '%s-%s' % (platform.arch(), platform.os()) options.target_tuple = '%s-%s' % (options.target_arch, options.target_os) options.host_build_root = fs.join(path.PROJECT_ROOT, options.builddir, 'host', options.host_tuple, options.buildtype) options.host_build_bins = fs.join(options.host_build_root, 'bin') options.build_root = fs.join(path.PROJECT_ROOT, options.builddir, options.target_tuple, options.buildtype) options.build_bins = fs.join(options.build_root, 'bin') options.build_libs = fs.join(options.build_root, 'lib') cmake_path = fs.join(path.PROJECT_ROOT, 'cmake', 'config', '%s.cmake') options.cmake_toolchain_file = cmake_path % options.target_tuple options.host_cmake_toolchain_file = cmake_path % options.host_tuple
def analyze_module_dependency(include_modules, exclude_modules): analyze_queue = set(include_modules) # copy the set analyze_queue.add('iotjs') js_modules = { 'native' } native_modules = { 'process' } while analyze_queue: item = analyze_queue.pop() js_modules.add(item) js_module_path = fs.join(path.PROJECT_ROOT, 'src', 'js', item + '.js') if not fs.exists(js_module_path): ex.fail('Cannot read file "%s"' % js_module_path) with open(js_module_path) as module: content = module.read() # Pretend to ignore comments in JavaScript re_js_comments = "\/\/.*|\/\*.*\*\/"; content = re.sub(re_js_comments, "", content) # Get all required modules re_js_module = 'require\([\'\"](.*?)[\'\"]\)' required_modules = set(re.findall(re_js_module, content)) # Check if there is any required modules in the exclude set problem_modules = required_modules & exclude_modules if problem_modules: ex.fail('Cannot exclude module(s) "%s" since "%s" requires them' % (', '.join(problem_modules), item)) # Add all modules to analytze queue which are not yet analyzed analyze_queue |= required_modules - js_modules # Get all native modules re_native_module = 'process.binding\(process.binding.(.*?)\)' native_modules |= set(re.findall(re_native_module, content)) js_modules.remove('native') modules = {'js': sorted(js_modules), 'native': sorted(native_modules)} return modules
def run_checktest(options): checktest_quiet = 'yes' if os.getenv('TRAVIS') == "true": checktest_quiet = 'no' # iot.js executable iotjs = fs.join(options.build_root, 'bin', 'iotjs') build_args = ['--', 'quiet=' + checktest_quiet] if options.iotjs_exclude_module: skip_module = ','.join(options.iotjs_exclude_module) build_args.append('skip-module=' + skip_module) # experimental if options.experimental: build_args.append('experimental=' + 'yes'); fs.chdir(path.PROJECT_ROOT) code = ex.run_cmd(iotjs, [path.CHECKTEST_PATH] + build_args) if code != 0: ex.fail('Failed to pass unit tests') if not options.no_check_valgrind: code = ex.run_cmd('valgrind', ['--leak-check=full', '--error-exitcode=5', '--undef-value-errors=no', iotjs, path.CHECKTEST_PATH] + build_args) if code == 5: ex.fail('Failed to pass valgrind test') if code != 0: ex.fail('Failed to pass unit tests in valgrind environment')
def run_checktest(options): checktest_quiet = 'yes' if os.getenv('TRAVIS') == "true": checktest_quiet = 'no' # iot.js executable iotjs = fs.join(options.build_root, 'iotjs', 'iotjs') build_args = ['--', 'quiet=' + checktest_quiet] if options.iotjs_exclude_module: skip_module = ','.join(options.iotjs_exclude_module) build_args.append('skip-module=' + skip_module) fs.chdir(path.PROJECT_ROOT) code = ex.run_cmd(iotjs, [path.CHECKTEST_PATH] + build_args) if code != 0: ex.fail('Failed to pass unit tests') if not options.no_check_valgrind: code = ex.run_cmd('valgrind', ['--leak-check=full', '--error-exitcode=5', '--undef-value-errors=no', iotjs, path.CHECKTEST_PATH] + build_args) if code == 5: ex.fail('Failed to pass valgrind test') if code != 0: ex.fail('Failed to pass unit tests in valgrind environment')
def run_checktest(option): checktest_quiet = 'yes' if os.getenv('TRAVIS') == "true": checktest_quiet = 'no' # iot.js executable iotjs = fs.join(build_root, 'iotjs', 'iotjs') fs.chdir(path.PROJECT_ROOT) code = ex.run_cmd(iotjs, [path.CHECKTEST_PATH, '--', 'quiet='+checktest_quiet]) if code != 0: ex.fail('Failed to pass unit tests') if not option.no_check_valgrind: code = ex.run_cmd('valgrind', ['--leak-check=full', '--error-exitcode=5', '--undef-value-errors=no', iotjs, path.CHECKTEST_PATH, '--', 'quiet='+checktest_quiet]) if code == 5: ex.fail('Failed to pass valgrind test') if code != 0: ex.fail('Failed to pass unit tests in valgrind environment') return True
def run_checktest(options): # IoT.js executable iotjs = fs.join(options.build_root, 'bin', 'iotjs') cmd = fs.join(path.TOOLS_ROOT, 'testrunner.py') args = [iotjs, "--platform=%s" % options.target_os] if options.run_test == "quiet": args.append('--quiet') if options.n_api: args.append('--n-api') fs.chdir(path.PROJECT_ROOT) code = ex.run_cmd(cmd, args) if code != 0: ex.fail('Failed to pass unit tests') if not options.no_check_valgrind: code = ex.run_cmd(cmd, ['--valgrind'] + args) if code != 0: ex.fail('Failed to pass unit tests in valgrind environment')
def adjust_option(option): if option.target_os.lower() == 'nuttx': option.buildlib = True if option.nuttx_home == '': ex.fail('--nuttx-home needed for nuttx target') else: option.nuttx_home = fs.abspath(option.nuttx_home) if not fs.exists(option.nuttx_home): ex.fail('--nuttx-home %s not exists' % option.nuttx_home) if option.target_arch == 'x86': option.target_arch = 'i686' if option.target_arch == 'x64': option.target_arch = 'x86_64' if option.target_board == 'rpi2': option.no_check_valgrind = True if option.cmake_param is None: option.cmake_param = [] if option.compile_flag is None: option.compile_flag = [] if option.link_flag is None: option.link_flag = [] if option.external_include_dir is None: option.external_include_dir = [] if option.external_static_lib is None: option.external_static_lib = [] if option.external_shared_lib is None: option.external_shared_lib = [] if option.iotjs_include_module is None: option.iotjs_include_module = [] if option.iotjs_exclude_module is None: option.iotjs_exclude_module = [] if option.iotjs_minimal_profile: option.no_check_test = True if option.jerry_cmake_param is None: option.jerry_cmake_param = [] if option.jerry_compile_flag is None: option.jerry_compile_flag = [] if option.jerry_link_flag is None: option.jerry_link_flag = []
def run_checktest(options): # IoT.js executable iotjs = fs.join(options.build_root, 'bin', 'iotjs') cmd = [] args = [] if options.test_driver == "js": cmd = iotjs args = [path.CHECKTEST_PATH] if options.run_test == "quiet": args.append('quiet=yes') # experimental if options.experimental: args.append('experimental=yes'); else: cmd = fs.join(path.TOOLS_ROOT, 'testrunner.py') args = [iotjs] if options.run_test == "quiet": args.append('--quiet') fs.chdir(path.PROJECT_ROOT) code = ex.run_cmd(cmd, args) if code != 0: ex.fail('Failed to pass unit tests') if not options.no_check_valgrind: if options.test_driver == "js": code = ex.run_cmd('valgrind', ['--leak-check=full', '--error-exitcode=5', '--undef-value-errors=no', cmd] + args) if code == 5: ex.fail('Failed to pass valgrind test') if code != 0: ex.fail('Failed to pass unit tests in valgrind environment') else: code = ex.run_cmd(cmd, ['--valgrind'] + args) if code != 0: ex.fail('Failed to pass unit tests in valgrind environment')
def run_checktest(options): checktest_quiet = 'yes' if os.getenv('TRAVIS') == "true": checktest_quiet = 'no' # IoT.js executable iotjs = fs.join(options.build_root, 'bin', 'iotjs') cmd = [] args = [] if options.test_driver == "js": cmd = iotjs args = [path.CHECKTEST_PATH, 'quiet=' + checktest_quiet] # experimental if options.experimental: cmd.append('experimental=' + 'yes') else: cmd = fs.join(path.TOOLS_ROOT, 'testrunner.py') args = [iotjs] if checktest_quiet: args.append('--quiet') fs.chdir(path.PROJECT_ROOT) code = ex.run_cmd(cmd, args) if code != 0: ex.fail('Failed to pass unit tests') if not options.no_check_valgrind: if options.test_driver == "js": code = ex.run_cmd('valgrind', [ '--leak-check=full', '--error-exitcode=5', '--undef-value-errors=no', cmd ] + args) if code == 5: ex.fail('Failed to pass valgrind test') if code != 0: ex.fail('Failed to pass unit tests in valgrind environment') else: code = ex.run_cmd(cmd, ['--valgrind'] + args) if code != 0: ex.fail('Failed to pass unit tests in valgrind environment')
def git_remove_remote(fork_name, branch_name): remote_name = get_merge_remote_name(fork_name, branch_name) return ex.run_cmd('git remote remove %s' % remote_name) def check_build(): return (ex.run_cmd(BUILD_SCRIPT_DEBUG) or ex.run_cmd(BUILD_SCRIPT_RELEASE)) def git_push(): return ex.run_cmd('git push origin master') if len(sys.argv) < 3: ex.fail( 'usage: <merge.py> <fork_name> <branch_name> [<id>]') fork_name = sys.argv[1] branch_name = sys.argv[2] git_id = "" git_passwd = "" if len(sys.argv) >= 4: git_id = sys.argv[3] git_passwd = getpass.getpass() merge_branch = get_merge_branch_name(fork_name, branch_name) # check if current branch is master.
elif test == "rpi2": for buildtype in option.buildtype: build(buildtype, ['--target-arch=arm', '--target-board=rpi2']) elif test == "nuttx": for buildtype in option.buildtype: nuttx_root=fs.join(path.PROJECT_ROOT, 'deps', 'nuttx') setup_nuttx_root(nuttx_root) build_nuttx(nuttx_root, buildtype) build(buildtype, ['--target-arch=arm', '--target-os=nuttx', '--nuttx-home=' + fs.join(nuttx_root, 'nuttx'), '--target-board=stm32f4dis', '--jerry-heaplimit=78']) if not build_nuttx(nuttx_root, buildtype): ex.fail('nuttx ' + buildtype + ' build failed') elif test == "misc": args = [] if os.getenv('TRAVIS') != None: args = ['--travis'] ex.check_run_cmd('tools/check_signed_off.sh', args) if not check_tidy(path.PROJECT_ROOT): ex.fail("Failed tidy check") build("debug", ['--no-snapshot', '--jerry-lto']) build("debug", ['--iotjs-minimal-profile'])
'--target-os=nuttx', '--nuttx-home=' + fs.join(nuttx_root, 'nuttx'), '--target-board=stm32f4dis', '--jerry-heaplimit=78'] + os_dependency_module['nuttx'] + build_args) build_nuttx(nuttx_root, buildtype, 'all') fs.chdir(current_dir) elif test == "misc": args = [] if os.getenv('TRAVIS') != None: args = ['--travis'] ex.check_run_cmd('tools/check_signed_off.sh', args) if not check_tidy(path.PROJECT_ROOT): ex.fail("Failed tidy check") build("debug", build_args) build("debug", ['--iotjs-minimal-profile'] + build_args) elif test == "no-snapshot": args = [] if os.getenv('TRAVIS') != None: args = ['--travis'] build("debug", ['--no-snapshot', '--jerry-lto'] + os_dependency_module['linux'] + build_args) elif test == "coverity": build("debug", ['--no-check-test']
def build_iotjs(option): # Run js2c fs.chdir(path.TOOLS_ROOT) js2c(option.buildtype, option.no_snapshot, option.js_modules, jerry_output_path) # Move working directory to IoT.js build directory. build_home = fs.join(build_root, 'iotjs') fs.maybe_make_directory(build_home) fs.chdir(build_home) # Set JerryScript cmake option. cmake_opt = [path.PROJECT_ROOT] cmake_opt.append('-DCMAKE_TOOLCHAIN_FILE=' + cmake_toolchain_file) cmake_opt.append('-DCMAKE_BUILD_TYPE=' + option.buildtype.capitalize()) cmake_opt.append('-DTARGET_OS=' + option.target_os) cmake_opt.append('-DPLATFORM_DESCRIPT=' + platform_descriptor) # IoT.js module list cmake_opt.append('-DIOTJS_MODULES=' + (' ').join(option.native_modules)) if not option.no_snapshot: option.compile_flag.append('-DENABLE_SNAPSHOT') if option.target_os == 'nuttx': cmake_opt.append('-DNUTTX_HOME=' + option.nuttx_home) option.buildlib = True # --build-lib if option.buildlib: cmake_opt.append('-DBUILD_TO_LIB=YES') # --cmake-param cmake_opt += option.cmake_param # --external_static_lib cmake_opt.append('-DEXTERNAL_STATIC_LIB=' + ' '.join(option.external_static_lib)) # --external_shared_lib config_shared_libs = option.config['shared_libs'] option.external_shared_lib += config_shared_libs['os'][option.target_os] cmake_opt.append('-DEXTERNAL_SHARED_LIB=' + ' '.join(option.external_shared_lib)) # inflate cmake option inflate_cmake_option(cmake_opt, option) # Run cmake. ex.check_run_cmd('cmake', cmake_opt) # Set make option. make_opt = [] if not option.no_parallel_build: make_opt.append('-j') # Run make ex.check_run_cmd('make', make_opt) # Output output = fs.join(build_home, 'liblibiotjs.a' if option.buildlib else 'iotjs') if not fs.exists(output): ex.fail('IoT.js build failed - target not produced.') # copy dest_path = libiotjs_output_path if option.buildlib else iotjs_output_path fs.copy(output, dest_path) return True
def print_warn(fmt, arg): print fmt % arg ex.fail('Failed to analyze module dependency')
def build_libjerry(option): # Check if JerryScript submodule exists. if not fs.exists(path.JERRY_ROOT): ex.fail('JerryScript submodule not exists!') # Move working directory to JerryScript build directory. build_home = fs.join(build_root, 'deps', 'jerry') fs.maybe_make_directory(build_home) fs.chdir(build_home) # Set JerryScript cmake option. cmake_opt = [path.JERRY_ROOT] cmake_opt.append('-DCMAKE_TOOLCHAIN_FILE=' + cmake_toolchain_file) if option.buildtype == 'debug': cmake_opt.append('-DCMAKE_BUILD_TYPE=Debug') cmake_opt.append('-DFEATURE_ERROR_MESSAGES=On') if option.target_os == 'nuttx': cmake_opt.append('-DEXTERNAL_LIBC_INTERFACE=' + fs.join(option.nuttx_home, 'include')) if option.target_arch == 'arm': cmake_opt.append('-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=arm') if option.target_os == 'linux': cmake_opt.append('-DJERRY_LIBC=OFF') cmake_opt.append('-DJERRY_LIBM=OFF') # --jerry-heaplimit if option.jerry_heaplimit: cmake_opt.append('-DMEM_HEAP_SIZE_KB=' + str(option.jerry_heaplimit)) # --jerry-heap-section if option.jerry_heap_section: cmake_opt.append('-DJERRY_HEAP_SECTION_ATTR=' + str(option.jerry_heap_section)) # --jerry-lto cmake_opt.append('-DENABLE_LTO=%s' % ('ON' if option.jerry_lto else 'OFF')) if option.jerry_memstat: cmake_opt.append('-DFEATURE_MEM_STATS=ON') # Turn on snapshot cmake_opt.append('-DFEATURE_SNAPSHOT_SAVE=OFF') if not option.no_snapshot: cmake_opt.append('-DFEATURE_SNAPSHOT_EXEC=ON') # --jerry-cmake-param cmake_opt += option.jerry_cmake_param # inflate cmake option. inflate_cmake_option(cmake_opt, option, for_jerry=True) # Run cmake. ex.check_run_cmd('cmake', cmake_opt) # make target - libjerry target_libjerry_name = 'jerry-core' target_libjerry = { 'target_name': target_libjerry_name, 'output_path': fs.join(build_home, 'lib', 'lib%s.a' % target_libjerry_name), 'dest_path': libjerry_output_path } targets = [] targets.append(target_libjerry) # make the target. for target in targets: # Make option. make_opt = ['-C', build_home, target['target_name']] if not option.no_parallel_build: make_opt.append('-j') # Run make for a target. ex.check_run_cmd('make', make_opt) # Check output output = target['output_path'] if not fs.exists(output): print output ex.fail('JerryScript build failed - target not produced.') # copy fs.copy(output, target['dest_path']) return True
def check_tidy(src_dir, options=None): allowed_exts = ['.c', '.h', '.js', '.py', '.sh', '.cmake'] allowed_files = ['CMakeLists.txt'] clang_format_exts = ['.c', '.h'] skip_dirs = ['deps', 'build', '.git', 'node_modules', 'coverage', 'iotjs_modules'] skip_files = ['check_signed_off.sh', '__init__.py', 'iotjs_js.c', 'iotjs_js.h', 'iotjs_string_ext.inl.h', "iotjs_module_inl.h", 'ble.js', 'ble_hci_socket_acl_stream.js', 'ble_hci_socket_smp.js', 'ble_hci_socket_hci.js', 'ble_hci_socket_gap.js', 'ble_hci_socket_gatt.js', 'ble_hci_socket_mgmt.js', 'ble_hci_socket_bindings.js', 'ble_characteristic.js', 'test_ble_setservices.js', '.eslintrc.js' ] style = StyleChecker() style.set_rules() clang = ClangFormat(clang_format_exts, skip_files, options) eslint = EslintChecker(options) file_filter = FileFilter(allowed_exts, allowed_files, skip_files) files = fs.files_under(src_dir, skip_dirs, file_filter) clang.check(files) style.check(files) eslint.check() if clang.error_count: print("Detected clang-format problems:") print("".join(clang.diffs)) print() if style.error_count: print("Detected style problems:") print("\n".join(style.errors)) print() if eslint.error_count: print("Detected eslint problems:") print("\n".join(eslint.errors)) print() total_errors = style.error_count + clang.error_count + eslint.error_count print("* total lines of code: %d" % style.count_lines) print("* total non-blank lines of code: %d" % style.count_valid_lines) print("* style errors: %d" % style.error_count) print("* clang-format errors: %d" % clang.error_count) print("* eslint errors: %d" % eslint.error_count) msg_color = ex._TERM_RED if total_errors > 0 else ex._TERM_GREEN print("%s* total errors: %d%s" % (msg_color, total_errors, ex._TERM_EMPTY)) print() if total_errors: ex.fail("Failed tidy check")
def build_libjerry(options): print_progress('Build JerryScript target library') # Check if JerryScript submodule exists. if not fs.exists(path.JERRY_ROOT): ex.fail('JerryScript submodule does not exists!') # Move working directory to JerryScript build directory. build_home = fs.join(options.build_root, 'deps', 'jerry') # Set JerryScript cmake options. cmake_opt = [ '-B%s' % build_home, '-H%s' % path.JERRY_ROOT, '-DCMAKE_TOOLCHAIN_FILE=%s' % options.cmake_toolchain_file, ] if options.buildtype == 'debug': cmake_opt.append('-DCMAKE_BUILD_TYPE=Debug') cmake_opt.append('-DFEATURE_ERROR_MESSAGES=On') if options.target_os == 'nuttx': cmake_opt.append("-DEXTERNAL_LIBC_INTERFACE='%s'" % fs.join(options.sysroot, 'include')) if options.target_arch == 'arm': cmake_opt.append('-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=arm') if options.target_os in ['linux', 'tizen', 'darwin']: cmake_opt.append('-DJERRY_LIBC=OFF') cmake_opt.append('-DJERRY_LIBM=OFF') # --jerry-heaplimit if options.jerry_heaplimit: cmake_opt.append('-DMEM_HEAP_SIZE_KB=%d' % options.jerry_heaplimit) # --jerry-heap-section if options.jerry_heap_section: cmake_opt.append("-DJERRY_HEAP_SECTION_ATTR='%s'" % options.jerry_heap_section) # --jerry-lto cmake_opt.append('-DENABLE_LTO=%s' % ('ON' if options.jerry_lto else 'OFF')) if options.jerry_memstat: cmake_opt.append('-DFEATURE_MEM_STATS=ON') # Turn off snapshot save and turn on snapshot exec if requested cmake_opt.append('-DFEATURE_SNAPSHOT_SAVE=OFF') if not options.no_snapshot: cmake_opt.append('-DFEATURE_SNAPSHOT_EXEC=ON') # --jerry-cmake-param cmake_opt.extend(options.jerry_cmake_param) # Add common cmake options. cmake_opt.extend(build_cmake_args(options, for_jerry=True)) # Run cmake. ex.check_run_cmd('cmake', cmake_opt) targets = [ # make target - libjerry { 'name': 'jerry-core', 'build_name': 'libjerry-core.a', 'build_path': fs.join(build_home, 'lib'), 'dest_name': 'libjerrycore.a', 'dest_path': options.build_libs, }, ] # make the target. for target in targets: run_make(options, build_home, target['name']) copy_build_target(target['build_name'], target['build_path'], target['dest_path'], target['dest_name'])
print_build_option(option) set_global_vars(option) # clean build directory. if option.clean: print_progress('Clear build directory') fs.rmtree(build_root) fs.rmtree(host_build_root) create_build_directories(option) # Anazlye module dependency print_progress('Analyze module dependency') if not analyze_module_dependency(option): ex.fail('Failed to analyze module dependency') # Perform init-submodule. print_progress('Initialize submodules') if not option.no_init_submodule: init_submodule() # make build directory. print_progress('Create build directory') fs.maybe_make_directory(build_root) # build tuv. print_progress('Build libtuv') if not build_tuv(option): ex.fail('Failed to build libtuv')