From 584755c41c6930c505ce7b3c8d4748fab0b1eb6f Mon Sep 17 00:00:00 2001 From: Nick P Date: Thu, 23 May 2024 13:54:28 -0600 Subject: [PATCH 1/2] Stops the creation of _build and _logs directories if CMakeLists.txt is not found This provides a better user experience for new users who run the tool outside of a CMake source tree, who would later have to clean up those directories. --- bin/polly.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/polly.py b/bin/polly.py index 0002103f..5688e926 100755 --- a/bin/polly.py +++ b/bin/polly.py @@ -307,6 +307,15 @@ def PositiveInt(string): else: cdir = os.getcwd() +home = '.' +if args.home: + home = args.home + +# Check the existence of CMakeLists.txt and exit before creating any directories +cmakelists_path = '{}/CMakeLists.txt'.format(home) +if not os.path.exists(cmakelists_path): + sys.exit('Specified path for CMakeList does not exist: {}'.format(cmakelists_path)) + build_dir = os.path.join(cdir, '_builds', build_tag) print("Build dir: {}".format(build_dir)) build_dir_option = "-B{}".format(build_dir) @@ -373,10 +382,6 @@ def PositiveInt(string): detail.call.call(['which', cmake_bin], logging) detail.call.call([cmake_bin, '--version'], logging) -home = '.' -if args.home: - home = args.home - generate_command = [ cmake_bin, '-H{}'.format(home), From e653160814907d3ec6ebd26c001b197dbb2c843b Mon Sep 17 00:00:00 2001 From: Nick P Date: Fri, 24 May 2024 00:05:18 -0600 Subject: [PATCH 2/2] Add support for vcpkg Added the --vcpkg flag which enables vcpkg support and optionally allows to specify path to vcpkg.cmake --- bin/polly.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/bin/polly.py b/bin/polly.py index 5688e926..b8def948 100755 --- a/bin/polly.py +++ b/bin/polly.py @@ -238,6 +238,18 @@ def PositiveInt(string): help="Print the corresponding CMake command and quit" ) +vcpkg_cmake_relative_path = 'scripts/buildsystems/vcpkg.cmake' +vcpkg_cmake_pwd = '{}/vcpkg/{}'.format(os.environ['PWD'], vcpkg_cmake_relative_path) +vcpkg_cmake_env_vcpkg_root = '{}/{}'.format(os.environ['VCPKG_ROOT'], vcpkg_cmake_relative_path) +vcpkg_cmake_path = vcpkg_cmake_pwd if os.path.exists(vcpkg_cmake_pwd) else vcpkg_cmake_env_vcpkg_root + +parser.add_argument( + '--vcpkg', + nargs='?', + const=vcpkg_cmake_path, + help='Enables vcpkg using on ${PWD}/vcpkg, if exists, or $VCPKG_ROOT followed by /scripts/buildsystems/vcpkg.cmake or given argument' +) + args = parser.parse_args() polly_toolchain = detail.toolchain_name.get(args.toolchain) @@ -296,7 +308,6 @@ def PositiveInt(string): toolchain_path = os.path.join(polly_root, "{}.cmake".format(polly_toolchain)) if not os.path.exists(toolchain_path): sys.exit("Toolchain file not found: {}".format(toolchain_path)) -toolchain_option = "-DCMAKE_TOOLCHAIN_FILE={}".format(toolchain_path) if args.output: if not os.path.isdir(args.output): @@ -318,7 +329,6 @@ def PositiveInt(string): build_dir = os.path.join(cdir, '_builds', build_tag) print("Build dir: {}".format(build_dir)) -build_dir_option = "-B{}".format(build_dir) install_dir = os.path.join(cdir, '_install', polly_toolchain) local_install = args.install or args.strip or args.framework or args.framework_device or args.archive @@ -385,9 +395,13 @@ def PositiveInt(string): generate_command = [ cmake_bin, '-H{}'.format(home), - build_dir_option + '-B{}'.format(build_dir), + '-DCMAKE_TOOLCHAIN_FILE={}'.format(args.vcpkg if args.vcpkg else toolchain_path) ] +if args.vcpkg: + generate_command.append('-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE={}'.format(toolchain_path)) + if args.cache: if not os.path.isfile(args.cache): sys.exit("Specified cache file does not exist: {}".format(args.cache)) @@ -408,9 +422,6 @@ def PositiveInt(string): toolset = 'v{}0_xp'.format(toolchain_entry.vs_version) generate_command.append('-T{}'.format(toolset)) -if toolchain_option: - generate_command.append(toolchain_option) - if args.verbosity == 'full': generate_command.append('-DCMAKE_VERBOSE_MAKEFILE=ON') generate_command.append('-DPOLLY_STATUS_DEBUG=ON')