Skip to content

Commit

Permalink
Merge pull request #60 from Vipon/win_setup_update
Browse files Browse the repository at this point in the history
Fix windows setup scripts. 

Improve work with PATH. PATH in windows environment properly updated
throught the winreg.
  • Loading branch information
Vipon committed May 19, 2024
2 parents f7a4d89 + 4c2f4f1 commit 0b0a8ca
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 15 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Set Env Variables
uses: ./.github/actions/set_env_var
with:
shell: bash
path: ${HOME}/.local/bin
cpath: ${HOME}/.local/include:/usr/local/opt/argp-standalone/include:${CPATH}
library_path: ${HOME}/.local/lib:/usr/local/opt/argp-standalone/lib/:${LIBRARY_PATH}
cpath: ${HOME}/.local/include:/opt/homebrew/include:${CPATH}
library_path: ${HOME}/.local/lib:/opt/homebrew/lib/:${LIBRARY_PATH}
- run: ./setup.sh
- name: Configure Debug Xcode
run: ./configure
Expand All @@ -25,13 +29,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Set Env Variables
uses: ./.github/actions/set_env_var
with:
shell: bash
path: ${HOME}/.local/bin
cpath: ${HOME}/.local/include:/usr/local/opt/argp-standalone/include:${CPATH}
library_path: ${HOME}/.local/lib:/usr/local/opt/argp-standalone/lib/:${LIBRARY_PATH}
cpath: ${HOME}/.local/include:/opt/homebrew/include:${CPATH}
library_path: ${HOME}/.local/lib:/opt/homebrew/lib/:${LIBRARY_PATH}
- run: ./setup.sh
- name: Configure Debug Gmake
run: ./configure --gmake --output gmake
Expand All @@ -45,13 +53,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Set Env Variables
uses: ./.github/actions/set_env_var
with:
shell: bash
path: ${HOME}/.local/bin
cpath: ${HOME}/.local/include:/usr/local/opt/argp-standalone/include:${CPATH}
library_path: ${HOME}/.local/lib:/usr/local/opt/argp-standalone/lib/:${LIBRARY_PATH}
cpath: ${HOME}/.local/include:/opt/homebrew/include:${CPATH}
library_path: ${HOME}/.local/lib:/opt/homebrew/lib/:${LIBRARY_PATH}
- run: ./setup.sh
- name: Configure Debug Ninja
run: ./configure --ninja --output ninja
Expand All @@ -65,13 +77,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Set Env Variables
uses: ./.github/actions/set_env_var
with:
shell: bash
path: ${HOME}/.local/bin
cpath: ${HOME}/.local/include:/usr/local/opt/argp-standalone/include:${CPATH}
library_path: ${HOME}/.local/lib:/usr/local/opt/argp-standalone/lib/:${LIBRARY_PATH}
cpath: ${HOME}/.local/include:/opt/homebrew/include:${CPATH}
library_path: ${HOME}/.local/lib:/opt/homebrew/lib/:${LIBRARY_PATH}
- run: ./setup.sh
- name: Configure Gmake Release
run: ./configure --gmake --release --output gmake_release
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ output/*
*.tar.gz
.cache/*
.DS_Store
*.zip
*.msi
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,11 @@
"editor.insertSpaces": true,

// When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.
"editor.detectIndentation": false
"editor.detectIndentation": false,

// Show WhiteSpases
"editor.renderWhitespace": "all",

// Remove Trailing WhiteSpases
"files.trimTrailingWhitespace": true
}
12 changes: 10 additions & 2 deletions python/setupEnv/setupEnv
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# SOFTWARE.

import sys
import os
from os.path import dirname, realpath, join, isabs
curDir = dirname(realpath(__file__))
vpyDir = dirname(curDir)
Expand All @@ -35,7 +36,7 @@ from typing import List
from vpy.cmd import execCmd
from vpy.importHelp import installImport
from vpy.type import isStr, isList, isDict
from vpy.os import execForOs
from vpy.os import execForOs, get_user_path

installImport('yaml', 'pyyaml')
import yaml
Expand Down Expand Up @@ -268,7 +269,14 @@ class SetUpQueue:
if i.dir is not None:
args += ['--install-prefix', i.dir]
print(f'Installing {i.name}:', flush=True)
execCmd(args)
env = None
if os.name == "nt":
# Previous installations can update user's PATH
env = dict(os.environ)
for p in get_user_path().split(';'):
if not p in env['PATH']:
env['PATH'] = env['PATH'] + p + ';'
execCmd(args, env)

i.status = SetUpQueue.SetUpInstance.InstanceState.INSTALLED

Expand Down
3 changes: 2 additions & 1 deletion python/setupEnv/tools/capstone/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def buildAndInstallCapstone():
, '..'
]
env = dict(os.environ)
env['CFLAGS'] = '-fpic'
if os.name != 'nt':
env['CFLAGS'] = '-fpic'
execCmd(cmd, env)

if isWin():
Expand Down
4 changes: 2 additions & 2 deletions python/vpy/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import subprocess
from . import cmd as cmd

GIT_BIN = 'git'

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

31 changes: 30 additions & 1 deletion python/vpy/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import os
import platform
if os.name == 'nt':
import winreg

from . import apt as apt
from . import brew as brew
Expand Down Expand Up @@ -80,11 +82,38 @@ def getForOs(linux=None, mac=None, win=None):
else:
raise 'Unknown OS'

def get_user_path() -> str:
def get_win_user_path() -> str:
# Get the current user registry
root = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
# Go to the environment key
key = winreg.OpenKey(root, 'Environment', 0, winreg.KEY_ALL_ACCESS)
# Grab the current path value
return winreg.QueryValueEx(key, 'PATH')[0]
def get_nix_user_path() -> str:
return ''

return execForOs( linux = get_nix_user_path
, mac = get_nix_user_path
, win = get_win_user_path
)

def appendPath(newPath):
def appendNixPath():
return
def appendWinPath():
os.system(f'setx path "%path%;{newPath}"')
# Get the current user registry
root = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
# Go to the environment key
key = winreg.OpenKey(root, 'Environment', 0, winreg.KEY_ALL_ACCESS)
# Grab the current path value
path = winreg.QueryValueEx(key, 'PATH')[0]
if newPath in path:
return
# Takes the current path value and appends the new program path
new_path = path + newPath + ';'
# Updated the path with the updated path
winreg.SetValueEx(key, 'PATH', 0, winreg.REG_EXPAND_SZ, new_path)

execForOs(
linux = appendNixPath,
Expand Down

0 comments on commit 0b0a8ca

Please sign in to comment.