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

Adds support for config specific imports #1793

Merged
merged 13 commits into from
Aug 29, 2018
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
18 changes: 9 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
env: PKG="_test"
dart: dev
- stage: unit_test
name: "SDK: dev - DIR: _test - TASKS: pub run build_runner test -- -p chrome"
script: ./tool/travis.sh command_0
name: "SDK: dev - DIR: _test - TASKS: [pub run build_runner test -- -p chrome, pub run build_runner test -- -p vm test/config_specific_import_test.dart]"
script: ./tool/travis.sh command_0 command_1
env: PKG="_test"
dart: dev
- stage: e2e_test
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
dart: dev
- stage: unit_test
name: "SDK: dev - DIR: bazel_codegen - TASKS: pub run build_runner test"
script: ./tool/travis.sh command_1
script: ./tool/travis.sh command_2
env: PKG="bazel_codegen"
dart: dev
- stage: analyze_and_format
Expand All @@ -82,7 +82,7 @@ jobs:
dart: dev
- stage: unit_test
name: "SDK: dev - DIR: build - TASKS: pub run build_runner test"
script: ./tool/travis.sh command_1
script: ./tool/travis.sh command_2
env: PKG="build"
dart: dev
- stage: analyze_and_format
Expand All @@ -92,7 +92,7 @@ jobs:
dart: dev
- stage: unit_test
name: "SDK: dev - DIR: build_config - TASKS: pub run build_runner test --delete-conflicting-outputs"
script: ./tool/travis.sh command_2
script: ./tool/travis.sh command_3
env: PKG="build_config"
dart: dev
- stage: analyze_and_format
Expand All @@ -102,7 +102,7 @@ jobs:
dart: dev
- stage: unit_test
name: "SDK: dev - DIR: build_modules - TASKS: pub run build_runner test --delete-conflicting-outputs -- -P presubmit"
script: ./tool/travis.sh command_3
script: ./tool/travis.sh command_4
env: PKG="build_modules"
dart: dev
- stage: analyze_and_format
Expand All @@ -112,7 +112,7 @@ jobs:
dart: dev
- stage: unit_test
name: "SDK: dev - DIR: build_resolvers - TASKS: pub run build_runner test"
script: ./tool/travis.sh command_1
script: ./tool/travis.sh command_2
env: PKG="build_resolvers"
dart: dev
- stage: analyze_and_format
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
dart: dev
- stage: unit_test
name: "SDK: dev - DIR: build_test - TASKS: pub run build_runner test"
script: ./tool/travis.sh command_1
script: ./tool/travis.sh command_2
env: PKG="build_test"
dart: dev
- stage: analyze_and_format
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:
dart: dev
- stage: unit_test
name: "SDK: dev - DIR: scratch_space - TASKS: pub run build_runner test"
script: ./tool/travis.sh command_1
script: ./tool/travis.sh command_2
env: PKG="scratch_space"
dart: dev

Expand Down
3 changes: 3 additions & 0 deletions _test/build.dart2js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ targets:
generate_for:
- web/main.dart
- web/sub/main.dart
- test/config_specific_import_test.dart
- test/config_specific_import_test.dart.browser_test.dart
- test/hello_world_test.dart
- test/hello_world_test.dart.browser_test.dart
- test/hello_world_deferred_test.dart
Expand All @@ -20,4 +22,5 @@ targets:
- test/sub-dir/subdir_test.dart.browser_test.dart
build_vm_compilers|entrypoint:
generate_for:
- test/config_specific_import_test.dart.vm_test.dart
- test/help_test.dart.vm_test.dart
3 changes: 3 additions & 0 deletions _test/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ targets:
generate_for:
- web/main.dart
- web/sub/main.dart
- test/config_specific_import_test.dart
- test/config_specific_import_test.dart.browser_test.dart
- test/hello_world_test.dart
- test/hello_world_test.dart.browser_test.dart
- test/hello_world_deferred_test.dart
Expand All @@ -16,4 +18,5 @@ targets:
- test/sub-dir/subdir_test.dart.browser_test.dart
build_vm_compilers|entrypoint:
generate_for:
- test/config_specific_import_test.dart.vm_test.dart
- test/help_test.dart.vm_test.dart
4 changes: 3 additions & 1 deletion _test/mono_pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ stages:
- analyze_and_format:
- dartanalyzer: --fatal-infos --fatal-warnings .
- unit_test:
- command: pub run build_runner test -- -p chrome
- group:
- command: pub run build_runner test -- -p chrome
- command: pub run build_runner test -- -p vm test/config_specific_import_test.dart
- e2e_test:
- test: --total-shards 6 --shard-index 0
- test: --total-shards 6 --shard-index 1
Expand Down
5 changes: 5 additions & 0 deletions _test/test/common/message_html.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2018, 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.

String get message => 'Hello World from Javascript!';
5 changes: 5 additions & 0 deletions _test/test/common/message_io.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2018, 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.

String get message => 'Hello World from the VM!';
22 changes: 22 additions & 0 deletions _test/test/config_specific_import_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2018, 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 'package:test/test.dart';

// ignore: uri_does_not_exist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we always going to need these ignore comments? That's quite annoying.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import 'common/message.dart'
// ignore: uri_does_not_exist
if (dart.library.io) 'common/message_io.dart'
// ignore: uri_does_not_exist
if (dart.library.html) 'common/message_html.dart';

main() {
test('Message matches expected', () {
if (1.0 is int) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need to provide support for this in a better way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, its really weird how the dart.library.* things aren't real constants just some special identifier thing that compilers know about?

expect(message, contains('Javascript'));
} else {
expect(message, contains('VM'));
}
});
}
52 changes: 42 additions & 10 deletions _test/test/goldens/generated_build_script.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,55 @@ final _builders = <_i1.BuilderApplication>[
_i1.toRoot(),
hideOutput: true,
defaultGenerateFor: const _i4.InputSet(include: const ['test/**'])),
_i1.apply('build_modules|module_library', [_i5.moduleLibraryBuilder],
_i1.toAllPackages(),
isOptional: true,
hideOutput: true,
appliesBuilders: ['build_modules|module_cleanup']),
_i1.apply(
'build_modules|modules',
'build_modules|vm',
[
_i5.moduleLibraryBuilder,
_i5.metaModuleBuilder,
_i5.metaModuleCleanBuilder,
_i5.moduleBuilder,
_i5.unlinkedSummaryBuilder,
_i5.linkedSummaryBuilder
_i5.metaModuleBuilderFactoryForPlatform('vm'),
_i5.metaModuleCleanBuilderFactoryForPlatform('vm'),
_i5.moduleBuilderFactoryForPlatform('vm')
],
_i1.toAllPackages(),
_i1.toNoneByDefault(),
isOptional: true,
hideOutput: true,
appliesBuilders: ['build_modules|module_cleanup']),
_i1.apply(
'build_modules|dart2js',
[
_i5.metaModuleBuilderFactoryForPlatform('dart2js'),
_i5.metaModuleCleanBuilderFactoryForPlatform('dart2js'),
_i5.moduleBuilderFactoryForPlatform('dart2js')
],
_i1.toNoneByDefault(),
isOptional: true,
hideOutput: true,
appliesBuilders: ['build_modules|module_cleanup']),
_i1.apply(
'build_modules|dartdevc',
[
_i5.metaModuleBuilderFactoryForPlatform('dartdevc'),
_i5.metaModuleCleanBuilderFactoryForPlatform('dartdevc'),
_i5.moduleBuilderFactoryForPlatform('dartdevc'),
_i5.unlinkedSummaryBuilderForPlatform('dartdevc'),
_i5.linkedSummaryBuilderForPlatform('dartdevc')
],
_i1.toNoneByDefault(),
isOptional: true,
hideOutput: true,
appliesBuilders: ['build_modules|module_cleanup']),
_i1.apply(
'build_web_compilers|ddc', [_i6.devCompilerBuilder], _i1.toAllPackages(),
isOptional: true,
hideOutput: true,
appliesBuilders: ['build_web_compilers|dart_source_cleanup']),
appliesBuilders: [
'build_web_compilers|dart_source_cleanup',
'build_modules|dartdevc',
'build_modules|dart2js'
]),
_i1.apply('build_web_compilers|entrypoint', [_i6.webEntrypointBuilder],
_i1.toRoot(),
hideOutput: true,
Expand All @@ -63,7 +93,9 @@ final _builders = <_i1.BuilderApplication>[
appliesBuilders: ['build_web_compilers|dart2js_archive_extractor']),
_i1.apply(
'build_vm_compilers|vm', [_i8.vmKernelModuleBuilder], _i1.toAllPackages(),
isOptional: true, hideOutput: true),
isOptional: true,
hideOutput: true,
appliesBuilders: ['build_modules|vm']),
_i1.apply('build_vm_compilers|entrypoint', [_i8.vmKernelEntrypointBuilder],
_i1.toRoot(),
hideOutput: true,
Expand Down
4 changes: 2 additions & 2 deletions _test/test/test_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ void main() {

test('create new test', () async {
await createFile(p.join('test', 'other_test.dart'), basicTestContents);
await expectTestsPass(expectedNumRan: 5);
await expectTestsPass(expectedNumRan: 6);
});

test('delete test', () async {
await deleteFile(p.join('test', 'sub-dir', 'subdir_test.dart'));
await expectTestsPass(expectedNumRan: 3);
await expectTestsPass(expectedNumRan: 4);
});
});
}
Expand Down
8 changes: 5 additions & 3 deletions _test/tool/build_kernel_ddc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:async';
import 'package:build_config/build_config.dart';
import 'package:build_web_compilers/builders.dart';
import 'package:build_web_compilers/build_web_compilers.dart';
import 'package:build_modules/build_modules.dart';
import 'package:build_modules/builders.dart';
import 'package:build_runner/build_runner.dart';
import 'package:build_test/builder.dart';
Expand All @@ -19,9 +20,10 @@ Future main(List<String> args) async {
apply(
'_test|ddc_kernel',
[
metaModuleBuilder,
metaModuleCleanBuilder,
moduleBuilder,
moduleLibraryBuilder,
metaModuleBuilderFactoryForPlatform(DartPlatform.dartdevc.name),
metaModuleCleanBuilderFactoryForPlatform(DartPlatform.dartdevc.name),
moduleBuilderFactoryForPlatform(DartPlatform.dartdevc.name),
ddcKernelBuilder,
],
toAllPackages(),
Expand Down
33 changes: 33 additions & 0 deletions build_modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
## 0.4.0

### Improvements

- Modules are now platform specific, and config specific imports using
`dart.library.*` constants are supported.

### Breaking Configuration Changes

- Module granularity now has to be configured per platform, so instead of
configuring it using the `build_modules|modules` builder, you now need to
configure the builder for each specific platform:

```yaml
targets:
$default:
build_modules|dartdevc:
options:
strategy: fine
```

The supported platforms are currently `dart2js`, `dartdevc`, and `vm`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we support flutter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it can't be discovered in the same libraries.json file 😢

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boo


### Breaking API Changes

- Output extensions of builders have changed to include the platform being built
for.
- All the top level file extension getters are now methods that take a
platform and return the extension for that platform.
- Most builders are no longer applied by default, you must manually apply them
using applies_builders in your builder.
- Most builder constructors now require a `platform` argument.

## 0.3.2

- Module strategies are now respected for all packages instead of just the root
Expand Down
67 changes: 54 additions & 13 deletions build_modules/build.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,67 @@
builders:
modules:
module_library:
import: "package:build_modules/builders.dart"
builder_factories:
- moduleLibraryBuilder
- metaModuleBuilder
- metaModuleCleanBuilder
- moduleBuilder
- unlinkedSummaryBuilder
- linkedSummaryBuilder
build_extensions:
$lib$:
- .meta_module.raw
- .meta_module.clean
.dart:
- .module.library
- .module
- .linked.sum
- .unlinked.sum
is_optional: True
auto_apply: all_packages
is_optional: True
required_inputs: [".dart"]
applies_builders: ["|module_cleanup"]
dartdevc:
import: "package:build_modules/builders.dart"
builder_factories:
- metaModuleBuilderFactoryForPlatform('dartdevc')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[aside] If we had union types I would totally make the BuilderFactory typedef be Builder|List<Builder> Function()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, would clean this up a bunch

- metaModuleCleanBuilderFactoryForPlatform('dartdevc')
- moduleBuilderFactoryForPlatform('dartdevc')
- unlinkedSummaryBuilderForPlatform('dartdevc')
- linkedSummaryBuilderForPlatform('dartdevc')
build_extensions:
$lib$:
- .dartdevc.meta_module.raw
- .dartdevc.meta_module.clean
.dart:
- .dartdevc.module
- .dartdevc.linked.sum
- .dartdevc.unlinked.sum
is_optional: True
auto_apply: none
required_inputs: [".dart", ".module.library"]
applies_builders: ["|module_cleanup"]
dart2js:
import: "package:build_modules/builders.dart"
builder_factories:
- metaModuleBuilderFactoryForPlatform('dart2js')
- metaModuleCleanBuilderFactoryForPlatform('dart2js')
- moduleBuilderFactoryForPlatform('dart2js')
build_extensions:
$lib$:
- .dart2js.meta_module.raw
- .dart2js.meta_module.clean
.dart:
- .dart2js.module
is_optional: True
auto_apply: none
required_inputs: [".dart", ".module.library"]
applies_builders: ["|module_cleanup"]
vm:
import: "package:build_modules/builders.dart"
builder_factories:
- metaModuleBuilderFactoryForPlatform('vm')
- metaModuleCleanBuilderFactoryForPlatform('vm')
- moduleBuilderFactoryForPlatform('vm')
build_extensions:
$lib$:
- .vm.meta_module.raw
- .vm.meta_module.clean
.dart:
- .vm.module
is_optional: True
auto_apply: none
required_inputs: [".dart", ".module.library"]
applies_builders: ["|module_cleanup"]
post_process_builders:
module_cleanup:
import: "package:build_modules/builders.dart"
Expand Down
1 change: 1 addition & 0 deletions build_modules/lib/build_modules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export 'src/module_builder.dart' show ModuleBuilder, moduleExtension;
export 'src/module_library_builder.dart'
show ModuleLibraryBuilder, moduleLibraryExtension;
export 'src/modules.dart';
export 'src/platform.dart' show DartPlatform;
export 'src/scratch_space.dart' show scratchSpace, scratchSpaceResource;
export 'src/summary_builder.dart'
show
Expand Down
Loading