2021-02-20 19:00:47 -06:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
2021-03-02 21:35:27 -06:00
|
|
|
#
|
|
|
|
# Copyright 2016 - 2021 gary@drinkingtea.net
|
|
|
|
#
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
#
|
|
|
|
|
2021-02-20 23:58:23 -06:00
|
|
|
# "Python Busy Box" - adds cross platform equivalents to Unix commands that
|
|
|
|
# don't translate well to that other operating system
|
|
|
|
|
2021-02-20 19:00:47 -06:00
|
|
|
import os
|
2021-02-20 20:03:54 -06:00
|
|
|
import shutil
|
2021-02-20 23:48:30 -06:00
|
|
|
import subprocess
|
2021-02-20 19:00:47 -06:00
|
|
|
import sys
|
|
|
|
|
2021-02-21 00:30:14 -06:00
|
|
|
|
2021-10-27 01:20:33 -05:00
|
|
|
def cat(paths: 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
|
2021-07-09 19:29:45 -05:00
|
|
|
|
|
|
|
|
2021-10-27 01:20:33 -05:00
|
|
|
def mkdir(path: str) -> int:
|
2021-02-20 19:00:47 -06:00
|
|
|
if not os.path.exists(path) and os.path.isdir(path):
|
|
|
|
os.mkdir(path)
|
2021-07-30 19:34:11 -05:00
|
|
|
return 0
|
2021-02-20 19:00:47 -06:00
|
|
|
|
2021-07-09 19:29:45 -05:00
|
|
|
|
2021-02-20 23:48:30 -06:00
|
|
|
# this exists because Windows is utterly incapable of providing a proper rm -rf
|
2021-10-27 01:20:33 -05:00
|
|
|
def rm(path: str) -> int:
|
2021-02-20 20:03:54 -06:00
|
|
|
if (os.path.exists(path) or os.path.islink(path)) and not os.path.isdir(path):
|
2021-02-20 19:00:47 -06:00
|
|
|
os.remove(path)
|
2021-02-20 20:03:54 -06:00
|
|
|
elif os.path.isdir(path):
|
|
|
|
shutil.rmtree(path)
|
2021-07-30 19:34:11 -05:00
|
|
|
return 0
|
2021-02-20 19:00:47 -06:00
|
|
|
|
2021-07-09 19:29:45 -05:00
|
|
|
|
2021-10-27 01:20:33 -05:00
|
|
|
def ctest_all() -> int:
|
2021-07-30 19:34:11 -05:00
|
|
|
base_path = sys.argv[2]
|
2021-07-30 00:00:03 -05:00
|
|
|
if not os.path.isdir(base_path):
|
2021-07-30 19:34:11 -05:00
|
|
|
# no generated projects
|
2021-07-30 00:00:03 -05:00
|
|
|
return 0
|
2021-07-30 19:34:11 -05:00
|
|
|
args = ['ctest'] + sys.argv[3:]
|
2021-07-30 00:00:03 -05:00
|
|
|
orig_dir = os.getcwd()
|
|
|
|
for d in os.listdir(base_path):
|
|
|
|
os.chdir(os.path.join(orig_dir, base_path, d))
|
|
|
|
err = subprocess.run(args).returncode
|
|
|
|
if err != 0:
|
|
|
|
return err
|
2021-07-30 19:34:11 -05:00
|
|
|
return 0
|
2021-07-30 00:00:03 -05:00
|
|
|
|
|
|
|
|
2021-10-27 01:20:33 -05:00
|
|
|
def cmake_build(base_path: str, target: str) -> int:
|
2021-03-27 22:56:13 -05:00
|
|
|
if not os.path.isdir(base_path):
|
|
|
|
# nothing to build
|
|
|
|
return 0
|
2021-02-20 23:48:30 -06:00
|
|
|
for d in os.listdir(base_path):
|
2021-03-27 23:16:04 -05:00
|
|
|
args = ['cmake', '--build', os.path.join(base_path, d)]
|
2021-02-20 23:48:30 -06:00
|
|
|
if target is not None:
|
2021-03-27 23:16:04 -05:00
|
|
|
args.extend(['--target', target])
|
2021-02-20 23:48:30 -06:00
|
|
|
err = subprocess.run(args).returncode
|
|
|
|
if err != 0:
|
2021-03-27 22:56:13 -05:00
|
|
|
return err
|
2021-07-30 19:34:11 -05:00
|
|
|
return 0
|
2021-02-20 23:48:30 -06:00
|
|
|
|
2021-07-09 19:29:45 -05:00
|
|
|
|
2021-12-17 20:55:15 -06:00
|
|
|
def conan() -> int:
|
|
|
|
project_name = sys.argv[2]
|
|
|
|
conan_dir = '.conanbuild'
|
|
|
|
err = mkdir(conan_dir)
|
|
|
|
if err != 0:
|
|
|
|
return err
|
|
|
|
args = ['conan', 'install', '../', '--build=missing', '-pr', project_name]
|
|
|
|
os.chdir(conan_dir)
|
|
|
|
err = subprocess.run(args).returncode
|
|
|
|
if err != 0:
|
|
|
|
return err
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2021-02-21 00:30:14 -06:00
|
|
|
def main():
|
2021-10-27 01:20:33 -05:00
|
|
|
err = 0
|
2021-02-20 23:48:30 -06:00
|
|
|
if sys.argv[1] == 'mkdir':
|
2021-10-27 01:20:33 -05:00
|
|
|
err = mkdir(sys.argv[2])
|
2021-02-20 23:48:30 -06:00
|
|
|
elif sys.argv[1] == 'rm':
|
|
|
|
for i in range(2, len(sys.argv)):
|
|
|
|
rm(sys.argv[i])
|
2021-12-17 20:55:15 -06:00
|
|
|
elif sys.argv[1] == 'conan-install':
|
|
|
|
err = conan()
|
2021-07-30 19:34:11 -05:00
|
|
|
elif sys.argv[1] == 'ctest-all':
|
|
|
|
err = ctest_all()
|
2021-02-20 23:48:30 -06:00
|
|
|
elif sys.argv[1] == 'cmake-build':
|
2021-03-27 22:56:13 -05:00
|
|
|
err = cmake_build(sys.argv[2], sys.argv[3] if len(sys.argv) > 3 else None)
|
2021-07-09 19:29:45 -05:00
|
|
|
elif sys.argv[1] == 'cat':
|
2021-10-27 01:20:33 -05:00
|
|
|
err = cat(sys.argv[2:])
|
|
|
|
sys.exit(err)
|
2021-07-09 19:29:45 -05:00
|
|
|
|
2021-02-21 00:30:14 -06:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(1)
|