diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 653637b4..b907ebf4 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -340,47 +340,7 @@ jobs: - job_004 - job_005 job_010: - name: "generate_and_analyze; Dart dev; PKG: web_generator; `dart analyze --fatal-infos .`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:web_generator;commands:analyze" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:web_generator - os:ubuntu-latest;pub-cache-hosted;sdk:dev - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 - with: - sdk: dev - - id: checkout - name: Checkout repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - id: web_generator_pub_upgrade - name: web_generator; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: web_generator - - name: "web_generator; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . - if: "always() && steps.web_generator_pub_upgrade.conclusion == 'success'" - working-directory: web_generator - needs: - - job_001 - - job_002 - - job_003 - - job_004 - - job_005 - - job_006 - - job_007 - - job_008 - - job_009 - job_011: - name: "generate_and_analyze; Dart dev; PKG: web_generator; `dart bin/update_bindings.dart`" + name: "generate_and_analyze; Dart dev; PKG: web_generator; `dart pub -C ../web get && dart bin/update_bindings.dart && dart analyze --fatal-infos ../web`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -405,8 +365,8 @@ jobs: run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: web_generator - - name: web_generator; dart bin/update_bindings.dart - run: dart bin/update_bindings.dart + - name: "web_generator; dart pub -C ../web get && dart bin/update_bindings.dart && dart analyze --fatal-infos ../web" + run: "dart pub -C ../web get && dart bin/update_bindings.dart && dart analyze --fatal-infos ../web" if: "always() && steps.web_generator_pub_upgrade.conclusion == 'success'" working-directory: web_generator needs: @@ -419,50 +379,8 @@ jobs: - job_007 - job_008 - job_009 - job_012: - name: "generate_all_and_analyze; Dart dev; PKG: web_generator; `dart analyze --fatal-infos .`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:web_generator;commands:analyze" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:web_generator - os:ubuntu-latest;pub-cache-hosted;sdk:dev - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 - with: - sdk: dev - - id: checkout - name: Checkout repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - id: web_generator_pub_upgrade - name: web_generator; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: web_generator - - name: "web_generator; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . - if: "always() && steps.web_generator_pub_upgrade.conclusion == 'success'" - working-directory: web_generator - needs: - - job_001 - - job_002 - - job_003 - - job_004 - - job_005 - - job_006 - - job_007 - - job_008 - - job_009 - - job_010 - - job_011 - job_013: - name: "generate_all_and_analyze; Dart dev; PKG: web_generator; `dart bin/update_bindings.dart --generate-all`" + job_011: + 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`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -487,8 +405,8 @@ jobs: run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: web_generator - - name: "web_generator; dart bin/update_bindings.dart --generate-all" - run: dart bin/update_bindings.dart --generate-all + - name: "web_generator; dart pub -C ../web get && dart bin/update_bindings.dart --generate-all && dart analyze --fatal-infos ../web" + run: "dart pub -C ../web get && dart bin/update_bindings.dart --generate-all && dart analyze --fatal-infos ../web" if: "always() && steps.web_generator_pub_upgrade.conclusion == 'success'" working-directory: web_generator needs: @@ -502,8 +420,7 @@ jobs: - job_008 - job_009 - job_010 - - job_011 - job_014: + job_012: name: "dart_fixes; Dart main; PKG: web; `dart fix --compare-to-golden test_fixes`" runs-on: ubuntu-latest steps: @@ -545,5 +462,3 @@ jobs: - job_009 - job_010 - job_011 - - job_012 - - job_013 diff --git a/tool/ci.sh b/tool/ci.sh index 667ea23f..7ab0b8e3 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -72,12 +72,12 @@ for PKG in ${PKGS}; do dart fix --compare-to-golden test_fixes || EXIT_CODE=$? ;; command_1) - echo 'dart bin/update_bindings.dart' - dart bin/update_bindings.dart || EXIT_CODE=$? + echo 'dart pub -C ../web get && dart bin/update_bindings.dart && dart analyze --fatal-infos ../web' + dart pub -C ../web get && dart bin/update_bindings.dart && dart analyze --fatal-infos ../web || EXIT_CODE=$? ;; command_2) - echo 'dart bin/update_bindings.dart --generate-all' - dart bin/update_bindings.dart --generate-all || EXIT_CODE=$? + echo 'dart pub -C ../web get && dart bin/update_bindings.dart --generate-all && dart analyze --fatal-infos ../web' + dart pub -C ../web get && dart bin/update_bindings.dart --generate-all && dart analyze --fatal-infos ../web || EXIT_CODE=$? ;; format) echo 'dart format --output=none --set-exit-if-changed .' diff --git a/web_generator/bin/update_bindings.dart b/web_generator/bin/update_bindings.dart index 2b18dfb2..cc4cb2ba 100644 --- a/web_generator/bin/update_bindings.dart +++ b/web_generator/bin/update_bindings.dart @@ -13,6 +13,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:args/args.dart'; import 'package:io/ansi.dart' as ansi; import 'package:io/io.dart'; +import 'package:package_config/package_config.dart'; import 'package:path/path.dart' as p; void main(List arguments) async { @@ -48,6 +49,7 @@ $_usage'''); await _generateJsTypeSupertypes(); if (argResult['compile'] as bool) { + final webPkgLangVersion = await _webPackageLanguageVersion(_webPackagePath); // Compile Dart to Javascript. await _runProc( Platform.executable, @@ -55,6 +57,8 @@ $_usage'''); 'compile', 'js', '--enable-asserts', + '--server-mode', + '-DlanguageVersion=$webPkgLangVersion', 'dart_main.dart', '-o', 'dart_main.js', @@ -64,8 +68,7 @@ $_usage'''); } // Determine the set of previously generated files. - final domDir = - Directory(Platform.script.resolve('../../web/lib/src/dom').path); + final domDir = Directory(p.join(_webPackagePath, 'lib/src/dom')); final existingFiles = domDir.listSync(recursive: true).whereType().where((file) { if (!file.path.endsWith('.dart')) return false; @@ -83,7 +86,7 @@ $_usage'''); 'node', [ 'main.mjs', - '--output-directory=${Platform.script.resolve('../../web/lib/src').path}', + '--output-directory=${p.join(_webPackagePath, 'lib/src')}', if (generateAll) '--generate-all', ], workingDirectory: _bindingsGeneratorPath, @@ -128,6 +131,25 @@ $_startComment } } +Future _webPackageLanguageVersion(String pkgPath) async { + final packageConfig = await findPackageConfig(Directory(pkgPath)); + if (packageConfig == null) { + throw StateError('No package config for "$pkgPath"'); + } + final package = + packageConfig.packageOf(Uri.file(p.join(pkgPath, 'pubspec.yaml'))); + if (package == null) { + throw StateError('No package at "$pkgPath"'); + } + final languageVersion = package.languageVersion; + if (languageVersion == null) { + throw StateError('No language version "$pkgPath"'); + } + return '$languageVersion.0'; +} + +final _webPackagePath = Platform.script.resolve('../../web').path; + String _packageLockVersion(String package) { final packageLockData = jsonDecode( File(p.join(_bindingsGeneratorPath, 'package-lock.json')) @@ -174,9 +196,8 @@ Future _runProc( // used by the translator to handle IDL types. Future _generateJsTypeSupertypes() async { // Use a file that uses `dart:js_interop` for analysis. - final contextCollection = AnalysisContextCollection(includedPaths: [ - p.fromUri(Platform.script.resolve('../../web/lib/src/dom.dart')) - ]); + final contextCollection = AnalysisContextCollection( + includedPaths: [p.join(_webPackagePath, 'lib/src/dom.dart')]); final dartJsInterop = (await contextCollection.contexts.single.currentSession .getLibraryByUri('dart:js_interop') as LibraryElementResult) .element; diff --git a/web_generator/lib/src/dart_main.dart b/web_generator/lib/src/dart_main.dart index 2fec9fb4..1304eb51 100644 --- a/web_generator/lib/src/dart_main.dart +++ b/web_generator/lib/src/dart_main.dart @@ -7,6 +7,7 @@ import 'dart:js_interop'; import 'package:args/args.dart'; import 'package:code_builder/code_builder.dart' as code; import 'package:dart_style/dart_style.dart'; +import 'package:pub_semver/pub_semver.dart'; import 'filesystem_api.dart'; import 'generate_bindings.dart'; @@ -19,15 +20,24 @@ import 'util.dart'; // probably involve parsing the TC39 spec. void main(List args) async { + var languageVersionString = const String.fromEnvironment('languageVersion'); + if (languageVersionString.isEmpty) { + languageVersionString = DartFormatter.latestLanguageVersion.toString(); + } final ArgResults argResult; argResult = _parser.parse(args); await _generateAndWriteBindings( - outputDirectory: argResult['output-directory'] as String, - generateAll: argResult['generate-all'] as bool); + outputDirectory: argResult['output-directory'] as String, + generateAll: argResult['generate-all'] as bool, + languageVersion: Version.parse(languageVersionString), + ); } -Future _generateAndWriteBindings( - {required String outputDirectory, required bool generateAll}) async { +Future _generateAndWriteBindings({ + required String outputDirectory, + required bool generateAll, + required Version languageVersion, +}) async { const librarySubDir = 'dom'; ensureDirectoryExists('$outputDirectory/$librarySubDir'); @@ -38,12 +48,12 @@ Future _generateAndWriteBindings( final libraryPath = entry.key; final library = entry.value; - final contents = _emitLibrary(library).toJS; + final contents = _emitLibrary(library, languageVersion).toJS; fs.writeFileSync('$outputDirectory/$libraryPath'.toJS, contents); } } -String _emitLibrary(code.Library library) { +String _emitLibrary(code.Library library, Version languageVersion) { final emitter = code.DartEmitter( allocator: code.Allocator(), orderDirectives: true, @@ -51,7 +61,7 @@ String _emitLibrary(code.Library library) { ); final source = library.accept(emitter); - return DartFormatter(languageVersion: DartFormatter.latestLanguageVersion) + return DartFormatter(languageVersion: languageVersion) .format(source.toString()); } diff --git a/web_generator/mono_pkg.yaml b/web_generator/mono_pkg.yaml index b9af430c..63fa719e 100644 --- a/web_generator/mono_pkg.yaml +++ b/web_generator/mono_pkg.yaml @@ -9,8 +9,12 @@ stages: - test: --test-randomize-ordering-seed=random -p chrome - test: --test-randomize-ordering-seed=random -p chrome -c dart2wasm - generate_and_analyze: - - command: dart bin/update_bindings.dart - - analyze: --fatal-infos . + - command: + - dart pub -C ../web get + - dart bin/update_bindings.dart + - dart analyze --fatal-infos ../web - generate_all_and_analyze: - - command: dart bin/update_bindings.dart --generate-all - - analyze: --fatal-infos . + - command: + - dart pub -C ../web get + - dart bin/update_bindings.dart --generate-all + - dart analyze --fatal-infos ../web diff --git a/web_generator/pubspec.yaml b/web_generator/pubspec.yaml index b3bc534c..746f5457 100644 --- a/web_generator/pubspec.yaml +++ b/web_generator/pubspec.yaml @@ -5,17 +5,19 @@ description: Generator scripts for package:web. repository: https://github.com/dart-lang/web environment: - sdk: ^3.6.0-0 + sdk: ^3.6.0 dependencies: - analyzer: ^6.3.0 + analyzer: ^7.0.0 args: ^2.4.0 build_runner: ^2.4.6 build_web_compilers: ^4.0.8 code_builder: ^4.10.0 collection: ^1.18.0 dart_flutter_team_lints: ^3.0.0 - dart_style: ^2.3.7 + dart_style: ^3.0.0 io: ^1.0.4 + package_config: ^2.1.1 path: ^1.8.3 + pub_semver: ^2.1.5 test: ^1.24.4