From 561c5ab91dd0e7c91db92756e627df908e358e7f Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Tue, 6 Apr 2021 18:59:48 +0900 Subject: [PATCH] update wandbox-cargo (#51) * update wandbox-cargo * fix --- samples/command/src/rust/Makefile | 10 +++- samples/command/src/rust/src/test1.rs | 8 +++ wandbox/__ghc__.py | 3 + wandbox/__init__.py | 2 +- wandbox/__rust__.py | 84 +++++++++++++++++++++------ 5 files changed, 87 insertions(+), 20 deletions(-) diff --git a/samples/command/src/rust/Makefile b/samples/command/src/rust/Makefile index b30a1b8..28bc01e 100644 --- a/samples/command/src/rust/Makefile +++ b/samples/command/src/rust/Makefile @@ -5,11 +5,17 @@ CARGO:=cargo RUST:=rustc local: + $(CARGO) build --bins ${CARGO} run - ${CARGO} run --bin main2 - ${CARGO} run --bin main3 + ${CARGO} -q r --bin main2 + ${CARGO} -v r --bin main3 $(RUST) src/sample.rs +test: + $(CARGO) test + $(CARGO) test --bin main + $(CARGO) t --bin main2 + clean: rm -rf sample diff --git a/samples/command/src/rust/src/test1.rs b/samples/command/src/rust/src/test1.rs index 8ffcfc4..f48123e 100644 --- a/samples/command/src/rust/src/test1.rs +++ b/samples/command/src/rust/src/test1.rs @@ -2,3 +2,11 @@ pub fn test1() { println!("Test1"); } + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/wandbox/__ghc__.py b/wandbox/__ghc__.py index 490f628..64ea177 100644 --- a/wandbox/__ghc__.py +++ b/wandbox/__ghc__.py @@ -112,6 +112,9 @@ def parse_command_line(self, argv): opts.dryrun = True return opts, args + def print_help(self): + self.parser.print_help() + def execute(self): self.execute_with_args() diff --git a/wandbox/__init__.py b/wandbox/__init__.py index 4ee40ff..e5c2a59 100644 --- a/wandbox/__init__.py +++ b/wandbox/__init__.py @@ -1,5 +1,5 @@ __author__ = 'srz_zumix' -__version__ = '0.9.28' +__version__ = '0.9.29' __copyright__ = '2014-2021 %s ' % __author__ __license__ = """ diff --git a/wandbox/__rust__.py b/wandbox/__rust__.py index 8f35c77..47090ae 100644 --- a/wandbox/__rust__.py +++ b/wandbox/__rust__.py @@ -1,5 +1,6 @@ import os import re +import sys import toml from argparse import ArgumentParser @@ -75,25 +76,57 @@ def setup(self, compiler): action='store_true', help='dryrun' ) + self.parser.add_argument( + '-q', + '--quiet', + action='store_true', + help='No output printed to stdout' + ) + self.parser.add_argument( + '-v', + '--verbose', + action='store_true', + help='Use verbose output' + ) + self.parser.add_argument( + '--explain', + metavar='CODE', + action='append', + default=[], + help='Run `rustc --explain CODE`' + ) subparser = self.parser.add_subparsers() run_cmd = subparser.add_parser( 'run', - description='build and run command', - help='build and run command. see `run +h`' - ) - run_cmd.add_argument( - '--bin', - help='Run the specified binary.' + aliases=['r'], + description='Run a binary or example of the local package', + help='Run a binary or example of the local package. see `run -h`' ) build_cmd = subparser.add_parser( 'build', - description='build and run command (run command alias)', - help='build and run command (run command alias). see `build +h`' + aliases=['b'], + description='Run a binary or example of the local package (run command alias)', + help='Run a binary or example of the local package (run command alias). see `build -h`' + ) + check_cmd = subparser.add_parser( + 'check', + aliases=['c'], + description='Run a binary or example of the local package (run command alias)', + help='Run a binary or example of the local package (run command alias). see `check -h`' ) - passthrough_cmds = [run_cmd, build_cmd] + passthrough_cmds = [run_cmd, build_cmd, check_cmd] for passthrough_cmd in passthrough_cmds: passthrough_cmd.set_defaults(handler=self.command_run) + passthrough_cmd.add_argument( + '--bin', + help='Run the specified binary.' + ) + passthrough_cmd.add_argument( + '--bins', + action='store_true', + help='Run the all binares.' + ) passthrough_cmd.add_argument( 'options', metavar='OPTIONS', @@ -107,6 +140,9 @@ def parse_command_line(self, argv): opts.dryrun = True return opts, args + def print_help(self): + self.parser.print_help() + def execute(self): self.execute_with_args() @@ -132,16 +168,30 @@ def command_run(self, opts, args): else: if 'default-run' in package: target_bin = package['default-run'] - src = 'src/main.rs' - if target_bin: + for explain in opts.explain: + run_options.append("--explain") + run_options.append(explain) + if opts.verbose: + run_options.append("--verbose") + srcs = [] + if opts.bins: for bin in config['bin']: - if bin['name'] == target_bin: - src = bin['path'] + srcs.append(bin['path']) else: - pass - run_options.append(src) - - cmd.execute_with_args(cli_options + run_options) + src = 'src/main.rs' + if target_bin: + for bin in config['bin']: + if bin['name'] == target_bin: + src = bin['path'] + srcs.append(src) + for src in srcs: + exit_code = 0 + try: + cmd.execute_with_args(cli_options + run_options + [src]) + except SystemExit as e: + if e.code != 0: + exit_code = e.code + sys.exit(exit_code) def rust(compiler=None):