From 538c3ac8ff38e7fa47702aa7522d595b1c7a9f30 Mon Sep 17 00:00:00 2001 From: David Poole Date: Fri, 7 Jul 2023 07:39:06 -0600 Subject: [PATCH] first pass of -n (aka dry-run) option Still need to add support for sub-makes. Need this option to debug problems with using pymake to build GNU Make. --- pymake/pargs.py | 13 ++++++++++--- tests/test_args.py | 13 +++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pymake/pargs.py b/pymake/pargs.py index e8535a2..7f27d70 100644 --- a/pymake/pargs.py +++ b/pymake/pargs.py @@ -25,6 +25,9 @@ def usage(): -h --help Print this help message and exit. + -n + --just-print, --dry-run, --recon + Don't run any recipes, just print them. -r --no-builtin-rules Disable reading GNU Make's built-in rules. @@ -75,6 +78,8 @@ def __init__(self): # -C aka --directory option self.directory = None + self.dry_run = False + self.warn_undefined_variables = False self.detailed_error_explain = False @@ -83,7 +88,7 @@ def parse_args(argv): Copyright (C) 2014-2023 David Poole davep@mbuf.com, testcluster@gmail.com""" % (Version.vstring(),) args = Args() - optlist, arglist = getopt.gnu_getopt(argv, "Bhvo:drSf:C:", + optlist, arglist = getopt.gnu_getopt(argv, "Bhvo:drSf:C:n", [ "help", "always-make", @@ -91,13 +96,13 @@ def parse_args(argv): "dotfile=", "html=", "explain", - "file=", - "makefile=", + "file=", "makefile=", "output=", "no-builtin-rules", "version", "warn-undefined-variables", "directory=", + "just-print", "dry-run", "recon" ] ) for opt in optlist: @@ -132,6 +137,8 @@ def parse_args(argv): if args.directory is None: args.directory = [] args.directory.append(opt[1]) + elif opt[0] in ('-n', '--just-print', '--dry-run', '--recon'): + args.dry_run = True else: # wtf? assert 0, opt diff --git a/tests/test_args.py b/tests/test_args.py index 1773a75..d28a224 100644 --- a/tests/test_args.py +++ b/tests/test_args.py @@ -85,3 +85,16 @@ def test_multiple_directory(): assert len(args.directory)==2 assert args.directory[0] == 'build' assert args.directory[1] == 'docs' + +def test_dry_run(): + args = pargs.parse_args(('-n',),) + assert args.dry_run + + args = pargs.parse_args(('--just-print',),) + assert args.dry_run + + args = pargs.parse_args(('--dry-run',),) + assert args.dry_run + + args = pargs.parse_args(('--recon',),) + assert args.dry_run