-
Notifications
You must be signed in to change notification settings - Fork 4
feat(formula): add onTest callback #109
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
Changes from 3 commits
ac53ca9
0d5449c
1fa8aa8
0320afe
5a04491
9ca22f1
73f3350
3df9ec5
0a185b4
a22a95f
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 |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/goplus/llar/internal/formula/repo" | ||
| "github.com/goplus/llar/internal/modules/modlocal" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var testVerbose bool | ||
|
|
||
| var testCmd = &cobra.Command{ | ||
| Use: "test [module@version]", | ||
| Short: "Build a module and run its onTest hook", | ||
| Long: `Test builds a module the same way as 'llar make', then executes | ||
| the module's onTest callback on the freshly-built artifacts. | ||
|
|
||
| The build cache is bypassed for test runs so onTest always executes against | ||
| a fresh build. Test runs do not update the cache either, so normal builds | ||
| remain cacheable.`, | ||
|
MeteorsLiu marked this conversation as resolved.
Outdated
|
||
| Args: cobra.ExactArgs(1), | ||
| RunE: runTest, | ||
| } | ||
|
|
||
| func init() { | ||
| testCmd.Flags().BoolVarP(&testVerbose, "verbose", "v", false, "Enable verbose build/test output") | ||
| rootCmd.AddCommand(testCmd) | ||
| } | ||
|
|
||
| func runTest(cmd *cobra.Command, args []string) error { | ||
| pattern, version, isLocal, err := parseModuleArg(args[0]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| ctx := context.Background() | ||
|
MeteorsLiu marked this conversation as resolved.
|
||
|
|
||
| // Reuse the verbose-redirection logic in buildModule by toggling the | ||
| // shared makeVerbose flag for the duration of the test run. | ||
| savedVerbose := makeVerbose | ||
| makeVerbose = testVerbose | ||
|
MeteorsLiu marked this conversation as resolved.
|
||
| defer func() { makeVerbose = savedVerbose }() | ||
|
fennoai[bot] marked this conversation as resolved.
Comment on lines
+44
to
+46
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. Code quality: shared mutable state for verbose flag The save/mutate/restore of Consider passing |
||
|
|
||
| matrixStr := hostMatrixCombo() | ||
|
|
||
| remoteStore, err := newRemoteStore() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !isLocal { | ||
|
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. Nit: code duplication with runMake Lines 55-83 duplicate the local module resolution logic from |
||
| return buildModule(ctx, remoteStore, pattern, version, matrixStr, true) | ||
| } | ||
|
|
||
| cwd, err := os.Getwd() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get working directory: %w", err) | ||
| } | ||
|
|
||
| localMods, err := modlocal.Resolve(cwd, pattern) | ||
|
MeteorsLiu marked this conversation as resolved.
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| locals := make(map[string]string, len(localMods)) | ||
| for _, m := range localMods { | ||
| locals[m.Path] = m.Dir | ||
| } | ||
| store := repo.NewOverlayStore(remoteStore, locals) | ||
|
|
||
| for _, m := range localMods { | ||
| ver := m.Version | ||
| if ver == "" { | ||
| ver = version | ||
| } | ||
| if err := buildModule(ctx, store, m.Path, ver, matrixStr, true); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
fennoai[bot] marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ type ModuleF struct { | |
|
|
||
| fOnRequire func(proj *Project, deps *ModuleDeps) | ||
| fOnBuild func(ctx *Context, proj *Project, out *BuildResult) | ||
| fOnTest func(ctx *Context, proj *Project, out *BuildResult) | ||
|
|
||
| modPath string | ||
| modFromVer string | ||
|
|
@@ -198,6 +199,13 @@ func (p *ModuleF) OnBuild(f func(ctx *Context, proj *Project, out *BuildResult)) | |
| p.fOnBuild = f | ||
| } | ||
|
|
||
| // OnTest event is used to run post-build verification for a project. | ||
| // It fires after OnBuild has completed successfully, reusing the same build | ||
|
Comment on lines
+221
to
+222
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. Docs: misleading for cache-hit path This says "It fires after OnBuild has completed successfully" but on a cache hit, |
||
| // context so tests can locate built artifacts via ctx.OutputDir. | ||
|
fennoai[bot] marked this conversation as resolved.
|
||
| func (p *ModuleF) OnTest(f func(ctx *Context, proj *Project, out *BuildResult)) { | ||
| p.fOnTest = f | ||
| } | ||
|
|
||
| // ----------------------------------------------------------------------------- | ||
|
|
||
| // Gopt_ModuleF_Main is main entry of this classfile. | ||
|
|
||
|
Collaborator
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. 这里
Collaborator
Author
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. onTest这里并不是写错了,而是有意为之,这主要是因为onTest需要使用构建产物才能完成编译 一个onTest E2E例子如下: tc := cmake.new(testSrc, testBuild, testBuild+"/_out")
tc.buildType "Release"
tc.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5"
tc.use installDir
Collaborator
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. 或者说我们现在对测试逻辑就是预期对installDir可写的嘛
Collaborator
Author
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. 其实是因为我们没办法控制它不可写,我们不是操作系统没有控制它仅可写的权限
Collaborator
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. Got it |
Uh oh!
There was an error while loading. Please reload this page.