Compare commits
3 Commits
8371f96d4a
...
43503dfec6
Author | SHA1 | Date | |
---|---|---|---|
43503dfec6 | |||
7916566d47 | |||
b47ceb81dc |
@ -255,11 +255,7 @@ def _lib_filename(env: Environment, name: str, type: str = 'static') -> str:
|
|||||||
}[type]
|
}[type]
|
||||||
return f'lib{name}.{ext}'
|
return f'lib{name}.{ext}'
|
||||||
elif os.name == 'nt':
|
elif os.name == 'nt':
|
||||||
ext = {
|
return f'{name}.lib'
|
||||||
'static': 'lib',
|
|
||||||
'shared': 'dll'
|
|
||||||
}[type]
|
|
||||||
return f'{name}.{ext}'
|
|
||||||
else:
|
else:
|
||||||
raise Exception('What OS is this?')
|
raise Exception('What OS is this?')
|
||||||
|
|
||||||
|
@ -105,6 +105,7 @@ def _cmake_project(env: Environment, project_root: str, generate_args: 'list[str
|
|||||||
libpath.append(full_path)
|
libpath.append(full_path)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
'build_dir': build_dir,
|
||||||
'install_dir': install_dir,
|
'install_dir': install_dir,
|
||||||
'BINPATH': [os.path.join(install_dir, 'bin')],
|
'BINPATH': [os.path.join(install_dir, 'bin')],
|
||||||
'LIBPATH': libpath,
|
'LIBPATH': libpath,
|
||||||
|
@ -3,6 +3,8 @@ from git import Repo
|
|||||||
from git.exc import GitError
|
from git.exc import GitError
|
||||||
import hashlib
|
import hashlib
|
||||||
import inspect
|
import inspect
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
from SCons.Script import *
|
from SCons.Script import *
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
@ -20,7 +22,41 @@ def _clone(env: Environment, repo_name: str, remote_url: str):
|
|||||||
|
|
||||||
def _git_branch(env: Environment, repo_name: str, remote_url: str, git_ref: str = 'main') -> dict:
|
def _git_branch(env: Environment, repo_name: str, remote_url: str, git_ref: str = 'main') -> dict:
|
||||||
repo, origin = _clone(env, repo_name, remote_url)
|
repo, origin = _clone(env, repo_name, remote_url)
|
||||||
worktree_dir = os.path.join(env['CLONE_DIR'], 'git', repo_name, hashlib.shake_128(git_ref.encode('utf-8')).hexdigest(6)) # TODO: commit hash would be better, right? -> not if it's a branch!
|
old_worktree_dir = os.path.join(env['CLONE_DIR'], 'git', repo_name, hashlib.shake_128(git_ref.encode('utf-8')).hexdigest(6))
|
||||||
|
worktree_dir = os.path.join(env['CLONE_DIR'], 'git', repo_name, git_ref.replace('/', '_'))
|
||||||
|
if os.path.exists(old_worktree_dir) and not os.path.islink(old_worktree_dir):
|
||||||
|
if not os.path.exists(worktree_dir):
|
||||||
|
print(f'Found old Git worktree at {old_worktree_dir}, moving it to {worktree_dir}.')
|
||||||
|
try:
|
||||||
|
repo.git.worktree('move', old_worktree_dir, worktree_dir)
|
||||||
|
except GitError:
|
||||||
|
print('Error while moving worktree, manually moving and repairing it instead.')
|
||||||
|
shutil.move(old_worktree_dir, worktree_dir)
|
||||||
|
try:
|
||||||
|
repo.git.worktree('repair', worktree_dir)
|
||||||
|
except GitError:
|
||||||
|
print('Also didn\'t work, removing and redownloading it.')
|
||||||
|
try:
|
||||||
|
repo.git.worktree('remove', '-f', worktree_dir)
|
||||||
|
except GitError: ...
|
||||||
|
|
||||||
|
try:
|
||||||
|
repo.git.worktree('remove', '-f', old_worktree_dir)
|
||||||
|
except GitError: ...
|
||||||
|
|
||||||
|
if os.path.exists(worktree_dir):
|
||||||
|
shutil.rmtree(worktree_dir, ignore_errors=True)
|
||||||
|
# this is all we can do, I guess
|
||||||
|
else:
|
||||||
|
print(f'Found old Git worktree at {old_worktree_dir}, but the new one at {worktree_dir} already exists. Removing the old one.')
|
||||||
|
repo.git.worktree('remove', '-f', old_worktree_dir)
|
||||||
|
|
||||||
|
print('Attempting to create a symlink for older S++ versions.')
|
||||||
|
try:
|
||||||
|
os.symlink(worktree_dir, old_worktree_dir, target_is_directory=True)
|
||||||
|
except Exception as e:
|
||||||
|
print(f'Failed: {e}')
|
||||||
|
|
||||||
update_submodules = False
|
update_submodules = False
|
||||||
if not os.path.exists(worktree_dir):
|
if not os.path.exists(worktree_dir):
|
||||||
print(f'Checking out into {worktree_dir}.')
|
print(f'Checking out into {worktree_dir}.')
|
||||||
@ -38,9 +74,17 @@ def _git_branch(env: Environment, repo_name: str, remote_url: str, git_ref: str
|
|||||||
update_submodules = True
|
update_submodules = True
|
||||||
else:
|
else:
|
||||||
print(f'Not updating git repository {worktree_dir} as it is not on a branch.')
|
print(f'Not updating git repository {worktree_dir} as it is not on a branch.')
|
||||||
|
else:
|
||||||
|
worktree_repo = Repo(worktree_dir)
|
||||||
if update_submodules:
|
if update_submodules:
|
||||||
for submodule in worktree_repo.submodules:
|
for submodule in worktree_repo.submodules:
|
||||||
submodule.update(init=True)
|
submodule.update(init=True)
|
||||||
|
for submodule in worktree_repo.submodules:
|
||||||
|
if os.listdir(submodule.abspath) == ['.git']:
|
||||||
|
print(f'Submodule {submodule.name} seems borked, attempting to fix it.')
|
||||||
|
worktree_repo.git.submodule('deinit', '-f', submodule.path)
|
||||||
|
worktree_repo.git.submodule('init', submodule.path)
|
||||||
|
worktree_repo.git.submodule('update', submodule.path)
|
||||||
return {
|
return {
|
||||||
'checkout_root': worktree_dir,
|
'checkout_root': worktree_dir,
|
||||||
'repo': repo,
|
'repo': repo,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user