-
Notifications
You must be signed in to change notification settings - Fork 211
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
Conversation
… and platform specific pipelines
_test/test/common/message_io.dart
Outdated
@@ -0,0 +1,5 @@ | |||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] 2018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
import 'package:test/test.dart'; | ||
|
||
// ignore: uri_does_not_exist |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
main() { | ||
test('Message matches expected', () { | ||
if (1.0 is int) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
strategy: fine | ||
``` | ||
|
||
The supported platforms are currently `dart2js`, `dartdevc`, and `vm`. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boo
var id = AssetId(buildStep.inputId.package, 'lib/$metaModuleExtension'); | ||
var platformLoader = await buildStep.fetchResource(platformsLoaderResource); | ||
var platforms = await platformLoader.load(buildStep); | ||
var platform = platforms[_platform]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we wrap this logic up in a method? It took a while to parse what was going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
'dart.library.<name> constants are supported.'); | ||
} | ||
var library = condition.substring('dart.library.'.length); | ||
var coreLibSupport = platform.libraries[library]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what's going on here with coreLibSupport.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically just checking if the current platform explicitly supports the core library that is being referenced in the conditional import. It might either omit the library entirely or explicitly have it marked as unsupported.
build_modules/lib/src/platform.dart
Outdated
PlatformsLoader._(); | ||
|
||
Future<Platforms> load(AssetReader reader) async { | ||
if (_invalidated) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional - not worth a rebase if you planned on merging instead of squashing] invert the condition and bail out early to reduce 1 level of nesting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
var conditions = <String, AssetId>{r'$default': linkedId}; | ||
for (var condition in conditionalDirectiveConfigurations) { | ||
if (Uri.parse(condition.uri.stringValue).scheme == 'dart') { | ||
throw 'Unsupported conditional import of ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this unsupported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it has any value (you can't use things from them anyways) - tracking it would have meant tracking sdk deps per platform which complicates things unnecessarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can't use things from them anyways
I don't understand, this seems valid:
import 'fake_io.dart'
if (dart.library.io) 'dart:io';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I guess in that sense you could use it, I hadn't considered the fake io case but I don't think that is a common use case anyways?
My thoughts regarding this were that the different libraries don't have any overlapping types, so directly doing this would not have any value:
import 'default.dart'
if (dart.library.io) 'dart:io'
if (dart.library.html) 'dart:html';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think the fake_io, fake_html thing is going to be a real use case...
I agree that there isn't much value in tracking it, and we can probably assume that they are "correct" in that you won't have something like if (dart.library.io) 'dart:html'
- and let the failure be late if you do.
Is it OK to ignore them instead of throw here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't actually think the fake_io case would be common though - in what scenario would that actually be a good pattern?
Primarily this feature is meant to be used by libraries I think, where they are going to want some real implementation and not just fall back on a fake. I don't think it is particularly cumbersome to simply force people to come up with a more generic api and have their actual platform specific imports hidden behind a conditional import.
In theory you could use a fake within a test but I don't understand the value that the feature provides there since you are typically only running on one platform or always running with a fake/mock.
build_modules/CHANGELOG.md
Outdated
### Improvements | ||
|
||
- Modules are now platform specific, and config specific imports are supported, | ||
but only for `dart.library.*` constants. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is already an constraint on conditional imports in the CFE (though it's maybe not documented super well?)
I don't think we should phrase this as if it's a limitation. "config specific imports against dart.library.*
constants are supported"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
though it's maybe not documented super well?
or at all ;)
dartdevc: | ||
import: "package:build_modules/builders.dart" | ||
builder_factories: | ||
- metaModuleBuilderFactoryForPlatform('dartdevc') |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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
strategy: fine | ||
``` | ||
|
||
The supported platforms are currently `dart2js`, `dartdevc`, and `vm`. |
There was a problem hiding this comment.
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 😢
Thanks for tagging me @natebosch! Will make sure to update when this lands. |
@natebosch @grouma I am reconsidering using the libraries.json file for a couple reasons, curious what you think.
|
I'm in favor of hard coding the mapping. As you said, it is unlikely that specific imports are added regularly. If that situation changes we can easily adjust the solution. I'd rather reduce the complexity for now. |
@vsmenon - can we expect stability in inclusion/exclusion of I'm OK with hardcoding this if we are reasonably confident that it's not going to allow for incompatibilities against newer SDKs before there is a breaking version bump. I was more nervous about this before stable. Other than old versions existing which are possible to pub solve against - do we think there are any reasons this isn't an easily reversible choice? We can hardcode for now and add back libraries.json parsing in the future if we decide it's warranted right? |
Right, it should be a transparent change. |
@natebosch Yes, I think so. We're not making breaking changes in 2.x here - and removing would clearly be breaking. We might consider new libraries / platform. We're hardcoding what's true and false in DDC today. |
Ok, refactored the platform support handling:
|
Looks like the build_script_generate test is getting flaky (timeouts) - submitting with red appveyor |
Most of the changes are to the build_modules package, and there is now a separate set of module files per platform.
applies_builders
config.cc @pulyaevskiy the build_node_compilers package will need an update as well - see the build_web_compilers package updates here.