Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
54 changes: 23 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ name: CI

on: [push, pull_request]

defaults:
run:
shell: bash

jobs:
build-linux:
runs-on: ubuntu-latest
container:
image: centos/devtoolset-7-toolchain-centos7
options: --user 0
steps:
- name: Install Git
run: yum install -y git

- name: Install CMake
env:
version: 3.17.3
Expand All @@ -25,29 +32,21 @@ jobs:
- name: Get sources
uses: actions/checkout@v2

- name: Cache FBS-C-Bridge build dir
id: fbs-bridge-cache
- name: Cache Deps
uses: actions/cache@v2
env:
cache-name: cache-fbs-c-bridge-build
with:
path: ./third_party/flatbuffers-c-bridge/cmake-build/*.a
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('./third_party/flatbuffers-c-bridge/*') }}
path: ./third_party/*
key: ${{ runner.os }}-deps-${{ hashFiles('./third_party/*') }}

- name: Build FBS-C-Bridge
if: steps.fbs-bridge-cache.outputs.cache-hit != 'true'
run: ./third_party/flatbuffers-c-bridge/build.sh

- name: Build
run: |
cd cmd/objectbox-generator
go build
- run: make
- run: make test-depend
- run: make test

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: objectbox-generator-${{ runner.os }}
path: cmd/objectbox-generator/objectbox-generator
path: objectbox-generator

build:
strategy:
Expand All @@ -57,30 +56,23 @@ jobs:
- macos-10.15
runs-on: ${{ matrix.os }}
steps:
- run: git config --global core.autocrlf false

- name: Get sources
uses: actions/checkout@v2

- name: Cache FBS-C-Bridge build dir
id: fbs-bridge-cache
- name: Cache Deps
uses: actions/cache@v2
env:
cache-name: cache-fbs-c-bridge-build
with:
path: ./third_party/flatbuffers-c-bridge/cmake-build/*.a
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('./third_party/flatbuffers-c-bridge/*') }}
path: ./third_party/*
key: ${{ runner.os }}-deps-${{ hashFiles('./third_party/*') }}

- name: Build FBS-C-Bridge
if: steps.fbs-bridge-cache.outputs.cache-hit != 'true'
shell: bash
run: ./third_party/flatbuffers-c-bridge/build.sh

- name: Build
run: |
cd cmd/objectbox-generator
go build
- run: make
- run: make test-depend
- run: make test

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: objectbox-generator-${{ runner.os }}
path: cmd/objectbox-generator/objectbox-generator*
path: objectbox-generator*
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Default target executed when no arguments are given to make.
default_target: all

.PHONY: default_target help clean depend build test
.PHONY: default_target help clean depend build test test-depend

help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'



#==============================================================================

all: depend build
Expand All @@ -23,6 +21,13 @@ clean: ## Clean previous builds
rm -f objectbox-generator
rm -f objectbox-generator.exe
rm -rf third_party/flatbuffers-c-bridge/cmake-build
./third_party/flatcc/clean.sh
./third_party/objectbox-c/clean.sh

depend: ## Build dependencies
./third_party/flatbuffers-c-bridge/build.sh

test-depend: depend ## Build test dependencies
./third_party/flatcc/build.sh
./third_party/objectbox-c/get-objectbox-c.sh

2 changes: 2 additions & 0 deletions internal/generator/flatbuffersc/fbsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestFbsSchemaParser(t *testing.T) {

_, err = file.WriteString(testSchema)
assert.NoErr(t, err)
assert.NoErr(t, file.Close())

schema, err = ParseSchemaFile(file.Name())
assert.NoErr(t, err)
Expand Down Expand Up @@ -123,6 +124,7 @@ func TestFbsFlatc(t *testing.T) {

_, err = file.WriteString(testSchema)
assert.NoErr(t, err)
assert.NoErr(t, file.Close())

code, err = ExecuteFlatc([]string{"--go", "-o", outDir, file.Name()})
assert.NoErr(t, err)
Expand Down
59 changes: 59 additions & 0 deletions test/build/c-compiler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2020 ObjectBox Ltd. All rights reserved.
* https://objectbox.io
*
* This file is part of ObjectBox Generator.
*
* ObjectBox Generator is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* ObjectBox Generator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ObjectBox Generator. If not, see <http://www.gnu.org/licenses/>.
*/

package build

import (
"testing"

"github.com/objectbox/objectbox-generator/test/assert"
"github.com/objectbox/objectbox-generator/test/cmake"
)

// Check verifies the C/C++ objectbox test code can be compiled - whether the required libraries are available.
func CanCompileObjectBoxCCpp(t *testing.T, repoRoot string, cpp, required bool) bool {
var err error

var includeDirs = IncludeDirs(repoRoot)
var libDirs = LibDirs(repoRoot)

// check objectbox lib
if cpp {
err = cmake.LibraryExists("objectbox", []string{"objectbox-cpp.h"}, includeDirs, libDirs)
} else {
err = cmake.LibraryExists("objectbox", []string{"objectbox.h"}, includeDirs, libDirs)
}
assert.NoErr(t, err)

// check flatbuffers library availability
if cpp {
// Note: we don't need flatbuffers library explicitly, it's part of objectbox at the moment.
err = cmake.LibraryExists("", []string{"flatbuffers/flatbuffers.h"}, includeDirs, libDirs)
} else {
err = cmake.LibraryExists("flatccrt", []string{"stddef.h", "flatcc/flatcc.h", "flatcc/flatcc_builder.h"}, includeDirs, libDirs)
}

if required {
assert.NoErr(t, err)
} else if err != nil {
t.Logf("C/C++ compilation not available because %s", err)
return false
}
return true
}
41 changes: 41 additions & 0 deletions test/build/conf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2020 ObjectBox Ltd. All rights reserved.
* https://objectbox.io
*
* This file is part of ObjectBox Generator.
*
* ObjectBox Generator is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* ObjectBox Generator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ObjectBox Generator. If not, see <http://www.gnu.org/licenses/>.
*/

package build

import "path"

const flatbuffersDir = "third_party/flatbuffers-c-bridge/third_party/flatbuffers"
const flatccDir = "third_party/flatcc"
const objectBoxCDir = "third_party/objectbox-c"

func IncludeDirs(repoRoot string) []string {
var result []string
result = append(result, path.Join(repoRoot, flatbuffersDir, "include"))
result = append(result, path.Join(repoRoot, flatccDir, "include"))
result = append(result, path.Join(repoRoot, objectBoxCDir, "include"))
return result
}

func LibDirs(repoRoot string) []string {
var result []string
result = append(result, path.Join(repoRoot, objectBoxCDir, "lib"))
result = append(result, path.Join(repoRoot, flatccDir, "lib"))
return result
}
Loading