Skip to content

Commit

Permalink
Replace --rootdir (-r) with --source-dir (-S)
Browse files Browse the repository at this point in the history
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 <john.pennycook@intel.com>
  • Loading branch information
Pennycook committed Feb 23, 2024
1 parent 0ebef0f commit c4c2e6d
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions codebasin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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="<path>",
dest="source_dir",
default=None,
help="Set path to source directory. "
+ "The default is the current directory.",
)
parser.add_argument(
"-c",
"--config",
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit c4c2e6d

Please sign in to comment.