Skip to content

Commit

Permalink
update wandbox-cargo (#51)
Browse files Browse the repository at this point in the history
* update wandbox-cargo

* fix
  • Loading branch information
srz-zumix authored Apr 6, 2021
1 parent 5e85f71 commit 561c5ab
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 20 deletions.
10 changes: 8 additions & 2 deletions samples/command/src/rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions samples/command/src/rust/src/test1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ pub fn test1()
{
println!("Test1");
}

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
3 changes: 3 additions & 0 deletions wandbox/__ghc__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion wandbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = 'srz_zumix'
__version__ = '0.9.28'
__version__ = '0.9.29'

__copyright__ = '2014-2021 %s ' % __author__
__license__ = """
Expand Down
84 changes: 67 additions & 17 deletions wandbox/__rust__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re
import sys
import toml

from argparse import ArgumentParser
Expand Down Expand Up @@ -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',
Expand All @@ -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()

Expand All @@ -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):
Expand Down

0 comments on commit 561c5ab

Please sign in to comment.