mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
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:
parent
59d1013a8f
commit
4dfb0eb438
2 changed files with 28 additions and 20 deletions
|
@ -351,14 +351,15 @@ func contractCompile(ctx *cli.Context) error {
|
|||
}
|
||||
manifestFile := ctx.String("manifest")
|
||||
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)
|
||||
}
|
||||
|
||||
o := &compiler.Options{
|
||||
Outfile: ctx.String("out"),
|
||||
|
||||
DebugInfo: ctx.String("debug"),
|
||||
DebugInfo: debugFile,
|
||||
ManifestFile: manifestFile,
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/tools/go/loader"
|
||||
)
|
||||
|
||||
|
@ -112,31 +113,37 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
|
|||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
if o.DebugInfo == "" {
|
||||
if o.DebugInfo == "" && o.ManifestFile == "" {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
p, err := filepath.Abs(src)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
di.Documents = append(di.Documents, p)
|
||||
data, err := json.Marshal(di)
|
||||
if err != nil {
|
||||
return b, err
|
||||
|
||||
if o.DebugInfo != "" {
|
||||
data, err := json.Marshal(di)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
if err := ioutil.WriteFile(o.DebugInfo, data, os.ModePerm); err != nil {
|
||||
return b, err
|
||||
}
|
||||
}
|
||||
if err := ioutil.WriteFile(o.DebugInfo, data, os.ModePerm); err != nil {
|
||||
return b, err
|
||||
|
||||
if o.ManifestFile != "" {
|
||||
m, err := di.convertToManifest(o.ContractFeatures)
|
||||
if err != nil {
|
||||
return b, errors.Wrap(err, "failed to convert debug info to manifest")
|
||||
}
|
||||
mData, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return b, errors.Wrap(err, "failed to marshal manifest")
|
||||
}
|
||||
return b, ioutil.WriteFile(o.ManifestFile, mData, os.ModePerm)
|
||||
}
|
||||
if o.ManifestFile == "" {
|
||||
return b, err
|
||||
}
|
||||
m, err := di.convertToManifest(o.ContractFeatures)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
mData, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
return b, ioutil.WriteFile(o.ManifestFile, mData, os.ModePerm)
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue