From e872b7addd81ce591355fe8af456dccdac662151 Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Thu, 19 Dec 2024 13:26:20 -0800 Subject: [PATCH] [web libraries] Capture annotations and header comments when expanding parts copy_dart.py parses the generated web libraries to split them into components so that it can expand part declarations. This script should recognize any annotations and header comments (like the license) so that it can accurately copy them over. Ideally, we shouldn't be parsing anything besides the part declarations and expanding them as we just attempt to copy anything else, but that can be done in a future change. Note that this change adds @deprecated back to the library declaration in web_sql_dart2js.dart. It makes no difference, however, as it's a compile time error to import dart:web_sql anyways. CoreLibraryReviewExempt: Doc-only change. Change-Id: Iad974434b858ea36358f908e8a25987105c586c7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401801 Reviewed-by: Sigmund Cherem Commit-Queue: Srujan Gaddam --- sdk/lib/html/dart2js/html_dart2js.dart | 15 +++++++------ .../dart2js/indexed_db_dart2js.dart | 15 +++++++------ sdk/lib/svg/dart2js/svg_dart2js.dart | 7 +++--- .../web_audio/dart2js/web_audio_dart2js.dart | 7 +++--- sdk/lib/web_gl/dart2js/web_gl_dart2js.dart | 7 +++--- sdk/lib/web_sql/dart2js/web_sql_dart2js.dart | 9 ++++---- tools/copy_dart.py | 22 ++++++++++++++----- tools/dom/scripts/dartdomgenerator.py | 1 + 8 files changed, 50 insertions(+), 33 deletions(-) diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart index 5e62668b563..64d5900b294 100644 --- a/sdk/lib/html/dart2js/html_dart2js.dart +++ b/sdk/lib/html/dart2js/html_dart2js.dart @@ -1,3 +1,11 @@ +// Copyright (c) 2012, 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. + +// DO NOT EDIT - unless you are editing documentation as per: +// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation +// Auto-generated dart:html library. + /// HTML elements and other resources for web-based applications that need to /// interact with the browser and the DOM (Document Object Model). /// @@ -36,13 +44,6 @@ import 'dart:web_gl' as gl; import 'dart:web_gl' show RenderingContext, RenderingContext2; import 'dart:_foreign_helper' show JS, JS_INTERCEPTOR_CONSTANT; import 'dart:js_util' as js_util; -// Copyright (c) 2012, 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. - -// DO NOT EDIT - unless you are editing documentation as per: -// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation -// Auto-generated dart:html library. // Not actually used, but imported since dart:html can generate these objects. import 'dart:_js_helper' diff --git a/sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart b/sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart index 58752a626eb..a3eafab4cb3 100644 --- a/sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart +++ b/sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart @@ -1,3 +1,11 @@ +// Copyright (c) 2012, 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. + +// DO NOT EDIT - unless you are editing documentation as per: +// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation +// Auto-generated dart:indexed_db library. + /// A client-side key-value store with support for indexes. /// /// > [!Note] @@ -78,13 +86,6 @@ import 'dart:_js_helper' show Creates, Returns, JSName, Native; import 'dart:_foreign_helper' show JS; import 'dart:_interceptors' show JavaScriptObject, JSExtendableArray; import 'dart:_js_helper' show convertDartClosureToJS; -// Copyright (c) 2012, 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. - -// DO NOT EDIT - unless you are editing documentation as per: -// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation -// Auto-generated dart:indexed_db library. class _KeyRangeFactoryProvider { static KeyRange createKeyRange_only(/*Key*/ value) => diff --git a/sdk/lib/svg/dart2js/svg_dart2js.dart b/sdk/lib/svg/dart2js/svg_dart2js.dart index d184660ed3b..03bab3ca346 100644 --- a/sdk/lib/svg/dart2js/svg_dart2js.dart +++ b/sdk/lib/svg/dart2js/svg_dart2js.dart @@ -1,3 +1,7 @@ +// DO NOT EDIT - unless you are editing documentation as per: +// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation +// Auto-generated dart:svg library. + /// Scalable Vector Graphics: /// Two-dimensional vector graphics with support for events and animation. /// @@ -21,9 +25,6 @@ import 'dart:html_common'; import 'dart:_js_helper' show Creates, Returns, JSName, Native; import 'dart:_foreign_helper' show JS; import 'dart:_interceptors' show JavaScriptObject; -// DO NOT EDIT - unless you are editing documentation as per: -// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation -// Auto-generated dart:svg library. // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a diff --git a/sdk/lib/web_audio/dart2js/web_audio_dart2js.dart b/sdk/lib/web_audio/dart2js/web_audio_dart2js.dart index 753359d7fc7..dd2a3c99c2b 100644 --- a/sdk/lib/web_audio/dart2js/web_audio_dart2js.dart +++ b/sdk/lib/web_audio/dart2js/web_audio_dart2js.dart @@ -1,3 +1,7 @@ +// DO NOT EDIT - unless you are editing documentation as per: +// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation +// Auto-generated dart:audio library. + /// High-fidelity audio programming in the browser. /// /// > [!Note] @@ -17,9 +21,6 @@ import 'dart:_native_typed_data'; import 'dart:typed_data'; import 'dart:_foreign_helper' show JS; import 'dart:_interceptors' show JavaScriptObject; -// DO NOT EDIT - unless you are editing documentation as per: -// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation -// Auto-generated dart:audio library. import 'dart:_js_helper' show diff --git a/sdk/lib/web_gl/dart2js/web_gl_dart2js.dart b/sdk/lib/web_gl/dart2js/web_gl_dart2js.dart index c36aaa5a7d2..9c162722264 100644 --- a/sdk/lib/web_gl/dart2js/web_gl_dart2js.dart +++ b/sdk/lib/web_gl/dart2js/web_gl_dart2js.dart @@ -1,3 +1,7 @@ +// DO NOT EDIT - unless you are editing documentation as per: +// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation +// Auto-generated dart:web_gl library. + /// 3D programming in the browser. /// /// > [!Note] @@ -19,9 +23,6 @@ import 'dart:_js_helper' show Creates, JSName, Native, Returns, convertDartClosureToJS; import 'dart:_foreign_helper' show JS; import 'dart:_interceptors' show JavaScriptObject, JSExtendableArray; -// DO NOT EDIT - unless you are editing documentation as per: -// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation -// Auto-generated dart:web_gl library. // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a diff --git a/sdk/lib/web_sql/dart2js/web_sql_dart2js.dart b/sdk/lib/web_sql/dart2js/web_sql_dart2js.dart index d0b1110d4e6..306a2e674ca 100644 --- a/sdk/lib/web_sql/dart2js/web_sql_dart2js.dart +++ b/sdk/lib/web_sql/dart2js/web_sql_dart2js.dart @@ -1,3 +1,7 @@ +// DO NOT EDIT - unless you are editing documentation as per: +// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation +// Auto-generated dart:web_sql library. + /// An API for storing data in the browser that can be queried with SQL. /// /// **Caution:** this specification is no longer actively maintained by the Web @@ -9,6 +13,7 @@ /// /// {@category Web (Legacy)} /// {@nodoc} +@deprecated library dart.dom.web_sql; import 'dart:async'; @@ -18,11 +23,7 @@ import 'dart:html'; import 'dart:html_common'; import 'dart:_foreign_helper' show JS; import 'dart:_interceptors' show JavaScriptObject; -// DO NOT EDIT - unless you are editing documentation as per: -// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation -// Auto-generated dart:web_sql library. -@deprecated import 'dart:_js_helper' show applyExtension, diff --git a/tools/copy_dart.py b/tools/copy_dart.py index fedc29b0daf..49f45321f8e 100755 --- a/tools/copy_dart.py +++ b/tools/copy_dart.py @@ -12,18 +12,22 @@ from os.path import basename, dirname, exists, isabs, join from glob import glob re_directive = re.compile(r'^(library|import|part|native|resource)\s+(.*);$') -re_comment = re.compile(r'^(///|/\*| \*).*$') +re_comment = re.compile(r'^(///?|/\*| \*).*$') +re_annotation = re.compile(r'^@.*$') +re_newline = re.compile(r'\n') class Library(object): - def __init__(self, name, imports, sources, natives, code, comment): + def __init__(self, name, imports, sources, natives, code, comment, + annotations): self.name = name self.imports = imports self.sources = sources self.natives = natives self.code = code self.comment = comment + self.annotations = annotations def parseLibrary(library): @@ -37,6 +41,7 @@ def parseLibrary(library): natives = [] inlinecode = [] librarycomment = [] + libraryannotations = [] if exists(library): # TODO(sigmund): stop parsing when import/source for line in fileinput.input(library): @@ -56,14 +61,17 @@ def parseLibrary(library): raise Exception( 'unknown directive %s in %s' % (directive, line)) else: - # Check for library comment. - if not libraryname and re_comment.match(line): - librarycomment.append(line) + # Check for library comments and annotations. + if not libraryname: + if re_comment.match(line) or re_newline.match(line): + librarycomment.append(line) + elif re_annotation.match(line): + libraryannotations.append(line) else: inlinecode.append(line) fileinput.close() return Library(libraryname, imports, sources, natives, inlinecode, - librarycomment) + librarycomment, libraryannotations) def normjoin(*args): @@ -126,6 +134,8 @@ except for dart files with absolute paths, which will be copied to if library.name: if library.comment: f.write('%s' % (''.join(library.comment))) + if library.annotations: + f.write('%s' % (''.join(library.annotations))) f.write("library %s;\n\n" % library.name) else: f.write("library %s;\n\n" % basename(lib)) diff --git a/tools/dom/scripts/dartdomgenerator.py b/tools/dom/scripts/dartdomgenerator.py index bf0ea0152ee..59f37a32236 100755 --- a/tools/dom/scripts/dartdomgenerator.py +++ b/tools/dom/scripts/dartdomgenerator.py @@ -206,6 +206,7 @@ def GenerateFromDatabase(common_database, def GenerateSingleFile(library_path, output_dir, generated_output_dir=None, prefix=None): library_dir = os.path.dirname(library_path) library_filename = os.path.basename(library_path) + # Expand part files and concatenate them. copy_dart_script = os.path.relpath('../../copy_dart.py', library_dir) output_dir = os.path.relpath(output_dir, library_dir) if not os.path.exists(library_dir):