Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ permissions:
env:
# Do code analysis with latest SDK.
# Pick a concrete version instead of "latest" to avoid builds breaking due to changes in new SDKs.
FLUTTER_VERSION: 3.29.2 # Available versions: https://docs.flutter.dev/release/archive
DART_VERSION: 3.7.2 # Available versions: https://dart.dev/get-dart/archive
FLUTTER_VERSION: 3.35.2 # Available versions: https://docs.flutter.dev/release/archive
DART_VERSION: 3.9.2 # Available versions: https://dart.dev/get-dart/archive

jobs:
format-and-analyze:
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ env:
# Run generator integration tests and init script with latest SDK.
# Pick a concrete version instead of "latest" to avoid builds breaking due to changes in new SDKs.
# NOTE: also update matrix configurations below!
FLUTTER_VERSION: 3.29.2 # Available versions: https://docs.flutter.dev/release/archive
DART_VERSION: 3.7.2 # Available versions: https://dart.dev/get-dart/archive
FLUTTER_VERSION: 3.35.2 # Available versions: https://docs.flutter.dev/release/archive
DART_VERSION: 3.9.2 # Available versions: https://dart.dev/get-dart/archive

jobs:

Expand Down Expand Up @@ -67,8 +67,8 @@ jobs:
# Pick a concrete version instead of "latest" to avoid builds breaking due to changes in new SDKs.
# Can not use env variables here, only within 'steps'.
# For available versions see https://dart.dev/get-dart/archive
- 3.7.2
- 3.5.4 # Use latest bugfix release to get tooling fixes
- 3.9.2
- 3.7.2 # Use latest bugfix release to get tooling fixes
runs-on: ${{ matrix.os }}
steps:
- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c # v1.7.1
Expand Down Expand Up @@ -111,17 +111,17 @@ jobs:
# Can not use env variables here, only within 'steps'.
# For available versions see https://docs.flutter.dev/release/archive
# NOTE Also update versions for Ubuntu below!
- 3.29.2
- 3.24.5 # Use latest bugfix release to get tooling fixes
- 3.35.2
- 3.29.3 # Use latest bugfix release to get tooling fixes
include:
# Test building for Android with highest supported JDK on latest Flutter SDK,
# lowest supported JDK on lowest supported Flutter SDK. (Android is only built if a Linux
# OS is detected, see integration-test.sh)
- os: ubuntu-24.04
flutter-version: 3.29.2
flutter-version: 3.35.2
jdk: 21
- os: ubuntu-24.04
flutter-version: 3.24.5 # Use latest bugfix release to get tooling fixes
flutter-version: 3.29.3 # Use latest bugfix release to get tooling fixes
jdk: 17
runs-on: ${{ matrix.os }}
steps:
Expand Down
9 changes: 6 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ variables:
# # Pick a concrete version instead of "latest" to avoid builds breaking due to changes in new
# SDKs.
# For available versions see https://hub.docker.com/_/dart/tags and https://dart.dev/get-dart/archive
DART_VERSION_LATEST: '3.7.2'
DART_VERSION_LOWEST: '3.5.4' # Use latest bugfix release to get tooling fixes
DART_VERSION_LATEST: '3.9.2'
DART_VERSION_LOWEST: '3.7.2' # Use latest bugfix release to get tooling fixes
DART_VERSION: $DART_VERSION_LATEST # Also used for caching, see .cache template

.common:
Expand Down Expand Up @@ -84,7 +84,10 @@ generator-integ-tests:
# Generator tests
- cd generator
- dart pub get
- dart test
# generator test suites must not run in parallel (see notes on GeneratorTestEnv):
# Set concurrency=1 to run only one test suite (== test file) at a time.
# Set --reporter expanded to print log for every completed test.
- dart test --concurrency=1 --reporter expanded
# ObjectBox tests
- cd ../objectbox_test
- ../install.sh
Expand Down
3 changes: 2 additions & 1 deletion generator/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ builders:
builder_factories: ["codeGeneratorFactory"]
# build_extensions: Required. A map from input extension to the list of output extensions that may be created
# for that input. This must match the merged buildExtensions maps from each Builder in builder_factories.
# See notes on CodeBuilder.buildExtensions.
build_extensions:
"$lib$": ["objectbox.g.dart"]
"$test": ["objectbox.g.dart"]
"$test$": ["objectbox.g.dart"]
required_inputs: ['.objectbox.info']
auto_apply: dependents
build_to: source
6 changes: 3 additions & 3 deletions generator/integration-tests/part-partof/lib/frozen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:objectbox/objectbox.dart';
part 'frozen.freezed.dart';

@freezed
class FrozenEntity with _$FrozenEntity {
sealed class FrozenEntity with _$FrozenEntity {
@Entity(realClass: FrozenEntity)
factory FrozenEntity(
{@Id(assignable: true) required int id,
Expand All @@ -13,15 +13,15 @@ class FrozenEntity with _$FrozenEntity {
}

@freezed
class FrozenPerson with _$FrozenPerson {
sealed class FrozenPerson with _$FrozenPerson {
@Entity(realClass: FrozenPerson)
factory FrozenPerson(
{@Id(assignable: true) required int id,
required String name}) = _FrozenPerson;
}

@freezed
class FrozenBook with _$FrozenBook {
sealed class FrozenBook with _$FrozenBook {
@Entity(realClass: FrozenBook)
factory FrozenBook(
{@Id(assignable: true) required int id,
Expand Down
13 changes: 5 additions & 8 deletions generator/integration-tests/part-partof/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
name: objectbox_generator_test

environment:
sdk: '>=2.14.0 <4.0.0'
sdk: '^3.0.0' # Require 3.0 to use sealed classes for freezed

dependencies:
objectbox: any # override below to use local package
json_annotation: '^4.6.0'
freezed_annotation: '^2.1.0'
freezed_annotation: '^3.1.0'

dev_dependencies:
json_serializable: '^6.3.1'
freezed: '^2.0.4' # 3.0.4 requires Dart 3.6
json_serializable: '^6.10.0' # Require 6.10.0 to allow build 3 required by objectbox_generator
freezed: '^3.0.0' # Require 3.0.0 to allow build 3 and source_gen 3.1 required by objectbox_generator
objectbox_generator: any # override below to use local package
test: '^1.21.4'
build_runner: '^2.3.3'
build_test: '^2.1.3'
build_test: '^3.0.0'
io: '^1.0.4'
path: '^1.8.3'
# analyzer 7.4.0 introduced breaking API changes in a minor release, breaking json_serializable
# https://github.com/google/json_serializable.dart/issues/1485
analyzer: '<=7.3.0'

dependency_overrides:
objectbox:
Expand Down
14 changes: 10 additions & 4 deletions generator/lib/src/analysis/analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ import 'build_properties.dart';
/// Requires [tokenFilePath] to exist, otherwise does nothing. See the
/// associated test (analysis_test.dart) on how to create this file.
class ObjectBoxAnalysis {
static const _debug = false;

/// Path is relative to lib folder.
static const tokenFilePath = "assets/analysis-token.txt";
static const defaultTokenFilePath = "assets/analysis-token.txt";

static const _url = "api.mixpanel.com";
static const _path = "track";

final bool _debug;
final String _tokenFilePath;

ObjectBoxAnalysis(
{bool debug = false, String tokenFilePath = defaultTokenFilePath})
: _debug = debug,
_tokenFilePath = tokenFilePath;

/// Builds a Build event and sends it with [sendEvent]. May not send if it
/// fails to store a unique identifier and last time sent, or if no valid API
/// token is found.
Expand Down Expand Up @@ -126,7 +132,7 @@ class ObjectBoxAnalysis {
}

Future<String?> _getToken() async {
final uri = Uri.parse("package:objectbox_generator/$tokenFilePath");
final uri = Uri.parse("package:objectbox_generator/$_tokenFilePath");
final resolvedUri = await Isolate.resolvePackageUri(uri);
if (resolvedUri != null) {
final file = File.fromUri(resolvedUri);
Expand Down
9 changes: 6 additions & 3 deletions generator/lib/src/builder_dirs.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:build/build.dart';
import 'package:path/path.dart' as path;

import 'config.dart';
Expand All @@ -12,11 +11,15 @@ class BuilderDirs {

BuilderDirs._(this.root, this.out);

factory BuilderDirs(BuildStep buildStep, Config config) {
/// For [pathInSourceRoot] expects the path to a file in the source root
/// directory (currently only lib or test are supported). It's used to
/// determine the [root] source path and [out] path for generated code.
/// A [config] may customize the [out] path relative to [root].
factory BuilderDirs(String pathInSourceRoot, Config config) {
// Paths from Config are supplied by the user and may contain duplicate
// slashes or be empty: normalize all paths to not return duplicate or
// trailing slashes to ensure they can be compared via strings.
final root = path.normalize(path.dirname(buildStep.inputId.path));
final root = path.normalize(path.dirname(pathInSourceRoot));
final String out;
if (root.endsWith('test')) {
out = path.normalize('$root/${config.outDirTest}');
Expand Down
6 changes: 5 additions & 1 deletion generator/lib/src/code_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ class CodeBuilder extends Builder {

@override
late final buildExtensions = {
// lib/$lib$ and test/$test$ are placeholder files of build_runner which are
// used as there is no clear primary input file for this builder.
r'$lib$': [path.join(_config.outDirLib, _config.codeFile)],
r'$test$': [path.join(_config.outDirTest, _config.codeFile)]
};

@override
FutureOr<void> build(BuildStep buildStep) async {
final builderDirs = BuilderDirs(buildStep, _config);
// This is only called twice, once with path lib/$lib$ and once with test/$test$
final inputFilePath = buildStep.inputId.path;
final builderDirs = BuilderDirs(inputFilePath, _config);

// build() will be called only twice, once for the `lib` directory and once for the `test` directory
// map from file name to a 'json' representation of entities
Expand Down
Loading
Loading