Skip to content

Commit

Permalink
Add interface to get run and test deps
Browse files Browse the repository at this point in the history
Since tests are identified as a single command, dependencies for tests
and run are implicitly assumed to be the same as for the Build step,
including the target binary. This is, however not correct because it
doesn't account for the fact that we may want to use  a different test
runner or some additional target that must be compiled before testing,
but not necessarily in the build step of the target.

With this purpose this change introduces an extendedTestInterface
and extendedRunInteface where the user may also specify a TestDeps() or
RunDeps() function to get the dependencies of the test/run step.
  • Loading branch information
Javier-varez committed Feb 7, 2023
1 parent 2640b77 commit 63703bc
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions RULES/core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,24 @@ type runInterface interface {
Run(args []string) string
}

// An interface for runnables that depend on some other set of targets to run, but not to build
// For example, when using a test wrapper.
type extendedRunInterface interface {
runInterface
RunDeps() []OutPath
}

type testInterface interface {
Test(args []string) string
}

// An interface for tests that depend on some other set of targets to run, but not to build
// For example, when using a test wrapper.
type extendedTestInterface interface {
testInterface
TestDeps() []OutPath
}

type CoverageInterface interface {
Test(args []string) string
Binaries() []Path
Expand Down Expand Up @@ -314,9 +328,17 @@ func (ctx *context) handleTarget(targetPath string, target buildInterface) {
})

if runIface, ok := target.(runInterface); ok {
deps := []string{}
if extendedRunIface, ok := target.(extendedRunInterface); ok {
depsPaths := extendedRunIface.RunDeps()
for _, dep := range depsPaths {
deps = append(deps, dep.Absolute())
}
}

ctx.targetRules = append(ctx.targetRules, TargetRule{
Target: fmt.Sprintf("%s#run", targetPath),
Ins: []string{targetPath},
Ins: append(deps, targetPath),
Variables: map[string]string{
"command": runIface.Run(input.RunArgs),
"description": fmt.Sprintf("Running %s:", targetPath),
Expand All @@ -326,9 +348,17 @@ func (ctx *context) handleTarget(targetPath string, target buildInterface) {
}

if testIface, ok := target.(testInterface); ok {
deps := []string{}
if extendedTestIface, ok := target.(extendedTestInterface); ok {
depsPaths := extendedTestIface.TestDeps()
for _, dep := range depsPaths {
deps = append(deps, dep.Absolute())
}
}

ctx.targetRules = append(ctx.targetRules, TargetRule{
Target: fmt.Sprintf("%s#test", targetPath),
Ins: []string{targetPath},
Ins: append(deps, targetPath),
Variables: map[string]string{
"command": testIface.Test(input.TestArgs),
"description": fmt.Sprintf("Testing %s:", targetPath),
Expand Down

0 comments on commit 63703bc

Please sign in to comment.