-
Notifications
You must be signed in to change notification settings - Fork 4
change prototype of onBuild, onTest #161
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import ( | |
| "io/fs" | ||
|
|
||
| "github.com/goplus/llar/mod/module" | ||
| "github.com/qiniu/x/errors" | ||
| ) | ||
|
|
||
| // ----------------------------------------------------------------------------- | ||
|
|
@@ -25,7 +26,10 @@ func (p *Project) ReadFile(path string) ([]byte, error) { | |
|
|
||
| // Context represents the build context. | ||
| type Context struct { | ||
| Proj *Project | ||
| SourceDir string | ||
| Out BuildResult | ||
| Errs errors.List | ||
|
|
||
| buildResults map[module.Version]BuildResult | ||
|
|
||
|
|
@@ -35,26 +39,36 @@ type Context struct { | |
| getOutputDir func(matrixStr string, mod module.Version) (string, error) | ||
| } | ||
|
|
||
| // NewContext creates a Context with build-internal fields. | ||
| func NewContext(sourceDir, installDir, matrixStr string, getOutputDir func(string, module.Version) (string, error)) *Context { | ||
| func NewContext(proj *Project, sourceDir, installDir, matrixStr string, getOutputDir func(string, module.Version) (string, error)) *Context { | ||
| return &Context{ | ||
| Proj: proj, | ||
| SourceDir: sourceDir, | ||
| installDir: installDir, | ||
| matrixStr: matrixStr, | ||
| getOutputDir: getOutputDir, | ||
| } | ||
| } | ||
|
|
||
| // SetMetadata sets the build output metadata. | ||
| func (c *Context) SetMetadata(metadata string) { | ||
| c.Out.SetMetadata(metadata) | ||
| } | ||
|
|
||
| // OutputDir__0 returns the current module's output (install) directory. | ||
| // In DSL: ctx.outputDir() | ||
| func (c *Context) OutputDir__0() (string, error) { | ||
| return c.installDir, nil | ||
| func (c *Context) OutputDir__0() string { | ||
| return c.installDir | ||
| } | ||
|
|
||
| // OutputDir__1 returns the output (install) directory for the given dependency. | ||
| // In DSL: ctx.outputDir(dep) | ||
| func (c *Context) OutputDir__1(mod module.Version) (string, error) { | ||
| return c.getOutputDir(c.matrixStr, mod) | ||
| func (c *Context) OutputDir__1(mod module.Version) string { | ||
| dir, err := c.getOutputDir(c.matrixStr, mod) | ||
| if err != nil { | ||
| c.Errs.Add(err) | ||
| panic(err) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two concerns with
Also: the doc comment ( |
||
| } | ||
| return dir | ||
| } | ||
|
|
||
| // BuildResult returns the stored build result for the module, if any. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -282,15 +282,14 @@ func (b *Builder) Build(ctx context.Context, targets []*modules.Module) ([]Resul | |
| getOutputDir := func(_ string, m module.Version) (string, error) { | ||
| return b.installDir(m.Path, m.Version) | ||
| } | ||
| buildContext := classfile.NewContext(tmpSourceDir, installDir, b.matrix, getOutputDir) | ||
| project := &classfile.Project{Deps: deps, SourceFS: mod.FS.(fs.ReadFileFS)} | ||
| buildContext := classfile.NewContext(project, tmpSourceDir, installDir, b.matrix, getOutputDir) | ||
|
|
||
| // Inject results of already-built dependencies | ||
| for modVer, result := range builtResults { | ||
| buildContext.AddBuildResult(modVer, result) | ||
| } | ||
|
|
||
| project := &classfile.Project{Deps: deps, SourceFS: mod.FS.(fs.ReadFileFS)} | ||
|
|
||
| var metadata string | ||
| if err := execbroker.Do(execbroker.Scope{ | ||
| Dir: tmpSourceDir, | ||
|
|
@@ -302,22 +301,20 @@ func (b *Builder) Build(ctx context.Context, targets []*modules.Module) ([]Resul | |
| if cacheHit { | ||
| metadata = entry.Metadata | ||
| } else { | ||
| var out classfile.BuildResult | ||
| mod.OnBuild(buildContext, project, &out) | ||
| if len(out.Errs()) > 0 { | ||
| return errors.Join(out.Errs()...) | ||
| mod.OnBuild(buildContext) | ||
| if len(buildContext.Errs) > 0 { | ||
| return errors.Join(buildContext.Errs...) | ||
| } | ||
| metadata = out.Metadata() | ||
| metadata = buildContext.Out.Metadata() | ||
| } | ||
|
|
||
| // Run OnTest (root only) against the just-built or cached | ||
| // artifacts, reusing the same build context so tests see a | ||
| // consistent environment either way. | ||
| if testThisMod { | ||
| var testOut classfile.TestResult | ||
| mod.OnTest(buildContext, project, &testOut) | ||
| if len(testOut.Errs()) > 0 { | ||
| return fmt.Errorf("onTest failed for %s@%s: %w", mod.Path, mod.Version, errors.Join(testOut.Errs()...)) | ||
| mod.OnTest(buildContext) | ||
| if len(buildContext.Errs) > 0 { | ||
| return fmt.Errorf("onTest failed for %s@%s: %w", mod.Path, mod.Version, buildContext.Errs) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The unchanged assertion in Suggest wrapping |
||
| } | ||
| } | ||
| return nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exported
NewContextlost its doc comment (// NewContext creates a Context with build-internal fields.) in this change and now gains a newprojparameter. Please restore a doc comment (mentioning the newproj) to keep the exported API documented.