From 5ee03de0ad8c2df38bc10acf67f02cf862c6c83c Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Wed, 30 Jan 2013 01:04:29 +0100 Subject: fix option handling in acprep Both the `--local` option and the default to build local if no build directory exists did not work, because `build_directory()` uses `self.options.build_dir`, but the default and the `--local` option used `self.build_dir`. I changed the code to always use `self.options` for options/flags. Now `self.options` is set to the default values of OptParser and is updated when `parse_args` is called in `run`. After this commit ledger will be built in: * The directory specified using `--output=` * Else in a subdirectory of `./build` or `~/Products` if one of those directories exist and `--local` is not used. * Else inside the source tree (default). --- acprep | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'acprep') diff --git a/acprep b/acprep index 26f8d8b2..6330a7f8 100755 --- a/acprep +++ b/acprep @@ -101,13 +101,6 @@ class CommandLineApp(object): log_handler = None boost_major = "1_50" - options = { - 'debug': False, - 'verbose': False, - 'logfile': False, - 'loglevel': False - } - def __init__(self): "Initialize CommandLineApp." # Create the logger @@ -137,7 +130,8 @@ class CommandLineApp(object): op.add_option('', '--loglevel', metavar='LEVEL', type='string', action='store', dest='loglevel', default=False, help='set log level: DEBUG, INFO, WARNING, ERROR, CRITICAL') - return + + self.options = op.get_default_values() def main(self, *args): """Main body of your application. @@ -167,7 +161,7 @@ class CommandLineApp(object): Process options and execute callback functions as needed. This method should not need to be overridden, if the main() method is defined.""" # Process the options supported and given - self.options, main_args = self.option_parser.parse_args() + self.options, main_args = self.option_parser.parse_args(values=self.options) if self.options.logfile: fh = logging.handlers.RotatingFileHandler(self.options.logfile, @@ -238,9 +232,7 @@ class PrepareBuild(CommandLineApp): self.current_ver = None #self.current_flavor = 'default' self.current_flavor = 'debug' - self.prefix_dir = None self.products_dir = None - self.build_dir = self.source_dir self.configure_args = [] self.CXXFLAGS = [] self.LDFLAGS = [] @@ -264,7 +256,7 @@ class PrepareBuild(CommandLineApp): products = self.default_products_directory() if (exists(products) and isdir(products)) or \ (exists('build') and isdir('build')): - self.build_dir = None + self.options.build_dir = None def __init__(self): CommandLineApp.__init__(self) @@ -272,8 +264,6 @@ class PrepareBuild(CommandLineApp): self.source_dir = os.getcwd() - self.initialize() - op = self.option_parser op.add_option('', '--help', action="callback", @@ -321,11 +311,16 @@ class PrepareBuild(CommandLineApp): dest="option_products", help='Collect all build products in this directory') op.add_option('', '--output', metavar='DIR', action="store", + default=self.source_dir, dest="build_dir", help='Build in the specified directory') op.add_option('', '--local', action="callback", callback=self.option_local, help='Build directly within the source tree (default)') + self.options = op.get_default_values() + + self.initialize() + def main(self, *args): if args and args[0] in ['default', 'debug', 'opt', 'gcov', 'gprof']: self.current_flavor = args[0] @@ -740,7 +735,7 @@ class PrepareBuild(CommandLineApp): def option_local(self, option=None, opt_str=None, value=None, parser=None): self.log.debug('Saw option --local') - self.build_dir = self.source_dir + self.options.build_dir = self.source_dir def option_help(self, option=None, opt_str=None, value=None, parser=None): self.phase_help() @@ -841,7 +836,7 @@ class PrepareBuild(CommandLineApp): try: os.chdir(build_dir) - need_to_config = not isfile('Makefile') + need_to_config = not isfile('rules.ninja' if self.options.use_ninja else 'Makefile') if need_to_config: self.log.debug('Source => ' + self.source_dir) self.log.debug('Build => ' + build_dir) @@ -945,10 +940,10 @@ class PrepareBuild(CommandLineApp): ######################################################################### def configure_flavor(self, flavor, reset=True): - self.initialize() # reset everything - self.build_dir = None # use the build/ tree + self.initialize() # reset everything self.current_flavor = flavor - self.prefix_dir = None + self.options.build_dir = None # use the build/ tree + self.options.prefix_dir = None if reset and exists(self.build_directory()) and \ isdir(self.build_directory()): -- cgit v1.2.3 From 9e3652dd4fc4bea3453b5b79f9a687501a63cb90 Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Wed, 30 Jan 2013 23:31:39 +0100 Subject: acprep: pass options starting with -D to CMake --- acprep | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'acprep') diff --git a/acprep b/acprep index 6330a7f8..fe49be47 100755 --- a/acprep +++ b/acprep @@ -875,7 +875,7 @@ class PrepareBuild(CommandLineApp): make_args = [] for arg in args: - if arg.startswith('--'): + if arg.startswith('--') or arg.startswith('-D'): config_args.append(arg) else: make_args.append(arg) @@ -1068,12 +1068,17 @@ typical user: submodule Updates Git submodules (better to use 'pull') version Output current HEAD version to version.m4 -NOTE: If you wish to pass options to configure or make, add "--" followed by -your options. Here are some real-world examples: +NOTE: If you wish to pass options to CMake or make, add "--" followed by +your options. Those starting with "-D" or "--" will be passed on to CMake, +positional arguments and other options will be passed to make. +For the 'config' and 'configure' phase everything will be passed to CMake. + +Here are some real-world examples: ./acprep - ./acprep opt -- make -j3 - ./acprep --enable-doxygen""" + ./acprep --python + ./acprep opt make + ./acprep make doc -- -DBUILD_WEB_DOCS=1""" sys.exit(0) PrepareBuild().run() -- cgit v1.2.3 From 20217e7c9c990039a264b94637bba6b2caffe885 Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Wed, 30 Jan 2013 23:37:37 +0100 Subject: fix --no-python option This would fail with `ValueError: list.remove(x): x not in list`. --- acprep | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'acprep') diff --git a/acprep b/acprep index fe49be47..ca718136 100755 --- a/acprep +++ b/acprep @@ -301,10 +301,9 @@ class PrepareBuild(CommandLineApp): help='Enable use of Doxygen to build ref manual ("make docs")') op.add_option('', '--python', action='store_true', dest='python', default=False, - help='Enable Python support (if disabled in acprep)') - op.add_option('', '--no-python', action='store_true', dest='no_python', - default=False, - help='Do not enable Python support by default') + help='Enable Python support') + op.add_option('', '--no-python', action='store_false', dest='python', + help='Disable python support (default)') op.add_option('', '--prefix', metavar='DIR', action="store", dest="prefix_dir", help='Use custom installation prefix') op.add_option('', '--products', metavar='DIR', action="store", @@ -684,8 +683,6 @@ class PrepareBuild(CommandLineApp): self.configure_args.append('-DUSE_DOXYGEN=1') if self.options.python: self.configure_args.append('-DUSE_PYTHON=1') - if self.options.no_python: - self.configure_args.remove('-DUSE_PYTHON=1') if self.options.use_ninja: self.configure_args.append('-GNinja') -- cgit v1.2.3