diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-01-26 15:53:54 +1300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-26 18:05:14 +0000 |
commit | 89a7ed5b67ca61c24abef07045e781cae892884d (patch) | |
tree | dd13559ff441974e40259d51b264b81f610a3a71 /scripts | |
parent | 84720c8ce9cde906e47e0390c0cdb7451d752c51 (diff) | |
download | poky-89a7ed5b67ca61c24abef07045e781cae892884d.tar.gz |
devtool: add configure-help subcommand
When you need to set EXTRA_OECONF for a recipe, you need to know what
options the configure script actually supports; the configure script
however is only accessible from within a devshell and (at least in the
case of autotooled software fetched from an SCM repository) may not
actually exist until do_configure has run. Thus, provide a "devtool
configure-help" subcommand that runs the configure script for a recipe
with --help and shows you the output through a pager (e.g. less),
prefaced by a header describing the current options being specified.
There is basic support for autotools, cmake and bare configure scripts.
The cmake support is a little hacky since cmake doesn't really have a
concise help option that lists user-defined knobs (without actually
running through the configure process), however that being a design
feature of cmake there's not much I can think of to do about that at
the moment.
(From OE-Core rev: 0e5d84d9705091b338000ef02720cfa090f76888)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/devtool/__init__.py | 9 | ||||
-rw-r--r-- | scripts/lib/devtool/utilcmds.py | 170 |
2 files changed, 175 insertions, 4 deletions
diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py index 0405d22874..ff97dfc94b 100644 --- a/scripts/lib/devtool/__init__.py +++ b/scripts/lib/devtool/__init__.py | |||
@@ -129,7 +129,7 @@ def get_recipe_file(cooker, pn): | |||
129 | logger.error("Unable to find any recipe file matching %s" % pn) | 129 | logger.error("Unable to find any recipe file matching %s" % pn) |
130 | return recipefile | 130 | return recipefile |
131 | 131 | ||
132 | def parse_recipe(config, tinfoil, pn, appends): | 132 | def parse_recipe(config, tinfoil, pn, appends, filter_workspace=True): |
133 | """Parse recipe of a package""" | 133 | """Parse recipe of a package""" |
134 | import oe.recipeutils | 134 | import oe.recipeutils |
135 | recipefile = get_recipe_file(tinfoil.cooker, pn) | 135 | recipefile = get_recipe_file(tinfoil.cooker, pn) |
@@ -138,9 +138,10 @@ def parse_recipe(config, tinfoil, pn, appends): | |||
138 | return None | 138 | return None |
139 | if appends: | 139 | if appends: |
140 | append_files = tinfoil.cooker.collection.get_file_appends(recipefile) | 140 | append_files = tinfoil.cooker.collection.get_file_appends(recipefile) |
141 | # Filter out appends from the workspace | 141 | if filter_workspace: |
142 | append_files = [path for path in append_files if | 142 | # Filter out appends from the workspace |
143 | not path.startswith(config.workspace_path)] | 143 | append_files = [path for path in append_files if |
144 | not path.startswith(config.workspace_path)] | ||
144 | else: | 145 | else: |
145 | append_files = None | 146 | append_files = None |
146 | return oe.recipeutils.parse_recipe(recipefile, append_files, | 147 | return oe.recipeutils.parse_recipe(recipefile, append_files, |
diff --git a/scripts/lib/devtool/utilcmds.py b/scripts/lib/devtool/utilcmds.py index 375d7a3756..a8f5e97833 100644 --- a/scripts/lib/devtool/utilcmds.py +++ b/scripts/lib/devtool/utilcmds.py | |||
@@ -61,6 +61,165 @@ def edit_recipe(args, config, basepath, workspace): | |||
61 | return 0 | 61 | return 0 |
62 | 62 | ||
63 | 63 | ||
64 | def configure_help(args, config, basepath, workspace): | ||
65 | """Entry point for the devtool 'configure-help' subcommand""" | ||
66 | import oe.utils | ||
67 | |||
68 | check_workspace_recipe(workspace, args.recipename) | ||
69 | tinfoil = setup_tinfoil(config_only=False, basepath=basepath) | ||
70 | try: | ||
71 | rd = parse_recipe(config, tinfoil, args.recipename, appends=True, filter_workspace=False) | ||
72 | if not rd: | ||
73 | return 1 | ||
74 | b = rd.getVar('B', True) | ||
75 | s = rd.getVar('S', True) | ||
76 | configurescript = os.path.join(s, 'configure') | ||
77 | confdisabled = 'noexec' in rd.getVarFlags('do_configure') or 'do_configure' not in (rd.getVar('__BBTASKS', False) or []) | ||
78 | configureopts = oe.utils.squashspaces(rd.getVar('CONFIGUREOPTS', True) or '') | ||
79 | extra_oeconf = oe.utils.squashspaces(rd.getVar('EXTRA_OECONF', True) or '') | ||
80 | extra_oecmake = oe.utils.squashspaces(rd.getVar('EXTRA_OECMAKE', True) or '') | ||
81 | do_configure = rd.getVar('do_configure', True) or '' | ||
82 | do_configure_noexpand = rd.getVar('do_configure', False) or '' | ||
83 | packageconfig = rd.getVarFlags('PACKAGECONFIG') or [] | ||
84 | autotools = bb.data.inherits_class('autotools', rd) and ('oe_runconf' in do_configure or 'autotools_do_configure' in do_configure) | ||
85 | cmake = bb.data.inherits_class('cmake', rd) and ('cmake_do_configure' in do_configure) | ||
86 | cmake_do_configure = rd.getVar('cmake_do_configure', True) | ||
87 | pn = rd.getVar('PN', True) | ||
88 | finally: | ||
89 | tinfoil.shutdown() | ||
90 | |||
91 | if 'doc' in packageconfig: | ||
92 | del packageconfig['doc'] | ||
93 | |||
94 | if autotools and not os.path.exists(configurescript): | ||
95 | logger.info('Running do_configure to generate configure script') | ||
96 | try: | ||
97 | stdout, _ = exec_build_env_command(config.init_path, basepath, | ||
98 | 'bitbake -c configure %s' % msg, args.recipename, | ||
99 | stderr=subprocess.STDOUT) | ||
100 | except bb.process.ExecutionError: | ||
101 | pass | ||
102 | |||
103 | if confdisabled or do_configure.strip() in ('', ':'): | ||
104 | raise DevtoolError("do_configure task has been disabled for this recipe") | ||
105 | elif args.no_pager and not os.path.exists(configurescript): | ||
106 | raise DevtoolError("No configure script found and no other information to display") | ||
107 | else: | ||
108 | configopttext = '' | ||
109 | if autotools and configureopts: | ||
110 | configopttext = ''' | ||
111 | Arguments currently passed to the configure script: | ||
112 | |||
113 | %s | ||
114 | |||
115 | Some of those are fixed.''' % (configureopts + ' ' + extra_oeconf) | ||
116 | if extra_oeconf: | ||
117 | configopttext += ''' The ones that are specified through EXTRA_OECONF (which you can change or add to easily): | ||
118 | |||
119 | %s''' % extra_oeconf | ||
120 | |||
121 | elif cmake: | ||
122 | in_cmake = False | ||
123 | cmake_cmd = '' | ||
124 | for line in cmake_do_configure.splitlines(): | ||
125 | if in_cmake: | ||
126 | cmake_cmd = cmake_cmd + ' ' + line.strip().rstrip('\\') | ||
127 | if not line.endswith('\\'): | ||
128 | break | ||
129 | if line.lstrip().startswith('cmake '): | ||
130 | cmake_cmd = line.strip().rstrip('\\') | ||
131 | if line.endswith('\\'): | ||
132 | in_cmake = True | ||
133 | else: | ||
134 | break | ||
135 | if cmake_cmd: | ||
136 | configopttext = ''' | ||
137 | The current cmake command line: | ||
138 | |||
139 | %s | ||
140 | |||
141 | Arguments specified through EXTRA_OECMAKE (which you can change or add to easily) | ||
142 | |||
143 | %s''' % (oe.utils.squashspaces(cmake_cmd), extra_oecmake) | ||
144 | else: | ||
145 | configopttext = ''' | ||
146 | The current implementation of cmake_do_configure: | ||
147 | |||
148 | cmake_do_configure() { | ||
149 | %s | ||
150 | } | ||
151 | |||
152 | Arguments specified through EXTRA_OECMAKE (which you can change or add to easily) | ||
153 | |||
154 | %s''' % (cmake_do_configure.rstrip(), extra_oecmake) | ||
155 | |||
156 | elif do_configure: | ||
157 | configopttext = ''' | ||
158 | The current implementation of do_configure: | ||
159 | |||
160 | do_configure() { | ||
161 | %s | ||
162 | }''' % do_configure.rstrip() | ||
163 | if '${EXTRA_OECONF}' in do_configure_noexpand: | ||
164 | configopttext += ''' | ||
165 | |||
166 | Arguments specified through EXTRA_OECONF (which you can change or add to easily): | ||
167 | |||
168 | %s''' % extra_oeconf | ||
169 | |||
170 | if packageconfig: | ||
171 | configopttext += ''' | ||
172 | |||
173 | Some of these options may be controlled through PACKAGECONFIG; for more details please see the recipe.''' | ||
174 | |||
175 | if args.arg: | ||
176 | helpargs = ' '.join(args.arg) | ||
177 | elif cmake: | ||
178 | helpargs = '-LH' | ||
179 | else: | ||
180 | helpargs = '--help' | ||
181 | |||
182 | msg = '''configure information for %s | ||
183 | ------------------------------------------ | ||
184 | %s''' % (pn, configopttext) | ||
185 | |||
186 | if cmake: | ||
187 | msg += ''' | ||
188 | |||
189 | The cmake %s output for %s follows. After "-- Cache values" you should see a list of variables you can add to EXTRA_OECMAKE (prefixed with -D and suffixed with = followed by the desired value, without any spaces). | ||
190 | ------------------------------------------''' % (helpargs, pn) | ||
191 | elif os.path.exists(configurescript): | ||
192 | msg += ''' | ||
193 | |||
194 | The ./configure %s output for %s follows. | ||
195 | ------------------------------------------''' % (helpargs, pn) | ||
196 | |||
197 | olddir = os.getcwd() | ||
198 | tmppath = tempfile.mkdtemp() | ||
199 | with tempfile.NamedTemporaryFile('w', delete=False) as tf: | ||
200 | if not args.no_header: | ||
201 | tf.write(msg + '\n') | ||
202 | tf.close() | ||
203 | try: | ||
204 | try: | ||
205 | cmd = 'cat %s' % tf.name | ||
206 | if cmake: | ||
207 | cmd += '; cmake %s %s 2>&1' % (helpargs, s) | ||
208 | os.chdir(b) | ||
209 | elif os.path.exists(configurescript): | ||
210 | cmd += '; %s %s' % (configurescript, helpargs) | ||
211 | if sys.stdout.isatty() and not args.no_pager: | ||
212 | pager = os.environ.get('PAGER', 'less') | ||
213 | cmd = '(%s) | %s' % (cmd, pager) | ||
214 | subprocess.check_call(cmd, shell=True) | ||
215 | except subprocess.CalledProcessError as e: | ||
216 | return e.returncode | ||
217 | finally: | ||
218 | os.chdir(olddir) | ||
219 | shutil.rmtree(tmppath) | ||
220 | os.remove(tf.name) | ||
221 | |||
222 | |||
64 | def register_commands(subparsers, context): | 223 | def register_commands(subparsers, context): |
65 | """Register devtool subcommands from this plugin""" | 224 | """Register devtool subcommands from this plugin""" |
66 | parser_edit_recipe = subparsers.add_parser('edit-recipe', help='Edit a recipe file in your workspace', | 225 | parser_edit_recipe = subparsers.add_parser('edit-recipe', help='Edit a recipe file in your workspace', |
@@ -68,3 +227,14 @@ def register_commands(subparsers, context): | |||
68 | parser_edit_recipe.add_argument('recipename', help='Recipe to edit') | 227 | parser_edit_recipe.add_argument('recipename', help='Recipe to edit') |
69 | parser_edit_recipe.add_argument('--any-recipe', '-a', action="store_true", help='Edit any recipe, not just where the recipe file itself is in the workspace') | 228 | parser_edit_recipe.add_argument('--any-recipe', '-a', action="store_true", help='Edit any recipe, not just where the recipe file itself is in the workspace') |
70 | parser_edit_recipe.set_defaults(func=edit_recipe) | 229 | parser_edit_recipe.set_defaults(func=edit_recipe) |
230 | |||
231 | # NOTE: Needed to override the usage string here since the default | ||
232 | # gets the order wrong - recipename must come before --arg | ||
233 | parser_configure_help = subparsers.add_parser('configure-help', help='Get help on configure script options', | ||
234 | usage='devtool configure-help [options] recipename [--arg ...]', | ||
235 | description='Displays the help for the configure script for the specified recipe (i.e. runs ./configure --help) prefaced by a header describing the current options being specified. Output is piped through less (or whatever PAGER is set to, if set) for easy browsing.') | ||
236 | parser_configure_help.add_argument('recipename', help='Recipe to show configure help for') | ||
237 | parser_configure_help.add_argument('-p', '--no-pager', help='Disable paged output', action="store_true") | ||
238 | parser_configure_help.add_argument('-n', '--no-header', help='Disable explanatory header text', action="store_true") | ||
239 | parser_configure_help.add_argument('--arg', help='Pass remaining arguments to the configure script instead of --help (useful if the script has additional help options)', nargs=argparse.REMAINDER) | ||
240 | parser_configure_help.set_defaults(func=configure_help) | ||