-
Notifications
You must be signed in to change notification settings - Fork 28
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
use msbuild -version, not %VisualStudioVersion% #92
Closed
Closed
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8acc411
use msbuild -version, not %VisualStudioVersion%
rotu e0571a4
return str, not bytes
rotu d0f1a9d
Python3.5 compatibility
rotu d3eae8b
Revert linter fixes
rotu 244d5c6
Cache msbuild version
rotu 5419859
Add identifiers to spell check dictionary
rotu b8f235c
Address feedback
rotu 5f9f8e1
Handle other MSBuild version failures.
rotu 9de6751
Flake
rotu a62d352
Merge branch 'master' into patch-2
rotu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import shutil | ||
import subprocess | ||
import sys | ||
import functools | ||
|
||
from colcon_core.environment_variable import EnvironmentVariable | ||
from colcon_core.subprocess import check_output | ||
|
@@ -206,6 +207,20 @@ def get_project_file(path, target): | |
return project_file | ||
|
||
|
||
@functools.lru_cache(maxsize=1) | ||
def get_msbuild_version(): | ||
""" | ||
Get the version of msbuild or throw an exception. | ||
|
||
:rtype: str | ||
""" | ||
completed_process = subprocess.run( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please invoke |
||
['msbuild', '-version', '-noLogo'], | ||
capture_output=True | ||
) | ||
return completed_process.stdout.decode(encoding=sys.getdefaultencoding()) | ||
|
||
|
||
def get_visual_studio_version(): | ||
""" | ||
Get the Visual Studio version. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ | |
from colcon_cmake.task.cmake import get_buildfile | ||
from colcon_cmake.task.cmake import get_cmake_version | ||
from colcon_cmake.task.cmake import get_generator | ||
from colcon_cmake.task.cmake import get_msbuild_version | ||
from colcon_cmake.task.cmake import get_variable_from_cmake_cache | ||
from colcon_cmake.task.cmake import get_visual_studio_version | ||
from colcon_cmake.task.cmake import has_target | ||
from colcon_cmake.task.cmake import is_multi_configuration_generator | ||
from colcon_core.environment import create_environment_scripts | ||
|
@@ -148,25 +148,22 @@ async def _reconfigure(self, args, env): | |
cmake_args += ['-DCMAKE_INSTALL_PREFIX=' + args.install_base] | ||
generator = get_generator(args.build_base, args.cmake_args) | ||
if os.name == 'nt' and generator is None: | ||
vsv = get_visual_studio_version() | ||
if vsv is None: | ||
try: | ||
msbuild_version = get_msbuild_version() | ||
rotu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
except FileNotFoundError as e: | ||
raise RuntimeError( | ||
'VisualStudioVersion is not set, ' | ||
'please run within a Visual Studio Command Prompt.') | ||
supported_vsv = { | ||
'16.0': 'Visual Studio 16 2019', | ||
'15.0': 'Visual Studio 15 2017', | ||
'14.0': 'Visual Studio 14 2015', | ||
} | ||
if vsv not in supported_vsv: | ||
'msbuild is not found, ' | ||
rotu marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: instead if "is" it should be "was". |
||
'please run within a Visual Studio Command Prompt.') from e | ||
major_version = int(msbuild_version.split('.')[0]) | ||
if major_version < 14: | ||
raise RuntimeError( | ||
"Unknown / unsupported VS version '{vsv}'" | ||
"Unknown / unsupported VS version '{msbuild_version}'" | ||
.format_map(locals())) | ||
cmake_args += ['-G', supported_vsv[vsv]] | ||
cmake_args += ['-G', 'Visual Studio ' + str(major_version)] | ||
# choose 'x64' on VS 14 and 15 if not specified explicitly | ||
# since otherwise 'Win32' is the default for those | ||
# newer versions default to the host architecture | ||
if '-A' not in cmake_args and vsv in ('14.0', '15.0'): | ||
if '-A' not in cmake_args and major_version < 16: | ||
cmake_args += ['-A', 'x64'] | ||
if CMAKE_EXECUTABLE is None: | ||
raise RuntimeError("Could not find 'cmake' executable") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docblock should contain more information what kind of exceptions can be raised. This should use the
:raises ExceptionType: ...
style.