summaryrefslogtreecommitdiff
path: root/adapters
diff options
context:
space:
mode:
authorFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-06 01:58:42 -0500
committerFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-06 01:58:42 -0500
commit788ae3e0266bdb12bdff6c260dda2e3bcbdfc79c (patch)
tree22f2dab21e0c6b56085f88fb0047945edc735e23 /adapters
parentccb11dfb1e539b4e5732442a7a1f701996b608c5 (diff)
downloaddeb-planr-788ae3e0266bdb12bdff6c260dda2e3bcbdfc79c.tar.xz
deb-planr-788ae3e0266bdb12bdff6c260dda2e3bcbdfc79c.zip
Add directives for compiler options and shared linking
Diffstat (limited to 'adapters')
-rw-r--r--adapters/gtest/config.go42
-rw-r--r--adapters/gtest/executable.go43
-rw-r--r--adapters/gtest/templating.go48
3 files changed, 93 insertions, 40 deletions
diff --git a/adapters/gtest/config.go b/adapters/gtest/config.go
index 533f266..71b5cca 100644
--- a/adapters/gtest/config.go
+++ b/adapters/gtest/config.go
@@ -13,21 +13,25 @@ const (
)
type Defaults struct {
- Name string
- Suite string
- Testfile string
- Srcs []string
- Timeout uint
+ Name string
+ Suite string
+ Testfile string
+ Srcs []string
+ Timeout uint
+ Include_src *bool
+ Compiler_options string
}
func (child *Defaults) Inherit(p interface{}) {
parent := p.(*Defaults)
- if(child.Name == "") { child.Name = parent.Name }
- if(child.Suite == "") { child.Suite = parent.Suite }
- if(child.Testfile == "") { child.Testfile = parent.Testfile }
- if(len(child.Srcs) == 0) { child.Srcs = parent.Srcs }
- if(child.Timeout == 0) { child.Timeout = parent.Timeout }
+ if(child.Name == "") { child.Name = parent.Name }
+ if(child.Suite == "") { child.Suite = parent.Suite }
+ if(child.Testfile == "") { child.Testfile = parent.Testfile }
+ if(len(child.Srcs) == 0) { child.Srcs = parent.Srcs }
+ if(child.Timeout == 0) { child.Timeout = parent.Timeout }
+ if(child.Compiler_options == "") { child.Compiler_options = parent.Compiler_options }
+ if(child.Include_src == nil) { child.Include_src = parent.Include_src}
}
@@ -47,6 +51,11 @@ func (c * Config) finalize(path string) {
if c.Timeout == 0 {
c.Timeout = DEFAULT_TIMEOUT;
}
+
+ if c.Include_src == nil {
+ c.Include_src = new(bool)
+ *c.Include_src = true
+ }
}
func srcList(srcdir string, srcs []string) string {
@@ -61,19 +70,6 @@ func srcList(srcdir string, srcs []string) string {
return builder.String()
}
-func cmakeUnits(e []executable, dirs planr.DirConfig) []cmakeUnit {
-
- units := make([]cmakeUnit, len(e))
- for i, exe := range e {
- testpath := path.Join(dirs.Tests(), exe.testpath)
- srclist := srcList(dirs.Src(), exe.srcs)
-
- units[i] = cmakeUnit { exe.exeNm, testpath, srclist }
- }
-
- return units
-}
-
func finalizeConfigs(tcs []planr.TestCase) {
for i := range tcs {
cfg := tcs[i].AdapterConfig().(*Config)
diff --git a/adapters/gtest/executable.go b/adapters/gtest/executable.go
index 25c83c1..80560c5 100644
--- a/adapters/gtest/executable.go
+++ b/adapters/gtest/executable.go
@@ -12,14 +12,22 @@ import (
"sort"
"context"
- "golang.flu0r1ne.net/planr"
-)
+ "golang.flu0r1ne.net/planr")
type executable struct {
- exeNm string
- testpath string
- srcs []string
- tcs []planr.TestCase
+ exeNm string
+ testpath string
+ srcs []string
+ includeSrc bool
+ compilerOptions string
+ tcs []planr.TestCase
+}
+
+func dieConflictingExeProperty(exe executable, tc planr.TestCase, property string) {
+ log.Fatalf(
+ "Two test cases (including %s) belonging to the same executable (%s) have one or more conflicting properties\nProperty :%s",
+ tc.Cname, exe.testpath, property,
+ )
}
func createExecutables(tcs []planr.TestCase) []executable {
@@ -39,10 +47,12 @@ func createExecutables(tcs []planr.TestCase) []executable {
exe := executable {
- planr.Cname("", file),
- file,
- cfg.Srcs,
- exeTcs,
+ exeNm: planr.Cname("", file),
+ testpath: file,
+ srcs: cfg.Srcs,
+ includeSrc: *cfg.Include_src,
+ compilerOptions: cfg.Compiler_options,
+ tcs: exeTcs,
}
exes[file] = exe
@@ -53,10 +63,15 @@ func createExecutables(tcs []planr.TestCase) []executable {
// We could create two different executables for each source list
// But, that would be confusing so we're going to disallow it
if !reflect.DeepEqual(exe.srcs, cfg.Srcs) {
- log.Fatalf(
- "Two test case definitions %s and %s have different lists of sources",
- exe.testpath, cfg.Testfile,
- )
+ dieConflictingExeProperty(exe, tc, "srcs")
+ }
+
+ if exe.compilerOptions != cfg.Compiler_options {
+ dieConflictingExeProperty(exe, tc, "compiler_options")
+ }
+
+ if exe.includeSrc != *cfg.Include_src {
+ dieConflictingExeProperty(exe, tc, "include_src")
}
exe.tcs = append(exe.tcs, tc)
diff --git a/adapters/gtest/templating.go b/adapters/gtest/templating.go
index 41c54c1..2380db9 100644
--- a/adapters/gtest/templating.go
+++ b/adapters/gtest/templating.go
@@ -5,15 +5,39 @@ import (
"log"
"os"
"golang.flu0r1ne.net/planr"
+ "path"
"text/template"
)
type cmakeUnit struct {
- ExeNm string
- File string
- Srcs string
+ ExeNm string
+ File string
+ Srcdir string
+ IncludeSrc bool
+ Srcs string
+ CompilerOptions string
};
+func cmakeUnits(e []executable, dirs planr.DirConfig) []cmakeUnit {
+
+ units := make([]cmakeUnit, len(e))
+ for i, exe := range e {
+ testpath := path.Join(dirs.Tests(), exe.testpath)
+ srclist := srcList(dirs.Src(), exe.srcs)
+
+ units[i] = cmakeUnit {
+ ExeNm: exe.exeNm,
+ File: testpath,
+ IncludeSrc: exe.includeSrc,
+ Srcdir: dirs.Src(),
+ Srcs: srclist,
+ CompilerOptions: compilerOptionsCmake(exe),
+ }
+ }
+
+ return units
+}
+
func generateCmakeScript(out string, units []cmakeUnit) {
file, err := os.OpenFile(out, os.O_RDWR | os.O_CREATE, 0644)
defer func () {
@@ -39,6 +63,13 @@ func generateCmakeScript(out string, units []cmakeUnit) {
}
}
+func compilerOptionsCmake(e executable) string {
+ if e.compilerOptions == "" {
+ return ""
+ }
+
+ return "target_compile_options(\"" + e.exeNm + "\" PRIVATE " + e.compilerOptions + ")";
+}
// TODO: Add comments
func unitTemplate() *template.Template {
@@ -54,6 +85,14 @@ add_executable(
{{.Srcs}}
)
+{{.CompilerOptions}}
+
+{{ if .IncludeSrc }}
+
+target_include_directories("{{.ExeNm}}" PRIVATE "{{.Srcdir}}")
+
+{{ end }}
+
target_link_libraries(
"{{.ExeNm}}"
gtest_main
@@ -85,6 +124,7 @@ func writeCmakeBoilerplate(w io.Writer) {
})
}
+// TODO: Make CXX Version Editable
func boilderTemplate() *template.Template {
tmpl, err := template.New("gtest_boilerplate").Parse(`
# AUTOMATICALLY GENERATED BY PLANR VERSION {{.Version}}
@@ -99,6 +139,8 @@ FetchContent_Declare(
URL {{.Url}}
)
+set(CMAKE_CXX_STANDARD 17)
+
include(GoogleTest)
FetchContent_MakeAvailable(googletest)
`)