2015-01-30 17:01:15 +00:00
|
|
|
// Copyright 2015 The go-python Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-01-04 19:34:20 +00:00
|
|
|
"fmt"
|
2019-01-11 11:00:12 +00:00
|
|
|
"io"
|
2015-01-30 17:01:15 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
2019-01-11 11:00:12 +00:00
|
|
|
"path"
|
2015-07-24 14:16:31 +00:00
|
|
|
|
|
|
|
"github.com/gonuts/commander"
|
|
|
|
"github.com/gonuts/flag"
|
2019-01-11 11:00:12 +00:00
|
|
|
"github.com/pkg/errors"
|
2021-03-17 21:02:07 +00:00
|
|
|
|
|
|
|
"github.com/go-python/gopy/bind"
|
2015-09-11 06:26:37 +00:00
|
|
|
)
|
|
|
|
|
2021-03-17 21:02:07 +00:00
|
|
|
// BuildCfg contains command options and binding generation options
|
|
|
|
type BuildCfg struct {
|
|
|
|
bind.BindCfg
|
|
|
|
|
|
|
|
// include symbols in output
|
|
|
|
Symbols bool
|
|
|
|
// suppress warning messages, which may be expected
|
|
|
|
NoWarn bool
|
|
|
|
// do not generate a Makefile, e.g., when called from Makefile
|
|
|
|
NoMake bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewBuildCfg returns a newly constructed build config
|
|
|
|
func NewBuildCfg() *BuildCfg {
|
|
|
|
var cfg BuildCfg
|
|
|
|
cfg.Cmd = argStr()
|
|
|
|
return &cfg
|
|
|
|
}
|
|
|
|
|
2018-03-27 14:43:34 +00:00
|
|
|
func run(args []string) error {
|
|
|
|
app := &commander.Command{
|
2015-07-24 14:16:31 +00:00
|
|
|
UsageLine: "gopy",
|
|
|
|
Subcommands: []*commander.Command{
|
|
|
|
gopyMakeCmdGen(),
|
2019-02-13 05:53:20 +00:00
|
|
|
gopyMakeCmdBuild(),
|
2019-02-20 11:09:23 +00:00
|
|
|
gopyMakeCmdPkg(),
|
2019-03-02 00:10:50 +00:00
|
|
|
gopyMakeCmdExe(),
|
2015-07-24 14:16:31 +00:00
|
|
|
},
|
|
|
|
Flag: *flag.NewFlagSet("gopy", flag.ExitOnError),
|
|
|
|
}
|
2015-01-30 17:01:15 +00:00
|
|
|
|
2018-01-04 19:34:20 +00:00
|
|
|
err := app.Flag.Parse(args)
|
2015-01-30 17:01:15 +00:00
|
|
|
if err != nil {
|
2018-01-04 19:34:20 +00:00
|
|
|
return fmt.Errorf("could not parse flags: %v", err)
|
2015-01-30 17:01:15 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 19:34:20 +00:00
|
|
|
appArgs := app.Flag.Args()
|
|
|
|
err = app.Dispatch(appArgs)
|
2015-01-30 17:01:15 +00:00
|
|
|
if err != nil {
|
2018-01-04 19:34:20 +00:00
|
|
|
return fmt.Errorf("error dispatching command: %v", err)
|
2015-01-30 17:01:15 +00:00
|
|
|
}
|
2018-01-04 19:34:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-01-30 17:01:15 +00:00
|
|
|
|
2018-01-04 19:34:20 +00:00
|
|
|
func main() {
|
|
|
|
err := run(os.Args[1:])
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2015-01-30 17:01:15 +00:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
2019-01-11 11:00:12 +00:00
|
|
|
|
|
|
|
func copyCmd(src, dst string) error {
|
|
|
|
srcf, err := os.Open(src)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not open source for copy")
|
|
|
|
}
|
|
|
|
defer srcf.Close()
|
|
|
|
|
|
|
|
os.MkdirAll(path.Dir(dst), 0755)
|
|
|
|
|
|
|
|
dstf, err := os.Create(dst)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not create destination for copy")
|
|
|
|
}
|
|
|
|
defer dstf.Close()
|
|
|
|
|
|
|
|
_, err = io.Copy(dstf, srcf)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not copy bytes to destination")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dstf.Sync()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not synchronize destination")
|
|
|
|
}
|
|
|
|
|
|
|
|
return dstf.Close()
|
|
|
|
}
|