Skip to content

Commit

Permalink
ObjectBox Swift database 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
greenrobot-team committed Jul 22, 2024
1 parent a502b40 commit 2ce1312
Show file tree
Hide file tree
Showing 92 changed files with 2,920 additions and 407 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
url = https://github.com/realm/SwiftLint.git
[submodule "Source/external/objectbox-swift-generator"]
path = Source/external/objectbox-swift-generator
url=https://github.com/objectbox/objectbox-swift-generator.git
url = https://github.com/objectbox/objectbox-swift-generator.git
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let package = Package(
targets: [
.binaryTarget(
name: "ObjectBox",
url: "https://github.com/objectbox/objectbox-swift/releases/download/v2.0.0/ObjectBox-xcframework-2.0.0.zip",
checksum: "20766ccf880bd66c4246f55536fbd3f33f1e8bb7adf55101a3dd06a8ee043116"
url: "https://github.com/objectbox/objectbox-swift/releases/download/v4.0.0/ObjectBox-xcframework-4.0.0.zip",
checksum: "2bed7b8b87dd46dda64fa1f5e7a0b1df87908a783690fda09c6dc943a01a32e5"
)
]
)
Expand Down
55 changes: 29 additions & 26 deletions Source/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.6)
CFPropertyList (3.0.7)
base64
nkf
rexml
activesupport (7.1.2)
activesupport (7.1.3.4)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
Expand All @@ -13,21 +15,21 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
base64 (0.2.0)
bigdecimal (3.1.4)
bigdecimal (3.1.8)
claide (1.1.0)
cocoapods (1.14.2)
cocoapods (1.15.2)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.14.2)
cocoapods-core (= 1.15.2)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 2.0)
cocoapods-downloader (>= 2.1, < 3.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.6.0, < 2.0)
Expand All @@ -40,7 +42,7 @@ GEM
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.23.0, < 2.0)
cocoapods-core (1.14.2)
cocoapods-core (1.15.2)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
Expand All @@ -51,7 +53,7 @@ GEM
public_suffix (~> 4.0)
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (2.0)
cocoapods-downloader (2.1)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.1)
Expand All @@ -60,58 +62,59 @@ GEM
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.2.2)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
drb (2.2.0)
ruby2_keywords
drb (2.2.1)
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.16.3)
ffi (1.17.0)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.14.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
jazzy (0.14.4)
jazzy (0.15.1)
cocoapods (~> 1.5)
mustache (~> 1.1)
open4 (~> 1.3)
redcarpet (~> 3.4)
rexml (~> 3.2)
rexml (>= 3.2.7, < 4.0)
rouge (>= 2.0.6, < 5.0)
sassc (~> 2.1)
sqlite3 (~> 1.3)
xcinvoke (~> 0.3.0)
json (2.6.3)
json (2.7.2)
liferaft (0.0.6)
mini_portile2 (2.8.5)
minitest (5.20.0)
mini_portile2 (2.8.7)
minitest (5.24.1)
molinillo (0.8.0)
mustache (1.1.1)
mutex_m (0.2.0)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
nkf (0.2.0)
open4 (1.3.4)
public_suffix (4.0.7)
redcarpet (3.6.0)
rexml (3.2.6)
rouge (4.2.0)
rexml (3.2.9)
strscan
rouge (4.3.0)
ruby-macho (2.5.1)
ruby2_keywords (0.0.5)
sassc (2.4.0)
ffi (~> 1.9)
sqlite3 (1.6.8)
sqlite3 (1.7.3)
mini_portile2 (~> 2.8.0)
typhoeus (1.4.0)
strscan (3.1.0)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcinvoke (0.3.0)
liferaft (~> 0.0.6)
xcodeproj (1.23.0)
xcodeproj (1.24.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
Expand Down
8 changes: 6 additions & 2 deletions Source/fetch_dependencies.command
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ set -e

# objectbox-swift release version on GitHub:
# https://github.com/objectbox/objectbox-swift/releases/download/v${version}
version=2.0.0
version=4.0.0

# C library version attached to the GitHub release:
# ObjectBoxCore-static-${c_version}.zip
c_version=4.0.0
c_version=4.0.1

# Params supported by apple-build-static-libs.sh
build_params=""
Expand Down Expand Up @@ -115,6 +115,10 @@ if [ -d "$code_dir" ] && [ "$staging_repo" != "true" ]; then # Do we have an exi
fi

# Build
# Temporary: ld warns that static library is not built for 10.15 (but macOS.cmake sets CMAKE_OSX_DEPLOYMENT_TARGET),
# to resolve set MACOSX_DEPLOYMENT_TARGET here until core build scripts are updated.
# Internal issue: objectbox/objectbox-swift#274
export MACOSX_DEPLOYMENT_TARGET="10.15"
"$code_dir/scripts/apple-build-static-libs.sh" $build_params "$dest_dir" release

if [ "$git_clean" = true ] ; then # clean before?
Expand Down
21 changes: 0 additions & 21 deletions Source/ios-framework/.swiftlint-macOS.yml

This file was deleted.

31 changes: 27 additions & 4 deletions Source/ios-framework/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
identifier_name:
excluded: # Object IDs are splendid!
- id

included:
- CommonSource
- CommonTests
- ObjectBox-macOS/ObjectBox
- ObjectBox-macOS/ObjectBoxTests
excluded:
# Exclude some generated code
- CommonSource/ConfigFlags.swift
- CommonSource/Entities/EntityFlags.swift
- CommonSource/Entities/PropertyType.swift
- CommonSource/Entities/HnswParams.swift
- CommonSource/Query/OrderFlags.swift
- CommonTests/Test Entities/RelatedEntities.swift
line_length: 120
reporter: "xcode"
disabled_rules:
- comment_spacing # Devs are good at this, sometimes no space if not a comment
- file_length
- identifier_name # Allow anything that Swift allows
- trailing_whitespace
- todo
- type_body_length # Best practice, do not enforce
- vertical_whitespace
type_name:
excluded:
- Id
- __EntityRelatable # TODO check this one; can we remove it altogether?
41 changes: 32 additions & 9 deletions Source/ios-framework/CodeGenTests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,35 @@ These tests require a copy of ObjectBox Swift Code Generator in a known location

Adding a test case requires the following steps:

1. Add a new command line tool target
2. Name it ToolTestProject`N` (where `N` is the next number)
3. Go to the bottom of `RunToolTests.sh` and add `test_target_num "Test Name" N || FAIL=1` where "Test Name" is the name you want to have used in the log messages for this test, and `N` is again, the number of the test target.
4. Add `-framework ObjectBox` to the "Other Linker Flags"
5. Add `@executable_path/../../../` and `$(TOOLCHAIN_DIR)/usr/lib/swift/macosx` to the "Runpath Search Paths"
6. Add a `ToolTestProjectN.swift` source file (`N` again is the number of the target) containing a `main(_ args: [String]) -> Int32` that does the actual test and returns 0 on success, something else > 0 on failure.
7. Add the `main.swift` file to your target, it calls the main() function for you.

The `RunToolTests.sh` script will run the code generator and pass you the "Test Name" as your first parameter. It will also check the code generator output against a file named `Entity.generatedN.swift`, the model file against a `modelN.json` and such.
1. Open `ToolTestProject.xcodeproj` in Xcode.
2. Duplicate one of the `ToolTestProjectN` command line tool targets and increase to next highest number `N`.
3. In `RunToolTests.sh` at the bottom add a command to run the test (replace `<N>` with the chosen number):
```bash
# If the code generator should succeed
test_target_num "Test Name" <N> || ((FAIL++))
# If the code generator should fail
fail_codegen_target_num "Test Name" <N> || ((FAIL++))
```
4. Add a `ToolTestProjectN.swift` source file (replace `N` again) to the command line tool target. It should look like:
```swift
import ObjectBox
// TODO Add entity classes
func main(_ args: [String]) throws -> Int32 {
// TODO Add test code, may print on error or throw
return 0 // on success
return 1 // or any value > 0 on failure (make sure to print error details)
}
```
5. If the code generator should succeed, add the generated `EntityInfo.generatedN.swift` to the `ToolTestProjectN`
command line tool target as well (so it's verified it compiles).
The `RunToolTests.sh` script will run the code generator and pass the "Test Name" as the first parameter. It will also check the code generator output against a file named `Entity.generatedN.swift`, the model file against a `modelN.json` and such.
### Command line tool target settings
For reference, all of the command line targets have these settings:
- Add `-framework ObjectBox` to the "Other Linker Flags"
- Add `@executable_path/../../../` and `$(TOOLCHAIN_DIR)/usr/lib/swift/macosx` to the "Runpath Search Paths"
- Add the `main.swift` file to the Compile sources build phase, it calls the main() function of the `ToolTestProjectN.swift` file.
12 changes: 10 additions & 2 deletions Source/ios-framework/CodeGenTests/RunToolTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if [ -z ${PROJECT_DIR} ]; then
exit 1
fi

MYDIR="${PROJECT_DIR}/CodeGenTests/" # Xcode copies our script into DerivedData before running it, so hard-code our path.
MYDIR="${PROJECT_DIR}/CodeGenTests" # Xcode copies our script into DerivedData before running it, so hard-code our path.

SOURCERY_APP="${PROJECT_DIR}/../external/objectbox-swift-generator/bin/Sourcery.app"
SOURCERY="${SOURCERY_APP}/Contents/MacOS/Sourcery"
Expand All @@ -29,6 +29,11 @@ MYOUTPUTDIR="${MYDIR}/generated/"

mkdir -p $MYOUTPUTDIR

echo ""
echo "====="
echo "Test projects are written to: $MYOUTPUTDIR"
echo "====="

cd ${BUILT_PRODUCTS_DIR}

test_target_num () {
Expand Down Expand Up @@ -168,7 +173,7 @@ fail_codegen_target_num () {
echo "note: ******************** $2: $1 ********************"

MODEL_FILE_EXPECTED="${EXPECTED_DIR}/model/model${2}.json"
ORIGINALMESSAGESFILE="${EXPECTED_DIR}/model/messages${2}.log"
ORIGINALMESSAGESFILE="${EXPECTED_DIR}/messages/messages${2}.log"
MODEL_FILE_BEFORE="${EXPECTED_DIR}/model/model${2}.before.json"
MODEL_FILE_ACTUAL="${BUILT_PRODUCTS_DIR}/model${2}.json"
TESTMESSAGESFILE="${BUILT_PRODUCTS_DIR}/messages${2}.log"
Expand Down Expand Up @@ -339,6 +344,9 @@ test_target_num "ToMany Backlink ensure applyToDb is needed" 55 || ((FAIL++))
test_target_num "Swift Property Wrappers are treated as wrapped type" 56 || ((FAIL++))
test_target_num "Optional Template Syntax recognized as optional" 57 || ((FAIL++))

fail_codegen_target_num "HNSW index not on float array" 58 || ((FAIL++))
test_target_num "HNSW index" 59 || ((FAIL++))

echo "note: Finished tests with $FAIL failures"

exit $FAIL
Loading

0 comments on commit 2ce1312

Please sign in to comment.