Commit bd68291e authored by Chris Blume's avatar Chris Blume Committed by LUCI CQ

Reland "Support multiple VS installations" (with fix)

This reverts commit 9ce8be33.

Reason for revert: To apply fix

Original change's description:
> Revert "Support multiple VS installations"
>
> This reverts commit 36d41cef.
>
> Reason for revert: Script references VS_VERSION variable that was
> renamed in the prior change, so it doesn't work.
>
> Original change's description:
> > Support multiple VS installations
> >
> > Currently, package_from_installed.py assumes only one version of VS is
> > installed. It takes the path of the first installation.
> >
> > This could be incorrect in several ways:
> > - Maybe both 2017 and 2019 (the supported versions) are installed and
> >   although the user specified using 2019, the 2017 path comes first.
> > - Maybe 2019 and 2022 are installed, and the 2022 path is used even
> >   though it isn't supported.
> >
> > This CL fixes that issue by parsing the vswhere.exe output to confirm
> > the VS version matches what the user specified, using its corresponding
> > path.
> >
> > Change-Id: I2029a4f7126d0a45b5370ad58ab257df55571b3b
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3458722
> > Reviewed-by: Gavin Mak <gavinmak@google.com>
> > Reviewed-by: Chris Blume <cblume@chromium.org>
> > Commit-Queue: Chris Blume <cblume@chromium.org>
> > Auto-Submit: Chris Blume <cblume@chromium.org>
>
> Change-Id: I3d9147a7786f7f54f861087d16967b75d4afe2c5
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3504193
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: Bruce Dawson <brucedawson@chromium.org>

Change-Id: Ica90cb8d5ce08b8b127da64969401cb40d4aee63
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3497899Reviewed-by: 's avatarBruce Dawson <brucedawson@chromium.org>
Commit-Queue: Chris Blume <cblume@chromium.org>
parent 57629303
......@@ -52,6 +52,7 @@ _vs_version = None
_win_version = None
_vc_tools = None
SUPPORTED_VS_VERSIONS = ['2017', '2019']
_allow_multiple_vs_installs = False
def GetVSPath():
......@@ -60,12 +61,34 @@ def GetVSPath():
# version is installed.
command = (r'C:\Program Files (x86)\Microsoft Visual Studio\Installer'
r'\vswhere.exe -prerelease')
marker = 'installationPath: '
vs_version_marker = 'catalog_productLineVersion: '
vs_path_marker = 'installationPath: '
output = subprocess.check_output(command, universal_newlines=True)
vs_path = None
vs_installs_count = 0
matching_vs_path = ""
for line in output.splitlines():
if line.startswith(marker):
return line[len(marker):]
if line.startswith(vs_path_marker):
# The path information comes first
vs_path = line[len(vs_path_marker):]
vs_installs_count += 1
if line.startswith(vs_version_marker):
# The version for that path comes later
if line[len(vs_version_marker):] == _vs_version:
matching_vs_path = vs_path
if vs_installs_count == 0:
raise Exception('VS %s path not found in vswhere output' % (_vs_version))
if vs_installs_count > 1:
if not _allow_multiple_vs_installs:
raise Exception('Multiple VS installs detected. This is unsupported. '
'It is recommended that packaging be done on a clean VM '
'with just one version installed. To proceed anyway add '
'the --allow_multiple_vs_installs flag to this script')
else:
print('Multiple VS installs were detected. This is unsupported. '
'Proceeding anyway')
return matching_vs_path
def ExpandWildcards(root, sub_dir):
......@@ -475,6 +498,9 @@ def main():
parser.add_option('--repackage', action='store', type='string',
dest='repackage_dir', default=None,
help='Specify raw directory to be packaged, for hot fixes.')
parser.add_option('--allow_multiple_vs_installs', action='store_true',
default=False, dest='allow_multiple_vs_installs',
help='Specify if multiple VS installs are allowed.')
(options, args) = parser.parse_args()
if options.repackage_dir:
......@@ -497,6 +523,8 @@ def main():
global _win_version
_win_version = options.winver
global _vc_tools
global _allow_multiple_vs_installs
_allow_multiple_vs_installs = options.allow_multiple_vs_installs
vs_path = GetVSPath()
temp_tools_path = ExpandWildcards(vs_path, 'VC/Tools/MSVC/14.*.*')
# Strip off the leading vs_path characters and switch back to / separators.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment