appveyor: fixup argument parsing

This commit is contained in:
Michael Davidsaver
2020-03-26 12:46:41 -07:00
committed by Ralph Lange
parent b7d505c2e2
commit a006293461
2 changed files with 38 additions and 23 deletions

View File

@@ -256,6 +256,6 @@ if __name__ == "__main__":
else: else:
unittest.main() unittest.main()
else: else:
do.actions['prepare']() do.main(['prepare'])
do.actions['build']() do.main(['build'])
do.actions['test']() do.main(['test'])

View File

@@ -359,7 +359,7 @@ def setup_for_build():
os.environ['PATH'] = os.pathsep.join([r'C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin', os.environ['PATH'] = os.pathsep.join([r'C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin',
os.environ['PATH']]) os.environ['PATH']])
def prepare(*args): def prepare(args):
host_info() host_info()
print('{0}Loading setup files{1}'.format(ANSI_YELLOW, ANSI_RESET)) print('{0}Loading setup files{1}'.format(ANSI_YELLOW, ANSI_RESET))
@@ -456,22 +456,22 @@ def prepare(*args):
print('{0}Building dependency {1} in {2}{3}'.format(ANSI_YELLOW, mod, place, ANSI_RESET)) print('{0}Building dependency {1} in {2}{3}'.format(ANSI_YELLOW, mod, place, ANSI_RESET))
call_make(cwd=place) call_make(cwd=place)
def build(*args): def build(args):
setup_for_build() setup_for_build()
print('{0}Building the main module{1}'.format(ANSI_YELLOW, ANSI_RESET)) print('{0}Building the main module{1}'.format(ANSI_YELLOW, ANSI_RESET))
call_make() call_make()
def test(*args): def test(args):
setup_for_build() setup_for_build()
print('{0}Running the main module tests{1}'.format(ANSI_YELLOW, ANSI_RESET)) print('{0}Running the main module tests{1}'.format(ANSI_YELLOW, ANSI_RESET))
call_make(['tapfiles']) call_make(['tapfiles'])
def doExec(*args): def doExec(args):
'exec user command with vcvars' 'exec user command with vcvars'
setup_for_build() setup_for_build()
print('Execute command {}'.format(args)) print('Execute command {}'.format(args.cmd))
sys.stdout.flush() sys.stdout.flush()
sp.check_call(' '.join(args), shell=True) sp.check_call(' '.join(args.cmd), shell=True)
def with_vcvars(cmd): def with_vcvars(cmd):
'''re-exec main script with a (hopefully different) command '''re-exec main script with a (hopefully different) command
@@ -523,21 +523,36 @@ call "{vcvars}" {arch}
if returncode != 0: if returncode != 0:
sys.exit(returncode) sys.exit(returncode)
actions = { def getargs():
'prepare': prepare, from argparse import ArgumentParser, REMAINDER
'build': build, P = ArgumentParser()
'test': test, P.add_argument('--no-vcvars', dest='vcvars', default=True, action='store_false',
'exec': doExec, help='Assume vcvarsall.bat has already been run')
'_vcvars':lambda:None, SP = P.add_subparsers()
}
if __name__=='__main__': CMD = SP.add_parser('prepare')
args = sys.argv[1:] CMD.set_defaults(func=prepare)
if args[0]!='_vcvars' and os.environ['CC']!='mingw':
CMD = SP.add_parser('build')
CMD.set_defaults(func=build)
CMD = SP.add_parser('test')
CMD.set_defaults(func=test)
CMD = SP.add_parser('exec')
CMD.add_argument('cmd', nargs=REMAINDER)
CMD.set_defaults(func=doExec)
return P
def main(raw):
args = getargs().parse_args(raw)
if args.vcvars and os.environ['CC'].startswith('vs'):
# re-exec with MSVC in PATH # re-exec with MSVC in PATH
with_vcvars(' '.join(['_vcvars']+args)) with_vcvars(' '.join(['--no-vcvars']+raw))
else: else:
name = args.pop(0) args.func(args)
logger.debug('DO running action %s with %s', name, args)
actions[name](*args) if __name__=='__main__':
main(sys.argv[1:])