Skip to content

Commit 852e4c3

Browse files
committed
Merge branch 'dev' into 'master'
v1.1.0 See merge request objectbox/objectbox-go!67
2 parents 55ba489 + 9a838b7 commit 852e4c3

File tree

217 files changed

+12430
-2676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+12430
-2676
lines changed

.gitlab-ci.yml

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
1-
test:linux:x64:
1+
.test:linux:x64:
22
stage: test
3-
image: golang
43
tags: [x64, linux, docker]
4+
before_script:
5+
- 'cd /usr/local/lib && { curl --fail -o libobjectbox.so -H "PRIVATE-TOKEN: $CI_API_TOKEN" "${OBXLIB_URL_Linux64}" ; ldconfig ; cd - ; }'
56
script:
6-
- 'cd /usr/local/lib && { curl -o libobjectbox.so -H "PRIVATE-TOKEN: $CI_API_TOKEN" "${OBXLIB_URL_Linux64}" ; ldconfig ; cd - ; }'
77
- ./build/build.sh
88

9+
# minimal supported Go version is 1.11.4
10+
test:linux:x64:go1.11.4:
11+
extends: .test:linux:x64
12+
image: golang:1.11.4
13+
script:
14+
- ./build/build.sh -test.short
15+
16+
test:linux:x64:go1.12:
17+
extends: .test:linux:x64
18+
image: golang:1.12
19+
script:
20+
- ./build/build.sh -test.short
21+
22+
test:linux:x64:go1.13:
23+
extends: .test:linux:x64
24+
image: golang:1.13
25+
926
test:linux:ARMv7hf:
1027
stage: test
11-
image: arm32v7/golang
28+
image: golang
1229
tags: [armv7hf, linux, docker]
1330
script:
14-
- 'cd /usr/local/lib && { curl -o libobjectbox.so -H "PRIVATE-TOKEN: $CI_API_TOKEN" "${OBXLIB_URL_LinuxARMv7hf}" ; ldconfig ; cd - ; }'
15-
- ./build/build.sh
31+
- 'cd /usr/local/lib && { curl --fail -o libobjectbox.so -H "PRIVATE-TOKEN: $CI_API_TOKEN" "${OBXLIB_URL_LinuxARMv7hf}" ; ldconfig ; cd - ; }'
32+
- ./build/build.sh -test.short
1633

1734
test:mac:x64:
1835
stage: test
1936
tags: [x64, mac, go]
2037
script:
21-
- 'curl -o /usr/local/lib/libobjectbox.dylib -H "PRIVATE-TOKEN: $CI_API_TOKEN" "$OBXLIB_URL_Mac64"'
38+
- 'curl --fail -o /usr/local/lib/libobjectbox.dylib -H "PRIVATE-TOKEN: $CI_API_TOKEN" "$OBXLIB_URL_Mac64"'
39+
- ./build/build.sh
40+
41+
test:win:x64:
42+
stage: test
43+
tags: [x64, windows, go]
44+
script:
45+
- libDir=$(realpath $(dirname $(which gcc))/../lib)
46+
- 'curl --fail -o $libDir/objectbox.dll -H "PRIVATE-TOKEN: $CI_API_TOKEN" "$OBXLIB_URL_Win64"'
2247
- ./build/build.sh

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ id, err := box.Put(&Person{ FirstName: "Joe", LastName: "Green" })
1818
Want details? **[Read the docs](https://golang.objectbox.io/)** or
1919
**[check out the API reference](https://godoc.org/github.com/objectbox/objectbox-go/objectbox)**.
2020

21-
Latest release: [v1.0.0 (2019-07-16)](https://golang.objectbox.io/)
21+
Latest release: [v1.1.0 (2019-12-16)](https://golang.objectbox.io/)
2222

2323
Some features
2424
-------------

build/build.sh

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
#!/usr/bin/env bash
22
set -eu
3-
3+
args="$@"
44
buildDir=${PWD}/build-artifacts
55

66
function preBuild {
77
echo "******** Preparing build ********"
88
echo "Creating build artifacts directory '$buildDir'"
9-
mkdir -p $buildDir
9+
mkdir -p "$buildDir"
1010
}
1111

1212
function build {
1313
echo "******** Building ********"
14-
for CMD in `ls cmd`; do
15-
echo "building cmd/${CMD}"
16-
cd cmd/${CMD}
17-
go build -o ${buildDir}/${CMD}
14+
for path in cmd/*; do
15+
echo "building ${path}"
16+
cd "${path}"
17+
cmd=$(basename "${path}")
18+
go build -o "${buildDir}/${cmd}"
1819
cd -
1920
done
2021
}
@@ -23,17 +24,17 @@ function postBuild {
2324
echo "******** Collecting artifacts ********"
2425

2526
echo "The $buildDir contains the following files: "
26-
ls -l $buildDir
27+
ls -l "$buildDir"
2728
}
2829

2930
function test {
3031
echo "******** Testing ********"
3132

3233
# on amd64, we run extended tests (memory sanitizer & race checks)
3334
if [[ $(go env GOARCH) == "amd64" ]]; then
34-
./build/test.sh -race
35+
./build/test.sh $args -race
3536
else
36-
./build/test.sh
37+
./build/test.sh $args
3738
fi
3839
}
3940

@@ -42,6 +43,8 @@ function generate {
4243
go generate ./...
4344
}
4445

46+
go version
47+
4548
preBuild
4649
build
4750
generate

build/test.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ fi
1010

1111
unformatted_files=$(gofmt -l .)
1212
if [[ ${unformatted_files} ]]; then
13-
echo "Some files are not formatted properly. You can use \`gofmt -l -w .\` to fix them."
14-
printf "%s\n" ${unformatted_files}
13+
echo "Some files are not formatted properly. You can use \`gofmt -l -w .\` to fix them:"
14+
printf "%s\n" "${unformatted_files}"
15+
exit 1
1516
fi
1617

1718
go vet ./...

cmd/objectbox-gogen/doc.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,29 @@ containing the struct that you want to persist and executing `go generate` in th
77
88
Alternatively, you can run the command manually:
99
10-
objectbox-gogen [flags]
10+
objectbox-gogen [flags] [path-pattern]
11+
to generate the binding code
1112
13+
or
1214
13-
The flags are
15+
objectbox-gogen clean [path-pattern]
16+
to remove the generated files instead of creating them - this removes *.obx.go and objectbox-model.go but keeps objectbox-model.json
1417
18+
path-pattern:
19+
* a path or a valid path pattern as accepted by the go tool (e.g. ./...)
20+
* if not given, the generator expects GOFILE environment variable to be set
21+
22+
Available flags:
1523
-byValue
1624
getters should return a struct value (a copy) instead of a struct pointer
25+
-help
26+
print this help
1727
-persist string
1828
path to the model information persistence file
1929
-source string
20-
path to the source file containing structs to process
30+
@deprecated, equivalent to passing the given source file path as as the path-pattern argument
31+
-version
32+
print the generator version info
2133
2234
2335

cmd/objectbox-gogen/objectbox-gogen.go

+75-11
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@ package main
1919
import (
2020
"flag"
2121
"fmt"
22-
"github.com/objectbox/objectbox-go/internal/generator"
2322
"os"
23+
24+
"github.com/objectbox/objectbox-go/internal/generator"
2425
)
2526

2627
func main() {
27-
sourceFile, options := getArgs()
28+
path, clean, options := getArgs()
2829

29-
fmt.Printf("Generating ObjectBox bindings for %s", sourceFile)
30-
fmt.Println()
30+
var err error
31+
if clean {
32+
fmt.Printf("Removing ObjectBox bindings for %s\n", path)
33+
err = generator.Clean(path)
34+
} else {
35+
fmt.Printf("Generating ObjectBox bindings for %s\n", path)
36+
err = generator.Process(path, options)
37+
}
3138

32-
err := generator.Process(sourceFile, options)
3339
stopOnError(err)
3440
}
3541

@@ -40,32 +46,90 @@ func stopOnError(err error) {
4046
}
4147
}
4248

49+
func showUsage() {
50+
fmt.Fprint(flag.CommandLine.Output(), `Usage:
51+
objectbox-gogen [flags] [path-pattern]
52+
to generate the binding code
53+
54+
or
55+
56+
objectbox-gogen clean [path-pattern]
57+
to remove the generated files instead of creating them - this removes *.obx.go and objectbox-model.go but keeps objectbox-model.json
58+
59+
path-pattern:
60+
* a path or a valid path pattern as accepted by the go tool (e.g. ./...)
61+
* if not given, the generator expects GOFILE environment variable to be set
62+
63+
Available flags:
64+
`)
65+
flag.PrintDefaults()
66+
}
67+
4368
func showUsageAndExit() {
44-
flag.Usage()
69+
showUsage()
4570
os.Exit(1)
4671
}
4772

48-
func getArgs() (file string, options generator.Options) {
73+
func getArgs() (path string, clean bool, options generator.Options) {
4974
var printVersion bool
50-
flag.StringVar(&file, "source", "", "path to the source file containing structs to process")
75+
var printHelp bool
76+
flag.Usage = showUsage
77+
flag.StringVar(&path, "source", "", "@deprecated, equivalent to passing the given source file path as as the path-pattern argument")
5178
flag.StringVar(&options.ModelInfoFile, "persist", "", "path to the model information persistence file")
5279
flag.BoolVar(&options.ByValue, "byValue", false, "getters should return a struct value (a copy) instead of a struct pointer")
5380
flag.BoolVar(&printVersion, "version", false, "print the generator version info")
81+
flag.BoolVar(&printHelp, "help", false, "print this help")
5482
flag.Parse()
5583

84+
if printHelp {
85+
showUsage()
86+
os.Exit(0)
87+
}
88+
5689
if printVersion {
5790
fmt.Println(fmt.Sprintf("ObjectBox Go binding code generator version: %d", generator.Version))
5891
os.Exit(0)
5992
}
6093

61-
if len(file) == 0 {
94+
if len(path) != 0 {
95+
fmt.Println("'source' flag is deprecated and will be removed in the future - use a standard positional argument instead. See command help for more information.")
96+
}
97+
98+
var argPath string
99+
100+
if flag.NArg() == 2 {
101+
clean = true
102+
if flag.Arg(0) != "clean" {
103+
fmt.Printf("Unknown argument %s", flag.Arg(0))
104+
showUsageAndExit()
105+
}
106+
107+
argPath = flag.Arg(1)
108+
109+
} else if flag.NArg() == 1 {
110+
argPath = flag.Arg(0)
111+
} else if flag.NArg() != 0 {
112+
showUsageAndExit()
113+
}
114+
115+
// if the path-pattern positional argument was given
116+
if len(argPath) > 0 {
117+
if len(path) == 0 {
118+
path = argPath
119+
} else if argPath != path {
120+
fmt.Printf("Path argument mismatch - given 'source' flag '%s' and the positional path argument '%s'\n", path, argPath)
121+
showUsageAndExit()
122+
}
123+
}
124+
125+
if len(path) == 0 {
62126
// if the command is run by go:generate some environment variables are set
63127
// https://golang.org/pkg/cmd/go/internal/generate/
64128
if gofile, exists := os.LookupEnv("GOFILE"); exists {
65-
file = gofile
129+
path = gofile
66130
}
67131

68-
if len(file) == 0 {
132+
if len(path) == 0 {
69133
showUsageAndExit()
70134
}
71135
}

examples/tasks/internal/model/objectbox-model.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/tasks/internal/model/objectbox-model.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"id": "1:2193439623591184445",
1313
"name": "Id",
1414
"type": 6,
15-
"flags": 8193
15+
"flags": 1
1616
},
1717
{
1818
"id": "2:6177929178231325611",

examples/tasks/internal/model/task.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package model
1818

1919
//go:generate go run github.com/objectbox/objectbox-go/cmd/objectbox-gogen
2020

21+
// Task model
2122
type Task struct {
2223
Id uint64
2324
Text string

0 commit comments

Comments
 (0)