コード例 #1
0
 def do_create_wheel(self, args):
     """
     Create a standalone Python wheel for the Python bindings.
     """
     packager = Packager(Packager.args_to_env(args), args.library_types,
                         None)
     packager.create_python_wheel(
         args.tag,
         getattr(args, 'wheel-dir'),
         getattr(args, 'build-dir'),
         getattr(args, 'dyn-deps-dir'),
         getattr(args, 'install-dir'),
         project_name=self.context.ada_api_settings.lib_name.lower(),
         lib_name='lib{}'.format(
             self.context.c_api_settings.shared_object_basename),
         python_interpreter=args.with_python)
コード例 #2
0
def package_std_dyn(args: Namespace) -> None:
    """
    Bundle all dependencies to create standalone packages.
    """
    pass
    p = Packager.from_args(args)
    pkg_dir = getattr(args, "package-dir")
    p.package_standalone_dyn(pkg_dir)
    p.package_langkit_support_dyn(pkg_dir)
コード例 #3
0
    def __init__(self):
        self.dirs = Directories(
            # It is assumed that manage.py is at the root of the language
            # definition source directory, if no source directory is explicitly
            # passed.
            lang_source_dir=path.dirname(
                path.abspath(inspect.getfile(self.__class__))))

        ########################
        # Main argument parser #
        ########################

        self.args_parser = args_parser = argparse.ArgumentParser(
            description='General manager to handle actions relative to'
            ' building/testing your language.')
        self.subparsers = subparsers = args_parser.add_subparsers()

        args_parser.add_argument(
            '--build-dir',
            default='build',
            help='Directory to use for generated source code and binaries. By'
            ' default, use "build" in the current directory.')
        args_parser.add_argument(
            '--library-types',
            default=LibraryTypes(relocatable=True),
            type=LibraryTypes.parse,
            help='Comma-separated list of library types to build (relocatable,'
            ' static-pic and static). By default, build only shared'
            ' libraries.')
        args_parser.add_argument('--verbosity',
                                 '-v',
                                 nargs='?',
                                 type=Verbosity,
                                 choices=Verbosity.choices(),
                                 default=Verbosity('info'),
                                 const=Verbosity('debug'),
                                 help='Verbosity level')
        args_parser.add_argument(
            '--full-error-traces',
            '-E',
            action='store_true',
            default=False,
            help='Always show full error traces, whatever the verbosity level'
            ' (default: disabled).')
        args_parser.add_argument('--trace',
                                 '-t',
                                 action='append',
                                 default=[],
                                 help='Activate given debug trace.')
        args_parser.add_argument(
            '--no-langkit-support',
            action='store_true',
            help='Assuming that Langkit_Support is already built and'
            ' installed. This is useful to package the generated library'
            ' only.')
        args_parser.add_argument(
            '--no-ada-api',
            action='store_true',
            help='Do not generate units to provide an Ada API, and disable the'
            ' generation of mains.')

        # Don't enable this by default so that errors will not make automated
        # tasks hang.
        args_parser.add_argument(
            '-g',
            '--debug',
            action='store_true',
            help='In case of internal error or diagnostic error, run a'
            ' post-mortem PDB session.')
        args_parser.add_argument(
            '--profile',
            action='store_true',
            help='Run cProfile and langkit, and generate a data file'
            ' "langkit.prof".')
        args_parser.add_argument('--diagnostic-style',
                                 '-D',
                                 type=DiagnosticStyle,
                                 default=DiagnosticStyle.default,
                                 help='Style for error messages.')
        args_parser.add_argument(
            '--plugin-pass',
            action='append',
            default=[],
            help='Fully qualified name to a Langkit plug-in pass constructor.'
            ' The function must return a Langkit pass, whose type derives'
            ' from langkit.passes.AbstractPass. It will be ran at the end'
            ' of the pass preexisting order.')

        def create_parser(fn, needs_context=False):
            """
            Create a subparser from a function. Uses the name and the docstring
            of the function to document the subparsers.

            :param (ManageScript, Namespace) -> None fn: The function to use.
            :param bool needs_context: Whether the executed function needs a
                CompileCtx created beforehand or not.
            :rtype: argparse.ArgumentParser
            """
            p = subparsers.add_parser(
                # Take the name of the function without the do_ prefix and with
                # dashes instead of underscores.
                fn.__name__.replace('do_', '').replace('_', '-'),

                # Take the first paragraph of the function's documentation as
                # help.
                help=fn.__doc__.split('\n\n')[0].strip())

            def internal(*args, **kwargs):
                if needs_context:
                    self.set_context(*args, **kwargs)
                fn(*args, **kwargs)

            p.set_defaults(func=internal)
            return p

        ########
        # Help #
        ########

        self.help_parser = create_parser(self.do_help)

        ############
        # Generate #
        ############

        self.generate_parser = generate_parser = create_parser(
            self.do_generate, True)
        self.add_generate_args(generate_parser)

        #########
        # Build #
        #########

        self.build_parser = build_parser = create_parser(self.do_build, True)
        self.add_build_args(build_parser)

        ########
        # Make #
        ########

        self.make_parser = make_parser = create_parser(self.do_make, True)
        self.add_generate_args(make_parser)
        self.add_build_args(make_parser)

        ###########
        # Install #
        ###########

        self.install_parser = install_parser = create_parser(
            self.do_install, True)
        install_parser.add_argument('install-dir',
                                    help='Installation directory.')

        self.add_build_mode_arg(install_parser)
        install_parser.add_argument(
            '--force',
            '-f',
            action='store_true',
            help='Force installation, overwrite files.')
        install_parser.add_argument('--disable-all-mains',
                                    action='store_true',
                                    help='Do not install main program.')

        ##########
        # Setenv #
        ##########

        self.setenv_parser = create_parser(self.do_setenv, True)

        self.add_build_mode_arg(self.setenv_parser)
        self.setenv_parser.add_argument(
            '--json',
            '-J',
            action='store_true',
            help='Output necessary env keys to JSON.')

        #######################
        # Create Python wheel #
        #######################

        self.create_wheel_parser = create_parser(self.do_create_wheel, True)
        Packager.add_platform_options(self.create_wheel_parser)
        self.create_wheel_parser.add_argument(
            '--with-python',
            help='Python intererpter to use in order to build the wheel. If'
            ' not provided, use the current one.')
        self.create_wheel_parser.add_argument(
            '--tag',
            help="Tag for the wheel (setup.py's --python-tag argument).")
        self.create_wheel_parser.add_argument(
            'wheel-dir', help='Destination directory for the wheel.')
        self.create_wheel_parser.add_argument(
            'build-dir',
            help='Temporary directory to use in order to build the wheel.')
        self.create_wheel_parser.add_argument(
            'dyn-deps-dir',
            help='Directory that contains all the dynamic libraries to ship in'
            ' the wheel (i.e. dependencies).')
        self.create_wheel_parser.add_argument(
            'install-dir', help='Directory in which the library is installed.')

        ###############################################
        # Generate, Build and Install Langkit_Support #
        ###############################################

        self.generate_lksp_parser = create_parser(
            self.do_generate_langkit_support)
        self.build_lksp_parser = create_parser(self.do_build_langkit_support)
        self.install_lksp_parser = create_parser(
            self.do_install_langkit_support)
        self.install_lksp_parser.add_argument('install-dir',
                                              help='Installation directory.')
        self.install_lksp_parser.add_argument(
            '--force',
            '-f',
            action='store_true',
            help='Force installation, overwrite files.')

        self.add_build_args(self.build_lksp_parser)
        self.add_build_args(self.install_lksp_parser)

        # The create_context method will create the context and set it here
        # only right before executing commands.
        self.context = None

        # This will be set in the run method, when we have parsed arguments
        # from the command line.
        self.verbosity = None
        ":type: Verbosity"
コード例 #4
0
def package_deps(args: Namespace) -> None:
    """
    Bundle all dependencies to complete GNAT Pro.
    """
    p = Packager.from_args(args)
    p.package_deps(getattr(args, "package-dir"))
コード例 #5
0
                     with_jobs=True,
                     with_gargs=True,
                     with_build_dir=True)
    create_subparser(subparsers, setenv_langkit_support, with_build_dir=True)
    install_lksp = create_subparser(subparsers, install_langkit_support,
                                    with_build_dir=True)
    install_lksp.add_argument(
        "prefix",
        help="Installation prefix"
    )

    package_deps_parser = create_subparser(subparsers, package_deps)
    package_std_dyn_parser = create_subparser(subparsers, package_std_dyn)
    for p in (package_deps_parser, package_std_dyn_parser):
        p.add_argument("package-dir", help="Destination directory")
        Packager.add_prefix_options(p)
        Packager.add_platform_options(p)

    create_subparser(subparsers, make,
                     with_jobs=True,
                     with_no_lksp=True,
                     with_gargs=True,
                     with_build_dir=True,
                     with_libs=True,
                     with_no_mypy=True)
    create_subparser(subparsers, setenv,
                     with_no_lksp=True,
                     with_build_dir=True,
                     with_libs=True)

    create_subparser(subparsers, run_mypy)
コード例 #6
0
def main():
    m = ManageScript()

    def add_build_mode_arg(parser):
        parser.add_argument(
            '--build-mode', '-b', choices=list(m.BUILD_MODES),
            default='dev',
            help='Selects a preset for build options'
        )

    args_parser = argparse.ArgumentParser(
        description='Helper to build and install Langkit_Support'
    )
    args_parser.add_argument(
        '--build-dir', default='build',
        help='Directory to use for generated source code and binaries. By'
             ' default, use "build" in the current directory.'
    )
    args_parser.add_argument(
        '--library-types', default=LibraryTypes(relocatable=True),
        type=LibraryTypes.parse,
        help='Comma-separated list of library types to build (relocatable,'
             ' static-pic and static). By default, build only shared'
             ' libraries.'
    )
    args_parser.add_argument(
        '--verbosity', '-v', nargs='?',
        type=Verbosity,
        choices=Verbosity.choices(),
        default=Verbosity('info'),
        const=Verbosity('debug'),
        help='Verbosity level'
    )

    subparsers = args_parser.add_subparsers()

    # Generate
    generate_parser = subparsers.add_parser(
        'generate',
        help='Generate build tree and project file for Langkit_Support.'
    )
    generate_parser.set_defaults(cmd='generate-langkit-support')

    # Build
    build_parser = subparsers.add_parser(
        'build',
        help='Build Langkit_Support.'
    )
    build_parser.add_argument(
        '--jobs', '-j', type=int, default=get_cpu_count(),
        help='Number of parallel jobs to spawn in parallel '
             '(default: your number of cpu)'
    )
    add_build_mode_arg(build_parser)
    build_parser.add_argument(
        '--gargs',
        help='Additional arguments to pass to GPRbuild'
    )
    build_parser.set_defaults(cmd='build-langkit-support')

    # Install
    install_parser = subparsers.add_parser(
        'install',
        help='Install Langkit_Support.'
    )
    add_build_mode_arg(install_parser)
    install_parser.add_argument(
        'install-dir',
        help='Installation directory.'
    )
    install_parser.set_defaults(cmd='install-langkit-support')

    # Package dependencies
    pkg_deps_parser = subparsers.add_parser(
        'package-deps',
        help='Bundle all dependencies to complete GNAT Pro'
    )
    pkg_deps_parser.add_argument(
        'package-dir',
        help='Destination directory.'
    )
    Packager.add_prefix_options(pkg_deps_parser)
    Packager.add_platform_options(pkg_deps_parser)
    pkg_deps_parser.set_defaults(cmd='package-deps')

    # Standalone package for dynamic libraries
    pkg_std_dyn_parser = subparsers.add_parser(
        'package-std-dyn',
        help='Bundle all dependencies to create standalone packages'
    )
    pkg_std_dyn_parser.add_argument(
        'package-dir',
        help='Destination directory.'
    )
    Packager.add_prefix_options(pkg_std_dyn_parser)
    Packager.add_platform_options(pkg_std_dyn_parser)
    pkg_std_dyn_parser.set_defaults(cmd='package-std-dyn')

    args = args_parser.parse_args()

    argv = ['-E', '--build-dir={}'.format(args.build_dir),
            '--verbosity={}'.format(args.verbosity),
            '--library-types={}'.format(args.library_types)]

    def add_build_mode():
        argv.append('--build-mode={}'.format(args.build_mode))

    argv.append(args.cmd)
    if args.cmd == 'build-langkit-support':
        add_build_mode()
        if args.gargs:
            argv.append('--gargs={}'.format(args.gargs))
    elif args.cmd == 'install-langkit-support':
        add_build_mode()
        argv.append(getattr(args, 'install-dir'))
    elif args.cmd == 'package-deps':
        p = Packager.from_args(args)
        p.package_deps(getattr(args, 'package-dir'))
        return
    elif args.cmd == 'package-std-dyn':
        p = Packager.from_args(args)
        pkg_dir = getattr(args, 'package-dir')
        p.package_standalone_dyn(pkg_dir)
        p.package_langkit_support_dyn(pkg_dir)
        return

    m.run(argv)
コード例 #7
0
ファイル: libmanage.py プロジェクト: Roldak/langkit
    def __init__(self, root_dir: Optional[str] = None) -> None:
        """
        :param root_dir: Root directory for the language specification. All
            source file under that directory are considered to be part of the
            language spec, and build trees are by default relative to it.

            If left to None, take the directory that contains the Python file
            that defined ``self``'s class.
        """
        self.dirs = Directories(
            lang_source_dir=root_dir
            or path.dirname(path.abspath(inspect.getfile(self.__class__))))

        ########################
        # Main argument parser #
        ########################

        self.args_parser = args_parser = argparse.ArgumentParser(
            description='General manager to handle actions relative to'
            ' building/testing your language.')
        self.subparsers = args_parser.add_subparsers()

        ########
        # Help #
        ########

        self.help_parser = self.add_subcommand(self.do_help)

        ############
        # Generate #
        ############

        self.generate_parser = generate_parser = self.add_subcommand(
            self.do_generate, needs_context=True)
        self.add_generate_args(generate_parser)

        #########
        # Build #
        #########

        self.build_parser = build_parser = self.add_subcommand(
            self.do_build, needs_context=True)
        self.add_build_args(build_parser)

        ########
        # Make #
        ########

        self.make_parser = make_parser = self.add_subcommand(
            self.do_make, needs_context=True)
        self.add_generate_args(make_parser)
        self.add_build_args(make_parser)

        ########################
        # List optional passes #
        ########################

        self.list_optional_passes_parser = self.add_subcommand(
            self.do_list_optional_passes, needs_context=True)
        self.add_generate_args(self.list_optional_passes_parser)

        ###########
        # Install #
        ###########

        self.install_parser = install_parser = self.add_subcommand(
            self.do_install, needs_context=True)
        self.add_build_mode_arg(install_parser)
        install_parser.add_argument(
            '--force',
            '-f',
            action='store_true',
            help='Force installation, overwrite files.')
        install_parser.add_argument('--disable-all-mains',
                                    action='store_true',
                                    help='Do not install main program.')
        install_parser.add_argument('install-dir',
                                    help='Installation directory.')

        ##########
        # Setenv #
        ##########

        self.setenv_parser = self.add_subcommand(self.do_setenv,
                                                 needs_context=True)
        self.add_build_mode_arg(self.setenv_parser)
        self.setenv_parser.add_argument(
            '--json',
            '-J',
            action='store_true',
            help='Output necessary env keys to JSON.')

        #######################
        # Create Python wheel #
        #######################

        self.create_wheel_parser = self.add_subcommand(self.do_create_wheel,
                                                       needs_context=True)
        Packager.add_platform_options(self.create_wheel_parser)
        self.create_wheel_parser.add_argument(
            '--with-python',
            help='Python intererpter to use in order to build the wheel. If'
            ' not provided, use the current one.')
        self.create_wheel_parser.add_argument(
            '--tag',
            help="Tag for the wheel (setup.py's --python-tag argument).")
        self.create_wheel_parser.add_argument(
            'wheel-dir', help='Destination directory for the wheel.')
        self.create_wheel_parser.add_argument(
            'build-dir',
            help='Temporary directory to use in order to build the wheel.')
        self.create_wheel_parser.add_argument(
            'dyn-deps-dir',
            help='Directory that contains all the dynamic libraries to ship in'
            ' the wheel (i.e. dependencies).')
        self.create_wheel_parser.add_argument(
            'install-dir', help='Directory in which the library is installed.')

        self.add_extra_subcommands()