add support for testing package resolution by distro and distro version

Summary:
Add support for overriding os, distro and distro version to command line when inspecting system packages so one can requested see ubuntu 18.04 package from other OS.  Makes testing easier

Used shlex to shell unquote the value to be tested in the getdeps expression evaluator. getdeps expression parser didn't tolerate 18.04 as . is special char to getdeps expressions, needed to be "18.04"

Reviewed By: quark-zju

Differential Revision: D33741323

fbshipit-source-id: d83397c7fb5180a4d985d0d8ae7b3ff33b72f828
This commit is contained in:
Alex Hornby 2022-01-25 01:33:41 -08:00 committed by Facebook GitHub Bot
parent edd73c3cb8
commit b34c0c5114
2 changed files with 46 additions and 11 deletions

View File

@ -347,10 +347,27 @@ class InstallSysDepsCmd(ProjectCmdBase):
help="Don't install, just print the commands specs we would run",
)
parser.add_argument(
"--package-type",
choices=["rpm", "deb"],
"--os-type",
help="Filter to just this OS type to run",
choices=["linux", "darwin", "windows"],
action="store",
dest="ostype",
default=None,
)
parser.add_argument(
"--distro",
help="Filter to just this distro to run",
choices=["ubuntu", "centos_stream"],
action="store",
dest="distro",
default=None,
)
parser.add_argument(
"--distro-version",
help="Filter to just this distro version",
action="store",
dest="distrovers",
default=None,
help="Allow overriding the package type so can see deb from centos",
)
def run_project_cmd(self, args, loader, manifest):
@ -359,6 +376,27 @@ class InstallSysDepsCmd(ProjectCmdBase):
else:
projects = [manifest]
rebuild_ctx_gen = False
if args.ostype:
loader.build_opts.host_type.ostype = args.ostype
loader.build_opts.host_type.distro = None
loader.build_opts.host_type.distrovers = None
rebuild_ctx_gen = True
if args.distro:
loader.build_opts.host_type.distro = args.distro
loader.build_opts.host_type.distrovers = None
rebuild_ctx_gen = True
if args.distrovers:
loader.build_opts.host_type.distrovers = args.distrovers
rebuild_ctx_gen = True
if rebuild_ctx_gen:
loader.ctx_gen = loader.build_opts.get_context_generator()
manager = loader.build_opts.host_type.get_package_manager()
all_packages = {}
for m in projects:
ctx = loader.ctx_gen.get_context(m.name)
@ -368,18 +406,13 @@ class InstallSysDepsCmd(ProjectCmdBase):
merged += v
all_packages[k] = merged
if args.package_type:
manager = args.package_type
else:
manager = loader.build_opts.host_type.get_package_manager()
cmd_args = None
if manager == "rpm":
packages = sorted(list(set(all_packages["rpm"])))
packages = sorted(set(all_packages["rpm"]))
if packages:
cmd_args = ["dnf", "install", "-y"] + packages
elif manager == "deb":
packages = sorted(list(set(all_packages["deb"])))
packages = sorted(set(all_packages["deb"]))
if packages:
cmd_args = ["apt", "install", "-y"] + packages
else:

View File

@ -139,7 +139,9 @@ class Parser(object):
if op == "=":
if name not in self.valid_variables:
raise Exception("unknown variable %r in expression" % (name,))
return EqualExpr(name, self.lex.get_token())
# remove shell quote from value so can test things with period in them, e.g "18.04"
unquoted = " ".join(shlex.split(self.lex.get_token()))
return EqualExpr(name, unquoted)
raise Exception(
"Unexpected token sequence '%s %s' in %s" % (name, op, self.text)