[buildcore] Add ability to setup host specific build directories

This commit is contained in:
2022-11-23 00:04:42 -06:00
parent 52efae287b
commit 94c663ff77
3 changed files with 55 additions and 29 deletions

View File

@ -12,25 +12,13 @@
# don't translate well to that other operating system
import os
import platform
import shutil
import subprocess
import sys
from typing import List, Optional
def cat(paths: List[str]) -> int:
for path in paths:
try:
with open(path) as f:
data = f.read()
sys.stdout.write(data)
except FileNotFoundError:
sys.stderr.write('cat: {}: no such file or directory\n'.format(path))
return 1
sys.stdout.write('\n')
return 0
def mkdir(path: str):
if not os.path.exists(path):
os.mkdir(path)
@ -91,6 +79,31 @@ def conan() -> int:
return 0
def cat(paths: List[str]) -> int:
for path in paths:
try:
with open(path) as f:
data = f.read()
sys.stdout.write(data)
except FileNotFoundError:
sys.stderr.write('cat: {}: no such file or directory\n'.format(path))
return 1
sys.stdout.write('\n')
return 0
def get_env(var_name: str) -> int:
if var_name not in os.environ:
return 1
sys.stdout.write(os.environ[var_name])
return 0
def hostname() -> int:
sys.stdout.write(platform.node())
return 0
def main() -> int:
err = 0
if sys.argv[1] == 'mkdir':
@ -109,6 +122,10 @@ def main() -> int:
err = cmake_build(sys.argv[2], sys.argv[3] if len(sys.argv) > 3 else None)
elif sys.argv[1] == 'cat':
err = cat(sys.argv[2:])
elif sys.argv[1] == 'getenv':
err = get_env(sys.argv[2])
elif sys.argv[1] == 'hostname':
err = hostname()
else:
sys.stderr.write('Command not found\n')
err = 1
@ -117,7 +134,6 @@ def main() -> int:
if __name__ == '__main__':
try:
err = main()
sys.exit(err)
sys.exit(main())
except KeyboardInterrupt:
sys.exit(err)
sys.exit(1)

View File

@ -24,6 +24,7 @@ def main() -> int:
default='{:s}-{:s}'.format(sys.platform, platform.machine()))
parser.add_argument('--build_type', help='Build type (asan,debug,release)', default='release')
parser.add_argument('--build_tool', help='Build tool (default,xcode)', default='')
parser.add_argument('--build_root', help='Path to the root of build directories (must be in project dir)', default='build')
parser.add_argument('--toolchain', help='Path to CMake toolchain file', default='')
parser.add_argument('--current_build', help='Indicates whether or not to make this the active build', default=1)
args = parser.parse_args()
@ -63,7 +64,7 @@ def main() -> int:
return 1
project_dir = os.getcwd()
build_dir = '{:s}/build/{:s}'.format(project_dir, build_config)
build_dir = '{:s}/{:s}/{:s}'.format(project_dir, args.build_root, build_config)
rm(build_dir)
cmake_cmd = [
'cmake', '-S', project_dir, '-B', build_dir, build_tool,
@ -89,7 +90,7 @@ def main() -> int:
rm('compile_commands.json')
if platform.system() != 'Windows':
os.symlink('build/{:s}/compile_commands.json'.format(build_config), 'compile_commands.json')
os.symlink('{:s}/compile_commands.json'.format(build_dir), 'compile_commands.json')
return 0