Skip to content

Commit b55f343

Browse files
authored
generator: Support the latest package dependencies (#328)
Also wired through the language version of the target `web` package
1 parent bdf112e commit b55f343

File tree

6 files changed

+69
-117
lines changed

6 files changed

+69
-117
lines changed

.github/workflows/dart.yml

+8-93
Original file line numberDiff line numberDiff line change
@@ -340,47 +340,7 @@ jobs:
340340
- job_004
341341
- job_005
342342
job_010:
343-
name: "generate_and_analyze; Dart dev; PKG: web_generator; `dart analyze --fatal-infos .`"
344-
runs-on: ubuntu-latest
345-
steps:
346-
- name: Cache Pub hosted dependencies
347-
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
348-
with:
349-
path: "~/.pub-cache/hosted"
350-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:web_generator;commands:analyze"
351-
restore-keys: |
352-
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:web_generator
353-
os:ubuntu-latest;pub-cache-hosted;sdk:dev
354-
os:ubuntu-latest;pub-cache-hosted
355-
os:ubuntu-latest
356-
- name: Setup Dart SDK
357-
uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
358-
with:
359-
sdk: dev
360-
- id: checkout
361-
name: Checkout repository
362-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
363-
- id: web_generator_pub_upgrade
364-
name: web_generator; dart pub upgrade
365-
run: dart pub upgrade
366-
if: "always() && steps.checkout.conclusion == 'success'"
367-
working-directory: web_generator
368-
- name: "web_generator; dart analyze --fatal-infos ."
369-
run: dart analyze --fatal-infos .
370-
if: "always() && steps.web_generator_pub_upgrade.conclusion == 'success'"
371-
working-directory: web_generator
372-
needs:
373-
- job_001
374-
- job_002
375-
- job_003
376-
- job_004
377-
- job_005
378-
- job_006
379-
- job_007
380-
- job_008
381-
- job_009
382-
job_011:
383-
name: "generate_and_analyze; Dart dev; PKG: web_generator; `dart bin/update_bindings.dart`"
343+
name: "generate_and_analyze; Dart dev; PKG: web_generator; `dart pub -C ../web get && dart bin/update_bindings.dart && dart analyze --fatal-infos ../web`"
384344
runs-on: ubuntu-latest
385345
steps:
386346
- name: Cache Pub hosted dependencies
@@ -405,8 +365,8 @@ jobs:
405365
run: dart pub upgrade
406366
if: "always() && steps.checkout.conclusion == 'success'"
407367
working-directory: web_generator
408-
- name: web_generator; dart bin/update_bindings.dart
409-
run: dart bin/update_bindings.dart
368+
- name: "web_generator; dart pub -C ../web get && dart bin/update_bindings.dart && dart analyze --fatal-infos ../web"
369+
run: "dart pub -C ../web get && dart bin/update_bindings.dart && dart analyze --fatal-infos ../web"
410370
if: "always() && steps.web_generator_pub_upgrade.conclusion == 'success'"
411371
working-directory: web_generator
412372
needs:
@@ -419,50 +379,8 @@ jobs:
419379
- job_007
420380
- job_008
421381
- job_009
422-
job_012:
423-
name: "generate_all_and_analyze; Dart dev; PKG: web_generator; `dart analyze --fatal-infos .`"
424-
runs-on: ubuntu-latest
425-
steps:
426-
- name: Cache Pub hosted dependencies
427-
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
428-
with:
429-
path: "~/.pub-cache/hosted"
430-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:web_generator;commands:analyze"
431-
restore-keys: |
432-
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:web_generator
433-
os:ubuntu-latest;pub-cache-hosted;sdk:dev
434-
os:ubuntu-latest;pub-cache-hosted
435-
os:ubuntu-latest
436-
- name: Setup Dart SDK
437-
uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
438-
with:
439-
sdk: dev
440-
- id: checkout
441-
name: Checkout repository
442-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
443-
- id: web_generator_pub_upgrade
444-
name: web_generator; dart pub upgrade
445-
run: dart pub upgrade
446-
if: "always() && steps.checkout.conclusion == 'success'"
447-
working-directory: web_generator
448-
- name: "web_generator; dart analyze --fatal-infos ."
449-
run: dart analyze --fatal-infos .
450-
if: "always() && steps.web_generator_pub_upgrade.conclusion == 'success'"
451-
working-directory: web_generator
452-
needs:
453-
- job_001
454-
- job_002
455-
- job_003
456-
- job_004
457-
- job_005
458-
- job_006
459-
- job_007
460-
- job_008
461-
- job_009
462-
- job_010
463-
- job_011
464-
job_013:
465-
name: "generate_all_and_analyze; Dart dev; PKG: web_generator; `dart bin/update_bindings.dart --generate-all`"
382+
job_011:
383+
name: "generate_all_and_analyze; Dart dev; PKG: web_generator; `dart pub -C ../web get && dart bin/update_bindings.dart --generate-all && dart analyze --fatal-infos ../web`"
466384
runs-on: ubuntu-latest
467385
steps:
468386
- name: Cache Pub hosted dependencies
@@ -487,8 +405,8 @@ jobs:
487405
run: dart pub upgrade
488406
if: "always() && steps.checkout.conclusion == 'success'"
489407
working-directory: web_generator
490-
- name: "web_generator; dart bin/update_bindings.dart --generate-all"
491-
run: dart bin/update_bindings.dart --generate-all
408+
- name: "web_generator; dart pub -C ../web get && dart bin/update_bindings.dart --generate-all && dart analyze --fatal-infos ../web"
409+
run: "dart pub -C ../web get && dart bin/update_bindings.dart --generate-all && dart analyze --fatal-infos ../web"
492410
if: "always() && steps.web_generator_pub_upgrade.conclusion == 'success'"
493411
working-directory: web_generator
494412
needs:
@@ -502,8 +420,7 @@ jobs:
502420
- job_008
503421
- job_009
504422
- job_010
505-
- job_011
506-
job_014:
423+
job_012:
507424
name: "dart_fixes; Dart main; PKG: web; `dart fix --compare-to-golden test_fixes`"
508425
runs-on: ubuntu-latest
509426
steps:
@@ -545,5 +462,3 @@ jobs:
545462
- job_009
546463
- job_010
547464
- job_011
548-
- job_012
549-
- job_013

tool/ci.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ for PKG in ${PKGS}; do
7272
dart fix --compare-to-golden test_fixes || EXIT_CODE=$?
7373
;;
7474
command_1)
75-
echo 'dart bin/update_bindings.dart'
76-
dart bin/update_bindings.dart || EXIT_CODE=$?
75+
echo 'dart pub -C ../web get && dart bin/update_bindings.dart && dart analyze --fatal-infos ../web'
76+
dart pub -C ../web get && dart bin/update_bindings.dart && dart analyze --fatal-infos ../web || EXIT_CODE=$?
7777
;;
7878
command_2)
79-
echo 'dart bin/update_bindings.dart --generate-all'
80-
dart bin/update_bindings.dart --generate-all || EXIT_CODE=$?
79+
echo 'dart pub -C ../web get && dart bin/update_bindings.dart --generate-all && dart analyze --fatal-infos ../web'
80+
dart pub -C ../web get && dart bin/update_bindings.dart --generate-all && dart analyze --fatal-infos ../web || EXIT_CODE=$?
8181
;;
8282
format)
8383
echo 'dart format --output=none --set-exit-if-changed .'

web_generator/bin/update_bindings.dart

+27-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:analyzer/dart/element/type.dart';
1313
import 'package:args/args.dart';
1414
import 'package:io/ansi.dart' as ansi;
1515
import 'package:io/io.dart';
16+
import 'package:package_config/package_config.dart';
1617
import 'package:path/path.dart' as p;
1718

1819
void main(List<String> arguments) async {
@@ -48,13 +49,16 @@ $_usage''');
4849
await _generateJsTypeSupertypes();
4950

5051
if (argResult['compile'] as bool) {
52+
final webPkgLangVersion = await _webPackageLanguageVersion(_webPackagePath);
5153
// Compile Dart to Javascript.
5254
await _runProc(
5355
Platform.executable,
5456
[
5557
'compile',
5658
'js',
5759
'--enable-asserts',
60+
'--server-mode',
61+
'-DlanguageVersion=$webPkgLangVersion',
5862
'dart_main.dart',
5963
'-o',
6064
'dart_main.js',
@@ -64,8 +68,7 @@ $_usage''');
6468
}
6569

6670
// Determine the set of previously generated files.
67-
final domDir =
68-
Directory(Platform.script.resolve('../../web/lib/src/dom').path);
71+
final domDir = Directory(p.join(_webPackagePath, 'lib/src/dom'));
6972
final existingFiles =
7073
domDir.listSync(recursive: true).whereType<File>().where((file) {
7174
if (!file.path.endsWith('.dart')) return false;
@@ -83,7 +86,7 @@ $_usage''');
8386
'node',
8487
[
8588
'main.mjs',
86-
'--output-directory=${Platform.script.resolve('../../web/lib/src').path}',
89+
'--output-directory=${p.join(_webPackagePath, 'lib/src')}',
8790
if (generateAll) '--generate-all',
8891
],
8992
workingDirectory: _bindingsGeneratorPath,
@@ -128,6 +131,25 @@ $_startComment
128131
}
129132
}
130133

134+
Future<String> _webPackageLanguageVersion(String pkgPath) async {
135+
final packageConfig = await findPackageConfig(Directory(pkgPath));
136+
if (packageConfig == null) {
137+
throw StateError('No package config for "$pkgPath"');
138+
}
139+
final package =
140+
packageConfig.packageOf(Uri.file(p.join(pkgPath, 'pubspec.yaml')));
141+
if (package == null) {
142+
throw StateError('No package at "$pkgPath"');
143+
}
144+
final languageVersion = package.languageVersion;
145+
if (languageVersion == null) {
146+
throw StateError('No language version "$pkgPath"');
147+
}
148+
return '$languageVersion.0';
149+
}
150+
151+
final _webPackagePath = Platform.script.resolve('../../web').path;
152+
131153
String _packageLockVersion(String package) {
132154
final packageLockData = jsonDecode(
133155
File(p.join(_bindingsGeneratorPath, 'package-lock.json'))
@@ -174,9 +196,8 @@ Future<void> _runProc(
174196
// used by the translator to handle IDL types.
175197
Future<void> _generateJsTypeSupertypes() async {
176198
// Use a file that uses `dart:js_interop` for analysis.
177-
final contextCollection = AnalysisContextCollection(includedPaths: [
178-
p.fromUri(Platform.script.resolve('../../web/lib/src/dom.dart'))
179-
]);
199+
final contextCollection = AnalysisContextCollection(
200+
includedPaths: [p.join(_webPackagePath, 'lib/src/dom.dart')]);
180201
final dartJsInterop = (await contextCollection.contexts.single.currentSession
181202
.getLibraryByUri('dart:js_interop') as LibraryElementResult)
182203
.element;

web_generator/lib/src/dart_main.dart

+17-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:js_interop';
77
import 'package:args/args.dart';
88
import 'package:code_builder/code_builder.dart' as code;
99
import 'package:dart_style/dart_style.dart';
10+
import 'package:pub_semver/pub_semver.dart';
1011

1112
import 'filesystem_api.dart';
1213
import 'generate_bindings.dart';
@@ -19,15 +20,24 @@ import 'util.dart';
1920
// probably involve parsing the TC39 spec.
2021

2122
void main(List<String> args) async {
23+
var languageVersionString = const String.fromEnvironment('languageVersion');
24+
if (languageVersionString.isEmpty) {
25+
languageVersionString = DartFormatter.latestLanguageVersion.toString();
26+
}
2227
final ArgResults argResult;
2328
argResult = _parser.parse(args);
2429
await _generateAndWriteBindings(
25-
outputDirectory: argResult['output-directory'] as String,
26-
generateAll: argResult['generate-all'] as bool);
30+
outputDirectory: argResult['output-directory'] as String,
31+
generateAll: argResult['generate-all'] as bool,
32+
languageVersion: Version.parse(languageVersionString),
33+
);
2734
}
2835

29-
Future<void> _generateAndWriteBindings(
30-
{required String outputDirectory, required bool generateAll}) async {
36+
Future<void> _generateAndWriteBindings({
37+
required String outputDirectory,
38+
required bool generateAll,
39+
required Version languageVersion,
40+
}) async {
3141
const librarySubDir = 'dom';
3242

3343
ensureDirectoryExists('$outputDirectory/$librarySubDir');
@@ -38,20 +48,20 @@ Future<void> _generateAndWriteBindings(
3848
final libraryPath = entry.key;
3949
final library = entry.value;
4050

41-
final contents = _emitLibrary(library).toJS;
51+
final contents = _emitLibrary(library, languageVersion).toJS;
4252
fs.writeFileSync('$outputDirectory/$libraryPath'.toJS, contents);
4353
}
4454
}
4555

46-
String _emitLibrary(code.Library library) {
56+
String _emitLibrary(code.Library library, Version languageVersion) {
4757
final emitter = code.DartEmitter(
4858
allocator: code.Allocator(),
4959
orderDirectives: true,
5060
useNullSafetySyntax: true,
5161
);
5262

5363
final source = library.accept(emitter);
54-
return DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
64+
return DartFormatter(languageVersion: languageVersion)
5565
.format(source.toString());
5666
}
5767

web_generator/mono_pkg.yaml

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ stages:
99
- test: --test-randomize-ordering-seed=random -p chrome
1010
- test: --test-randomize-ordering-seed=random -p chrome -c dart2wasm
1111
- generate_and_analyze:
12-
- command: dart bin/update_bindings.dart
13-
- analyze: --fatal-infos .
12+
- command:
13+
- dart pub -C ../web get
14+
- dart bin/update_bindings.dart
15+
- dart analyze --fatal-infos ../web
1416
- generate_all_and_analyze:
15-
- command: dart bin/update_bindings.dart --generate-all
16-
- analyze: --fatal-infos .
17+
- command:
18+
- dart pub -C ../web get
19+
- dart bin/update_bindings.dart --generate-all
20+
- dart analyze --fatal-infos ../web

web_generator/pubspec.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ description: Generator scripts for package:web.
55
repository: https://github.com/dart-lang/web
66

77
environment:
8-
sdk: ^3.6.0-0
8+
sdk: ^3.6.0
99

1010
dependencies:
11-
analyzer: ^6.3.0
11+
analyzer: ^7.0.0
1212
args: ^2.4.0
1313
build_runner: ^2.4.6
1414
build_web_compilers: ^4.0.8
1515
code_builder: ^4.10.0
1616
collection: ^1.18.0
1717
dart_flutter_team_lints: ^3.0.0
18-
dart_style: ^2.3.7
18+
dart_style: ^3.0.0
1919
io: ^1.0.4
20+
package_config: ^2.1.1
2021
path: ^1.8.3
22+
pub_semver: ^2.1.5
2123
test: ^1.24.4

0 commit comments

Comments
 (0)