lib, lang, docs: Add --only-unify option

This adds a new run flag for the lang frontend to exit immediately
following type unification. This makes it easier to use this as a step
in CI, and also to type the execution for performance comparison
reasons.
This commit is contained in:
James Shubin
2024-01-02 13:06:19 -05:00
parent 32ca815896
commit 24054f905f
3 changed files with 36 additions and 2 deletions

View File

@@ -24,6 +24,7 @@ import (
"fmt"
"strings"
"sync"
"time"
"github.com/purpleidea/mgmt/gapi"
"github.com/purpleidea/mgmt/lang"
@@ -97,6 +98,10 @@ func (obj *GAPI) CliFlags(command string) []cli.Flag {
Name: "update",
Usage: "update all dependencies to the latest versions",
},
&cli.BoolFlag{
Name: "only-unify",
Usage: "stop after type unification",
},
}
result = append(result, runFlags...)
}
@@ -318,14 +323,25 @@ func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) {
}
}
logf("running type unification...")
startTime := time.Now()
unifier := &unification.Unifier{
AST: iast,
Solver: unification.SimpleInvariantSolverLogger(unificationLogf),
Debug: debug,
Logf: unificationLogf,
}
if err := unifier.Unify(); err != nil {
return nil, errwrap.Wrapf(err, "could not unify types")
unifyErr := unifier.Unify()
delta := time.Since(startTime)
if unifyErr != nil {
if c.Bool("only-unify") {
logf("type unification failed after %s", delta)
}
return nil, errwrap.Wrapf(unifyErr, "could not unify types")
}
if c.Bool("only-unify") {
logf("type unification succeeded in %s", delta)
return nil, nil // we end early
}
// get the list of needed files (this is available after SetScope)