Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
c2go -run
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jul 16, 2022
1 parent f0ecd29 commit 468cdde
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion c2go.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func isFile(name string) bool {
}

type Config struct {
Select string
SelectFile string
SelectCmd string
}

func Run(pkgname, infile string, flags int, conf *Config) {
Expand Down
11 changes: 6 additions & 5 deletions cmd/c2go/impl/c2go.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func Main(flag *flag.FlagSet, args []string) {
json = flag.Bool("json", false, "dump C AST to a file in json format")
test = flag.Bool("test", false, "run test")
testmain = flag.Bool("testmain", false, "generate TestMain as entry instead of main (only for cmd/test_xxx)")
sel = flag.String("sel", "", "select a file (only available in project mode)")
runcmd = flag.String("run", "", "select a command to run (only available in project mode)")
selfile = flag.String("sel", "", "select a file (only available in project mode)")
)
flag.Parse(args)
var pkgname, infile string
Expand All @@ -50,7 +51,7 @@ func Main(flag *flag.FlagSet, args []string) {
preprocessor.SetDebug(preprocessor.DbgFlagAll)
gox.SetDebug(gox.DbgFlagInstruction) // | gox.DbgFlagMatch)
}
if *test {
if *test || *runcmd != "" {
flags |= c2go.FlagRunTest
}
if *testmain {
Expand All @@ -68,9 +69,9 @@ func Main(flag *flag.FlagSet, args []string) {
if *json {
flags |= c2go.FlagDumpJson
}
var conf *c2go.Config
if *sel != "" {
conf = &c2go.Config{Select: *sel}
conf := &c2go.Config{
SelectFile: *selfile,
SelectCmd: *runcmd,
}
c2go.Run(pkgname, infile, flags, conf)
}
11 changes: 9 additions & 2 deletions proj.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ func execProj(projfile string, flags int, in *Config) {
conf.public, err = cpackages.ReadPubFile(pubfile)
check(err)

if in != nil && in.Select != "" {
execProjFile(canonical(base, in.Select), &conf, appFlags)
if in != nil && in.SelectFile != "" {
execProjFile(canonical(base, in.SelectFile), &conf, appFlags)
return
}
execProjSource(base, appFlags, &conf)
Expand All @@ -121,7 +121,14 @@ func execProj(projfile string, flags int, in *Config) {
if cmds := conf.Target.Cmds; len(cmds) != 0 {
conf.Target.Cmds = nil
conf.public = nil
cmdSel := ""
if in != nil {
cmdSel = in.SelectCmd
}
for _, cmd := range cmds {
if cmdSel != "" && cmd.Dir != cmdSel {
continue
}
conf.Target.Name = "main"
appFlags := flags
if (flags & FlagTestMain) != 0 {
Expand Down

0 comments on commit 468cdde

Please sign in to comment.