def test_evaluate_shell_command(self):
        if sysutil.unversioned_platform() != 'linux':
            # This test runs shell commands, so only run it on Linux for now.
            pass

        opts_string = """
!! unix- _ K1 = a \\"`echo 123`\\" b
!! unix- _ K2 = $(shell echo 123)
!! unix- _ K3 = $(subst 1,,$(K2))
        """
        opts_file = StringIO(opts_string)
        parser = optionsparser.OptionsParser(opts_file)
        parser.parse()

        ev = optionsevaluator.OptionsEvaluator(
            optiontypes.Uplid.from_str('unix-linux-x86-3.2.0-gcc-4.7.2'),
            optiontypes.Ufid.from_str('dbg_mt_exc'))

        # ev.store_option_rules(parser.option_rules, ['K1', 'K2'])
        # ev.evaluate(['K1', 'K2'])
        ev.store_option_rules(parser.option_rules)
        ev.evaluate()

        expected_results = {
            'K1': 'a "123" b',
            'K2': '123',
        }
        self.assertEqual(ev.results, expected_results)
示例#2
0
def print_envs(options, info):
    ufid = optionsutil.make_ufid_from_cmdline_options(options)
    os_type, os_name, cpu_type, os_ver = get_os_info()

    uplid = optiontypes.Uplid(os_type, os_name, cpu_type, os_ver, info.type_,
                              info.version)

    print("Using compiler: %s" % info.description(), file=sys.stderr)
    print("Using ufid: %s" % ufid, file=sys.stderr)

    print("export BDE_CMAKE_UPLID=%s" % uplid)
    print("export BDE_CMAKE_UFID=%s" % ufid)
    id_str = "%s-%s" % (uplid, ufid)

    if options.build_dir:
        print('export BDE_CMAKE_BUILD_DIR="%s"' % options.build_dir)
    else:
        print('export BDE_CMAKE_BUILD_DIR="_build/%s"' % id_str)

    if os_type != "windows":
        print("export CXX=%s" % info.cxx_path)
        print("export CC=%s" % info.c_path)
    else:
        print("export CXX=cl")
        print("export CC=cl")

    if info.toolchain:
        print("export BDE_CMAKE_TOOLCHAIN=toolchains/%s/%s" %
              (sysutil.unversioned_platform(), info.toolchain))
    else:
        print("export BDE_CMAKE_TOOLCHAIN=toolchains/%s/default" %
              sysutil.unversioned_platform())

    install_dir = options.install_dir if options.install_dir else "_install"

    print(
        "Using install directory: %s" % os.path.abspath(install_dir),
        file=sys.stderr,
    )
    print('export BDE_CMAKE_INSTALL_DIR="%s"' % os.path.abspath(install_dir))
示例#3
0
def print_envs(options, info):
    ufid = optionsutil.make_ufid_from_cmdline_options(options)
    os_type, os_name, cpu_type, os_ver = get_os_info()

    uplid = optiontypes.Uplid(os_type, os_name, cpu_type, os_ver, info.type_,
                              info.version)

    print('Using compiler: %s' % info.description(), file=sys.stderr)
    print('Using ufid: %s' % ufid, file=sys.stderr)

    print('export BDE_WAF_UPLID=%s' % uplid)
    print('export BDE_WAF_UFID=%s' % ufid)
    id_str = '%s-%s' % (uplid, ufid)
    print('export BDE_WAF_BUILD_DIR="_build/%s"' % id_str)
    print('export WAFLOCK=".lock-waf-%s"' % id_str)

    if os_type != 'windows':
        print('export CXX=%s' % info.cxx_path)
        print('export CC=%s' % info.c_path)

    if info.flags:
        print('export BDE_WAF_COMP_FLAGS="%s"' % info.flags)
    else:
        print('unset BDE_WAF_COMP_FLAGS')

    if options.install_dir:
        install_dir = options.install_dir
    else:
        install_dir = _determine_installation_location(
            os.environ.get('PREFIX'), uplid)

    if install_dir:
        print('Using install directory: %s' % install_dir, file=sys.stderr)
        PREFIX = os.path.join(install_dir, id_str)
        if sysutil.unversioned_platform() == 'cygwin':
            PREFIX = sysutil.shell_command('cygpath -m "%s"' % PREFIX).rstrip()

        print('export PREFIX="%s"' % PREFIX)
        pkg_path = '%s/lib/pkgconfig' % PREFIX
        extra_pkg_path = os.environ.get('BDE_WAF_EXTRA_PKG_CONFIG_PATH')
        if extra_pkg_path:
            pkg_path += ':' + extra_pkg_path
        print('export PKG_CONFIG_PATH="%s"' % pkg_path)
示例#4
0
文件: main.py 项目: exg77/bde-tools
def print_envs(options, info):
    ufid = optionsutil.make_ufid_from_cmdline_options(options)
    os_type, os_name, cpu_type, os_ver = get_os_info()

    uplid = optiontypes.Uplid(os_type, os_name, cpu_type, os_ver,
                              info.type_, info.version)

    print('Using compiler: %s' % info.description(), file=sys.stderr)
    print('Using ufid: %s' % ufid, file=sys.stderr)

    print('export BDE_WAF_UPLID=%s' % uplid)
    print('export BDE_WAF_UFID=%s' % ufid)
    id_str = '%s-%s' % (uplid, ufid)
    print('export BDE_WAF_BUILD_DIR="_build/%s"' % id_str)
    print('export WAFLOCK=".lock-waf-%s"' % id_str)

    if os_type != 'windows':
        print('export CXX=%s' % info.cxx_path)
        print('export CC=%s' % info.c_path)

    if info.flags:
        print('export BDE_WAF_COMP_FLAGS="%s"' % info.flags)
    else:
        print('unset BDE_WAF_COMP_FLAGS')

    if options.install_dir:
        install_dir = options.install_dir
    else:
        install_dir = _determine_installation_location(
            os.environ.get('PREFIX'), uplid)

    if install_dir:
        print('Using install directory: %s' % install_dir, file=sys.stderr)
        PREFIX = os.path.join(install_dir, id_str)
        if sysutil.unversioned_platform() == 'cygwin':
            PREFIX = sysutil.shell_command('cygpath -m "%s"' % PREFIX).rstrip()

        print('export PREFIX="%s"' % PREFIX)
        pkg_path = '%s/lib/pkgconfig' % PREFIX
        extra_pkg_path = os.environ.get('BDE_WAF_EXTRA_PKG_CONFIG_PATH')
        if extra_pkg_path:
            pkg_path += ':' + extra_pkg_path
        print('export PKG_CONFIG_PATH="%s"' % pkg_path)
示例#5
0
def program():
    platform_str = sysutil.unversioned_platform()

    if platform_str not in ('win32', 'cygwin', 'linux', 'aix', 'sunos',
                            'darwin'):
        print('Unsupported platform: %s' % platform_str, file=sys.stderr)
        sys.exit(1)

    if platform_str == 'win32' and not sysutil.is_mingw_environment():
        print('This tool is used to configure unix-style environment '
              'variables. On Windows platforms it must be run from a unix '
              'shell environment, either cygwin, or mingw/msys/msysgit')
        sys.exit(1)

    parser = cmdline.get_option_parser()

    options, args = parser.parse_args()

    if len(args) > 1:
        parser.print_help()
        sys.exit(1)

    if len(args) == 0:
        command = 'set'
    else:
        command = args[0]

    if command not in ('set', 'unset', 'list'):
        print('Invalid command: %s' % command)
        parser.print_help()
        sys.exit(1)

    if command == 'unset':
        unset_command()
        sys.exit(0)

    compiler_infos = get_compilerinfos()

    if not compiler_infos:
        print('No valid compilers on this machine.', file=sys.stderr)
        sys.exit(1)

    if command == 'list':
        list_compilers(compiler_infos)
        sys.exit(0)

    # command == 'set'

    if options.compiler is None:
        info = compiler_infos[0]
    else:
        compiler_key_map = {}
        for c in compiler_infos:
            compiler_key_map[c.key()] = c

        if options.compiler in compiler_key_map:
            info = compiler_key_map[options.compiler]
        else:
            list_compilers(compiler_infos)
            sys.exit(1)

    print_envs(options, info)
示例#6
0
def get_os_info():
    platform_str = sysutil.unversioned_platform()
    if platform_str == 'cygwin':
        return sysutil.get_win32_os_info_from_cygwin()
    else:
        return sysutil.get_os_info()
示例#7
0
def program():
    platform_str = sysutil.unversioned_platform()

    if platform_str not in ('win32', 'cygwin', 'linux', 'aix', 'sunos',
                            'darwin', 'freebsd'):
        print('Unsupported platform: %s' % platform_str, file=sys.stderr)
        sys.exit(1)

    if platform_str == 'win32' and not sysutil.is_mingw_environment():
        print('This tool is used to configure unix-style environment '
              'variables. On Windows platforms it must be run from a unix '
              'shell environment, either cygwin, or mingw/msys/msysgit')
        sys.exit(1)

    parser = cmdline.get_option_parser()

    options, args = parser.parse_args()

    if len(args) > 1:
        parser.print_help()
        sys.exit(1)

    if len(args) == 0:
        command = 'set'
    else:
        command = args[0]

    if command not in ('set', 'unset', 'list'):
        print('Invalid command: %s' % command, file=sys.stderr)
        parser.print_help()
        sys.exit(1)

    if command == 'unset':
        unset_command()
        sys.exit(0)

    compiler_infos = get_compilerinfos()

    if not compiler_infos:
        print('No valid compilers on this machine.', file=sys.stderr)
        sys.exit(1)

    if command == 'list':
        list_compilers(compiler_infos)
        sys.exit(0)

    # command == 'set'
    info = None
    if options.compiler is None:
        info = compiler_infos[0]
    elif sysutil.is_int_string(options.compiler):
        idx = int(options.compiler)
        if idx < len(compiler_infos):
            info = compiler_infos[idx]
    else:

        for c in compiler_infos:
            if c.key() == options.compiler:
                info = c

    if not info:
        print("Invalid compiler: %s" % options.compiler, file=sys.stderr)
        list_compilers(compiler_infos)
        sys.exit(1)

    if options.cpp_std is None:
        options.cpp_std = optionsutil.get_default_cpp_std(
            info.type_, info.version)
    print_envs(options, info)
示例#8
0
文件: main.py 项目: exg77/bde-tools
def program():
    platform_str = sysutil.unversioned_platform()

    if platform_str not in ('win32', 'cygwin', 'linux', 'aix', 'sunos',
                            'darwin'):
        print('Unsupported platform: %s' % platform_str, file=sys.stderr)
        sys.exit(1)

    if platform_str == 'win32' and not sysutil.is_mingw_environment():
        print('This tool is used to configure unix-style environment '
              'variables. On Windows platforms it must be run from a unix '
              'shell environment, either cygwin, or mingw/msys/msysgit')
        sys.exit(1)

    parser = cmdline.get_option_parser()

    options, args = parser.parse_args()

    if len(args) > 1:
        parser.print_help()
        sys.exit(1)

    if len(args) == 0:
        command = 'set'
    else:
        command = args[0]

    if command not in ('set', 'unset', 'list'):
        print('Invalid command: %s' % command, file=sys.stderr)
        parser.print_help()
        sys.exit(1)

    if command == 'unset':
        unset_command()
        sys.exit(0)

    compiler_infos = get_compilerinfos()

    if not compiler_infos:
        print('No valid compilers on this machine.', file=sys.stderr)
        sys.exit(1)

    if command == 'list':
        list_compilers(compiler_infos)
        sys.exit(0)

    # command == 'set'
    info = None
    if options.compiler is None:
        info = compiler_infos[0]
    elif sysutil.is_int_string(options.compiler):
        idx = int(options.compiler)
        if idx < len(compiler_infos):
            info = compiler_infos[idx]
    else:

        for c in compiler_infos:
            if c.key() == options.compiler:
                info = c

    if not info:
        print("Invalid compiler: %s" % options.compiler, file=sys.stderr)
        list_compilers(compiler_infos)
        sys.exit(1)

    if options.cpp_std is None:
        options.cpp_std = optionsutil.get_default_cpp_std(info.type_, info.version)
    print_envs(options, info)
示例#9
0
文件: main.py 项目: exg77/bde-tools
def get_os_info():
    platform_str = sysutil.unversioned_platform()
    if platform_str == 'cygwin':
        return sysutil.get_win32_os_info_from_cygwin()
    else:
        return sysutil.get_os_info()
示例#10
0
def get_comp_info(ctx):
    """Return the compiler information part of the UPLID.

    See sysutil.get_os_info() which gets the operating system part of the
    UPLID.

    Args:
        ctx (ConfigurationContext): The waf configuration context.

    Returns:
        comp_type, compiler_version
    """

    def sanitize_comp_info(comp_type, comp_ver):
        """Correct problematic compiler information.

        waf sets `CXX` to `gcc` for both `clang` and `gcc`. This function
        changes the `cxx_name-cxx_version` combination for `clang` to
        distinctly identify `clang` when invoked as `gcc` and indicate the
        `clang` compiler version that `waf` correctly extracts into
        `CC_VERSION`.
        """

        if comp_type != 'gcc':
            return comp_type, comp_ver

        cmd = ctx.env.CXX + ['-dM', '-E', '-']
        env = ctx.env.env or None

        try:
            p = Utils.subprocess.Popen(
                cmd,
                stdin=Utils.subprocess.PIPE,
                stdout=Utils.subprocess.PIPE,
                stderr=Utils.subprocess.PIPE,
                env=env)
            p.stdin.write('\n'.encode())
            out = p.communicate()[0]
        except Exception:
            ctx.conf.fatal('Could not determine the compiler version %r' % cmd)

        if not isinstance(out, str):
            out = out.decode(sys.stdout.encoding or 'iso8859-1')

        if out.find("__clang__ 1") < 0:
            return comp_type, comp_ver

        return 'clang', '.'.join(ctx.env.CC_VERSION)

    def get_linux_comp_info(ctx):
        return ctx.env.CXX_NAME, '.'.join(ctx.env.CC_VERSION)

    def get_aix_comp_info(ctx):
        cxx_name = ctx.env.CXX_NAME
        if cxx_name == 'xlc++':
            cxx_name = 'xlc'

        return cxx_name, '.'.join(ctx.env.CC_VERSION)

    def get_sunos_comp_info(ctx):
        cxx_name = ctx.env.CXX_NAME
        if cxx_name == 'sun':
            cxx_name = 'cc'

        return cxx_name, '.'.join(ctx.env.CC_VERSION)

    def get_darwin_comp_info(ctx):
        return ctx.env.CXX_NAME, '.'.join(ctx.env.CC_VERSION)

    def get_windows_comp_info(ctx):
        env = dict(ctx.environ)
        env.update(PATH=';'.join(ctx.env['PATH']))
        err = ctx.cmd_and_log(ctx.env['CXX'], output=Context.STDERR, env=env)

        m = re.search(r'Compiler Version ([0-9]+\.[0-9]+).*? for (\S*)', err)
        if m:
            compiler = 'cl'
            compilerversion = m.group(1)

        return compiler, compilerversion

    def get_freebsd_comp_info(ctx):
        return ctx.env.CXX_NAME, '.'.join(ctx.env.CC_VERSION)

    platform_str = sysutil.unversioned_platform()
    comp_info_getters = {
        'linux': get_linux_comp_info,
        'aix': get_aix_comp_info,
        'sunos': get_sunos_comp_info,
        'darwin': get_darwin_comp_info,
        'win32': get_windows_comp_info,
        'freebsd': get_freebsd_comp_info
        }

    if platform_str not in comp_info_getters:
        raise blderror.UnsupportedPlatformError(
            'Unsupported platform %s' % platform_str)

    uplid = sanitize_comp_info(*comp_info_getters[platform_str](ctx))

    return uplid
示例#11
0
def get_comp_info(ctx):
    """Return the compiler information part of the UPLID.

    See sysutil.get_os_info() which gets the operating system part of the
    UPLID.

    Args:
        ctx (ConfigurationContext): The waf configuration context.

    Returns:
        comp_type, compiler_version
    """
    def sanitize_comp_info(comp_type, comp_ver):
        """Correct problematic compiler information.

        waf sets `CXX` to `gcc` for both `clang` and `gcc`. This function
        changes the `cxx_name-cxx_version` combination for `clang` to
        distinctly identify `clang` when invoked as `gcc` and indicate the
        `clang` compiler version that `waf` correctly extracts into
        `CC_VERSION`.
        """

        if comp_type != 'gcc':
            return comp_type, comp_ver

        cmd = ctx.env.CXX + ['-dM', '-E', '-']
        env = ctx.env.env or None

        try:
            p = Utils.subprocess.Popen(cmd,
                                       stdin=Utils.subprocess.PIPE,
                                       stdout=Utils.subprocess.PIPE,
                                       stderr=Utils.subprocess.PIPE,
                                       env=env)
            p.stdin.write('\n'.encode())
            out = p.communicate()[0]
        except Exception:
            ctx.conf.fatal('Could not determine the compiler version %r' % cmd)

        if not isinstance(out, str):
            out = out.decode(sys.stdout.encoding or 'iso8859-1')

        if out.find("__clang__ 1") < 0:
            return comp_type, comp_ver

        return 'clang', '.'.join(ctx.env.CC_VERSION)

    def get_linux_comp_info(ctx):
        return ctx.env.CXX_NAME, '.'.join(ctx.env.CC_VERSION)

    def get_aix_comp_info(ctx):
        cxx_name = ctx.env.CXX_NAME
        if cxx_name == 'xlc++':
            cxx_name = 'xlc'

        return cxx_name, '.'.join(ctx.env.CC_VERSION)

    def get_sunos_comp_info(ctx):
        cxx_name = ctx.env.CXX_NAME
        if cxx_name == 'sun':
            cxx_name = 'cc'

        return cxx_name, '.'.join(ctx.env.CC_VERSION)

    def get_darwin_comp_info(ctx):
        return ctx.env.CXX_NAME, '.'.join(ctx.env.CC_VERSION)

    def get_windows_comp_info(ctx):
        env = dict(ctx.environ)
        env.update(PATH=';'.join(ctx.env['PATH']))
        err = ctx.cmd_and_log(ctx.env['CXX'], output=Context.STDERR, env=env)

        m = re.search(r'Compiler Version ([0-9]+\.[0-9]+).*? for (\S*)', err)
        if m:
            compiler = 'cl'
            compilerversion = m.group(1)

        return compiler, compilerversion

    def get_freebsd_comp_info(ctx):
        return ctx.env.CXX_NAME, '.'.join(ctx.env.CC_VERSION)

    platform_str = sysutil.unversioned_platform()
    comp_info_getters = {
        'linux': get_linux_comp_info,
        'aix': get_aix_comp_info,
        'sunos': get_sunos_comp_info,
        'darwin': get_darwin_comp_info,
        'win32': get_windows_comp_info,
        'freebsd': get_freebsd_comp_info
    }

    if platform_str not in comp_info_getters:
        raise blderror.UnsupportedPlatformError('Unsupported platform %s' %
                                                platform_str)

    uplid = sanitize_comp_info(*comp_info_getters[platform_str](ctx))

    return uplid
示例#12
0
def program():
    platform_str = sysutil.unversioned_platform()

    if platform_str not in (
            "win32",
            "cygwin",
            "linux",
            "aix",
            "sunos",
            "darwin",
            "freebsd",
    ):
        print("Unsupported platform: %s" % platform_str, file=sys.stderr)
        sys.exit(1)

    if platform_str == "win32" and not sysutil.is_mingw_environment():
        print("This tool is used to configure unix-style environment "
              "variables. On Windows platforms it must be run from a unix "
              "shell environment, either cygwin, or mingw/msys/msysgit")
        sys.exit(1)

    parser = cmdline.get_option_parser()

    options, args = parser.parse_args()

    if len(args) > 1:
        parser.print_help()
        sys.exit(1)

    if len(args) == 0:
        command = "set"
    else:
        command = args[0]

    if command not in ("set", "unset", "list"):
        print("Invalid command: %s" % command, file=sys.stderr)
        parser.print_help()
        sys.exit(1)

    if command == "unset":
        unset_command()
        sys.exit(0)

    compiler_infos = get_compilerinfos()

    if not compiler_infos:
        print("No valid compilers on this machine.", file=sys.stderr)
        sys.exit(1)

    if command == "list":
        list_compilers(compiler_infos)
        sys.exit(0)

    # command == 'set'
    info = None
    if options.compiler is None:
        info = compiler_infos[0]
    elif sysutil.is_int_string(options.compiler):
        idx = int(options.compiler)
        if idx < len(compiler_infos):
            info = compiler_infos[idx]
    else:
        for c in compiler_infos:
            if c.key().startswith(options.compiler):
                info = c
                break

    if not info:
        print("Invalid compiler: %s" % options.compiler, file=sys.stderr)
        list_compilers(compiler_infos)
        sys.exit(1)

    if options.cpp_std is None:
        options.cpp_std = optionsutil.get_default_cpp_std(
            info.type_, info.version)
    print_envs(options, info)