Ejemplo n.º 1
0
def run(args):
    build(args)

    plan('Launching an emulator')
    cmd = [get_var('HAL_RUN'), get_var('EXECUTABLE_PATH')]
    progress(' '.join(cmd))
    run_emulator(cmd)
Ejemplo n.º 2
0
def install(requirements):
    missing = []
    for package in requirements.get('apt', {}).get('packages', []):
        args = package.split(' ')
        package = list(filter(lambda x: not x.startswith('-'), args))[0]
        if not is_installed(package):
            missing.append(args)

    if missing != []:
        plan('Install OS requirements')
        update()
        for package in missing:
            apt_install(package)
Ejemplo n.º 3
0
def doctor():
    resea.commands.clean.main([])
    tmp_dir = os.path.join('tmp', 'doctor')
    shutil.rmtree(tmp_dir, ignore_errors=True)
    os.makedirs(tmp_dir)

    plan('Validate the package')
    progress('check for the existence of README.md')
    if not os.path.exists('README.md'):
        notice('README.md not found')

    progress('validate package.yaml')
    try:
        yml = load_yaml('package.yaml', validator=validate_package_yml)
    except FileNotFoundError:
        error("'package.yaml' not found")

    if yml['category'] in ['application', 'library', 'lang', 'hal']:
        load_packages([yml['name']] + yml['depends'], {})
        lang = yml.get("lang")
        if lang is None:
            error("lang is not speicified in package.yaml")

        # run lang's doctor
        lang_html_path = os.path.join(tmp_dir, 'lang.html')
        doctor = expand_var(get_var('LANGS')[lang]['doctor'])
        subprocess.Popen('{} {} {}'.format(doctor, lang_html_path, tmp_dir),
                         shell=True).wait()

        # generate index.html
        progress('Generating index.html')
        with open(lang_html_path) as f:
            lang_html = f.read()
    else:
        lang_html = ''

    index_html_path = os.path.join(tmp_dir, 'index.html')
    with open(index_html_path, 'w') as f:
        f.write(
            render(INDEX_HTML, {
                'lang': lang_html,
                'created_at': str(datetime.datetime.now())
            }))

    return index_html_path
Ejemplo n.º 4
0
def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('outdir')
    args = parser.parse_args(argv)

    outdir = os.path.abspath(args.outdir)
    if os.path.exists(outdir):
        shutil.rmtree(outdir)

    os.makedirs(outdir)

    packages = []
    for package_yml_path in glob.glob('**/package.yaml', recursive=True):
        yml = load_yaml(package_yml_path, validator=validate_package_yml)
        package_name = yml['name']

        cwd = os.getcwd()
        os.chdir(os.path.dirname(package_yml_path))

        plan('Doctor {}'.format(package_name))

        try:
            doctor_main([])
        except:
            notice('failed to doctor {}'.format(package_name))
            packages.append((False, package_name))
        else:
            shutil.move('tmp/doctor', os.path.join(outdir, package_name))
            packages.append((True, package_name))

        os.chdir(cwd)

    index_html_path = os.path.join(outdir, 'index.html')
    with open(index_html_path, 'w') as f:
        f.write(
            render(INDEX_HTML, {
                'packages': packages,
                'created_at': str(datetime.datetime.now())
            }))
Ejemplo n.º 5
0
def build(args):
    """Builds an executable."""

    # load package.yaml in the current directory
    try:
        yml = load_yaml('package.yaml', validator=validate_package_yml)
    except FileNotFoundError:
        error("'package.yaml' not found (are you in a package directory?)")

    global_config.setdefault('ENV', 'release')
    global_config.setdefault('MAKE', 'make')
    global_config.setdefault('TEST', False)
    global_config.set('BUILD_DIR', 'build/' + get_var('ENV'))
    global_config.set('EXECUTABLE_PATH',
                      expand_var('{{ BUILD_DIR }}/application'))

    load_configsets(args.configset)
    load_cmdline_config(args.config)

    if get_var('HAL', default=None) is None:
        error('HAL is not speicified')

    # resolve dependencies
    progress('Loading packages')
    if get_var('PACKAGES', default=[]) != []:
        packages = get_var('PACKAGES', default=[])
    else:
        packages = [yml['name']]

    packages = list(set([get_var('HAL')] + packages))

    if get_var('TEST'):
        if 'kernel' not in packages:
            packages.append('kernel')
        if yml['name'] not in packages:
            error("test target '" + yml['name'] +
                  "' is not included in builtin packages " +
                  '(did you include it in PACKAGES?)')

    ymls = load_packages(packages, enable_if=True, update_env=True)

    build_dir = get_var('BUILD_DIR')
    plan('Building {CATEGORY} with {HAL} HAL in {BUILD_DIR} ({ENV})'.format(
        **global_config.getdict()))

    # install os requirements
    os_requirements_pickle = os.path.join(build_dir, 'os_requirements.pickle')
    os_requirements = list(map(lambda y: y['os_requirements'], ymls.values()))
    if not is_object_equals_to_pickle(os_requirements, os_requirements_pickle):
        plan('Checking OS requirements')
        for x in os_requirements:
            install_os_requirements(x)

    sources = []
    autogen_files = []
    libs = []
    stubs = []
    deps_files = []
    stub_files = []
    target_deps = []
    for package in ymls.keys():
        package_dir = get_package_dir(package)
        libs += get_var('LIBS', package, default=[])

        ext_lang = {}
        for lang_name, lang in get_var('LANGS').items():
            ext_lang[lang['ext']] = lang

            if 'stub' not in lang:
                continue

            stub_file = os.path.join(
                build_dir, 'stubs', lang_name,
                lang['stub']['prefix'] + package + lang['stub']['suffix'])
            stubs.append((stub_file, os.path.join(package_dir, 'package.yaml'),
                          expand_var(
                              get_var('LANGS', package)['cpp']['genstub'],
                              package)))
            stub_files.append(stub_file)

        source_files = []
        for src in get_var('SOURCES', package, default=[]):
            base, ext = os.path.splitext(src)
            deps_file = os.path.join(build_dir, 'deps', package,
                                     base + '.deps')
            deps_files.append(deps_file)
            sources.append(
                ([(os.path.join(get_package_dir(package), src),
                   os.path.join(build_dir, 'objs', package,
                                base + '.o'), deps_file)],
                 expand_var(ext_lang[ext.lstrip('.')]['abbrev'], package),
                 expand_var(ext_lang[ext.lstrip('.')]['compile'], package),
                 expand_var(ext_lang[ext.lstrip('.')]['mkdeps'], package)))

        for f in get_var('FILES', package, default=[]):
            path = os.path.join(package_dir, f['path'])
            cmd = expand_var(f['cmd'], package)
            autogen_files.append((path, cmd))

            if f.get('rebuild_on') == 'always':
                try:
                    os.remove(path)
                except FileNotFoundError:
                    pass

            if f.get('required_on') == 'link':
                target_deps += [path]

    target_deps += libs

    # start
    if get_var('TEST'):
        genstart_args = ['--test', '--test-target', yml['name']]
    else:
        genstart_args = []

    genstart = ' '.join([get_var('HAL_GENSTART'), '--with-threading'] +
                        genstart_args + list(set(get_var('BUILTIN_APPS'))))

    start_file = os.path.join(build_dir,
                              'start.' + get_var('LANGS')['cpp']['ext'])
    start_deps_file = os.path.join(build_dir, 'start.deps')
    start_obj_file = os.path.join(build_dir, 'start.o')
    lang = get_var('HAL_START_LANG')
    sources.append(
        ([(start_file, start_obj_file, start_deps_file)],
         expand_var(get_var('LANGS', package)[lang]['abbrev'], package),
         expand_var(get_var('LANGS', package)[lang]['compile'], package),
         expand_var(get_var('LANGS', package)[lang]['mkdeps'], package)))

    # target
    if get_var('TEST'):
        global_config.set('CATEGORY', 'application')

    category = get_var('CATEGORY')
    if category == 'application':
        hal_link = get_var('HAL_LINK')
    elif category == 'library':
        hal_link = get_var('HAL_LIBLINK')
    else:
        error("unknown category '{}'".format(category))

    target = os.path.join(build_dir, category)
    for files, _, _, _ in sources:
        for _, obj, _ in files:
            target_deps.append(obj)

    buildconfig = (global_config.getdict(),
                   [c.getdict() for c in local_config.values()])
    buildconfig_pickle = os.path.join(build_dir, 'buildconfig.pickle')
    generate_makefile = True
    if os.path.exists(build_dir):
        # clean up if build config have been changed
        if is_object_equals_to_pickle(buildconfig, buildconfig_pickle):
            generate_makefile = False
        else:
            plan('detected build config changes; cleaning the build directory')
            progress('deleting {}'.format(build_dir))
            shutil.rmtree(build_dir)

    os.makedirs(build_dir, exist_ok=True)

    # save the build config and the os requirements to detect changes
    pickle.dump(buildconfig, open(buildconfig_pickle, 'wb'))
    pickle.dump(os_requirements, open(os_requirements_pickle, 'wb'))

    makefile = build_dir + '/Makefile'

    # generate makefile if needed
    if generate_makefile:
        with open(makefile, 'w') as f:
            f.write(render(MAKEFILE_TEMPLATE, locals()))

    # Everything is ready now. Let's start building!
    progress('executing make')
    if run_make(get_var('MAKE'), makefile, args.prettify) != 0:
        error('something went wrong in make(1)')