Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how to configure build.yaml to "disable" provided/inherited builder? #3595

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions _test/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ targets:
- test/hello_world_custom_html_test.dart.browser_test.dart
- test/other_test.dart.browser_test.dart
- test/sub-dir/subdir_test.dart.browser_test.dart
# HELP: the settings below won't have any effect on the builders applied in `build.dart`
provides_builder|not_enabled_builder:
enabled: false
# HELP: Only when adding (even an empty) `other_builder.build.yaml` file, the builder won't show up in `build.dart`
other_builder|other_builder:
enabled: false
5 changes: 5 additions & 0 deletions _test/other_builder.build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#---
## disable all inherited "provides_builder" builders...
#targets:
# $default:
# auto_apply_builders: false
5 changes: 5 additions & 0 deletions _test/pkgs/other_builder/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
builders:
other_builder:
import: "package:provides_builder/builders.dart"
builder_factories: ["someBuilder"]
build_extensions: {".dart": [".something.dart"]}
36 changes: 36 additions & 0 deletions _test/pkgs/other_builder/lib/builders.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:build/build.dart';

class _SomeBuilder implements Builder {
const _SomeBuilder();

factory _SomeBuilder.fromOptions(BuilderOptions options) {
if (options.config['throw_in_constructor'] == true) {
throw StateError('Throwing on purpose cause you asked for it!');
}
return const _SomeBuilder();
}

@override
final buildExtensions = const {
'.dart': ['.something.dart']
};

@override
Future build(BuildStep buildStep) async {
if (!await buildStep.canRead(buildStep.inputId)) return;

await buildStep.writeAsBytes(
buildStep.inputId.changeExtension('.something.dart'),
buildStep.readAsBytes(buildStep.inputId));
}
}


Builder otherBuilder(BuilderOptions options) =>
_SomeBuilder.fromOptions(options);
10 changes: 10 additions & 0 deletions _test/pkgs/other_builder/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: other_builder

environment:
sdk: ^3.0.0

dependencies:
build:
path: ../../../build
provides_builder:
path: ../provides_builder
4 changes: 4 additions & 0 deletions _test/pkgs/provides_builder/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ builders:
builder_factories: ["throwingBuilder"]
build_extensions: {".fail": [".fail.message"]}
auto_apply: dependents
not_enabled_builder:
import: "package:provides_builder/builders.dart"
builder_factories: [ "notEnabledBuilder" ]
build_extensions: { ".not.enabled": [ ".not.enabled.message" ] }
post_process_builders:
some_post_process_builder:
target: "provides_builder"
Expand Down
2 changes: 2 additions & 0 deletions _test/pkgs/provides_builder/lib/builders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ Builder notApplied(BuilderOptions options) => _SomeBuilder.fromOptions(options);
PostProcessBuilder somePostProcessBuilder(BuilderOptions options) =>
_SomePostProcessBuilder.fromOptions(options);
Builder throwingBuilder(_) => _ThrowingBuilder();
Builder notEnabledBuilder(BuilderOptions options) =>
_SomeBuilder.fromOptions(options);
2 changes: 2 additions & 0 deletions _test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dev_dependencies:
build_web_compilers: any
dart_flutter_team_lints: ^2.0.0
io: ^1.0.0
other_builder:
path: pkgs/other_builder/
path: ^1.8.0
provides_builder:
path: pkgs/provides_builder/
Expand Down
14 changes: 14 additions & 0 deletions _test/test/generated_script_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void main() {
await runCommand(['generate-build-script']);
});

// TODO: this test fails, because the "not_enabled_builder" still shows up...
test('Generates a build script matching the golden', () {
var generatedScript =
File('.dart_tool/build/entrypoint/build.dart').readAsStringSync();
Expand All @@ -22,4 +23,17 @@ void main() {
.replaceAll('\r', '');
expect(generatedScript, expected);
});


/// Nog een ander probleem:
/// of zo lijkt toch:
/// - er worden té veel builders binnengepakt obv dependencies...
/// - maar nu: both scorekeeper_codege:serializer_generator and scorekeeper_codege:serializer_generator may output lib/proto.config.json
///
/// ik DENK dat het probleem als volgt is:
/// - scorekeeper_example_domain wordt in tests / dev_dependencies van scorekeeper_codegen binnengetrokken
/// - scorekeeper_example_domain is ook een dependency van ????
/// -> kan ik dependency tree opzoeken van een dart project?


}