Skip to content

Commit adcdaff

Browse files
committed
Merge branch '26-go-test-integration-cmake' into 'dev'
Integrate standalone cmake tests as go test See merge request objectbox/objectbox-generator!22
2 parents 1fc6ed4 + 8aab481 commit adcdaff

38 files changed

Lines changed: 395 additions & 50 deletions

.github/workflows/ci.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ jobs:
3535
- run: make
3636
- run: make test-depend
3737
- run: make test
38-
- if: matrix.os == 'windows-2019'
39-
run: cd test/standalone-cmake && cmake -DMULTI="Visual Studio 16 2019" -P test-cmake-generators.cmake
40-
- if: matrix.os == 'ubuntu-22.04'
41-
run: cd test/standalone-cmake && cmake -DSINGLE="Unix Makefiles" -P test-cmake-generators.cmake
42-
- if: matrix.os == 'macos-12'
43-
# Exclude cpp-*-multiple-targets test-projects for Xcode
44-
run: cd test/standalone-cmake && cmake -DMULTI="Xcode" -DPROJECTS="cpp-flat;cpp-tree;cpp-multiple-schema-dirs" -P test-cmake-generators.cmake
4538

4639
- name: Upload artifact
4740
uses: actions/upload-artifact@v4

.gitlab-ci.yml

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# 1.19.13 | /root/sdk/go1.19.13 | Additional version installed via go install
1616

1717
#
18-
b:go1.18:
18+
bt:linux-x64:go1.18:
1919
extends: [ .build ]
2020
script:
2121
- export PATH=/usr/lib/go-1.18/bin:$PATH
@@ -24,7 +24,7 @@ b:go1.18:
2424
- make test-depend
2525
- make test
2626

27-
b:go1.19:
27+
bt:linux-x64:go1.19:
2828
extends: [ .build ]
2929
script:
3030
- export PATH=/root/sdk/go1.19.13/bin:$PATH
@@ -33,32 +33,24 @@ b:go1.19:
3333
- make test-depend
3434
- make test
3535

36-
b:go1.22:
36+
bt:linux-x64:go1.22:
3737
extends: [ .build ]
3838
script:
3939
- make info
4040
- make
4141
- make test-depend
4242
- make test
4343

44-
t:cmake:linux-x64:
45-
tags: [ x64, linux, docker ]
46-
image:
47-
name: objectboxio/buildenv-core:2024-07-11
44+
bt:mac-x64:
45+
tags: [ mac, x64 ]
4846
script:
49-
- cd test/standalone-cmake && cmake -DAUTO=1 -P test-cmake-generators.cmake
47+
- make info
48+
- make
49+
- make test-depend
50+
- make test
5051

52+
# TODO: Prepare CI/Windows to build and test this project; Prerequisites: MinGW Make
5153
t:cmake:win-x64:
5254
tags: [ windows ]
5355
script:
54-
- cd test/standalone-cmake && cmake -DMULTI="Visual Studio 17 2022" -P test-cmake-generators.cmake
55-
56-
t:cmake:mac-x64:
57-
tags: [ mac, x64 ]
58-
script:
59-
- cd test/standalone-cmake
60-
# Test using just make/ninja if found
61-
- cmake -DAUTO=1 -P test-cmake-generators.cmake
62-
# Test Xcode excluding multiple-targets test projects
63-
- cmake -DMULTI="Xcode" -DPROJECTS="cpp-flat;cpp-tree;cpp-multiple-schema-dirs" -P test-cmake-generators.cmake
64-
56+
- cd test/integration/cmake/projects && cmake -DMULTI="Visual Studio 17 2022" -P test-cmake-generators.cmake

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ reinstall: build ## Update installed objectbox-generator
2929
test: ## Test all targets
3030
go test -timeout 1h ./...
3131

32-
test-cmake:
33-
cd test/standalone-cmake && cmake -DAUTO=1 -P test-cmake-generators.cmake
34-
3532
clean: ## Clean previous builds
3633
go clean -cache
3734
go clean ./..

test/cmake/cmake.go

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ import (
3737
// Cmake contains all configuration necessary to configure and build a CMake project
3838
type Cmake struct {
3939
// Configs required for CMakeLists.txt
40-
Name string // Executable name
41-
IsCpp bool
42-
Standard int // CMAKE_C/CXX_STANDARD
43-
Files []string
44-
IncludeDirs []string
45-
LinkLibs []string // Library names or full paths
46-
LinkDirs []string // Where should the linker look for libraries
47-
Generator string
40+
Name string // Executable name
41+
IsCpp bool
42+
Standard int // CMAKE_C/CXX_STANDARD
43+
Files []string
44+
IncludeDirs []string
45+
LinkLibs []string // Library names or full paths
46+
LinkDirs []string // Where should the linker look for libraries
47+
Generator string
48+
ConfigureFlags []string
4849

4950
// Build configuration
5051
ConfDir string
@@ -159,20 +160,79 @@ func (cmake *Cmake) Configure() ([]byte, []byte, error) {
159160
cmake.Generator = "MinGW Makefiles"
160161
}
161162

162-
if len(cmake.Generator) > 0 {
163-
return cmakeExec(cmake.BuildDir, cmake.ConfDir, "-G", cmake.Generator)
164-
} else {
165-
return cmakeExec(cmake.BuildDir, cmake.ConfDir)
163+
var args = []string{cmake.ConfDir}
164+
args = append(args, cmake.ConfigureFlags[:]...)
165+
166+
if len(cmake.Generator) > 0 && cmake.Generator != "default" {
167+
args = append(args, "-G", cmake.Generator)
166168
}
169+
170+
return cmakeExec(cmake.BuildDir, args[:]...)
167171
}
168172

169-
// Build runs cmake build step.
170-
func (cmake *Cmake) Build() ([]byte, []byte, error) {
173+
// Configure runs cmake configuration step without any CI quirks as is.
174+
func (cmake *Cmake) ConfigureRaw() ([]byte, []byte, error) {
175+
var args = []string{cmake.ConfDir}
176+
args = append(args, cmake.ConfigureFlags[:]...)
177+
178+
if len(cmake.Generator) > 0 && cmake.Generator != "default" {
179+
args = append(args, "-G", cmake.Generator)
180+
}
181+
182+
return cmakeExec(cmake.BuildDir, args[:]...)
183+
}
184+
185+
// Build runs cmake build "Name" target step.
186+
func (cmake *Cmake) BuildTarget() ([]byte, []byte, error) {
171187
return cmakeExec(cmake.ConfDir,
172188
"--build", cmake.BuildDir,
173189
"--target", cmake.Name,
174-
"--",
175-
"-j"+strconv.FormatInt(int64(runtime.NumCPU()/2), 10))
190+
"--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
191+
)
192+
}
193+
194+
// Build runs cmake build "Name" target step.
195+
func (cmake *Cmake) BuildWithTarget(target string) ([]byte, []byte, error) {
196+
return cmakeExec(cmake.ConfDir,
197+
"--build", cmake.BuildDir,
198+
"--target", target,
199+
// "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
200+
)
201+
}
202+
203+
// Build runs cmake build step.
204+
func (cmake *Cmake) BuildDefaults() ([]byte, []byte, error) {
205+
return cmakeExec(cmake.ConfDir,
206+
"--build", cmake.BuildDir,
207+
// "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
208+
)
209+
}
210+
211+
// Build runs cmake default build step with config
212+
func (cmake *Cmake) BuildDefaultsWithConfig(config string) ([]byte, []byte, error) {
213+
return cmakeExec(cmake.ConfDir,
214+
"--build", cmake.BuildDir,
215+
"--config", config,
216+
// "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
217+
)
218+
}
219+
220+
// Build runs cmake default build step with config
221+
func (cmake *Cmake) BuildTargetWithConfig(config, target string) ([]byte, []byte, error) {
222+
return cmakeExec(cmake.ConfDir,
223+
"--build", cmake.BuildDir,
224+
"--config", config,
225+
"--target", target,
226+
// "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
227+
)
228+
}
229+
230+
func CopyDir(cwd string, src string, dst string) ([]byte, []byte, error) {
231+
return cmakeExec(cwd, "-E", "copy_directory", src, dst)
232+
}
233+
234+
func CopyFile(cwd string, file string, dst string) ([]byte, []byte, error) {
235+
return cmakeExec(cwd, "-E", "copy", file, dst)
176236
}
177237

178238
func cmakeExec(cwd string, args ...string) (stdOut []byte, stdErr []byte, err error) {

test/cmake/libcheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func LibraryExists(name string, includeFiles, includeDirs, linkDirs, predefines
7272
return fmt.Errorf("cmake configuration failed: \n%s\n%s\n%s", stdOut, stdErr, err)
7373
}
7474

75-
if stdOut, stdErr, err := build.Build(); err != nil {
75+
if stdOut, stdErr, err := build.BuildTarget(); err != nil {
7676
return fmt.Errorf("cmake build failed: \n%s\n%s\n%s", stdOut, stdErr, err)
7777
}
7878

test/comparison/c-helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (h cTestHelper) build(t *testing.T, conf testSpec, dir string, expectedErro
130130
t.Logf("configuration output:\n%s", string(stdOut))
131131
}
132132

133-
if stdOut, stdErr, err := cmak.Build(); err != nil {
133+
if stdOut, stdErr, err := cmak.BuildTarget(); err != nil {
134134
checkBuildError(t, errorTransformer, stdOut, stdErr, err, expectedError)
135135
assert.Failf(t, "cmake build failed: \n%s\n%s\n%s", stdOut, stdErr, err)
136136
} else {

0 commit comments

Comments
 (0)