def gprbuild(self, args, project_file, is_library, mains=None): """ Run GPRbuild on a project file. :param argparse.Namespace args: The arguments parsed from the command line invocation of manage.py. :param str project_file: Path to the project file to pass to GPRbuild. :param bool is_library: See the "what_to_build" method. :param set[str]|None mains: If provided, list of main programs to build. By default, GPRbuild builds them all, so this arguments makes it possible to build only a subset of them. """ base_argv = [ 'gprbuild', '-p', '-j{}'.format(args.jobs), '-P{}'.format(project_file), ] if not args.with_rpath: # Prevent GPRbuild from adding RPATH to links, as paths will not be # valid once generated libraries are installed. base_argv.append('-R') if args.verbosity == Verbosity('none'): base_argv.append('-q') elif args.verbosity == Verbosity('debug'): base_argv.append('-vl') # Depending on where this is invoked, the "--gargs" option may not be # set. Don't call shlex.split with an empty input, otherwise it will # try to read something from stdin... gargs = getattr(args, 'gargs') or [] gargs = sum((shlex.split(args) for args in gargs), []) def run(library_type): argv = list(base_argv) argv.extend(self.gpr_scenario_vars(args, library_type=library_type)) if mains: argv.extend('{}.adb'.format(main) for main in mains) if Diagnostics.style == DiagnosticStyle.gnu_full: argv.append('-gnatef') argv.extend(gargs) self.check_call(args, 'Build', argv) build_shared, build_static_pic, build_static = self.what_to_build( args, is_library) if build_shared: run('relocatable') if build_static_pic: run('static-pic') if build_static: run('static')
def gprbuild(self, args, project_file, is_library, mains=None): """ Run GPRbuild on a project file. :param argparse.Namespace args: The arguments parsed from the command line invocation of manage.py. :param str project_file: Path to the project file to pass to GPRbuild. :param bool is_library: If true, build both relocatable and static libraries (depending on modes enabled in "args"). Otherwise, use relocatable if available or static mode otherwise. :param set[str]|None mains: If provided, list of main programs to build. By default, GPRbuild builds them all, so this arguments makes it possible to build only a subset of them. """ base_argv = [ 'gprbuild', '-m', '-p', '-j{}'.format(args.jobs), '-P{}'.format(project_file), '-XBUILD_MODE={}'.format(args.build_mode) ] if args.enable_warnings: base_argv.append('-X{}_WARNINGS=true'.format( self.lib_name.upper())) if args.verbosity == Verbosity('none'): base_argv.append('-q') elif args.verbosity == Verbosity('debug'): base_argv.append('-vl') cargs = [] # Depending on where this is invoked, the "cargs" option may not be set if hasattr(args, 'cargs'): cargs.extend(args.cargs) def run(library_type): argv = list(base_argv) argv.append('-XLIBRARY_TYPE={}'.format(library_type)) if mains: argv.extend('{}.adb'.format(main) for main in mains) if args.parsable_errors: argv.append('-gnatef') argv.append('-cargs') argv.extend(cargs) self.check_call(args, 'Build', argv) build_shared, build_static = self.what_to_build(args, is_library) if build_shared: run('relocatable') if build_static: run('static')
def gprinstall(self, args, project_file, is_library): """ Run GPRinstall on a project file. See gprbuild for arguments description. :type args: argparse.Namespace """ assert project_file.endswith('.gpr') project_name = os.path.basename(project_file)[:-4].upper() base_argv = [ 'gprinstall', '-p', '-P{}'.format(project_file), '--prefix={}'.format(self.dirs.install_dir()), '--build-var=LIBRARY_TYPE', '--build-var={}_LIBRARY_TYPE'.format(project_name) ] # If this is a library, install sources in an unique location: there is # no need to have one location per build mode as sources are going to # be exactly the same. If this is a program, no need to install # anything but the executable itself. if is_library: lib_name, _ = os.path.splitext(os.path.basename(project_file)) base_argv.append('--sources-subdir={}'.format( os.path.join('include', lib_name))) else: base_argv.append('--mode=usage') if args.force: base_argv.append('-f') if args.verbosity == Verbosity('none'): base_argv.append('-q') def run(library_type): argv = list(base_argv) argv.append('--build-name={}'.format(library_type)) argv.extend(self.gpr_scenario_vars(args, library_type)) self.check_call(args, 'Install', argv) # Install the static libraries first, so that in the resulting project # files, "static" is the default library type. build_shared, build_static_pic, build_static = self.what_to_build( args, is_library) if build_static: run('static') if build_static_pic: run('static-pic') if build_shared: run('relocatable')
def gprinstall(self, args, project_file, is_library): """ Run GPRinstall on a project file. See gprbuild for arguments description. :type args: argparse.Namespace """ base_argv = [ 'gprinstall', '-p', '-P{}'.format(project_file), '--prefix={}'.format(self.dirs.install_dir()), '--build-var=LIBRARY_TYPE', '-XBUILD_MODE=prod' ] # If this is a library, install sources in an unique location: there is # no need to have one location per build mode as sources are going to # be exactly the same. If this is a program, no need to install # anything but the executable itself. if is_library: lib_name, _ = os.path.splitext(os.path.basename(project_file)) base_argv.append('--sources-subdir={}'.format( os.path.join('include', lib_name))) else: base_argv.append('--mode=usage') if args.verbosity == Verbosity('none'): base_argv.append('-q') def run(library_type): argv = list(base_argv) argv.append('--build-name={}'.format(library_type)) argv.append('-XLIBRARY_TYPE={}'.format(library_type)) self.check_call(args, 'Install', argv) build_shared, build_static = self.what_to_build(args, is_library) if build_shared: run('relocatable') if build_static: run('static')
def main(): m = ManageScript() 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( '--enable-static', action='store_true', help='Enable the generation of static libraries (default:' ' disabled)' ) args_parser.add_argument( '--disable-static', action='store_false', dest='enable_static', help='Disable the generation of static libraries' ) args_parser.add_argument( '--enable-shared', action='store_true', default=True, help='Enable the generation (and testing) of shared libraries' ' (default: enabled)' ) args_parser.add_argument( '--disable-shared', action='store_false', dest='enable_shared', help='Disable the generation (and testing) of 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)' ) build_parser.add_argument( '--build-mode', '-b', choices=list(m.BUILD_MODES), default='dev', help='Selects a preset for build options' ) build_parser.set_defaults(cmd='build-langkit-support') # Install install_parser = subparsers.add_parser( 'install', help='Install Langkit_Support.' ) install_parser.add_argument( 'install-dir', help='Installation directory.' ) install_parser.set_defaults(cmd='install-langkit-support') args = args_parser.parse_args() argv = ['-E', '--build-dir={}'.format(args.build_dir), '--verbosity={}'.format(args.verbosity)] if args.enable_static: argv.append('--enable-static') if not args.enable_shared: argv.append('--disable-shared') argv.append(args.cmd) if args.cmd == 'install-langkit-support': argv.append(getattr(args, 'install-dir')) m.run(argv)
def gprbuild(self, args, project_file, is_library, mains=None, obj_dirs=[]): """ Run GPRbuild on a project file. :param argparse.Namespace args: The arguments parsed from the command line invocation of manage.py. :param str project_file: Path to the project file to pass to GPRbuild. :param bool is_library: See the "what_to_build" method. :param list[str] obj_dirs: List of paths (relative to the project file directory) to the object directory where gprbuild creates the "*.lexch" files. We will remove all such files before each gprbuild run. This allows us to workaround a GPRbuild bug (see SB18-035). Library types share the same object directory, however GPRbuild uses a file in the object directory (*.lexch) to know if the library must be rebuilt. Not removing it will make it skip the "static" build after the "static-pic" was built. So we remove it. :param set[str]|None mains: If provided, list of main programs to build. By default, GPRbuild builds them all, so this arguments makes it possible to build only a subset of them. """ lexch_patterns = [ os.path.join(os.path.dirname(project_file), obj_dir, '*.lexch') for obj_dir in obj_dirs ] base_argv = [ 'gprbuild', '-p', '-j{}'.format(args.jobs), '-P{}'.format(project_file), ] if not args.with_rpath: # Prevent GPRbuild from adding RPATH to links, as paths will not be # valid once generated libraries are installed. base_argv.append('-R') if args.verbosity == Verbosity('none'): base_argv.append('-q') elif args.verbosity == Verbosity('debug'): base_argv.append('-vl') # Depending on where this is invoked, the "--gargs" option may not be # set. Don't call shlex.split with an empty input, otherwise it will # try to read something from stdin... gargs = getattr(args, 'gargs') or [] gargs = sum((shlex.split(args) for args in gargs), []) def run(library_type): # Remove the "*.lexch" file for pattern in lexch_patterns: files = glob.glob(pattern) for f in files: self.log_debug('Removing {}'.format(f), Colors.CYAN) os.remove(f) if not files: self.log_debug( 'No *.lexch file to remove from {}'.format(pattern), Colors.CYAN) argv = list(base_argv) argv.extend(self.gpr_scenario_vars(args, library_type=library_type)) if mains: argv.extend('{}.adb'.format(main) for main in mains) if Diagnostics.style == DiagnosticStyle.gnu_full: argv.append('-gnatef') argv.extend(gargs) self.check_call(args, 'Build', argv) build_shared, build_static_pic, build_static = self.what_to_build( args, is_library) if build_shared: run('relocatable') if build_static_pic: run('static-pic') if build_static: run('static')
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"
def __init__(self): self.dirs = Directories( # It is assumed that manage.py is at the root of the language # definition source directory. lang_source_dir=path.dirname( path.abspath(inspect.getfile(self.__class__)))) Diagnostics.set_lang_source_dir(self.dirs.lang_source_dir()) ######################## # Main argument parser # ######################## self.args_parser = args_parser = argparse.ArgumentParser( description='General manager to handle actions relative to' ' building/testing libadalang') 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( '--enable-static', action='store_true', help='Enable the generation of static libraries (default:' ' disabled)') args_parser.add_argument( '--disable-static', action='store_false', dest='enable_static', help='Disable the generation of static libraries') args_parser.add_argument( '--enable-shared', action='store_true', default=True, help='Enable the generation (and testing) of shared libraries' ' (default: enabled)') args_parser.add_argument( '--disable-shared', action='store_false', dest='enable_shared', help='Disable the generation (and testing) of shared libraries') args_parser.add_argument( '--bindings', '-b', nargs='+', choices=('python', ), default=['python'], help='Bindings to generate (by default: only Python)') args_parser.add_argument('--verbosity', '-v', nargs='?', type=Verbosity, choices=Verbosity.choices(), default=Verbosity('info'), const=Verbosity('debug'), help='Verbosity level') # 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( '--parsable-errors', '-P', action='store_true', default=False, help='Generate error messages parsable by tools') 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 fn.__name__.replace('do_', ''), # 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.') ########## # Setenv # ########## self.setenv_parser = create_parser(self.do_setenv, True) self.setenv_parser.add_argument( '--json', '-J', action='store_true', help='Output necessary env keys to json') # The create_context method will create the context and set it here # only right before executing commands so that coverage computation # will apply to create_context. self.context = None
def __init__(self): self.dirs = Directories( # It is assumed that manage.py is at the root of the language # definition source directory. lang_source_dir=path.dirname( path.abspath(inspect.getfile(self.__class__)) ) ) Diagnostics.set_lang_source_dir(self.dirs.lang_source_dir()) ######################## # Main argument parser # ######################## self.args_parser = args_parser = argparse.ArgumentParser( description='General manager to handle actions relative to' ' building/testing libadalang' ) 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( '--enable-static', action='store_true', help='Enable the generation of static libraries (default:' ' disabled)' ) args_parser.add_argument( '--disable-static', action='store_false', dest='enable_static', help='Disable the generation of static libraries' ) args_parser.add_argument( '--enable-shared', action='store_true', default=True, help='Enable the generation (and testing) of shared libraries' ' (default: enabled)' ) args_parser.add_argument( '--disable-shared', action='store_false', dest='enable_shared', help='Disable the generation (and testing) of shared libraries' ) args_parser.add_argument( '--bindings', '-b', nargs='+', choices=('python', ), default=['python'], help='Bindings to generate (by default: only Python)' ) args_parser.add_argument( '--verbosity', '-v', nargs='?', type=Verbosity, choices=Verbosity.choices(), default=Verbosity('info'), const=Verbosity('debug'), help='Verbosity level' ) # 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' ) 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 fn.__name__.replace('do_', ''), # 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.' ) ########## # Setenv # ########## self.setenv_parser = create_parser(self.do_setenv, True) # The create_context method will create the context and set it here # only right before executing commands so that coverage computation # will apply to create_context. self.context = None
def __init__(self, override_lang_source_dir=True): self.dirs = Directories( # It is assumed that manage.py is at the root of the language # definition source directory. lang_source_dir=path.dirname( path.abspath(inspect.getfile(self.__class__)))) if override_lang_source_dir: Diagnostics.set_lang_source_dir(self.dirs.lang_source_dir()) ######################## # Main argument parser # ######################## self.args_parser = args_parser = argparse.ArgumentParser( description='General manager to handle actions relative to' ' building/testing libadalang.') self.subparsers = subparsers = args_parser.add_subparsers() args_parser.add_argument( '--pp', action='store_true', default=False, help='Whether to automatically generate a pretty-printer along' ' with the parser for the grammar.') 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( '--enable-static', action='store_true', help='Enable the generation of static libraries (default:' ' disabled).') args_parser.add_argument( '--disable-static', action='store_false', dest='enable_static', help='Disable the generation of static libraries.') args_parser.add_argument( '--enable-shared', action='store_true', default=True, help='Enable the generation (and testing) of shared libraries' ' (default: enabled).') args_parser.add_argument( '--disable-shared', action='store_false', dest='enable_shared', help='Disable the generation (and testing) of 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.') # 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.') 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.') ########## # Setenv # ########## self.setenv_parser = create_parser(self.do_setenv, True) self.setenv_parser.add_argument( '--json', '-J', action='store_true', help='Output necessary env keys to JSON.') ############################################### # 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.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"
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)
def add_common_args(subparser: argparse.ArgumentParser) -> None: """ Add command-line arguments common to all subcommands to ``subparser``. """ subparser.add_argument( '--build-dir', default='build', help='Directory to use for generated source code and binaries. By' ' default, use "build" in the current directory.') LibraryTypes.add_option(subparser) subparser.add_argument('--verbosity', '-v', nargs='?', type=Verbosity, choices=Verbosity.choices(), default=Verbosity('info'), const=Verbosity('debug'), help='Verbosity level') subparser.add_argument( '--full-error-traces', '-E', action='store_true', default=False, help='Always show full error traces, whatever the verbosity level' ' (default: disabled).') subparser.add_argument('--trace', '-t', action='append', default=[], help='Activate given debug trace.') subparser.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. subparser.add_argument( '-g', '--debug', action='store_true', help='In case of internal error or diagnostic error, run a' ' post-mortem PDB session.') subparser.add_argument( '--profile', action='store_true', help='Run cProfile and langkit, and generate a data file' ' "langkit.prof".') subparser.add_argument('--diagnostic-style', '-D', type=DiagnosticStyle, default=DiagnosticStyle.default, help='Style for error messages.') subparser.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.') subparser.add_argument('--pass-on', type=str, action='append', default=[], help='Activate an optional pass by name.') subparser.add_argument('--pass-off', type=str, action='append', default=[], help='Deactivate an optional pass by name.')
def main(): m = ManageScript() 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)' ) build_parser.add_argument( '--build-mode', '-b', choices=list(m.BUILD_MODES), default='dev', help='Selects a preset for build options' ) 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.' ) install_parser.add_argument( 'install-dir', help='Installation directory.' ) install_parser.set_defaults(cmd='install-langkit-support') args = args_parser.parse_args() argv = ['-E', '--build-dir={}'.format(args.build_dir), '--verbosity={}'.format(args.verbosity), '--library-types={}'.format(args.library_types)] argv.append(args.cmd) if args.cmd == 'build-langkit-support': argv.append('--build-mode={}'.format(args.build_mode)) if args.gargs: argv.append('--gargs={}'.format(args.gargs)) if args.cmd == 'install-langkit-support': argv.append(getattr(args, 'install-dir')) m.run(argv)