Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vsdownload: Add an option to skip packages that do not match host arch #148

Merged
merged 1 commit into from
Oct 9, 2024
Merged
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
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
Loading