diff options
author | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2021-09-06 14:36:18 -0500 |
---|---|---|
committer | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2021-09-06 14:36:18 -0500 |
commit | 989412cd49c4d922d2a6fdcebb1c51fbc91bc066 (patch) | |
tree | ddcf528afbfb5f0720884b223674913ea6ce15d1 | |
parent | 5a5c9d98ea15ac15a86901808ac4b966fec5e012 (diff) | |
parent | 7343fd274c37246ba449550cf29f638351794ba4 (diff) | |
download | deb-planr-989412cd49c4d922d2a6fdcebb1c51fbc91bc066.tar.xz deb-planr-989412cd49c4d922d2a6fdcebb1c51fbc91bc066.zip |
Merge branch 'upstream' into ppa
Update v0.1.2
-rw-r--r-- | CHANGELOG.md | 10 | ||||
-rw-r--r-- | adapters.go | 8 | ||||
-rw-r--r-- | adapters/bash/adapter.go | 14 | ||||
-rw-r--r-- | adapters/gtest/adapter.go | 31 | ||||
-rw-r--r-- | dirtyscripting.go | 10 | ||||
-rw-r--r-- | runner.go | 29 | ||||
-rw-r--r-- | version.go | 2 |
7 files changed, 71 insertions, 33 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f48554b..d478208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [ v0.1.2 ] +- BUG: Fix build issue where adapters would change parent process's env in conflicting ways (chdir) +- BUG: Precompile `gtest` and `gmock` to prevent runtime issues + +## [ v0.1.1 ] + +### Added +- `compiler_options` directive +- `include_srcs` directive + ## [ v0.1.0 ] ### Added diff --git a/adapters.go b/adapters.go index f6c48cb..03f0b11 100644 --- a/adapters.go +++ b/adapters.go @@ -11,7 +11,7 @@ import ( type Adapter interface { Config() AdapterConfig - Init(dirs DirConfig) + Init(ctx PipelineContext) // Called once to preform expensive code generation Build(testCase []TestCase) @@ -20,6 +20,12 @@ type Adapter interface { Evaluate(testCase []TestCase) []TestResult } +// Additional information required during the build / evaluation stages +type PipelineContext struct { + Dirs DirConfig + AdapterDir string +} + // A parser function takes a blob of TOML and decodes it into // configuration relevant to an adapter type TomlParser func (toml.Primitive) (InheritableConfig, error) diff --git a/adapters/bash/adapter.go b/adapters/bash/adapter.go index 65a6c80..8c7713c 100644 --- a/adapters/bash/adapter.go +++ b/adapters/bash/adapter.go @@ -15,7 +15,8 @@ import ( ) type Adapter struct { - dirs planr.DirConfig + dirs planr.DirConfig + buildDir string } func (a *Adapter) Config() planr.AdapterConfig { @@ -36,13 +37,14 @@ func safeWd() string{ return wd } -func (a *Adapter) Init(dirs planr.DirConfig) { - a.dirs = dirs +func (a *Adapter) Init(ctx planr.PipelineContext) { + a.dirs = ctx.Dirs + a.buildDir = ctx.AdapterDir } func (adapter Adapter) Build(tcs []planr.TestCase) { } -func executeScriptedTest(testdir string, tc planr.TestCase) planr.TestResult { +func executeScriptedTest(builddir, testdir string, tc planr.TestCase) planr.TestResult { cfg := tc.AdapterConfig().(*Config) timeout := time.Duration(cfg.Timeout) * time.Millisecond @@ -57,6 +59,8 @@ func executeScriptedTest(testdir string, tc planr.TestCase) planr.TestResult { result.Tc = tc cmd := exec.CommandContext(ctx, "bash", path) + + cmd.Dir = builddir if out, err := cmd.CombinedOutput(); err != nil { result.Status = planr.RUNTIME_FAILURE @@ -87,7 +91,7 @@ func (adapter Adapter) Evaluate(tcs []planr.TestCase) [] planr.TestResult { c := make(chan planr.TestResult, 0) for i := range tcs { go func(i int) { - c <- executeScriptedTest(adapter.dirs.Tests(), tcs[i]) + c <- executeScriptedTest(adapter.buildDir, adapter.dirs.Tests(), tcs[i]) }(i) } diff --git a/adapters/gtest/adapter.go b/adapters/gtest/adapter.go index 2961f29..96b6976 100644 --- a/adapters/gtest/adapter.go +++ b/adapters/gtest/adapter.go @@ -4,6 +4,7 @@ import ( "log" "os" "path" + "os/exec" "golang.flu0r1ne.net/planr" ) @@ -20,7 +21,8 @@ func safeWd() string{ } type Adapter struct { - dirs planr.DirConfig + dirs planr.DirConfig + buildDir string } func (a *Adapter) Config() planr.AdapterConfig { @@ -31,28 +33,35 @@ func (a *Adapter) Config() planr.AdapterConfig { } } -func (a *Adapter) Init(dirs planr.DirConfig) { - a.dirs = dirs +func (a *Adapter) Init(ctx planr.PipelineContext) { + a.dirs = ctx.Dirs + a.buildDir = ctx.AdapterDir } func (adapter Adapter) Build(tcs []planr.TestCase) { - buildDir := safeWd() - finalizeConfigs(tcs) exes := createExecutables(tcs) - cmakeFile := path.Join(buildDir, GTEST_CMAKE) + cmakeFile := path.Join(adapter.buildDir, GTEST_CMAKE) cmakeUnits := cmakeUnits(exes, adapter.dirs) generateCmakeScript(cmakeFile, cmakeUnits) - planr.RunCmd("cmake", "-S", ".", "-B", ".") + cmd := exec.Command("cmake", "-S", ".", "-B", ".") + + cmd.Dir = adapter.buildDir + + planr.Exec(cmd) + + cmd = exec.Command("make", "gtest", "gmock") + + cmd.Dir = adapter.buildDir + + planr.Exec(cmd) } func (adapter *Adapter) Evaluate(tcs []planr.TestCase) [] planr.TestResult { - buildDir := safeWd() - finalizeConfigs(tcs) results := make([]planr.TestResult, 0) @@ -62,14 +71,14 @@ func (adapter *Adapter) Evaluate(tcs []planr.TestCase) [] planr.TestResult { c := make(chan []planr.TestResult, len(exes)) for i := range exes { go func(exe *executable) { - succeed, buildFailures := exe.compile(buildDir) + succeed, buildFailures := exe.compile(adapter.buildDir) if ! succeed { c <- buildFailures return } - runtimeResults := exe.execute(buildDir) + runtimeResults := exe.execute(adapter.buildDir) c <- runtimeResults }(&exes[i]) diff --git a/dirtyscripting.go b/dirtyscripting.go index 9924d54..ee8531d 100644 --- a/dirtyscripting.go +++ b/dirtyscripting.go @@ -7,9 +7,7 @@ import ( "log" ) -func RunCmd(name string, args ...string) { - cmd := exec.Command(name, args...) - +func Exec(cmd * exec.Cmd) { stderr, err := cmd.StderrPipe() if err != nil { log.Fatal(err); @@ -40,3 +38,9 @@ func RunCmd(name string, args ...string) { log.Fatalf("Could not execute cmake command\n%v", err) } } + +func RunCmd(name string, args ...string) { + cmd := exec.Command(name, args...) + + Exec(cmd) +} @@ -29,17 +29,19 @@ func (r Runner) checkConfig(tcs []TestCase) { } } -func (r Runner) setupEnv(adapter Adapter) { - nm := adapter.Config().Name - wd := path.Join(r.dirs.Build(), nm) +func adapterBuildDir(dirs DirConfig, adapter Adapter) string { + return path.Join(dirs.Build(), adapter.Config().Name) +} + +func (r Runner) createAdapterBuildDir(adapter Adapter) { + build := adapterBuildDir(r.dirs, adapter) - if !directoryExists(wd) { - if err := os.Mkdir(wd, 0755); err != nil { - log.Fatalf("Could not create adapter config %s %v\n", wd, err) + if !directoryExists(build) { + if err := os.Mkdir(build, 0755); err != nil { + log.Fatalf("Could not create adapter config %s %v\n", build, err) } } - safeCd(wd) } type adapterTestSet struct { @@ -101,12 +103,10 @@ func (r Runner) Build(tcs []TestCase) { adapter := pair.adapter cases := pair.tcs - r.setupEnv(adapter) + r.createAdapterBuildDir(adapter) adapter.Build(cases) } - - safeCd(r.dirs.Config()) } func (r Runner) Evaluate(tcs []TestCase) []TestResult { @@ -119,7 +119,6 @@ func (r Runner) Evaluate(tcs []TestCase) []TestResult { adapter := pair.adapter cases := pair.tcs - r.setupEnv(adapter) resultSet := adapter.Evaluate(cases) c <- resultSet @@ -155,9 +154,15 @@ func (r Runner) SrcDir() string { func NewRunner(adapters map[string]Adapter, dirs DirConfig) Runner { r := Runner{adapters, dirs} + for _, adapter := range r.adapters { - adapter.Init(dirs) + ctx := PipelineContext { + Dirs: dirs, + AdapterDir: adapterBuildDir(dirs, adapter), + } + + adapter.Init(ctx) } return r @@ -1,3 +1,3 @@ package planr -const VERSION = "0.1.1" +const VERSION = "0.1.2" |