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

Add interface to get run and test deps #98

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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