shithub: mc

Download patch

ref: f2d12752c483648d554700e6ac7dc100801dfa59
parent: 21422e62f15776a5abf3bf16e8416ffa9f8771fc
author: Mura Li <github@ctli.io>
date: Tue Oct 22 06:35:08 EDT 2019

Use optparse's .arg to pass run target

--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -25,7 +25,7 @@
 			[.opt='T', .arg="tag", .desc="build with only the specified systag"],
 			[.opt='S', .desc="generate assembly when building"],
 			[.opt='I', .arg="inc", .desc="add 'inc' to your include path"],
-			[.opt='R', .desc="source to compile and run"],
+			[.opt='R', .arg="src", .desc="source to compile and run"],
 			[.opt='B', .arg="base", .desc="install into 'base'"],
 			[.opt='b', .arg="bin", .desc="compile binary 'bin' from inputs"],
 			[.opt='r', .arg="rt", .desc="link against runtime 'rt'"],
@@ -39,6 +39,7 @@
 	targname = ""
 	ok = true
 	objdir = ""
+	srcs = cmd.args
 
 	bld.initopts()
 	for opt : cmd.opts
@@ -57,7 +58,7 @@
 				std.fatal("at most one -b and -R may be specified\n")
 			;;
 			targname = arg
-		| ('R', arg):
+		| ('R', src):
 			if targname.len != 0
 				std.fatal("at most one -b and -R may be specified\n")
 			;;
@@ -64,6 +65,7 @@
 			bld.opt_verbosity = -1
 			runsrc = true
 			targname = std.mktemppath("runmyr")
+			srcs = [src][:]
 		| _:	
 			std.die("unreachable\n")
 		;;
@@ -75,23 +77,16 @@
 		std.setenv(e, v)
 	;;
 
-	std.put("cmd.args: {}\n", cmd.args)
 	b = mkbuild(tags)
 	if targname.len != 0
-		if cmd.args.len == 0
+		if srcs.len == 0
 			std.fatal("nothing to compile\n")
 		;;
 
-		if runsrc
-			srcs = cmd.args[0:1]
-		else
-			srcs = cmd.args
-		;;
-
 		bld.opt_objdir = objdir
 		ok = buildimm(b, targname, srcs)
 		if runsrc && ok
-			pid = runcmd(targname, cmd.args[1:])
+			pid = runcmd(targname, cmd.args)
 			match std.wait(pid)
 			| `std.Wsuccess:	ok = true
 			| _:			ok = false