Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting filesystem accesses; 'workspace inspect' command #13

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
58 changes: 52 additions & 6 deletions cmd/warpforge/winspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ import (
"os"
"path/filepath"

"github.com/warpfork/warpforge/pkg/dab"

"github.com/urfave/cli/v2"

"github.com/warpfork/warpforge/pkg/dab"
"github.com/warpfork/warpforge/pkg/plotexec"
)

var cmdDefWorkspaceInspect = cli.Command{
Name: "inspect",
Usage: "Inspect and report upon the situation of the current workspace (how many modules are there, have we got a cached evaluation of them, etc).",
Action: cmdFnWorkspaceInspect,
// Aliases: []string{"winspect"}, // doesn't put them at the top level. Womp.
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "gohard",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha. Maybe health-check?

Usage: "whether to spend effort checking the health of modules found; if false, just list them.",
Value: true,
},
},
}

func cmdFnWorkspaceInspect(c *cli.Context) error {
Expand All @@ -33,7 +41,7 @@ func cmdFnWorkspaceInspect(c *cli.Context) error {
fmt.Fprintf(c.App.Writer, "Workspace: %s%s\n", wsFs, wsPath)

// Search for modules within the workspace.
fs.WalkDir(wsFs, wsPath, func(path string, d fs.DirEntry, err error) error {
return fs.WalkDir(wsFs, wsPath, func(path string, d fs.DirEntry, err error) error {
// fmt.Fprintf(c.App.Writer, "hi: %s%s\n", wsFs, path)

if err != nil {
Expand Down Expand Up @@ -66,12 +74,50 @@ func cmdFnWorkspaceInspect(c *cli.Context) error {
modName = "!!Unknown!!"
}

everythingParses := false
importsResolve := false
noticeIngestUsage := false
noticeMountUsage := false
havePacksCached := false // maybe should have a variant for "or we have a replay we're hopeful about"?
haveRunrecord := false
haveHappyExit := false
if c.Bool("gohard") {
if err != nil {
goto _checksDone
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oy.

}
plot, err := dab.PlotFromFile(wsFs, filepath.Join(filepath.Dir(path), dab.MagicFilename_Plot))
if err != nil {
goto _checksDone
}
everythingParses = true
plotStats, err := plotexec.ComputeStats(plot, wss)
if err != nil {
return err // if it's hardcore catalog errors, rather than just unresolvables, I'm out
}
if plotStats.ResolvableCatalogInputs == plotStats.InputsUsingCatalog {
importsResolve = true
}
if plotStats.InputsUsingIngest > 0 {
noticeIngestUsage = true
}
if plotStats.InputsUsingMount > 0 {
noticeMountUsage = true
}
// TODO: havePacksCached is not supported right now :(
// TODO: haveRunrecord needs to both do resolve, and go peek at memos, and yet (obviously) not actually run.
// TODO: haveHappyExit needs the above.
}
_checksDone:

// Tell me about it.
fmt.Fprintf(c.App.Writer, "Module found: %q -- at path %q\n", modName, modPathWithinWs)
fmt.Fprintf(c.App.Writer, "Module found: %q -- at path %q", modName, modPathWithinWs)
if c.Bool("gohard") {
fmt.Fprintf(c.App.Writer, " -- %v %v %v %v %v %v %v",
everythingParses, importsResolve, noticeIngestUsage, noticeMountUsage, havePacksCached, haveRunrecord, haveHappyExit)
}
fmt.Fprintf(c.App.Writer, "\n")
}

return nil
})

return nil
}