Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/bash-completion/bob
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ __bob_show()
else
__bob_complete_path "-D -c --sandbox --no-sandbox --slim-sandbox
--dev-sandbox --strict-sandbox --show-empty
--show-common --indent --no-indent --format -f"
--show-common --recursive --indent --no-indent --format -f"
fi
}

Expand Down
15 changes: 15 additions & 0 deletions doc/manpages/bob-show.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Synopsis
fingerprintIf,jobServer,meta,metaEnvironment,packageNetAccess,
packageTools,packageToolsWeak,packageVars,packageVarsWeak,
relocatable,root,sandbox,scriptLanguage,shared}]
[--recursive]
packages [packages ...]


Expand Down Expand Up @@ -52,6 +53,13 @@ the following synthetic properties are shown:

* ``sandbox``: The sandbox package that is used for this package.

The used tools (``checkoutTools``, ``buildTools``, ``packageTools`` and their
``*Weak`` counterparts) are shown as map of the tool name to its properties:

* ``package``: The package that provides the tool
* ``path``: The path of the tool, relative to the package workspace
* ``libs``: The library paths of the tool, relative to the package workspace

By default the information is shown as YAML document. If multiple packages are
selected then multiple YAML documents are generated too. The output format can
be controlled with the ``--format`` option. The ``flat`` format is a custom
Expand Down Expand Up @@ -86,6 +94,13 @@ Options
``--no-sandbox``
Disable sandboxing.

``--recursive``
With ``--format diff``, find the first package with a direct difference
by following differing dependencies from the same recipe. Display each
package diff along the path and identify the dependency that leads to the
next comparison. The selected fields and output options apply to every
diff. Exactly two packages must be selected.

``--sandbox``
Enable partial sandboxing.

Expand Down
17 changes: 2 additions & 15 deletions pym/bob/cmds/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later

from ..utils import dumpFlat

def processDefines(defs):
"""Convert a list of 'KEY=VALUE' strings into a dict"""
defines = {}
Expand Down Expand Up @@ -40,18 +42,3 @@ def dumpJson(doc, indent):
import json
return json.dumps(doc, indent=indent, sort_keys=True)

def dumpFlat(doc, prefix=""):
ret = []
if isinstance(doc, dict):
for k,v in sorted(doc.items()):
ret.extend(dumpFlat(v, prefix+"."+k if prefix else k))
elif isinstance(doc, list):
i = 0
for v in doc:
ret.extend(dumpFlat(v, "{}[{}]".format(prefix, i)))
i += 1
else:
doc = str(doc).replace('\n', '\\n')
ret = [ "{}={}".format(prefix, doc) ]

return ret
179 changes: 12 additions & 167 deletions pym/bob/cmds/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

from ..errors import ParseError
from ..input import RecipeSet
from ..tty import colorize, ADDED, DELETED, DEFAULT, ADDED_HIGHLIGHT, DELETED_HIGHLIGHT
from ..utils import asHexStr
from ..pkgdiff import diffPackages, dumpPackage, calcPackageDiffRecursive, renderPackageDiffChain
from .helpers import processDefines, addStandardArgs, dumpYaml, dumpJson, dumpFlat
import argparse
import difflib
import json
import sys
import yaml
Expand All @@ -24,113 +22,6 @@
"shared",
)

def dumpPackage(package):
recipe = package.getRecipe()

doc = {
"meta" : {
"name" : package.getName(),
"recipe" : recipe.getName(),
"package" : "/".join(package.getStack()),
"deterministic" : package.getPackageStep().isDeterministic(),
},
"scriptLanguage" : recipe.scriptLanguage.index.value,
"shared" : package.isShared(),
"metaEnvironment" : package.getMetaEnv(),
"relocatable" : package.isRelocatable(),
"jobServer" : recipe.jobServer(),
"root" : recipe.isRoot(),
}

checkoutStep = package.getCheckoutStep()
if checkoutStep.isValid():
doc["meta"]["checkoutVariantId"] = asHexStr(checkoutStep.getVariantId())
doc["checkoutDeterministic"] = checkoutStep.isDeterministic()
doc["checkoutSCM"] = [
{ k:v for k,v in s.getProperties(False, True).items() if not k.startswith("__") }
for s in checkoutStep.getScmList()
]
doc["checkoutAssert"] = [
{ k:v for k,v in a.items() if not k.startswith("__") }
for a in recipe.checkoutAsserts
]
doc["checkoutTools"] = {
name : "/".join(t.getStep().getPackage().getStack())
for name, t in checkoutStep.getTools().items()
if name in (checkoutStep.toolDep - checkoutStep.toolDepWeak)
}
doc["checkoutToolsWeak"] = {
name : "/".join(t.getStep().getPackage().getStack())
for name, t in checkoutStep.getTools().items()
if name in checkoutStep.toolDepWeak
}
doc["checkoutVars"] = {
k : v for k, v in checkoutStep.getEnv().items()
if k in recipe.checkoutVars
}
doc["checkoutVarsWeak"] = {
k : v for k, v in checkoutStep.getEnv().items()
if k in recipe.checkoutVarsWeak
}

buildStep = package.getBuildStep()
if buildStep.isValid():
doc["meta"]["buildVariantId"] = asHexStr(buildStep.getVariantId())
doc["buildNetAccess"] = buildStep.hasNetAccess()
doc["depends"] = [
"/".join(d.getPackage().getStack())
for d in buildStep.getArguments()[1:]
]
doc["buildTools"] = {
name : "/".join(t.getStep().getPackage().getStack())
for name, t in buildStep.getTools().items()
if name in (buildStep.toolDep - buildStep.toolDepWeak)
}
doc["buildToolsWeak"] = {
name : "/".join(t.getStep().getPackage().getStack())
for name, t in buildStep.getTools().items()
if name in buildStep.toolDepWeak
}
doc["buildVars"] = {
k : v for k, v in buildStep.getEnv().items()
if k in recipe.buildVars
}
doc["buildVarsWeak"] = {
k : v for k, v in buildStep.getEnv().items()
if k in recipe.buildVarsWeak
}

packageStep = package.getPackageStep()
doc["meta"]["packageVariantId"] = asHexStr(packageStep.getVariantId())
doc["packageTools"] = {
name : "/".join(t.getStep().getPackage().getStack())
for name, t in packageStep.getTools().items()
if name in (packageStep.toolDep - packageStep.toolDepWeak)
}
doc["packageToolsWeak"] = {
name : "/".join(t.getStep().getPackage().getStack())
for name, t in packageStep.getTools().items()
if name in packageStep.toolDepWeak
}
doc["packageVars"] = {
k : v for k, v in packageStep.getEnv().items()
if k in recipe.packageVars
}
doc["packageVarsWeak"] = {
k : v for k, v in packageStep.getEnv().items()
if k in recipe.packageVarsWeak
}
doc["packageNetAccess"] = packageStep.hasNetAccess()
doc["fingerprintIf"] = packageStep._isFingerprinted()

sandbox = packageStep.getSandbox()
if sandbox and sandbox.isEnabled():
doc["sandbox"] = "/".join(sandbox.getStep().getPackage().getStack())
else:
doc["sandbox"] = None

return doc

def filterEmpty(doc):
if isinstance(doc, dict):
return { k : filterEmpty(v) for k, v in doc.items() if v }
Expand Down Expand Up @@ -164,63 +55,6 @@ def showPackagesFlat(docs):

return "\n".join(ret)

def getSegments(indicator):
mode = False
start = 0
end = 1
ret = []
for c in indicator[2:]:
newMode = c != " "
end += 1
if mode != newMode:
ret.append((mode, start, end))
mode = newMode
start = end
ret.append((mode, start, end+1))
return ret

def diffPackages(left, right, show_common):
left = [ l+"\n" for l in dumpFlat(left) ]
right = [ l+"\n" for l in dumpFlat(right) ]
diff = [ l for l in difflib.Differ().compare(left, right)
if not l.startswith(" ") or show_common ]

# Colorize lines with the intraline information from difflib. A bit
# complicated because the affected characters are specified with the next
# line. If the intraline diff is too big then no context is given.
prevLine = origPrevLine = None
ret = []
for l in diff:
nextLine = origNextLine = l.rstrip()
if nextLine.startswith("? "):
if origPrevLine.startswith("+ "):
codes = { False : ADDED, True : ADDED_HIGHLIGHT }
elif origPrevLine.startswith("- "):
codes = { False : DELETED, True : DELETED_HIGHLIGHT }
else:
codes = { False : DEFAULT, True : DEFAULT }

res = ""
for mode, start, end in getSegments(nextLine):
res += colorize(origPrevLine[start:end], codes[mode])
if end < len(origPrevLine):
res += colorize(origPrevLine[end:], codes[False])
prevLine = res
nextLine = origNextLine = None
elif nextLine.startswith("+ "):
nextLine = colorize(nextLine, ADDED)
elif nextLine.startswith("- "):
nextLine = colorize(nextLine, DELETED)

if prevLine is not None: ret.append(prevLine)
prevLine = nextLine
origPrevLine = origNextLine

if prevLine is not None:
ret.append(prevLine)

return "\n".join(ret)

def doShow(argv, bobRoot):
parser = argparse.ArgumentParser(prog="bob show",
description="Show properties of one or more packages.")
Expand All @@ -243,7 +77,10 @@ def doShow(argv, bobRoot):
choices=sorted(ALL_FIELDS),
help="Show particular field(s) instead of all")

group.add_argument('--recursive', action='store_true', help='Explain variant differences recursively')
args = parser.parse_args(argv)
if args.recursive and args.format != 'diff':
parser.error('--recursive requires diff format')
defines = processDefines(args.defines)

recipes = RecipeSet()
Expand All @@ -260,10 +97,12 @@ def doShow(argv, bobRoot):
filt = lambda x, filt=filt: filterFields(filt(x), args.field)

docs = []
selected = []
with packages:
for p in args.packages:
for package in packages.queryPackagePath(p):
docs.append(("/".join(package.getStack()), filt(dumpPackage(package))))
selected.append(package)

if not docs:
print("Your query matched no packets!", file=sys.stderr)
Expand All @@ -276,6 +115,12 @@ def doShow(argv, bobRoot):
ret = showPackagesFlat(docs)
elif len(docs) != 2:
raise ParseError("Diff format requires exactly two packages")
elif args.recursive:
pair = calcPackageDiffRecursive(selected[0].getPackageStep(), selected[1].getPackageStep())
if pair:
ret = renderPackageDiffChain(pair, filt, args.show_common)
else:
ret = ""
else:
ret = diffPackages(docs[0][1], docs[1][1], args.show_common)

Expand Down
Loading
Loading