From c4c2e6d97a64da72dbab6597fb61decc61e808a2 Mon Sep 17 00:00:00 2001 From: John Pennycook Date: Fri, 23 Feb 2024 12:00:34 -0800 Subject: [PATCH] Replace --rootdir (-r) with --source-dir (-S) Experience with real codebases suggests that we will eventually want to support the ability to independently identify source and build directories. This commit does not add that functionality, but introduces the "source directory" as a replacement for the concept of a "root directory" without breaking backwards compatibility. Signed-off-by: John Pennycook --- codebasin.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/codebasin.py b/codebasin.py index f6f8fc1..a245272 100755 --- a/codebasin.py +++ b/codebasin.py @@ -9,6 +9,7 @@ import logging import os import sys +import warnings from codebasin import config, finder, report, util from codebasin.walkers.platform_mapper import PlatformMapper @@ -47,10 +48,18 @@ def main(): "--rootdir", dest="rootdir", metavar="DIR", - default=os.getcwd(), - type=str, + default=None, help="Set working root directory (default .)", ) + parser.add_argument( + "-S", + "--source-dir", + metavar="", + dest="source_dir", + default=None, + help="Set path to source directory. " + + "The default is the current directory.", + ) parser.add_argument( "-c", "--config", @@ -131,7 +140,23 @@ def main(): logging.getLogger("codebasin").setLevel( max(1, logging.WARNING - 10 * (args.verbose - args.quiet)), ) - rootdir = os.path.realpath(args.rootdir) + + # Determine the root directory based on the -S and -r flags. + rootpath = None + if args.source_dir and args.rootdir: + raise RuntimeError( + "Cannot specify both --source-dir (-S) and --rootdir (-r).", + ) + if not args.source_dir and not args.rootdir: + rootpath = os.getcwd() + elif args.source_dir: + rootpath = args.source_dir + elif args.rootdir: + warnings.warn( + "--rootdir (-r) is deprecated. Use --source-dir (-S) instead.", + ) + rootpath = args.rootdir + rootdir = os.path.realpath(rootpath) # Process the -p flag first to infer wider context. filtered_platforms = []