Ejemplo n.º 1
0
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 = []
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def check_tidy(src_dir):
    count_lines = 0
    count_empty_lines = 0

    for (dirpath, dirnames, filenames) in os.walk(src_dir):
        if any(d in fs.relpath(dirpath, src_dir) for d in skip_dirs):
            continue

        files = [
            fs.join(dirpath, name) for name in filenames
            if is_interesting(name)
        ]

        if not files:
            continue

        for line in fileinput.input(files):
            if '\t' in line:
                report_error('TAB character')
            if '\r' in line:
                report_error('CR character')
            if line.endswith(' \n') or line.endswith('\t\n'):
                report_error('trailing whitespace')
            if not line.endswith('\n'):
                report_error('line ends without NEW LINE character')

            if len(line) - 1 > column_limit:
                report_error('line exceeds %d characters' % column_limit)

            if fileinput.isfirstline():
                if not CheckLicenser.check(fileinput.filename()):
                    report_error_name_line(fileinput.filename(), None,
                                           'incorrent license')

            count_lines += 1
            if not line.strip():
                count_empty_lines += 1

    print "* total lines of code: %d" % count_lines
    print("* total non-blank lines of code: %d" %
          (count_lines - count_empty_lines))
    print "%s* total errors: %d%s" % (TERM_RED if count_err > 0 else
                                      TERM_GREEN, count_err, TERM_EMPTY)
    print

    return count_err == 0
Ejemplo n.º 5
0
def run_tests(testtype, testpath):
    pass_list = []
    fail_list = []
    skip_list = []

    for (dirpath, dirnames, filenames) in os.walk(testpath):
        tests = [fs.join(dirpath, name) for name in filenames
                 if is_javascript(name)]

        pool = multiprocessing.Pool(processes=PROCESSES)
        res = pool.map(run_test, ([testtype, iotjs, test] for test in tests))

        pass_list += list(map(lambda x: x[1],
                              filter(lambda x: x[0] == TestResult.Pass, res)))
        fail_list += list(map(lambda x: x[1],
                              filter(lambda x: x[0] == TestResult.Fail, res)))
        skip_list += list(map(lambda x: x[1],
                              filter(lambda x: x[0] == TestResult.Skip, res)))

    return (pass_list, fail_list, skip_list)
Ejemplo n.º 6
0
def get_test_attribute(test):
    test_attr = {
      'stdout': '',
      'timeout': TEST_TIMEOUT,
      'skip': False,
      'notest': False,
      'exitcode': (False, 0)
    }

    f = open(test, 'r')
    for line in f.readlines():
        strip = line.strip()

        if strip.startswith('@STDOUT'):
            meta_stdout = strip.split('=')[1]
            if meta_stdout.startswith('FILE['):
                filename = meta_stdout[5:-1]
                test_attr['stdout'] = read_file_contents(
                        fs.join(path.RESOURCE_DIR, filename))
            elif meta_stdout.startswith('COMMAND['):
                command = meta_stdout[8:-1].split()
                test_attr['stdout'] = subprocess.check_output(command)
                test_attr['stdout'] = test_attr['stdout'].decode().strip()
            else:
                test_attr['stdout'] = meta_stdout

        if strip.startswith('@TIMEOUT'):
            test_attr['timeout'] = int(strip.split('=')[1])

        if strip == '@SKIP':
            test_attr['skip'] = True

        if strip == '@NOTEST':
            test_attr['notest'] = True

        if strip.startswith('@EXITCODE'):
            meta_exitcode = int(strip.split('=')[1])
            test_attr['exitcode'] = (True, meta_exitcode)

    return test_attr
Ejemplo n.º 7
0
def js2c(buildtype, no_snapshot, js_modules, DUMPER):

    SRC_PATH = '../src/'
    JS_PATH = SRC_PATH + 'js/'

    fout_h = open(SRC_PATH + 'iotjs_js.h', 'w')
    fout_cpp = open(SRC_PATH + 'iotjs_js.cpp', 'w')
    fout_magic_str = open(SRC_PATH + 'iotjs_string_ext.inl.h', 'w')
    fout_h.write(LICENSE)
    fout_h.write(HEADER1)
    fout_cpp.write(LICENSE)
    fout_cpp.write(HEADER2)
    fout_magic_str.write(LICENSE)
    fout_magic_str.write(HEADER3)

    files = glob.glob(JS_PATH + '*.js')
    magic_string_set = {'process'}
    for path in files:
        name = extractName(path)
        if name not in js_modules:
            continue
        fout_cpp.write('const char ' + name + '_n[] = "' + name + '";\n')
        fout_h.write('extern const char ' + name + '_n[];\n')
        fout_h.write('extern const int ' + name + '_l;\n')
        if no_snapshot is True:
            fout_h.write('extern const char ' + name + '_s[];\n')
            fout_cpp.write('const char ' + name + '_s[] = {\n')
            code = open(path, 'r').read() + '\0'

            # minimize code when release mode
            if buildtype != 'debug':
                code = removeComments(code)
                code = removeWhitespaces(code)

            for line in regroup(code, 10):
                buf = ', '.join(map(lambda ch: str(ord(ch)), line))
                if line[-1] != '\0':
                    buf += ','
                writeLine(fout_cpp, buf, 1)

            writeLine(fout_cpp, '};')
            writeLine(fout_cpp,
                      'const int ' + name + '_l = ' + str(len(code) - 1) + ';')

        else:
            fout_h.write('extern const unsigned char ' + name + '_s[];\n')
            fout_cpp.write('const unsigned char ' + name + '_s[] = {\n')

            fmodule = open(path, 'r')
            module = fmodule.read()
            fmodule.close()

            fmodule_wrapped = open(path + '.wrapped', 'w')
            # FIXME
            if name != 'iotjs':
                # fmodule_wrapped.write ("(function (a, b, c) {\n")
                fmodule_wrapped.write(
                    "(function(exports, require, module) {\n")

            fmodule_wrapped.write(module)

            if name != 'iotjs':
                fmodule_wrapped.write("});\n")
                # fmodule_wrapped.write ("wwwwrap(a, b, c); });\n")
            fmodule_wrapped.close()

            # FIXME
            ret = subprocess.call([
                DUMPER, '--save-snapshot-for-eval', path + '.snapshot',
                path + '.wrapped'
            ])
            if ret != 0:
                msg = 'Failed to dump ' + path + (": - %d]" % (ret))
                print "%s%s%s" % ("\033[1;31m", msg, "\033[0m")
                exit(1)

            code = open(path + '.snapshot', 'r').read()

            fs.remove(path + '.wrapped')
            fs.remove(path + '.snapshot')

            for line in regroup(code, 8):
                buf = ', '.join(
                    map(lambda ch: "0x{:02x}".format(ord(ch)), line))
                buf += ','
                writeLine(fout_cpp, buf, 1)
            writeLine(fout_cpp, '};')
            writeLine(fout_cpp,
                      'const int ' + name + '_l = sizeof(' + name + '_s);')

            magic_string_set = magic_string_set | parseLiterals(code)

    NATIVE_STRUCT1 = '''
struct native_mod {
const char* name;
const void* code;
const size_t length;
};

extern const struct native_mod natives[];
'''

    NATIVE_STRUCT2 = '''
__attribute__ ((used)) const struct native_mod natives[] = {
'''

    fout_h.write(NATIVE_STRUCT1)
    fout_cpp.write(NATIVE_STRUCT2)
    filenames = map(extractName, files)
    for name in filenames:
        if name not in js_modules:
            continue
        writeLine(fout_cpp,
                  '{ ' + name + '_n, ' + name + '_s, ' + name + '_l },', 1)
    writeLine(fout_cpp, '{ NULL, NULL, 0 }', 1)
    writeLine(fout_cpp, '};')

    fout_h.write(FOOTER1)
    fout_cpp.write(FOOTER2)

    for idx, magic_string in enumerate(sorted(magic_string_set)):
        fout_magic_str.write('  MAGICSTR_EX_DEF(MAGIC_STR_%d, "%s") \\\n' %
                             (idx, repr(magic_string)[1:-1]))

    fout_magic_str.write(FOOTER3)
Ejemplo n.º 8
0
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')

    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')

    # --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
Ejemplo n.º 9
0
    return True


def run_fail_test(iotjs):
    passes, fails, skips = run_tests('run_fail', path.RUN_FAIL_DIR)
    if len(fails) > 0:
        print()
        print('%s[ run_fail] Test Failed%s' % (TERM_RED, TERM_EMPTY))
        for fail_test in fails:
            print('  * %s' % path.basename(fail_test))
        return False
    return True


if len(sys.argv) < 2:
    print('Usage: %s <path for iotjs>' % fs.basename(sys.argv[0]))
    exit(1)

iotjs = fs.abspath(sys.argv[1])

if not fs.exists(iotjs):
    print('No iotjs executable: %s' % iotjs)
    exit(1)

tests = [
    {
      'type': 'run_pass',
      'handler': run_pass_test
    },
    {
      'type': 'run_fail',
Ejemplo n.º 10
0
def init_option():
    # Check config option.
    arg_config = filter(lambda x: x.startswith('--config='), sys.argv)

    if not fs.exists(path.WORKING_CONFIG_PATH):
        fs.copy(path.DEFAULT_CONFIG_PATH, path.WORKING_CONFIG_PATH)

    config_path = path.WORKING_CONFIG_PATH

    if len(arg_config) != 0:
        config_path = arg_config[-1].split('=', 1)[1]

    # Read config file and apply it to argv.
    argv = []
    config = {}
    with open(config_path, 'r') as f:
        config = json.loads(f.read().encode('ascii'))
        config_option = config['build_option']
        for opt_key in config_option:
            opt_val = config_option[opt_key]
            if isinstance(opt_val, basestring) and opt_val != '':
                argv.append('--%s=%s' % (opt_key, opt_val))
            elif isinstance(opt_val, bool):
                if opt_val:
                    argv.append('--%s' % opt_key)
            elif isinstance(opt_val, int):
                argv.append('--%s=%s' % (opt_key, opt_val))
            elif isinstance(opt_val, list):
                for val in opt_val:
                    argv.append('--%s=%s' % (opt_key, val))

    # Apply command line argument to argv.
    argv = argv + (
        [arg for arg in sys.argv[1:] if not arg.startswith('--config=')])

    # Prepare aguemnt parser.
    parser = argparse.ArgumentParser()

    parser.add_argument('--buildtype',
                        choices=['debug', 'release'],
                        default='debug')

    parser.add_argument('--builddir', default=path.BUILD_ROOT)

    parser.add_argument('--clean', action='store_true')

    parser.add_argument('--buildlib', action='store_true')

    parser.add_argument('--target-arch',
                        choices=['arm', 'x86', 'i686', 'x86_64', 'x64'],
                        default=platform.arch())

    parser.add_argument('--target-os',
                        choices=['linux', 'darwin', 'osx', 'nuttx'],
                        default=platform.os())

    parser.add_argument('--target-board', default='')

    parser.add_argument('--cmake-param', action='append')

    parser.add_argument('--compile-flag', action='append')

    parser.add_argument('--link-flag', action='append')

    parser.add_argument('--external-include-dir', action='append')

    parser.add_argument('--external-static-lib', action='append')

    parser.add_argument('--external-shared-lib', action='append')

    parser.add_argument('--iotjs-include-module', action='append')

    parser.add_argument('--iotjs-exclude-module', action='append')

    parser.add_argument('--jerry-cmake-param', action='append')

    parser.add_argument('--jerry-compile-flag', action='append')

    parser.add_argument('--jerry-link-flag', action='append')

    parser.add_argument('--jerry-lto', action='store_true')

    parser.add_argument('--jerry-heap-section', action='store')

    parser.add_argument('--jerry-heaplimit', type=int)

    parser.add_argument('--jerry-memstat', action='store_true')

    parser.add_argument('--no-init-submodule', action='store_true')

    parser.add_argument('--no-check-tidy', action='store_true')

    parser.add_argument('--no-check-test', action='store_true')

    parser.add_argument('--no-parallel-build', action='store_true')

    parser.add_argument('--nuttx-home', default='')

    parser.add_argument('--no-snapshot', action='store_true')

    # parse argument.
    option = parser.parse_args(argv)
    option.config = config

    return option
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
def create_build_directories(option):
    fs.maybe_make_directory(build_root)
    fs.maybe_make_directory(build_bins)
    fs.maybe_make_directory(build_libs)
    fs.maybe_make_directory(host_build_root)
    fs.maybe_make_directory(host_build_bins)
Ejemplo n.º 13
0
            # fmodule_wrapped.write ("wwwwrap(a, b, c); });\n")
        fmodule_wrapped.close()

        # FIXME
        ret = subprocess.call([
            DUMPER, '--save-snapshot-for-eval', path + '.snapshot',
            path + '.wrapped'
        ])
        if ret != 0:
            msg = 'Failed to dump ' + path + (": - %d]" % (ret))
            print "%s%s%s" % ("\033[1;31m", msg, "\033[0m")
            exit(1)

        code = open(path + '.snapshot', 'r').read()

        fs.remove(path + '.wrapped')
        fs.remove(path + '.snapshot')

        for line in regroup(code, 8):
            buf = ', '.join(map(lambda ch: "0x{:02x}".format(ord(ch)), line))
            buf += ','
            writeLine(fout_cpp, buf, 1)
        writeLine(fout_cpp, '};')
        writeLine(fout_cpp,
                  'const int ' + name + '_l = sizeof(' + name + '_s);')

        magic_string_set = magic_string_set | parseLiterals(code)

NATIVE_STRUCT1 = '''
struct native_mod {
const char* name;
Ejemplo n.º 14
0
def run_checktest():
    # iot.js executable
    iotjs = fs.join(build_root, 'iotjs', 'iotjs')
    return ex.run_cmd(path.CHECKTEST_PATH, [iotjs]) == 0
Ejemplo n.º 15
0
def analyze_module_dependency(option):
    def print_warn(fmt, arg):
        print fmt % arg
        ex.fail('Failed to analyze module dependency')

    for name in option.config['module']['always']:
        if name in option.iotjs_include_module:
            print_warn('Module \"%s\" is already included', name)
        else:
            option.iotjs_include_module.append(name)

    for name in option.config['module']['optional']:
        if name in option.iotjs_include_module:
            print_warn('Module \"%s\" is already included', name)
        else:
            option.iotjs_include_module.append(name)

    for name in option.config['module']['exclude']:
        if name in option.iotjs_exclude_module:
            print_warn('Module \"%s\" is already excluded', name)
        else:
            option.iotjs_exclude_module.append(name)

    analyze_queue = set()
    for name in option.iotjs_include_module:
        analyze_queue.add(name)
    for name in option.iotjs_exclude_module:
        if name in option.config['module']['always']:
            print_warn('Cannot exclude mandatory module \"%s\"', name)
        else:
            if name in analyze_queue:
                analyze_queue.remove(name)
            else:
                print_warn('Cannot find module \"%s\" to exclude', name)

    js_modules = {'iotjs', 'native'}
    native_modules = {'process'}
    while len(analyze_queue) != 0:
        item = analyze_queue.pop()
        js_modules.add(item)

        content = open(fs.join(path.PROJECT_ROOT, 'src', 'js',
                               item + '.js')).read()

        re_js_module = 'require\([\'\"](.*)[\'\"]\)'
        for js_module in re.findall(re_js_module, content):
            if js_module in option.iotjs_exclude_module:
                print_warn('Cannot exclude \"%s\" since \"%s\" requires it',
                           (js_module, item))
            if js_module not in js_modules:
                analyze_queue.add(js_module)

        re_native_module = 'process.binding\(process.binding.(.*)\)'
        for native_module in re.findall(re_native_module, content):
            native_modules.add(native_module)

    js_modules.remove('native')

    option.js_modules = js_modules
    option.native_modules = native_modules

    print 'Building js modules: %s\nBuilding native modules: %s' \
          % (', '.join(js_modules), ', '.join(native_modules))
    print

    return True
Ejemplo n.º 16
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" common path for scripts """

from common.system.filesystem import FileSystem as fs

# Root directory for the project.
PROJECT_ROOT = fs.abspath(fs.join(fs.dirname(__file__), fs.pardir, fs.pardir))

# Root Build directory.
BUILD_ROOT = fs.join(PROJECT_ROOT, 'build')

# Root Build directory.
TOOLS_ROOT = fs.join(PROJECT_ROOT, 'tools')

# Root directory for dependencies.
DEPS_ROOT = fs.join(PROJECT_ROOT, 'deps')

# Root directory for test.
TEST_ROOT = fs.join(PROJECT_ROOT, 'test')

RUN_PASS_DIR = fs.join(TEST_ROOT, 'run_pass')
Ejemplo n.º 17
0
def get_expected_stdout(filename):
    file_path = fs.join(path.RESOURCE_DIR, filename)
    f = open(file_path, 'r')
    return f.read().encode()
Ejemplo n.º 18
0
def is_javascript(name):
    _, ext = fs.splitext(name)
    return ext == '.js'
Ejemplo n.º 19
0
def run_test(arg):
    test_type, iotjs, test = arg
    test_dir = fs.dirname(test)

    # fail test ?
    should_fail = True if test_type == 'run_fail' else False

    # working directory
    fs.chdir(test_dir)

    # Check test attributes.
    test_attr = get_test_attribute(test)

    if test_attr['skip']:
        print('%s[ %s ] %s - SKIP%s' % (TERM_BLUE,
                                        test_type, fs.basename(test),
                                        TERM_EMPTY))
        return (TestResult.Skip, test)

    if test_attr['notest']:
        return (TestResult.Notest, test)


    test_output = ''
    exitcode = 0
    attr_mismatched = False
    error_msg = ''
    timeout_expired = False

    # run the test.
    try:
        test_output = subprocess.check_output([iotjs, test],
                                              stderr=subprocess.STDOUT,
                                              timeout=test_attr['timeout'])
        test_output = test_output.decode().strip()
    except subprocess.TimeoutExpired:
        timeout_expired = True
    except Exception as e:
        exitcode = int(e.returncode)
        test_output = e.output.decode().strip()
        error_msg = str(e)

    # check attributes
    if test_attr['stdout'] != '' and test_output != test_attr['stdout']:
        attr_mismatched = True
        error_msg = 'unexpected stdout'

    if test_attr['exitcode'][0] and test_attr['exitcode'][1] != exitcode:
        attr_mismatched = True
        error_msg = ('unexpected exitcode - expected: %d, actuall: %d'
                   % (test_attr['exitcode'][1], exitcode))

    test_failed = False

    # attribute mismatched
    if attr_mismatched:
        test_failed = True

    # timeout expired
    if timeout_expired:
        test_failed = True
        error_msg = 'timed out after %d seconds' % test_attr['timeout']

    # This test should have passed but failed.
    if not should_fail and exitcode != 0:
        test_failed = True

    # This test should have failed but passed.
    if should_fail and exitcode == 0:
        test_failed = True
        if error_msg != '':
            error_msg = 'NOT FAILED'

    if test_failed:
        print('%s[ %s ] %s - %s%s' % (TERM_RED,
                                      test_type,
                                      fs.basename(test),
                                      error_msg,
                                      TERM_EMPTY))
        print(test_output)
        return (TestResult.Fail, test)

    print('[ %s ] %s' % (test_type, fs.basename(test)))
    return (TestResult.Pass, test)
Ejemplo n.º 20
0
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
    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
Ejemplo n.º 21
0
    return ex.run_cmd(path.CHECKTEST_PATH, [iotjs]) == 0


# Initialize build option object.
option = init_option()

adjust_option(option)

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)

# Perform tidy check.
print_progress('Tidy checking')
if not option.no_check_tidy:
    if not check_tidy(path.PROJECT_ROOT):
        ex.fail("Failed check_tidy")

# Anazlye module dependency
print_progress('Analyze module dependency')
if not analyze_module_dependency(option):
    ex.fail('Failed to analyze module dependency')
Ejemplo n.º 22
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import subprocess
import getpass

from common.system.filesystem import FileSystem as fs
from common.system.executor import Executor as ex

SCRIPT_PATH = fs.dirname(fs.abspath(__file__))

BUILD_SCRIPT_DEBUG = fs.join(
    SCRIPT_PATH,
    'build.py --clean --config=.build.default.config --buildtype=debug')

BUILD_SCRIPT_RELEASE = fs.join(
    SCRIPT_PATH,
    'build.py --clean --config=.build.default.config --buildtype=release')

GIT_REPO_FORMAT = 'https://github.com/%s/iotjs.git'


def get_repo_url(fork_name):
    return GIT_REPO_FORMAT % fork_name
Ejemplo n.º 23
0
def set_global_vars(option):
    global host_tuple
    host_tuple = '%s-%s' % (platform.arch(), platform.os())

    global host_build_root
    host_build_root = fs.join(path.PROJECT_ROOT, option.builddir, 'host',
                              host_tuple, option.buildtype)

    global host_build_bins
    host_build_bins = fs.join(host_build_root, 'bin')

    global target_tuple
    target_tuple = '%s-%s' % (option.target_arch, option.target_os)

    global build_root
    build_root = fs.join(path.PROJECT_ROOT, option.builddir, target_tuple,
                         option.buildtype)

    global build_bins
    build_bins = fs.join(build_root, 'bin')

    global build_libs
    build_libs = fs.join(build_root, 'lib')

    global build_jerry_deps
    build_jerry_deps = fs.join(build_root, 'deps', 'jerry')

    global build_jerry_deps_libs
    build_jerry_deps_libs = fs.join(build_jerry_deps, "lib")

    global libtuv_output_path
    libtuv_output_path = fs.join(build_libs, 'libtuv.a')

    global libhttpparser_output_path
    libhttpparser_output_path = fs.join(build_libs, 'libhttpparser.a')

    global jerry_output_path
    jerry_output_path = fs.join(host_build_bins, 'jerry')

    global libjerry_output_path
    libjerry_output_path = fs.join(build_libs, 'libjerrycore.a')

    global iotjs_output_path
    iotjs_output_path = fs.join(build_bins, 'iotjs')

    global libiotjs_output_path
    libiotjs_output_path = fs.join(build_libs, 'libiotjs.a')

    global libjerry_libc_output_path
    libjerry_libc_output_path = fs.join(build_jerry_deps_libs,
                                        'libjerry-libc.a')

    global libjerry_libm_output_path
    libjerry_libm_output_path = fs.join(build_jerry_deps_libs,
                                        'libjerry-libm.a')

    global cmake_toolchain_file
    cmake_toolchain_file = fs.join(path.PROJECT_ROOT, 'cmake', 'config',
                                   target_tuple + '.cmake')

    global host_cmake_toolchain_file
    host_cmake_toolchain_file = fs.join(path.PROJECT_ROOT, 'cmake', 'config',
                                        host_tuple + '.cmake')

    global platform_descriptor
    platform_descriptor = '%s-%s' % (option.target_arch, option.target_os)
Ejemplo n.º 24
0
def extractName(path):
    return fs.splitext(os.path.basename(path))[0]
Ejemplo n.º 25
0
def is_interesting(file):
    _, ext = fs.splitext(file)
    return ext in interesting_exts and file not in skip_files