Skip to content

Commit 0b0a8ca

Browse files
authored
Merge pull request #60 from Vipon/win_setup_update
Fix windows setup scripts. Improve work with PATH. PATH in windows environment properly updated throught the winreg.
2 parents f7a4d89 + 4c2f4f1 commit 0b0a8ca

File tree

7 files changed

+77
-15
lines changed

7 files changed

+77
-15
lines changed

.github/workflows/main.yml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ jobs:
55
steps:
66
- name: Checkout
77
uses: actions/checkout@v4
8+
- name: Install Python
9+
uses: actions/setup-python@v5
10+
with:
11+
python-version: '3.10'
812
- name: Set Env Variables
913
uses: ./.github/actions/set_env_var
1014
with:
1115
shell: bash
1216
path: ${HOME}/.local/bin
13-
cpath: ${HOME}/.local/include:/usr/local/opt/argp-standalone/include:${CPATH}
14-
library_path: ${HOME}/.local/lib:/usr/local/opt/argp-standalone/lib/:${LIBRARY_PATH}
17+
cpath: ${HOME}/.local/include:/opt/homebrew/include:${CPATH}
18+
library_path: ${HOME}/.local/lib:/opt/homebrew/lib/:${LIBRARY_PATH}
1519
- run: ./setup.sh
1620
- name: Configure Debug Xcode
1721
run: ./configure
@@ -25,13 +29,17 @@ jobs:
2529
steps:
2630
- name: Checkout
2731
uses: actions/checkout@v4
32+
- name: Install Python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: '3.10'
2836
- name: Set Env Variables
2937
uses: ./.github/actions/set_env_var
3038
with:
3139
shell: bash
3240
path: ${HOME}/.local/bin
33-
cpath: ${HOME}/.local/include:/usr/local/opt/argp-standalone/include:${CPATH}
34-
library_path: ${HOME}/.local/lib:/usr/local/opt/argp-standalone/lib/:${LIBRARY_PATH}
41+
cpath: ${HOME}/.local/include:/opt/homebrew/include:${CPATH}
42+
library_path: ${HOME}/.local/lib:/opt/homebrew/lib/:${LIBRARY_PATH}
3543
- run: ./setup.sh
3644
- name: Configure Debug Gmake
3745
run: ./configure --gmake --output gmake
@@ -45,13 +53,17 @@ jobs:
4553
steps:
4654
- name: Checkout
4755
uses: actions/checkout@v4
56+
- name: Install Python
57+
uses: actions/setup-python@v5
58+
with:
59+
python-version: '3.10'
4860
- name: Set Env Variables
4961
uses: ./.github/actions/set_env_var
5062
with:
5163
shell: bash
5264
path: ${HOME}/.local/bin
53-
cpath: ${HOME}/.local/include:/usr/local/opt/argp-standalone/include:${CPATH}
54-
library_path: ${HOME}/.local/lib:/usr/local/opt/argp-standalone/lib/:${LIBRARY_PATH}
65+
cpath: ${HOME}/.local/include:/opt/homebrew/include:${CPATH}
66+
library_path: ${HOME}/.local/lib:/opt/homebrew/lib/:${LIBRARY_PATH}
5567
- run: ./setup.sh
5668
- name: Configure Debug Ninja
5769
run: ./configure --ninja --output ninja
@@ -65,13 +77,17 @@ jobs:
6577
steps:
6678
- name: Checkout
6779
uses: actions/checkout@v4
80+
- name: Install Python
81+
uses: actions/setup-python@v5
82+
with:
83+
python-version: '3.10'
6884
- name: Set Env Variables
6985
uses: ./.github/actions/set_env_var
7086
with:
7187
shell: bash
7288
path: ${HOME}/.local/bin
73-
cpath: ${HOME}/.local/include:/usr/local/opt/argp-standalone/include:${CPATH}
74-
library_path: ${HOME}/.local/lib:/usr/local/opt/argp-standalone/lib/:${LIBRARY_PATH}
89+
cpath: ${HOME}/.local/include:/opt/homebrew/include:${CPATH}
90+
library_path: ${HOME}/.local/lib:/opt/homebrew/lib/:${LIBRARY_PATH}
7591
- run: ./setup.sh
7692
- name: Configure Gmake Release
7793
run: ./configure --gmake --release --output gmake_release

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ output/*
44
*.tar.gz
55
.cache/*
66
.DS_Store
7+
*.zip
8+
*.msi

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,11 @@
147147
"editor.insertSpaces": true,
148148

149149
// When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.
150-
"editor.detectIndentation": false
150+
"editor.detectIndentation": false,
151+
152+
// Show WhiteSpases
153+
"editor.renderWhitespace": "all",
154+
155+
// Remove Trailing WhiteSpases
156+
"files.trimTrailingWhitespace": true
151157
}

python/setupEnv/setupEnv

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# SOFTWARE.
2424

2525
import sys
26+
import os
2627
from os.path import dirname, realpath, join, isabs
2728
curDir = dirname(realpath(__file__))
2829
vpyDir = dirname(curDir)
@@ -35,7 +36,7 @@ from typing import List
3536
from vpy.cmd import execCmd
3637
from vpy.importHelp import installImport
3738
from vpy.type import isStr, isList, isDict
38-
from vpy.os import execForOs
39+
from vpy.os import execForOs, get_user_path
3940

4041
installImport('yaml', 'pyyaml')
4142
import yaml
@@ -268,7 +269,14 @@ class SetUpQueue:
268269
if i.dir is not None:
269270
args += ['--install-prefix', i.dir]
270271
print(f'Installing {i.name}:', flush=True)
271-
execCmd(args)
272+
env = None
273+
if os.name == "nt":
274+
# Previous installations can update user's PATH
275+
env = dict(os.environ)
276+
for p in get_user_path().split(';'):
277+
if not p in env['PATH']:
278+
env['PATH'] = env['PATH'] + p + ';'
279+
execCmd(args, env)
272280

273281
i.status = SetUpQueue.SetUpInstance.InstanceState.INSTALLED
274282

python/setupEnv/tools/capstone/install.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def buildAndInstallCapstone():
7979
, '..'
8080
]
8181
env = dict(os.environ)
82-
env['CFLAGS'] = '-fpic'
82+
if os.name != 'nt':
83+
env['CFLAGS'] = '-fpic'
8384
execCmd(cmd, env)
8485

8586
if isWin():

python/vpy/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25-
import subprocess
25+
from . import cmd as cmd
2626

2727
GIT_BIN = 'git'
2828

2929
def clone(args: [str]):
3030
args = [GIT_BIN, 'clone'] + args
31-
subprocess.run(args)
31+
cmd.execCmd(args, captureOut=True)
3232

python/vpy/os.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import os
2626
import platform
27+
if os.name == 'nt':
28+
import winreg
2729

2830
from . import apt as apt
2931
from . import brew as brew
@@ -80,11 +82,38 @@ def getForOs(linux=None, mac=None, win=None):
8082
else:
8183
raise 'Unknown OS'
8284

85+
def get_user_path() -> str:
86+
def get_win_user_path() -> str:
87+
# Get the current user registry
88+
root = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
89+
# Go to the environment key
90+
key = winreg.OpenKey(root, 'Environment', 0, winreg.KEY_ALL_ACCESS)
91+
# Grab the current path value
92+
return winreg.QueryValueEx(key, 'PATH')[0]
93+
def get_nix_user_path() -> str:
94+
return ''
95+
96+
return execForOs( linux = get_nix_user_path
97+
, mac = get_nix_user_path
98+
, win = get_win_user_path
99+
)
100+
83101
def appendPath(newPath):
84102
def appendNixPath():
85103
return
86104
def appendWinPath():
87-
os.system(f'setx path "%path%;{newPath}"')
105+
# Get the current user registry
106+
root = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
107+
# Go to the environment key
108+
key = winreg.OpenKey(root, 'Environment', 0, winreg.KEY_ALL_ACCESS)
109+
# Grab the current path value
110+
path = winreg.QueryValueEx(key, 'PATH')[0]
111+
if newPath in path:
112+
return
113+
# Takes the current path value and appends the new program path
114+
new_path = path + newPath + ';'
115+
# Updated the path with the updated path
116+
winreg.SetValueEx(key, 'PATH', 0, winreg.REG_EXPAND_SZ, new_path)
88117

89118
execForOs(
90119
linux = appendNixPath,

0 commit comments

Comments
 (0)