예제 #1
0
def validate_args(args):
    """Check that supplied args are all valid. By definition logging is
       working when we get here.

       Update the gp dictionary with all the useful info"""
    if os.path.isabs(args.builddir):
        gp['bd'] = args.builddir
    else:
        gp['bd'] = os.path.join(gp['rootdir'], args.builddir)

    if not os.path.isdir(gp['bd']):
        log.error(f'ERROR: build directory {gp["bd"]} not found: exiting')
        sys.exit(1)

    if not os.access(gp['bd'], os.R_OK):
        log.error(f'ERROR: Unable to read build directory {gp["bd"]}: exiting')
        sys.exit(1)

    gp['absolute'] = args.absolute

    # Sort out the list of section names to use
    gp['secnames'] = dict()

    for argname in ['text', 'rodata', 'data', 'bss']:
        secnames = getattr(args, argname)
        if secnames:
            gp['secnames'][argname] = secnames
        else:
            gp['secnames'][argname] = ['.' + argname]

    # If no sections are specified, we just use .text
    if args.metric:
        gp['metric'] = args.metric
    else:
        gp['metric'] = ['text']
예제 #2
0
def validate_tools():
    """Check the compiler and linker are available."""
    # Validate C compiler
    if not shutil.which(gp['cc']):
        log.error(f'ERROR: Compiler {gp["cc"]} not found on path: exiting')
        sys.exit(1)

    # Validate linker
    if not shutil.which(gp['ld']):
        log.error(f'ERROR: Linker {gp["ld"]} not found on path: exiting')
        sys.exit(1)
예제 #3
0
def set_parameters(args):
    """Determine all remaining parameters"""
    # Directories we need
    gp['supportdir'] = os.path.join(gp['rootdir'], 'support')
    gp['bd_supportdir'] = os.path.join(gp['bd'], 'support')

    # Default values of parameters
    config = {}
    config['default'] = populate_defaults()

    # Read each config file. Note that we pass in the config file itself as
    # local dictionary, since then it won't get filled with global variables.
    for conf in ['arch', 'chip', 'board']:
        config[conf] = {}
        conf_file = os.path.join(gp[conf + 'dir'], conf + '.cfg')
        if os.path.isfile(conf_file):
            with open(conf_file) as fileh:
                try:
                    exec(fileh.read(), globals(), config[conf])
                except PermissionError:
                    log.error(
                        'ERROR: Corrupt config file {conf_file}: exiting')
                    sys.exit(1)

    # Populate user values from the command line
    config['user'] = populate_user(args)

    # Priority is in increasing priority: default, arch, chip, board,
    # user. Flags are different in that they are additive. All others later
    # values replace earlier ones.
    gp['cflags'] = []
    gp['ldflags'] = []

    for conf in ['default', 'arch', 'chip', 'board', 'user']:
        for key, val in config[conf].items():
            if (key == 'cflags') or (key == 'ldflags'):
                gp[key].extend(val)
            else:
                gp[key] = val

    # Linker should match compiler if it hasn't been set
    if 'ld' not in gp:
        gp['ld'] = gp['cc']

    # Add our own flags to the command line, then validate the tools
    add_internal_flags()
    validate_tools()
예제 #4
0
def validate_args(args):
    """Check that supplied args are all valid. By definition logging is
       working when we get here.

       Update the gp dictionary with all the useful info"""
    gp['format'] = args.format

    if os.path.isabs(args.builddir):
        gp['bd'] = args.builddir
    else:
        gp['bd'] = os.path.join(gp['rootdir'], args.builddir)

    if not os.path.isdir(gp['bd']):
        log.error(f'ERROR: build directory {gp["bd"]} not found: exiting')
        sys.exit(1)

    if not os.access(gp['bd'], os.R_OK):
        log.error(f'ERROR: Unable to read build directory {gp["bd"]}: exiting')
        sys.exit(1)

    if os.path.isabs(args.baselinedir):
        gp['baseline_dir'] = args.baselinedir
    else:
        gp['baseline_dir'] = os.path.join(gp['rootdir'], args.baselinedir)

    gp['absolute'] = args.absolute
    if args.output_format:
        gp['output_format'] = args.output_format
    else:
        gp['output_format'] = output_format.TEXT

    # Produce the list of section names associated with each category
    gp['secnames'] = dict()

    for argname in ALL_CATEGORIES:
        secnames = getattr(args, argname)
        if secnames:
            gp['secnames'][argname] = secnames
        else:
            gp['secnames'][argname] = (
                DEFAULT_SECNAMELIST_DICT[gp['format']])[argname]

    # If no categories are specified, we just use text
    if args.metric:
        gp['metric'] = args.metric
    else:
        gp['metric'] = ['text']
예제 #5
0
def create_builddir(builddir, clean):
    """Create the build directory, which can be relative to the current
       directory or absolute. If the "clean" is True, delete any existing
       build directory"""
    if os.path.isabs(builddir):
        gp['bd'] = builddir
    else:
        gp['bd'] = os.path.join(gp['rootdir'], builddir)

    if os.path.isdir(gp['bd']) and clean:
        try:
            shutil.rmtree(gp['bd'])
        except PermissionError:
            log.error(f'ERROR: Unable to clean build directory "{gp["bd"]}: ' +
                      'exiting')
            sys.exit(1)

    if not os.path.isdir(gp['bd']):
        try:
            os.makedirs(gp['bd'])
        except PermissionError:
            log.error(
                f'ERROR: Unable to create build directory {gp["bd"]}: exiting')
            sys.exit(1)

    if not os.access(gp['bd'], os.W_OK):
        log.error(
            f'ERROR: Unable to write to build directory {gp["bd"]}, exiting')
        sys.exit(1)
예제 #6
0
def validate_args(args):
    """Check that supplied args are all valid. By definition logging is
       working when we get here.

       Update the gp dictionary with all the useful info"""
    if os.path.isabs(args.builddir):
        gp['bd'] = args.builddir
    else:
        gp['bd'] = os.path.join(gp['rootdir'], args.builddir)

    if not os.path.isdir(gp['bd']):
        log.error(f'ERROR: build directory {gp["bd"]} not found: exiting')
        sys.exit(1)

    if not os.access(gp['bd'], os.R_OK):
        log.error(f'ERROR: Unable to read build directory {gp["bd"]}: exiting')
        sys.exit(1)

    gp['absolute'] = args.absolute

    try:
        newmodule = importlib.import_module(args.target_module)
    except ImportError as error:
        log.error(f'ERROR: Target module import failure: {error}: exiting')
        sys.exit(1)

    globals()['get_target_args'] = newmodule.get_target_args
    globals()['build_benchmark_cmd'] = newmodule.build_benchmark_cmd
    globals()['decode_results'] = newmodule.decode_results
예제 #7
0
def validate_args(args):
    """Check that supplied args are all valid. By definition logging is
       working when we get here. Don't bother with build directory, since
       that will be checked when we create it.

       Update the gp dictionary with all the useful info"""
    gp['configdir'] = os.path.join(gp['rootdir'], 'config')
    gp['bd_configdir'] = os.path.join(gp['bd'], 'config')

    # Architecture
    if not args.arch:
        log.error('ERROR: Null achitecture not permitted: exiting')
        sys.exit(1)

    gp['archdir'] = os.path.join(gp['configdir'], args.arch)
    gp['bd_archdir'] = os.path.join(gp['bd_configdir'], args.arch)
    if not os.path.isdir(gp['archdir']):
        log.error(f'ERROR: Architecture "{args.arch}" not found: exiting')
        sys.exit(1)
    if not os.access(gp['archdir'], os.R_OK):
        log.error(f'ERROR: Unable to read achitecture "{args.arch}": exiting')
        sys.exit(1)

    # Chip
    if not args.chip:
        log.error('ERROR: Null chip not permitted: exiting')

    gp['chipdir'] = os.path.join(gp['archdir'], 'chips', args.chip)
    gp['bd_chipdir'] = os.path.join(gp['bd_archdir'], 'chips', args.chip)
    if not os.path.isdir(gp['chipdir']):
        log.error(f'ERROR: Chip "{args.chip}" not found for architecture ' +
                  f'"{args.arch}: exiting')
        sys.exit(1)
    if not os.access(gp['chipdir'], os.R_OK):
        log.error(
            f'ERROR: Unable to read chip "{args.chip}" for architecture ' +
            f'"{args.arch}": exiting')
        sys.exit(1)

    # Board
    if not args.board:
        log.error('ERROR: Null board not permitted: exiting')

    gp['boarddir'] = os.path.join(gp['archdir'], 'boards', args.board)
    gp['bd_boarddir'] = os.path.join(gp['bd_archdir'], 'boards', args.board)
    if not os.path.isdir(gp['boarddir']):
        log.error(f'ERROR: Board "{args.board}" not found for architecture ' +
                  f'"{args.arch}: exiting')
        sys.exit(1)
    if not os.access(gp['boarddir'], os.R_OK):
        log.error(
            f'ERROR: Unable to read board "{args.board}" for architecture ' +
            f'"{args.arch}": exiting')
        sys.exit(1)

    # The supplementary environment
    gp['env'] = dict()
    if args.env:
        envlist = args.env.split(',')
        for envarg in envlist:
            var, val = envarg.split('=', 1)
            gp['env'][var] = val