예제 #1
0
def create_optparser(sdk_dir):
    """Create the parser for the command line.
    """
    def store_abspath(option, opt_str, value, parser):
        setattr(parser.values, option.dest, os.path.abspath(value))

    def store_abspath_dir(option, opt_str, value, parser):
        if not os.path.isdir(value):
            raise optparse.OptionValueError("'%s' is not a directory" % value)
        setattr(parser.values, option.dest, os.path.abspath(value))

    def store_abspath_file(option, opt_str, value, parser):
        if not os.path.isfile(value):
            raise optparse.OptionValueError("'%s' is not a file" % value)
        setattr(parser.values, option.dest, os.path.abspath(value))

    def store_version(option, opt_str, value, parser):
        version = version_from_string(value)
        if version is None:
            raise optparse.OptionValueError(
                "'%s' is not a valid version number" % value)
        setattr(parser.values, option.dest, version)

    p = optparse.OptionParser(usage="python %prog [opts] [macro=value] "
                              "[macro+=value]",
                              version=sip_version_str)

    # Note: we don't use %default to be compatible with Python 2.3.
    p.add_option("-k",
                 "--static",
                 action="store_true",
                 default=False,
                 dest="static",
                 help="build the SIP module as a static library")
    p.add_option("-p",
                 "--platform",
                 action="store",
                 type="string",
                 metavar="PLATFORM",
                 dest="platform",
                 help="the platform/compiler "
                 "configuration [default: %s]" % build_platform)
    p.add_option("-u",
                 "--debug",
                 action="store_true",
                 default=False,
                 help="build with debugging symbols")
    p.add_option("--sip-module",
                 action="store",
                 default="sip",
                 type="string",
                 metavar="NAME",
                 dest="sip_module",
                 help="the package.module name "
                 "of the sip module [default: sip]")
    p.add_option("--configuration",
                 dest='config_file',
                 type='string',
                 action='callback',
                 callback=store_abspath_file,
                 metavar="FILE",
                 help="FILE contains the target configuration")
    p.add_option("--target-py-version",
                 dest='target_py_version',
                 type='string',
                 action='callback',
                 callback=store_version,
                 metavar="VERSION",
                 help="the major.minor version of the target Python [default: "
                 "%s]" % siputils.version_to_string(py_version, parts=2))
    p.add_option("--sysroot",
                 dest='sysroot',
                 type='string',
                 action='callback',
                 callback=store_abspath_dir,
                 metavar="DIR",
                 help="DIR is the target system root directory")
    p.add_option("--no-tools",
                 action="store_true",
                 default=False,
                 dest="no_tools",
                 help="disable the building of the code generator "
                 "and the installation of the build system [default: enabled]")
    p.add_option("--use-qmake",
                 action="store_true",
                 default=False,
                 dest="use_qmake",
                 help="generate qmake .pro files instead of "
                 "Makefiles")

    if sys.platform == 'darwin':
        # Get the latest SDK to use as the default.
        sdks = glob.glob(sdk_dir + '/MacOSX*.sdk')
        if len(sdks) > 0:
            sdks.sort()
            _, default_sdk = os.path.split(sdks[-1])
        else:
            default_sdk = 'MacOSX10.4u.sdk'

        g = optparse.OptionGroup(p, title="MacOS X Configuration")
        g.add_option("--arch",
                     action="append",
                     default=[],
                     dest="arch",
                     choices=["i386", "x86_64", "ppc"],
                     help="build for architecture ARCH")
        g.add_option("--deployment-target",
                     action="store",
                     default='',
                     metavar="VERSION",
                     dest="deployment_target",
                     help="set the value of the MACOSX_DEPLOYMENT_TARGET "
                     "environment variable in generated Makefiles")
        g.add_option(
            "-n",
            "--universal",
            action="store_true",
            default=False,
            dest="universal",
            help="build the SIP code generator and module as universal "
            "binaries")
        g.add_option("-s",
                     "--sdk",
                     action="store",
                     default=default_sdk,
                     type="string",
                     metavar="SDK",
                     dest="sdk",
                     help="the name of the SDK used when building universal "
                     "binaries [default: %s]" % default_sdk)
        p.add_option_group(g)

    # Querying.
    g = optparse.OptionGroup(p, title="Query")
    g.add_option("--show-platforms",
                 action="store_true",
                 default=False,
                 dest="show_platforms",
                 help="show the list of supported "
                 "platform/compiler configurations")
    g.add_option("--show-build-macros",
                 action="store_true",
                 default=False,
                 dest="show_build_macros",
                 help="show the list of supported build "
                 "macros")
    p.add_option_group(g)

    # Installation.
    g = optparse.OptionGroup(p, title="Installation")
    g.add_option(
        "-b",
        "--bindir",
        action="callback",
        type="string",
        metavar="DIR",
        dest="sipbindir",
        callback=store_abspath,
        help="where the SIP code generator will be installed [default: "
        "%s]" % plat_bin_dir)
    g.add_option("-d",
                 "--destdir",
                 action="callback",
                 type="string",
                 metavar="DIR",
                 dest="sipmoddir",
                 callback=store_abspath,
                 help="where the SIP module will be installed [default: "
                 "%s]" % plat_py_site_dir)
    g.add_option("-e",
                 "--incdir",
                 action="callback",
                 type="string",
                 metavar="DIR",
                 dest="sipincdir",
                 callback=store_abspath,
                 help="where the SIP header file will be installed [default: "
                 "%s]" % plat_py_inc_dir)
    g.add_option("-v",
                 "--sipdir",
                 action="callback",
                 type="string",
                 metavar="DIR",
                 dest="sipsipdir",
                 callback=store_abspath,
                 help="where .sip files are normally installed [default: "
                 "%s]" % plat_sip_dir)
    p.add_option_group(g)

    return p
예제 #2
0
파일: configure.py 프로젝트: z80/lcu03
def create_optparser(sdk_dir):
    """Create the parser for the command line.
    """

    def store_abspath(option, opt_str, value, parser):
        setattr(parser.values, option.dest, os.path.abspath(value))

    def store_abspath_dir(option, opt_str, value, parser):
        if not os.path.isdir(value):
            raise optparse.OptionValueError("'%s' is not a directory" % value)
        setattr(parser.values, option.dest, os.path.abspath(value))

    def store_abspath_file(option, opt_str, value, parser):
        if not os.path.isfile(value):
            raise optparse.OptionValueError("'%s' is not a file" % value)
        setattr(parser.values, option.dest, os.path.abspath(value))

    def store_version(option, opt_str, value, parser):
        version = siputils.version_from_string(value)
        if version is None:
            raise optparse.OptionValueError("'%s' is not a valid version number" % value)
        setattr(parser.values, option.dest, version)

    p = optparse.OptionParser(usage="python %prog [opts] [macro=value] " "[macro+=value]", version=sip_version_str)

    # Note: we don't use %default to be compatible with Python 2.3.
    p.add_option(
        "-k",
        "--static",
        action="store_true",
        default=False,
        dest="static",
        help="build the SIP module as a static library",
    )
    p.add_option(
        "-p",
        "--platform",
        action="store",
        type="string",
        metavar="PLATFORM",
        dest="platform",
        help="the platform/compiler " "configuration [default: %s]" % build_platform,
    )
    p.add_option("-u", "--debug", action="store_true", default=False, help="build with debugging symbols")
    p.add_option(
        "--sip-module",
        action="store",
        default="sip",
        type="string",
        metavar="NAME",
        dest="sip_module",
        help="the package.module name " "of the sip module [default: sip]",
    )
    p.add_option(
        "--configuration",
        dest="config_file",
        type="string",
        action="callback",
        callback=store_abspath_file,
        metavar="FILE",
        help="FILE contains the target configuration",
    )
    p.add_option(
        "--target-py-version",
        dest="target_py_version",
        type="string",
        action="callback",
        callback=store_version,
        metavar="VERSION",
        help="the major.minor version of the target Python [default: "
        "%s]" % siputils.version_to_string(py_version, parts=2),
    )
    p.add_option(
        "--sysroot",
        dest="sysroot",
        type="string",
        action="callback",
        callback=store_abspath_dir,
        metavar="DIR",
        help="DIR is the target system root directory",
    )
    p.add_option(
        "--no-tools",
        action="store_true",
        default=False,
        dest="no_tools",
        help="disable the building of the code generator "
        "and the installation of the build system [default: enabled]",
    )
    p.add_option(
        "--use-qmake",
        action="store_true",
        default=False,
        dest="use_qmake",
        help="generate qmake .pro files instead of " "Makefiles",
    )

    if sys.platform == "darwin":
        # Get the latest SDK to use as the default.
        sdks = glob.glob(sdk_dir + "/MacOSX*.sdk")
        if len(sdks) > 0:
            sdks.sort()
            _, default_sdk = os.path.split(sdks[-1])
        else:
            default_sdk = "MacOSX10.4u.sdk"

        g = optparse.OptionGroup(p, title="MacOS X Configuration")
        g.add_option(
            "--arch",
            action="append",
            default=[],
            dest="arch",
            choices=["i386", "x86_64", "ppc"],
            help="build for architecture ARCH",
        )
        g.add_option(
            "--deployment-target",
            action="store",
            default="",
            metavar="VERSION",
            dest="deployment_target",
            help="set the value of the MACOSX_DEPLOYMENT_TARGET " "environment variable in generated Makefiles",
        )
        g.add_option(
            "-n",
            "--universal",
            action="store_true",
            default=False,
            dest="universal",
            help="build the SIP code generator and module as universal " "binaries",
        )
        g.add_option(
            "-s",
            "--sdk",
            action="store",
            default=default_sdk,
            type="string",
            metavar="SDK",
            dest="sdk",
            help="the name of the SDK used when building universal " "binaries [default: %s]" % default_sdk,
        )
        p.add_option_group(g)

    # Querying.
    g = optparse.OptionGroup(p, title="Query")
    g.add_option(
        "--show-platforms",
        action="store_true",
        default=False,
        dest="show_platforms",
        help="show the list of supported " "platform/compiler configurations",
    )
    g.add_option(
        "--show-build-macros",
        action="store_true",
        default=False,
        dest="show_build_macros",
        help="show the list of supported build " "macros",
    )
    p.add_option_group(g)

    # Installation.
    g = optparse.OptionGroup(p, title="Installation")
    g.add_option(
        "-b",
        "--bindir",
        action="callback",
        type="string",
        metavar="DIR",
        dest="sipbindir",
        callback=store_abspath,
        help="where the SIP code generator will be installed [default: " "%s]" % plat_bin_dir,
    )
    g.add_option(
        "-d",
        "--destdir",
        action="callback",
        type="string",
        metavar="DIR",
        dest="sipmoddir",
        callback=store_abspath,
        help="where the SIP module will be installed [default: " "%s]" % plat_py_site_dir,
    )
    g.add_option(
        "-e",
        "--incdir",
        action="callback",
        type="string",
        metavar="DIR",
        dest="sipincdir",
        callback=store_abspath,
        help="where the SIP header file will be installed [default: " "%s]" % plat_py_venv_inc_dir,
    )
    g.add_option(
        "-v",
        "--sipdir",
        action="callback",
        type="string",
        metavar="DIR",
        dest="sipsipdir",
        callback=store_abspath,
        help="where .sip files are normally installed [default: " "%s]" % plat_sip_dir,
    )
    p.add_option_group(g)

    return p
예제 #3
0
def update_from_configuration_file(config_file):
    """ Update a number of globals from values read from a configuration file.
    """

    siputils.inform("Reading configuration from %s..." % config_file)

    config = {}

    # Read the file into the dict.
    cfg = open(config_file)
    line_nr = 0

    for l in cfg:
        line_nr += 1

        # Strip comments and blank lines.
        l = l.split('#')[0].strip()
        if l == '':
            continue

        parts = l.split('=', 1)
        if len(parts) == 2:
            name = parts[0].strip()
            value = parts[1].strip()
        else:
            name = value = ''

        if name == '' or value == '':
            siputils.error("%s:%d: Invalid line." % (config_file, line_nr))

        config[name] = value
        last_name = name

    cfg.close()

    # Enforce the presets.
    version = siputils.version_to_string(py_version).split('.')
    config['py_major'] = version[0]
    config['py_minor'] = version[1]
    config['sysroot'] = sysroot

    # Override the relevent values.
    global py_platform, plat_py_conf_inc_dir, plat_py_inc_dir, plat_py_lib_dir
    global sip_bin_dir, sip_inc_dir, sip_module_dir, sip_sip_dir

    py_platform = _get_configuration_value(config, 'py_platform', py_platform)
    plat_py_inc_dir = _get_configuration_value(config, 'py_inc_dir',
                                               plat_py_inc_dir)
    plat_py_lib_dir = _get_configuration_value(config, 'py_pylib_dir',
                                               plat_py_lib_dir)

    # The pyconfig.h directory defaults to the Python.h directory.
    plat_py_conf_inc_dir = _get_configuration_value(config, 'py_conf_inc_dir',
                                                    plat_py_inc_dir)

    sip_bin_dir = _get_configuration_value(config, 'sip_bin_dir', sip_bin_dir)
    sip_module_dir = _get_configuration_value(config, 'sip_module_dir',
                                              sip_module_dir)

    # Note that this defaults to any 'py_inc_dir' specified in the
    # configuration file.
    sip_inc_dir = _get_configuration_value(config, 'sip_inc_dir',
                                           plat_py_inc_dir)

    # Note that this is only used when creating sipconfig.py.
    sip_sip_dir = _get_configuration_value(config, 'sip_sip_dir', sip_sip_dir)
예제 #4
0
파일: configure.py 프로젝트: z80/lcu03
def update_from_configuration_file(config_file):
    """ Update a number of globals from values read from a configuration file.
    """

    siputils.inform("Reading configuration from %s..." % config_file)

    config = {}

    # Read the file into the dict.
    cfg = open(config_file)
    line_nr = 0

    for l in cfg:
        line_nr += 1

        # Strip comments and blank lines.
        l = l.split("#")[0].strip()
        if l == "":
            continue

        parts = l.split("=", 1)
        if len(parts) == 2:
            name = parts[0].strip()
            value = parts[1].strip()
        else:
            name = value = ""

        if name == "" or value == "":
            siputils.error("%s:%d: Invalid line." % (config_file, line_nr))

        config[name] = value
        last_name = name

    cfg.close()

    # Enforce the presets.
    version = siputils.version_to_string(py_version).split(".")
    config["py_major"] = version[0]
    config["py_minor"] = version[1]
    config["sysroot"] = sysroot

    # Override the relevent values.
    global py_platform, plat_py_conf_inc_dir, plat_py_inc_dir, plat_py_lib_dir
    global sip_bin_dir, sip_inc_dir, sip_module_dir, sip_sip_dir

    py_platform = _get_configuration_value(config, "py_platform", py_platform)
    plat_py_inc_dir = _get_configuration_value(config, "py_inc_dir", plat_py_inc_dir)
    plat_py_lib_dir = _get_configuration_value(config, "py_pylib_dir", plat_py_lib_dir)

    # The pyconfig.h directory defaults to the Python.h directory.
    plat_py_conf_inc_dir = _get_configuration_value(config, "py_conf_inc_dir", plat_py_inc_dir)

    sip_bin_dir = _get_configuration_value(config, "sip_bin_dir", sip_bin_dir)
    sip_module_dir = _get_configuration_value(config, "sip_module_dir", sip_module_dir)

    # Note that this defaults to any 'py_inc_dir' specified in the
    # configuration file.
    sip_inc_dir = _get_configuration_value(config, "sip_inc_dir", plat_py_inc_dir)

    # Note that this is only used when creating sipconfig.py.
    sip_sip_dir = _get_configuration_value(config, "sip_sip_dir", sip_sip_dir)