Select which version of Visual Studio projects to generate. Arguments: version: Hook to allow caller to force a particular version (vs auto). Returns: An object representing a visual studio project format version.
(version="auto", allow_fallback=True)
| 547 | |
| 548 | |
| 549 | def SelectVisualStudioVersion(version="auto", allow_fallback=True): |
| 550 | """Select which version of Visual Studio projects to generate. |
| 551 | |
| 552 | Arguments: |
| 553 | version: Hook to allow caller to force a particular version (vs auto). |
| 554 | Returns: |
| 555 | An object representing a visual studio project format version. |
| 556 | """ |
| 557 | # In auto mode, check environment variable for override. |
| 558 | if version == "auto": |
| 559 | version = os.environ.get("GYP_MSVS_VERSION", "auto") |
| 560 | version_map = { |
| 561 | "auto": ( |
| 562 | "18.0", |
| 563 | "17.0", |
| 564 | "16.0", |
| 565 | "15.0", |
| 566 | "14.0", |
| 567 | "12.0", |
| 568 | "10.0", |
| 569 | "9.0", |
| 570 | "8.0", |
| 571 | "11.0", |
| 572 | ), |
| 573 | "2005": ("8.0",), |
| 574 | "2005e": ("8.0",), |
| 575 | "2008": ("9.0",), |
| 576 | "2008e": ("9.0",), |
| 577 | "2010": ("10.0",), |
| 578 | "2010e": ("10.0",), |
| 579 | "2012": ("11.0",), |
| 580 | "2012e": ("11.0",), |
| 581 | "2013": ("12.0",), |
| 582 | "2013e": ("12.0",), |
| 583 | "2015": ("14.0",), |
| 584 | "2017": ("15.0",), |
| 585 | "2019": ("16.0",), |
| 586 | "2022": ("17.0",), |
| 587 | "2026": ("18.0",), |
| 588 | } |
| 589 | if override_path := os.environ.get("GYP_MSVS_OVERRIDE_PATH"): |
| 590 | msvs_version = os.environ.get("GYP_MSVS_VERSION") |
| 591 | if not msvs_version: |
| 592 | raise ValueError( |
| 593 | "GYP_MSVS_OVERRIDE_PATH requires GYP_MSVS_VERSION to be " |
| 594 | "set to a particular version (e.g. 2010e)." |
| 595 | ) |
| 596 | return _CreateVersion(msvs_version, override_path, sdk_based=True) |
| 597 | version = str(version) |
| 598 | versions = _DetectVisualStudioVersions(version_map[version], "e" in version) |
| 599 | if not versions: |
| 600 | if not allow_fallback: |
| 601 | raise ValueError("Could not locate Visual Studio installation.") |
| 602 | if version == "auto": |
| 603 | # Default to 2005 if we couldn't find anything |
| 604 | return _CreateVersion("2005", None) |
| 605 | else: |
| 606 | return _CreateVersion(version, None) |