compiler, cli: generate manifest.json and debug.json independently

We should be able to generate manifest.json without debug.json and vice
versa.
This commit is contained in:
Anna Shaleva 2020-06-30 14:21:58 +03:00
parent 59d1013a8f
commit 4dfb0eb438
2 changed files with 28 additions and 20 deletions

View file

@ -351,14 +351,15 @@ func contractCompile(ctx *cli.Context) error {
} }
manifestFile := ctx.String("manifest") manifestFile := ctx.String("manifest")
confFile := ctx.String("config") confFile := ctx.String("config")
if len(manifestFile) != 0 && len(confFile) == 0 { debugFile := ctx.String("debug")
if len(confFile) == 0 && (len(manifestFile) != 0 || len(debugFile) != 0) {
return cli.NewExitError(errNoConfFile, 1) return cli.NewExitError(errNoConfFile, 1)
} }
o := &compiler.Options{ o := &compiler.Options{
Outfile: ctx.String("out"), Outfile: ctx.String("out"),
DebugInfo: ctx.String("debug"), DebugInfo: debugFile,
ManifestFile: manifestFile, ManifestFile: manifestFile,
} }

View file

@ -13,6 +13,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef" "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
"github.com/pkg/errors"
"golang.org/x/tools/go/loader" "golang.org/x/tools/go/loader"
) )
@ -112,14 +113,17 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
if err != nil { if err != nil {
return b, err return b, err
} }
if o.DebugInfo == "" { if o.DebugInfo == "" && o.ManifestFile == "" {
return b, nil return b, nil
} }
p, err := filepath.Abs(src) p, err := filepath.Abs(src)
if err != nil { if err != nil {
return b, err return b, err
} }
di.Documents = append(di.Documents, p) di.Documents = append(di.Documents, p)
if o.DebugInfo != "" {
data, err := json.Marshal(di) data, err := json.Marshal(di)
if err != nil { if err != nil {
return b, err return b, err
@ -127,16 +131,19 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
if err := ioutil.WriteFile(o.DebugInfo, data, os.ModePerm); err != nil { if err := ioutil.WriteFile(o.DebugInfo, data, os.ModePerm); err != nil {
return b, err return b, err
} }
if o.ManifestFile == "" {
return b, err
} }
if o.ManifestFile != "" {
m, err := di.convertToManifest(o.ContractFeatures) m, err := di.convertToManifest(o.ContractFeatures)
if err != nil { if err != nil {
return b, err return b, errors.Wrap(err, "failed to convert debug info to manifest")
} }
mData, err := json.Marshal(m) mData, err := json.Marshal(m)
if err != nil { if err != nil {
return b, err return b, errors.Wrap(err, "failed to marshal manifest")
} }
return b, ioutil.WriteFile(o.ManifestFile, mData, os.ModePerm) return b, ioutil.WriteFile(o.ManifestFile, mData, os.ModePerm)
} }
return b, nil
}