Skip to content

Commit 241b862

Browse files
authored
Merge pull request #649 from jkloetzke/ls-recipes
Add new 'ls-recipes' command
2 parents c7df228 + d457925 commit 241b862

File tree

13 files changed

+198
-5
lines changed

13 files changed

+198
-5
lines changed

contrib/bash-completion/bob

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ __bob_complete_dir()
3030
}
3131

3232
__bob_commands="build dev clean graph help init jenkins ls project status \
33-
query-scm query-recipe query-path query-meta show layers"
33+
query-scm query-recipe query-path query-meta show layers \
34+
ls-recipes"
3435

3536
# Complete a Bob path
3637
#
@@ -433,6 +434,12 @@ __bob_show()
433434
fi
434435
}
435436

437+
__bob_ls_recipes()
438+
{
439+
__bob_complete_path "-c -D --sandbox --no-sandbox --slim-sandbox --dev-sandbox --strict-sandbox
440+
--all --used --orphaned --sources"
441+
}
442+
436443
__bob_subcommands()
437444
{
438445
local i c command completion_func

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def __getattr__(cls, name):
269269
('manpages/bob-jenkins', 'bob-jenkins', 'Configure Jenkins server', ['Jan Klötzke'], 1),
270270
('manpages/bob-layers', 'bob-layers', 'Manage Layers', ['BobBuildTool Team'], 1),
271271
('manpages/bob-ls', 'bob-ls', 'List package hierarchy', ['Jan Klötzke'], 1),
272+
('manpages/bob-ls-recipes', 'bob-ls-recipes', 'List all known recipes', ['Jan Klötzke'], 1),
272273
('manpages/bobpaths', 'bobpaths', 'Specifying paths to Bob packages', ['Jan Klötzke'], 7),
273274
('manpages/bob-project', 'bob-project', 'Create IDE project files', ['Jan Klötzke'], 1),
274275
('manpages/bob-query-meta', 'bob-query-meta', 'Query metaEnvironment variables', ['Ralf Hubert'], 1),

doc/manpages/bob-ls-recipes.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.. _manpage-ls-recipes:
2+
3+
bob-ls-recipes
4+
==============
5+
6+
.. only:: not man
7+
8+
Name
9+
----
10+
11+
bob-ls-recipes - List all known recipes
12+
13+
Synopsis
14+
--------
15+
16+
::
17+
18+
bob ls-recipes [-h] [-D DEFINES] [-c CONFIGFILE]
19+
[--sandbox | --slim-sandbox | --dev-sandbox | --strict-sandbox | --no-sandbox]
20+
[--all | --used | --orphaned] [--sources]
21+
22+
23+
Description
24+
-----------
25+
26+
List known recipes. In contrast to the :ref:`manpage-bob-ls` command, which works
27+
on packages, this command works on recipes.
28+
29+
By default, all found recipes are printed (``--all``). Because the recipe YAML
30+
files can declare more than one recipe (see
31+
:ref:`configuration-recipes-multipackage`), the number of listed recipes is
32+
usually bigger than the number of YAML files. Add the ``--sources`` option too
33+
see which file declared what recipe.
34+
35+
Note that listing used or orphaned recipes very much depends on the project
36+
configuration. Especially when using layers, there may be a large number of
37+
unused recipes.
38+
39+
Options
40+
-------
41+
42+
``--all``
43+
List all recipes (default).
44+
45+
``-c CONFIGFILE``
46+
Use config File
47+
48+
``--dev-sandbox``
49+
Enable development sandboxing.
50+
51+
``-D DEFINES``
52+
Override default environment variable
53+
54+
``--no-sandbox``
55+
Disable sandboxing.
56+
57+
``--orphaned``
58+
List recipes that are unused.
59+
60+
``--sandbox``
61+
Enable partial sandboxing.
62+
63+
``--slim-sandbox``
64+
Enable slim sandboxing.
65+
66+
``--sources``
67+
Print source YAML file names. This includes the recipe and all inherited
68+
classes. The file names are separated by TAB character.
69+
70+
``--strict-sandbox``
71+
Enable strict sandboxing.
72+
73+
``--used``
74+
List all used recipes. These are recipes that are referenced directly or
75+
indirectly by a root package.

doc/manpages/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Contents:
1616
bob-jenkins
1717
bob-layers
1818
bob-ls
19+
bob-ls-recipes
1920
bobpaths
2021
bob-project
2122
bob-query-meta

pym/bob/cmds/misc.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,66 @@ def doInit(argv, bobRoot):
340340
f.write(os.path.abspath(args.project))
341341
except OSError as e:
342342
raise ParseError("Cannot create project link: " + str(e))
343+
344+
def doLsRecipes(argv, bobRoot):
345+
parser = argparse.ArgumentParser(prog="bob ls-recipes", description="List all known recipes.")
346+
parser.add_argument('-D', default=[], action='append', dest="defines",
347+
help="Override default environment variable")
348+
parser.add_argument('-c', dest="configFile", default=[], action='append',
349+
help="Use config File")
350+
351+
group = parser.add_mutually_exclusive_group()
352+
group.add_argument('--sandbox', action='store_true', default=False,
353+
help="Enable sandboxing")
354+
group.add_argument('--slim-sandbox', action='store_false', dest='sandbox',
355+
help="Enable slim sandboxing")
356+
group.add_argument('--dev-sandbox', action='store_true', dest='sandbox',
357+
help="Enable development sandboxing")
358+
group.add_argument('--strict-sandbox', action='store_true', dest='sandbox',
359+
help="Enable strict sandboxing")
360+
group.add_argument('--no-sandbox', action='store_false', dest='sandbox',
361+
help="Disable sandboxing (default)")
362+
363+
group = parser.add_mutually_exclusive_group()
364+
group.add_argument('--all', action='store_const', dest='mode', const='all', default='all',
365+
help="List all recipes (default)")
366+
group.add_argument('--used', action='store_const', dest='mode', const='used',
367+
help="List recipes used for packages")
368+
group.add_argument('--orphaned', action='store_const', dest='mode', const='orphaned',
369+
help="List unused recipes")
370+
371+
parser.add_argument('--sources', action='store_true', help="Show recipe source files")
372+
373+
args = parser.parse_args(argv)
374+
375+
defines = processDefines(args.defines)
376+
377+
recipes = RecipeSet()
378+
recipes.setConfigFiles(args.configFile)
379+
recipes.parse(defines)
380+
381+
if args.mode in ('used', 'orphaned'):
382+
packages = recipes.generatePackages(lambda s,m: "unused", args.sandbox)
383+
used = set(p.getName() for p in packages.queryPackagePath("//*"))
384+
385+
if args.mode in ('all', 'orphaned'):
386+
# filter virtual root recipe
387+
available = set(r for r in recipes.getRecipes() if r != "")
388+
389+
if args.sources:
390+
def show(p):
391+
print(p, *recipes.getRecipe(p).getSources(), sep="\t")
392+
else:
393+
def show(p):
394+
print(p)
395+
396+
if args.mode == 'all':
397+
for i in sorted(available):
398+
show(i)
399+
elif args.mode == 'used':
400+
for i in sorted(used):
401+
show(i)
402+
else:
403+
assert args.mode == 'orphaned'
404+
for i in sorted(available - used):
405+
show(i)

pym/bob/input.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,17 +2981,18 @@ def loadFromFile(recipeSet, rootDir, fileName):
29812981

29822982
alias = recipeSet.loadYaml(fileName, (AliasPackage.SCHEMA, b''))
29832983
if isinstance(alias, str):
2984-
return [ AliasPackage(recipeSet, alias, baseName) ]
2984+
return [ AliasPackage(recipeSet, alias, baseName, fileName) ]
29852985
else:
29862986
return [
2987-
AliasPackage(recipeSet, subAlias, baseName + ("-"+subName if subName else ""))
2987+
AliasPackage(recipeSet, subAlias, baseName + ("-"+subName if subName else ""), fileName)
29882988
for (subName, subAlias) in alias["multiPackage"].items()
29892989
]
29902990

2991-
def __init__(self, recipeSet, target, packageName):
2991+
def __init__(self, recipeSet, target, packageName, fileName):
29922992
self.__recipeSet = recipeSet
29932993
self.__target = target
29942994
self.__packageName = packageName
2995+
self.__source = fileName
29952996

29962997
def prepare(self, env, sandboxEnabled, states, sandbox, tools, stack, packageName=None):
29972998
target = env.substitute(self.__target, "alias package")
@@ -3010,6 +3011,12 @@ def resolveClasses(self, env):
30103011
def isRoot(self):
30113012
return False
30123013

3014+
def getPrimarySource(self):
3015+
return self.__source
3016+
3017+
def getSources(self):
3018+
return [self.__source]
3019+
30133020

30143021
class PackageMatcher:
30153022
__slots__ = ( 'corePackage', 'env', 'tools', 'states', 'sandbox',
@@ -4115,6 +4122,9 @@ def __createSchemas(self):
41154122
self.__userConfigSchema = (schema.Schema(userConfigSchemaSpec), self.__pluginSettingsDeps)
41164123

41174124

4125+
def getRecipes(self):
4126+
return self.__recipes.keys()
4127+
41184128
def getRecipe(self, packageName):
41194129
if packageName not in self.__recipes:
41204130
raise ParseError("Package {} requested but not found.".format(packageName))

pym/bob/scripts.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def __jenkinsExecute(*args, **kwargs):
107107
from .cmds.jenkins.exec import doJenkinsExecute
108108
return doJenkinsExecute(*args, **kwargs)
109109

110+
def __lsrecipes(*args, **kwargs):
111+
from .cmds.misc import doLsRecipes
112+
doLsRecipes(*args, **kwargs)
113+
return 0
114+
110115
availableCommands = {
111116
"archive" : ('hl', __archive, "Manage binary artifact archives"),
112117
"build" : ('hl', __build, "Build (sub-)packages in release mode"),
@@ -122,6 +127,7 @@ def __jenkinsExecute(*args, **kwargs):
122127
"show" : ('hl', __show, "Show properties of a package"),
123128
"status" : ('hl', __status, "Show SCM status"),
124129

130+
"ls-recipes" : ('ll', __lsrecipes, "List all known recipes"),
125131
"query-scm" : ('ll', __queryscm, "Query SCM information"),
126132
"query-recipe" : ('ll', __queryrecipe, "Query package sources"),
127133
"query-path" : ('ll', __querypath, "Query path information"),

test/black-box/commands/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ for c in $cmds; do
2020
case "$c" in
2121
archive | init | jenkins | layers | help | _*)
2222
;;
23-
clean)
23+
clean | ls-recipes)
2424
run_bob $c -DBAR=1 -c testconfig
2525
;;
2626
project)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bobMinimumVersion: "1.0"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packageScript: |
2+
echo lib

0 commit comments

Comments
 (0)