Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
576a455a
Unverified
Commit
576a455a
authored
Sep 12, 2019
by
Francisco Magdaleno
Committed by
GitHub
Sep 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[windows] Refactor to optimize vswhere queries (#40197)
parent
91af0715
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
18 deletions
+74
-18
visual_studio.dart
packages/flutter_tools/lib/src/windows/visual_studio.dart
+53
-18
visual_studio_test.dart
..._tools/test/general.shard/windows/visual_studio_test.dart
+21
-0
No files found.
packages/flutter_tools/lib/src/windows/visual_studio.dart
View file @
576a455a
...
...
@@ -18,11 +18,11 @@ class VisualStudio {
/// Versions older than 2017 Update 2 won't be detected, so error messages to
/// users should take into account that [false] may mean that the user may
/// have an old version rather than no installation at all.
bool
get
isInstalled
=>
_bestVisualStudioDetails
!=
null
;
bool
get
isInstalled
=>
_bestVisualStudioDetails
.
isNotEmpty
;
/// True if there is a version of Visual Studio with all the components
/// necessary to build the project.
bool
get
hasNecessaryComponents
=>
_usableVisualStudioDetails
!=
null
;
bool
get
hasNecessaryComponents
=>
_usableVisualStudioDetails
.
isNotEmpty
;
/// The name of the Visual Studio install.
///
...
...
@@ -32,8 +32,12 @@ class VisualStudio {
/// The user-friendly version number of the Visual Studio install.
///
/// For instance: "15.4.0".
String
get
displayVersion
=>
_bestVisualStudioDetails
[
_catalogKey
][
_catalogDisplayVersionKey
];
String
get
displayVersion
{
if
(
_bestVisualStudioDetails
[
_catalogKey
]
==
null
)
{
return
null
;
}
return
_bestVisualStudioDetails
[
_catalogKey
][
_catalogDisplayVersionKey
];
}
/// The directory where Visual Studio is installed.
String
get
installLocation
=>
_bestVisualStudioDetails
[
_installationPathKey
];
...
...
@@ -47,11 +51,25 @@ class VisualStudio {
// Visual Studio versions that don't include them, so default to a "valid" value to
// avoid false negatives.
/// True there is complete installation of Visual Studio.
bool
get
isComplete
=>
_bestVisualStudioDetails
[
_isCompleteKey
]
??
false
;
/// True if there is a complete installation of Visual Studio.
///
/// False if installation is not found.
bool
get
isComplete
{
if
(
_bestVisualStudioDetails
.
isEmpty
)
{
return
false
;
}
return
_bestVisualStudioDetails
[
_isCompleteKey
]
??
true
;
}
/// True if Visual Studio is launchable.
bool
get
isLaunchable
=>
_bestVisualStudioDetails
[
_isLaunchableKey
]
??
false
;
///
/// False if installation is not found.
bool
get
isLaunchable
{
if
(
_bestVisualStudioDetails
.
isEmpty
)
{
return
false
;
}
return
_bestVisualStudioDetails
[
_isLaunchableKey
]
??
true
;
}
/// True if the Visual Studio installation is as pre-release version.
bool
get
isPrerelease
=>
_bestVisualStudioDetails
[
_isPrereleaseKey
]
??
false
;
...
...
@@ -75,7 +93,7 @@ class VisualStudio {
/// the components necessary to build.
String
get
vcvarsPath
{
final
Map
<
String
,
dynamic
>
details
=
_usableVisualStudioDetails
;
if
(
details
==
null
)
{
if
(
details
.
isEmpty
)
{
return
null
;
}
return
fs
.
path
.
join
(
...
...
@@ -211,39 +229,56 @@ class VisualStudio {
}
/// Returns the details dictionary for the latest version of Visual Studio
/// that has all required components.
/// that has all required components, or {} if there is no such installation.
///
/// If no installation is found, the cached VS details are set to an empty map
/// to avoid repeating vswhere queries that have already not found an installation.
Map
<
String
,
dynamic
>
_cachedUsableVisualStudioDetails
;
Map
<
String
,
dynamic
>
get
_usableVisualStudioDetails
{
_cachedUsableVisualStudioDetails
??=
if
(
_cachedUsableVisualStudioDetails
!=
null
)
{
return
_cachedUsableVisualStudioDetails
;
}
Map
<
String
,
dynamic
>
visualStudioDetails
=
_visualStudioDetails
(
requiredComponents:
_requiredComponents
().
keys
);
// If a stable version is not found, try searching for a pre-release version.
_cachedUsableV
isualStudioDetails
??=
_visualStudioDetails
(
v
isualStudioDetails
??=
_visualStudioDetails
(
requiredComponents:
_requiredComponents
().
keys
,
additionalArguments:
<
String
>[
_prereleaseKey
]);
if
(
_cachedUsableVisualStudioDetails
!=
null
)
{
if
(
installationHasIssues
(
_cachedUsableVisualStudioDetails
))
{
_cachedAnyVisualStudioDetails
=
_cachedUsableVisualStudioDetails
;
return
null
;
if
(
visualStudioDetails
!=
null
)
{
if
(
installationHasIssues
(
visualStudioDetails
))
{
_cachedAnyVisualStudioDetails
=
visualStudioDetails
;
}
else
{
_cachedUsableVisualStudioDetails
=
visualStudioDetails
;
}
}
_cachedUsableVisualStudioDetails
??=
<
String
,
dynamic
>{};
return
_cachedUsableVisualStudioDetails
;
}
/// Returns the details dictionary of the latest version of Visual Studio,
/// regardless of components.
/// regardless of components, or {} if no such installation is found.
///
/// If no installation is found, the cached
/// VS details are set to an empty map to avoid repeating vswhere queries that
/// have already not found an installation.
Map
<
String
,
dynamic
>
_cachedAnyVisualStudioDetails
;
Map
<
String
,
dynamic
>
get
_anyVisualStudioDetails
{
// Search for all types of installations.
_cachedAnyVisualStudioDetails
??=
_visualStudioDetails
(
additionalArguments:
<
String
>[
_prereleaseKey
,
'-all'
]);
// Add a sentinel empty value to avoid querying vswhere again.
_cachedAnyVisualStudioDetails
??=
<
String
,
dynamic
>{};
return
_cachedAnyVisualStudioDetails
;
}
/// Returns the details dictionary of the best available version of Visual
/// Studio. If there's a version that has all the required components, that
/// Studio.
///
/// If there's a version that has all the required components, that
/// will be returned, otherwise returs the lastest installed version (if any).
Map
<
String
,
dynamic
>
get
_bestVisualStudioDetails
{
if
(
_usableVisualStudioDetails
!=
null
)
{
if
(
_usableVisualStudioDetails
.
isNotEmpty
)
{
return
_usableVisualStudioDetails
;
}
return
_anyVisualStudioDetails
;
...
...
packages/flutter_tools/test/general.shard/windows/visual_studio_test.dart
View file @
576a455a
...
...
@@ -184,6 +184,27 @@ void main() {
ProcessManager:
()
=>
mockProcessManager
,
});
testUsingContext
(
'VisualStudio getters return the right values if no installation is found'
,
()
{
setMockCompatibleVisualStudioInstallation
(
null
);
setMockPrereleaseVisualStudioInstallation
(
null
);
setMockAnyVisualStudioInstallation
(
null
);
visualStudio
=
VisualStudio
();
expect
(
visualStudio
.
isInstalled
,
false
);
expect
(
visualStudio
.
hasNecessaryComponents
,
false
);
expect
(
visualStudio
.
isComplete
,
false
);
expect
(
visualStudio
.
isRebootRequired
,
false
);
expect
(
visualStudio
.
isLaunchable
,
false
);
expect
(
visualStudio
.
displayName
,
null
);
expect
(
visualStudio
.
displayVersion
,
null
);
expect
(
visualStudio
.
installLocation
,
null
);
expect
(
visualStudio
.
fullVersion
,
null
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
memoryFilesystem
,
Platform:
()
=>
windowsPlatform
,
ProcessManager:
()
=>
mockProcessManager
,
});
testUsingContext
(
'isInstalled returns true even with missing status information'
,
()
{
setMockCompatibleVisualStudioInstallation
(
null
);
setMockPrereleaseVisualStudioInstallation
(
null
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment