-
Notifications
You must be signed in to change notification settings - Fork 46
ci: replace msvc-dev-cmd with WIP vanilla bat #409
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
Open
VJanKraemer
wants to merge
2
commits into
main
Choose a base branch
from
remove_msvc_cmd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #! /bin/env python3 | ||
|
|
||
| # SPDX-FileCopyrightText: 2025 Vector Informatik GmbH | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| import subprocess | ||
| import json | ||
| import logging | ||
| import os | ||
| import argparse | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
| handler = logging.StreamHandler() | ||
| logger.addHandler(handler) | ||
| logger.setLevel(logging.DEBUG) | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| def find_VsDevCmd() -> str: | ||
|
|
||
| some_out = subprocess.run( | ||
| ["vswhere", "-latest", "-property", "InstallationPath"], | ||
| capture_output=True, encoding="utf-8", check=True) | ||
|
|
||
| print(some_out.stdout) | ||
|
|
||
|
|
||
| return Path(some_out.stdout.rstrip()) / r'Common7\Tools\VsDevCmd.bat' | ||
|
|
||
| def main(): | ||
|
|
||
| parser = argparse.ArgumentParser(prog="Microsoft Dev Env Creator", | ||
| description="Setup the development environment under Windows") | ||
| parser.add_argument('--arch', type=str, default='x64', | ||
| help='The architecture for which to build the binary for') | ||
| parser.add_argument('--hostarch', type=str, default='x64', | ||
| help='The architecture of the host build machine') | ||
| parser.add_argument('--vcvars_ver', type=str, default='14.2', | ||
| help='The version of the toolset to be used') | ||
| args = parser.parse_args() | ||
|
|
||
| vsdevcmd_path = find_VsDevCmd() | ||
|
|
||
| vsdevcmd = f'"{vsdevcmd_path}" -arch={args.arch} -host_arch={args.hostarch} -vcvars_ver={args.vcvars_ver}' | ||
|
|
||
| logger.debug(f"Executing cmd:\n{vsdevcmd}") | ||
|
|
||
| osenvcmd = '( python -c "import os, json; print(json.dumps(dict(os.environ)))" )' | ||
| print(f"Found at: {vsdevcmd_path}") | ||
| vsdevcmd_proc = subprocess.run( | ||
| executable=r'C:\Windows\System32\cmd.exe', | ||
| args=f'/S /C "( ( {vsdevcmd} >NUL 2>&1 ) && {osenvcmd} ) & exit"', | ||
| capture_output=True, encoding="utf-8", check=False) | ||
|
|
||
| new_env = vsdevcmd_proc.stdout | ||
| logger.debug(f"New Env:\n{new_env}") | ||
| logger.debug(f"Old Env: \n{json.dumps(dict(os.environ), indent=2)}") | ||
| if not new_env: | ||
| logger.error("Could not acquire a new shell env!") | ||
| exit(1) | ||
|
|
||
| environment = json.loads(vsdevcmd_proc.stdout) | ||
|
|
||
| with open(os.environ['GITHUB_ENV'], 'a') as f: | ||
| for k, v in environment.items(): | ||
| logger.debug(f"updating environment variable {k!r} = {v!r}") | ||
|
|
||
| if not v.startswith(('GITHUB_', 'RUNNER_', 'CI')): | ||
| f.write(f"{k}={v}\n") | ||
|
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
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.
Before 'publishing' the new environment to
GITHUB_ENV, we should filter out any environment variable starting withGITHUB_,RUNNER_, and theCIvariable.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.
Good idea
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.
Done