Unverified Commit 719268b4 authored by ekibun's avatar ekibun Committed by GitHub

add different workload & add -products * to vswhere calls to check both Visual...

add different workload & add -products * to vswhere calls to check both Visual Studio IDE and standalone Build Tools. (#64251)
parent 2d02c70a
...@@ -185,8 +185,12 @@ class VisualStudio { ...@@ -185,8 +185,12 @@ class VisualStudio {
/// Workload ID for use with vswhere requirements. /// Workload ID for use with vswhere requirements.
/// ///
/// Workload ID is different between Visual Studio IDE and Build Tools.
/// See https://docs.microsoft.com/en-us/visualstudio/install/workload-and-component-ids /// See https://docs.microsoft.com/en-us/visualstudio/install/workload-and-component-ids
static const String _requiredWorkload = 'Microsoft.VisualStudio.Workload.NativeDesktop'; static const List<String> _requiredWorkloads = <String>[
'Microsoft.VisualStudio.Workload.NativeDesktop',
'Microsoft.VisualStudio.Workload.VCTools'
];
/// Components for use with vswhere requirements. /// Components for use with vswhere requirements.
/// ///
...@@ -270,17 +274,19 @@ class VisualStudio { ...@@ -270,17 +274,19 @@ class VisualStudio {
Map<String, dynamic> _visualStudioDetails({ Map<String, dynamic> _visualStudioDetails({
bool validateRequirements = false, bool validateRequirements = false,
List<String> additionalArguments, List<String> additionalArguments,
String requiredWorkload
}) { }) {
final List<String> requirementArguments = validateRequirements final List<String> requirementArguments = validateRequirements
? <String>[ ? <String>[
'-requires', '-requires',
_requiredWorkload, requiredWorkload,
..._requiredComponents(_minimumSupportedVersion).keys ..._requiredComponents(_minimumSupportedVersion).keys
] ]
: <String>[]; : <String>[];
try { try {
final List<String> defaultArguments = <String>[ final List<String> defaultArguments = <String>[
'-format', 'json', '-format', 'json',
'-products', '*',
'-utf8', '-utf8',
'-latest', '-latest',
]; ];
...@@ -343,13 +349,18 @@ class VisualStudio { ...@@ -343,13 +349,18 @@ class VisualStudio {
_vswhereMinVersionArgument, _vswhereMinVersionArgument,
_minimumSupportedVersion.toString(), _minimumSupportedVersion.toString(),
]; ];
Map<String, dynamic> visualStudioDetails = _visualStudioDetails( Map<String, dynamic> visualStudioDetails;
validateRequirements: true, // Check in the order of stable VS, stable BT, pre-release VS, pre-release BT
additionalArguments: minimumVersionArguments); for (final bool checkForPrerelease in <bool>[false, true]) {
// If a stable version is not found, try searching for a pre-release version. for (final String requiredWorkload in _requiredWorkloads) {
visualStudioDetails ??= _visualStudioDetails( visualStudioDetails ??= _visualStudioDetails(
validateRequirements: true, validateRequirements: true,
additionalArguments: <String>[...minimumVersionArguments, _vswherePrereleaseArgument]); additionalArguments: checkForPrerelease
? <String>[...minimumVersionArguments, _vswherePrereleaseArgument]
: minimumVersionArguments,
requiredWorkload: requiredWorkload);
}
}
if (visualStudioDetails != null) { if (visualStudioDetails != null) {
if (installationHasIssues(visualStudioDetails)) { if (installationHasIssues(visualStudioDetails)) {
......
...@@ -41,6 +41,20 @@ const Map<String, dynamic> _defaultResponse = <String, dynamic>{ ...@@ -41,6 +41,20 @@ const Map<String, dynamic> _defaultResponse = <String, dynamic>{
}, },
}; };
// A minimum version of a response where a Build Tools installation was found.
const Map<String, dynamic> _defaultBuildToolsResponse = <String, dynamic>{
'installationPath': visualStudioPath,
'displayName': 'Visual Studio Build Tools 2019',
'installationVersion': '16.7.30413.136',
'isRebootRequired': false,
'isComplete': true,
'isLaunchable': true,
'isPrerelease': false,
'catalog': <String, dynamic>{
'productDisplayVersion': '16.7.2',
},
};
// A response for a VS installation that's too old. // A response for a VS installation that's too old.
const Map<String, dynamic> _tooOldResponse = <String, dynamic>{ const Map<String, dynamic> _tooOldResponse = <String, dynamic>{
'installationPath': visualStudioPath, 'installationPath': visualStudioPath,
...@@ -74,6 +88,14 @@ const List<String> _requirements = <String>[ ...@@ -74,6 +88,14 @@ const List<String> _requirements = <String>[
'Microsoft.VisualStudio.Component.VC.CMake.Project', 'Microsoft.VisualStudio.Component.VC.CMake.Project',
]; ];
// Arguments for a vswhere query to search for a Build Tools installation with the
// requirements.
const List<String> _requirementsBuildTools = <String>[
'Microsoft.VisualStudio.Workload.VCTools',
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'Microsoft.VisualStudio.Component.VC.CMake.Project',
];
// Sets up the mock environment so that searching for Visual Studio with // Sets up the mock environment so that searching for Visual Studio with
// exactly the given required components will provide a result. By default it // exactly the given required components will provide a result. By default it
// return a preset installation, but the response can be overridden. // return a preset installation, but the response can be overridden.
...@@ -98,6 +120,8 @@ void setMockVswhereResponse( ...@@ -98,6 +120,8 @@ void setMockVswhereResponse(
vswherePath, vswherePath,
'-format', '-format',
'json', 'json',
'-products',
'*',
'-utf8', '-utf8',
'-latest', '-latest',
...?additionalArguments, ...?additionalArguments,
...@@ -139,6 +163,38 @@ void setMockPrereleaseVisualStudioInstallation( ...@@ -139,6 +163,38 @@ void setMockPrereleaseVisualStudioInstallation(
); );
} }
// Sets whether or not a vswhere query with the required components will
// return an Build Tools installation.
void setMockCompatibleVisualStudioBuildToolsInstallation(
Map<String, dynamic> response,
FileSystem fileSystem,
FakeProcessManager processManager,
) {
setMockVswhereResponse(
fileSystem,
processManager,
_requirementsBuildTools,
<String>['-version', '16'],
response,
);
}
// Sets whether or not a vswhere query with the required components will
// return a pre-release Build Tools installation.
void setMockPrereleaseVisualStudioBuildToolsInstallation(
Map<String, dynamic> response,
FileSystem fileSystem,
FakeProcessManager processManager,
) {
setMockVswhereResponse(
fileSystem,
processManager,
_requirementsBuildTools,
<String>['-version', '16', '-prerelease'],
response,
);
}
// Sets whether or not a vswhere query searching for 'all' and 'prerelease' // Sets whether or not a vswhere query searching for 'all' and 'prerelease'
// versions will return an installation. // versions will return an installation.
void setMockAnyVisualStudioInstallation( void setMockAnyVisualStudioInstallation(
...@@ -229,6 +285,32 @@ VisualStudioFixture setUpVisualStudio() { ...@@ -229,6 +285,32 @@ VisualStudioFixture setUpVisualStudio() {
return VisualStudioFixture(visualStudio, fileSystem, processManager); return VisualStudioFixture(visualStudio, fileSystem, processManager);
} }
// Set all vswhere query with the required components return null.
void setNoViableToolchainInstallation(
VisualStudioFixture fixture,
) {
setMockCompatibleVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockCompatibleVisualStudioBuildToolsInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioBuildToolsInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
}
void main() { void main() {
group('Visual Studio', () { group('Visual Studio', () {
testWithoutContext('isInstalled returns false when vswhere is missing', () { testWithoutContext('isInstalled returns false when vswhere is missing', () {
...@@ -296,16 +378,8 @@ void main() { ...@@ -296,16 +378,8 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
null, null,
fixture.fileSystem, fixture.fileSystem,
...@@ -343,16 +417,8 @@ void main() { ...@@ -343,16 +417,8 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
_tooOldResponse, _tooOldResponse,
fixture.fileSystem, fixture.fileSystem,
...@@ -368,16 +434,8 @@ void main() { ...@@ -368,16 +434,8 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
_missingStatusResponse, _missingStatusResponse,
fixture.fileSystem, fixture.fileSystem,
...@@ -391,16 +449,8 @@ void main() { ...@@ -391,16 +449,8 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
_defaultResponse, _defaultResponse,
fixture.fileSystem, fixture.fileSystem,
...@@ -414,16 +464,8 @@ void main() { ...@@ -414,16 +464,8 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
_tooOldResponse, _tooOldResponse,
fixture.fileSystem, fixture.fileSystem,
...@@ -444,13 +486,13 @@ void main() { ...@@ -444,13 +486,13 @@ void main() {
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
setMockPrereleaseVisualStudioInstallation( setMockCompatibleVisualStudioBuildToolsInstallation(
response, null,
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
setMockAnyVisualStudioInstallation( setMockPrereleaseVisualStudioInstallation(
null, response,
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
...@@ -459,20 +501,43 @@ void main() { ...@@ -459,20 +501,43 @@ void main() {
expect(visualStudio.isPrerelease, true); expect(visualStudio.isPrerelease, true);
}); });
testWithoutContext('isAtLeastMinimumVersion returns false when the version found is too old', () { testWithoutContext('isInstalled returns true when a prerelease version of Build Tools is present', () {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultBuildToolsResponse)
..['isPrerelease'] = true;
setMockCompatibleVisualStudioInstallation( setMockCompatibleVisualStudioInstallation(
null, null,
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
setMockCompatibleVisualStudioBuildToolsInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation( setMockPrereleaseVisualStudioInstallation(
null, null,
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
setMockPrereleaseVisualStudioBuildToolsInstallation(
response,
fixture.fileSystem,
fixture.processManager,
);
expect(visualStudio.isInstalled, true);
expect(visualStudio.isPrerelease, true);
});
testWithoutContext('isAtLeastMinimumVersion returns false when the version found is too old', () {
final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio;
setNoViableToolchainInstallation(fixture);
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
_tooOldResponse, _tooOldResponse,
fixture.fileSystem, fixture.fileSystem,
...@@ -487,16 +552,7 @@ void main() { ...@@ -487,16 +552,7 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse) final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
..['isComplete'] = false; ..['isComplete'] = false;
...@@ -515,16 +571,7 @@ void main() { ...@@ -515,16 +571,7 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse) final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
..['isLaunchable'] = false; ..['isLaunchable'] = false;
...@@ -542,16 +589,7 @@ void main() { ...@@ -542,16 +589,7 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse) final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
..['isRebootRequired'] = true; ..['isRebootRequired'] = true;
...@@ -569,16 +607,8 @@ void main() { ...@@ -569,16 +607,8 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
_defaultResponse, _defaultResponse,
fixture.fileSystem, fixture.fileSystem,
...@@ -592,16 +622,8 @@ void main() { ...@@ -592,16 +622,8 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
_defaultResponse, _defaultResponse,
fixture.fileSystem, fixture.fileSystem,
...@@ -622,11 +644,6 @@ void main() { ...@@ -622,11 +644,6 @@ void main() {
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
expect(visualStudio.cmakePath, isNull); expect(visualStudio.cmakePath, isNull);
}); });
...@@ -642,11 +659,6 @@ void main() { ...@@ -642,11 +659,6 @@ void main() {
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
expect(visualStudio.hasNecessaryComponents, false); expect(visualStudio.hasNecessaryComponents, false);
}); });
...@@ -655,16 +667,8 @@ void main() { ...@@ -655,16 +667,8 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
_defaultResponse, _defaultResponse,
fixture.fileSystem, fixture.fileSystem,
...@@ -681,16 +685,8 @@ void main() { ...@@ -681,16 +685,8 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation( setNoViableToolchainInstallation(fixture);
null,
fixture.fileSystem,
fixture.processManager,
);
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
setMockEncodedAnyVisualStudioInstallation( setMockEncodedAnyVisualStudioInstallation(
'{', '{',
fixture.fileSystem, fixture.fileSystem,
...@@ -709,13 +705,24 @@ void main() { ...@@ -709,13 +705,24 @@ void main() {
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
setMockPrereleaseVisualStudioInstallation(
expect(visualStudio.isInstalled, true);
expect(visualStudio.isAtLeastMinimumVersion, true);
expect(visualStudio.hasNecessaryComponents, true);
expect(visualStudio.cmakePath, equals(cmakePath));
});
testWithoutContext('Everything returns good values when Build Tools is present with all components', () {
final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio;
setMockCompatibleVisualStudioInstallation(
null, null,
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
setMockAnyVisualStudioInstallation( setMockCompatibleVisualStudioBuildToolsInstallation(
null, _defaultBuildToolsResponse,
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
...@@ -745,11 +752,6 @@ void main() { ...@@ -745,11 +752,6 @@ void main() {
fixture.fileSystem, fixture.fileSystem,
fixture.processManager, fixture.processManager,
); );
setMockPrereleaseVisualStudioInstallation(
null,
fixture.fileSystem,
fixture.processManager,
);
// Return a different version for queries without the required packages. // Return a different version for queries without the required packages.
final Map<String, dynamic> incompleteVersionResponse = <String, dynamic>{ final Map<String, dynamic> incompleteVersionResponse = <String, dynamic>{
'installationPath': visualStudioPath, 'installationPath': visualStudioPath,
......
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