Update to new buildcore

This commit is contained in:
Gary Talent 2023-07-16 22:50:14 -05:00
parent 6c00d960bd
commit a8327b2b67
4 changed files with 86 additions and 54 deletions

View File

@ -44,12 +44,13 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-field-initializers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnull-dereference")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-null-dereference")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-variable")
# release build options

View File

@ -1,5 +1,5 @@
#
# Copyright 2016 - 2021 gary@drinkingtea.net
# Copyright 2016 - 2023 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
@ -24,7 +24,7 @@ ifneq ($(shell which docker 2> /dev/null),)
endif
endif
ifneq ($(shell which python3 2> /dev/null),)
ifneq ($(shell ${ENV_RUN} which python3 2> /dev/null),)
PYTHON3=python3
else
ifeq ($(shell ${ENV_RUN} python -c 'import sys; print(sys.version_info[0])'),3)
@ -36,8 +36,16 @@ SCRIPTS=${BUILDCORE_PATH}/scripts
SETUP_BUILD=${PYTHON3} ${SCRIPTS}/setup-build.py
PYBB=${PYTHON3} ${SCRIPTS}/pybb.py
CMAKE_BUILD=${PYBB} cmake-build
GET_ENV=${PYBB} getenv
CTEST=${PYBB} ctest-all
RM_RF=${PYBB} rm
HOST=$(shell ${PYBB} hostname)
BUILDCORE_HOST_SPECIFIC_BUILDPATH=$(shell ${GET_ENV} BUILDCORE_HOST_SPECIFIC_BUILDPATH)
ifneq (${BUILDCORE_HOST_SPECIFIC_BUILDPATH},)
BUILD_PATH=build/${HOST}
else
BUILD_PATH=build
endif
ifdef USE_VCPKG
ifndef VCPKG_DIR_BASE
VCPKG_DIR_BASE=.vcpkg
@ -54,31 +62,32 @@ else
endif
VCPKG_DIR=$(VCPKG_DIR_BASE)/$(VCPKG_VERSION)-$(HOST_ENV)
CURRENT_BUILD=$(HOST_ENV)-$(shell ${PYBB} cat .current_build)
CURRENT_BUILD=$(HOST_ENV)-$(shell ${ENV_RUN} ${PYBB} cat .current_build)
.PHONY: build
build:
${ENV_RUN} ${CMAKE_BUILD} build
${ENV_RUN} ${CMAKE_BUILD} ${BUILD_PATH}
.PHONY: install
install:
${ENV_RUN} ${CMAKE_BUILD} build install
${ENV_RUN} ${CMAKE_BUILD} ${BUILD_PATH} install
.PHONY: clean
clean:
${ENV_RUN} ${CMAKE_BUILD} build clean
${ENV_RUN} ${CMAKE_BUILD} ${BUILD_PATH} clean
.PHONY: purge
purge:
${ENV_RUN} ${RM_RF} .current_build
${ENV_RUN} ${RM_RF} build
${ENV_RUN} ${RM_RF} ${BUILD_PATH}
${ENV_RUN} ${RM_RF} dist
.PHONY: test
test: build
${ENV_RUN} ${CMAKE_BUILD} build test
${ENV_RUN} mypy ${SCRIPTS}
${ENV_RUN} ${CMAKE_BUILD} ${BUILD_PATH} test
.PHONY: test-verbose
test-verbose: build
${ENV_RUN} ${CTEST} build --output-on-failure
${ENV_RUN} ${CTEST} ${BUILD_PATH} --output-on-failure
.PHONY: test-rerun-verbose
test-rerun-verbose: build
${ENV_RUN} ${CTEST} build --rerun-failed --output-on-failure
${ENV_RUN} ${CTEST} ${BUILD_PATH} --rerun-failed --output-on-failure
.PHONY: devenv-image
devenv-image:
@ -146,19 +155,21 @@ conan:
${ENV_RUN} ${PYBB} conan-install ${PROJECT_NAME}
endif # USE_VCPKG ###############################################
ifeq (${OS},darwin)
.PHONY: configure-xcode
configure-xcode:
${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_tool=xcode --current_build=0
${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_tool=xcode --current_build=0 --build_root=${BUILD_PATH}
endif
.PHONY: configure-release
configure-release:
${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=release
${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=release --build_root=${BUILD_PATH}
.PHONY: configure-debug
configure-debug:
${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=debug
${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=debug --build_root=${BUILD_PATH}
.PHONY: configure-asan
configure-asan:
${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=asan
${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=asan --build_root=${BUILD_PATH}

View File

@ -12,43 +12,24 @@
# 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: [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) -> int:
def mkdir(path: str):
if not os.path.exists(path):
try:
os.mkdir(path)
except:
return 1
return 0
if os.path.isdir(path):
return 0
return 1
# this exists because Windows is utterly incapable of providing a proper rm -rf
def rm(path: str) -> int:
def rm(path: str):
if (os.path.exists(path) or os.path.islink(path)) and not os.path.isdir(path):
os.remove(path)
elif os.path.isdir(path):
shutil.rmtree(path)
return 0
def ctest_all() -> int:
@ -66,12 +47,15 @@ def ctest_all() -> int:
return 0
def cmake_build(base_path: str, target: str) -> int:
def cmake_build(base_path: str, target: Optional[str]) -> int:
if not os.path.isdir(base_path):
# nothing to build
return 0
for d in os.listdir(base_path):
args = ['cmake', '--build', os.path.join(base_path, d)]
path = os.path.join(base_path, d)
if not os.path.isdir(path):
continue
args = ['cmake', '--build', path]
if target is not None:
args.extend(['--target', target])
err = subprocess.run(args).returncode
@ -83,7 +67,11 @@ def cmake_build(base_path: str, target: str) -> int:
def conan() -> int:
project_name = sys.argv[2]
conan_dir = '.conanbuild'
err = mkdir(conan_dir)
err = 0
try:
mkdir(conan_dir)
except:
return 1
if err != 0:
return err
args = ['conan', 'install', '../', '--build=missing', '-pr', project_name]
@ -94,10 +82,38 @@ def conan() -> int:
return 0
def main():
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':
err = mkdir(sys.argv[2])
try:
mkdir(sys.argv[2])
except:
err = 1
elif sys.argv[1] == 'rm':
for i in range(2, len(sys.argv)):
rm(sys.argv[i])
@ -109,6 +125,10 @@ def main():
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 +137,6 @@ def main():
if __name__ == '__main__':
try:
err = main()
sys.exit(err)
sys.exit(main())
except KeyboardInterrupt:
sys.exit(1)

View File

@ -18,12 +18,13 @@ import sys
from pybb import mkdir, rm
def main():
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--target', help='Platform target',
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()
@ -39,7 +40,7 @@ def main():
sanitizer_status = 'OFF'
else:
print('Error: Invalid build tool')
sys.exit(1)
return 1
if args.build_tool == 'xcode':
build_config = '{:s}-{:s}'.format(args.target, args.build_tool)
@ -60,12 +61,11 @@ def main():
build_tool = '-GXcode'
else:
print('Error: Invalid build tool')
sys.exit(1)
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)
mkdir(build_dir)
cmake_cmd = [
'cmake', '-S', project_dir, '-B', build_dir, build_tool,
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
@ -90,11 +90,12 @@ def main():
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
if __name__ == '__main__':
try:
main()
sys.exit(main())
except KeyboardInterrupt:
sys.exit(1)