Skip to content

Commit

Permalink
vsdownload: Add an option to skip packages that do not match host arch
Browse files Browse the repository at this point in the history
  • Loading branch information
huangqinjin authored and mstorsjo committed Oct 9, 2024
1 parent 612aeda commit f7e6662
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions vsdownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def getArgsParser():
parser.add_argument("--sdk-version", metavar="version", help="Install a specific Windows SDK version")
parser.add_argument("--with-wdk-installers", metavar="dir", help="Install Windows Driver Kit using the provided MSI installers")
parser.add_argument("--host-arch", metavar="arch", choices=["x86", "x64", "arm64"], help="Specify the host architecture of packages to install")
parser.add_argument("--only-host", default=True, const=True, action="store_const", help="Only download packages that match host arch")
return parser

def setPackageSelectionMSVC16(args, packages, userversion, sdk, toolversion, defaultPackages):
Expand Down Expand Up @@ -288,6 +289,22 @@ def findPackage(packages, id, constraints={}, warn=True):
return a
return candidates[0]

def matchPackageHostArch(p, host):
if host is None:
return True

known_archs = ["x86", "x64", "arm64"]

# Some packages have host arch in their ids, e.g.
# - Microsoft.VisualCpp.Tools.HostARM64.TargetX64
# - Microsoft.VisualCpp.Tools.HostX64.TargetX64
id = p["id"].lower()
for a in known_archs:
if "host" + a in id:
return a == host

return True

def printDepends(packages, target, constraints, indent, args):
chipstr = ""
for k in ["chip", "machineArch"]:
Expand All @@ -312,6 +329,9 @@ def printDepends(packages, target, constraints, indent, args):
if p == None:
ignorestr = " (NotFound)"
ignore = True
elif args.only_host and not matchPackageHostArch(p, args.host_arch):
ignorestr = " (HostArchMismatch)"
ignore = True
print(indent + target + chipstr + deptypestr + ignorestr)
if ignore:
return
Expand Down Expand Up @@ -359,6 +379,8 @@ def aggregateDepends(packages, included, target, constraints, args):
p = findPackage(packages, target, constraints)
if p == None:
return []
if args.only_host and not matchPackageHostArch(p, args.host_arch):
return []
packagekey = getPackageKey(p)
if packagekey in included:
return []
Expand Down

0 comments on commit f7e6662

Please sign in to comment.