From f784d9180fa75eab695186a390cd7e657713e651 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Fri, 20 Jul 2018 13:52:10 -0700 Subject: [PATCH 1/9] dartfmt --- lib/src/model.dart | 6 +++--- pubspec.lock | 2 +- test/compare_output_test.dart | 3 +-- test/dartdoc_options_test.dart | 14 ++++++++++++-- test/model_test.dart | 2 +- test/src/utils.dart | 4 ++-- tool/doc_packages.dart | 3 +-- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/src/model.dart b/lib/src/model.dart index 530a9d6b31..58c8437746 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -1629,7 +1629,7 @@ abstract class GetterSetterCombo implements ModelElement { buffer.write('${getter.oneLineDoc}'); } if (hasPublicSetter && setter.oneLineDoc.isNotEmpty) { - buffer.write('${getterSetterBothAvailable ? "": setter.oneLineDoc}'); + buffer.write('${getterSetterBothAvailable ? "" : setter.oneLineDoc}'); } _oneLineDoc = buffer.toString(); } @@ -5724,8 +5724,8 @@ class PackageBuilder { driver.addFile(filename); addedFiles.add(filename); }); - await Future - .wait(files.map((f) => processLibrary(f, libraries, sources))); + await Future.wait( + files.map((f) => processLibrary(f, libraries, sources))); /// We don't care about upstream analysis errors, so save the first /// source list. diff --git a/pubspec.lock b/pubspec.lock index d00fc3ba41..fc126f7a76 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -492,4 +492,4 @@ packages: source: hosted version: "2.1.13" sdks: - dart: ">=2.0.0-dev.59.0 <=2.0.0-dev.63.0.flutter-4c9689c1d2" + dart: ">=2.0.0-dev.59.0 <=2.0.0-dev.69.1" diff --git a/test/compare_output_test.dart b/test/compare_output_test.dart index 3fcb718828..b29a583106 100644 --- a/test/compare_output_test.dart +++ b/test/compare_output_test.dart @@ -200,8 +200,7 @@ void main() { fail('dartdoc failed'); } - var jsonValues = LineSplitter - .split(result.stdout) + var jsonValues = LineSplitter.split(result.stdout) .map((j) => json.decode(j) as Map) .toList(); diff --git a/test/dartdoc_options_test.dart b/test/dartdoc_options_test.dart index a3b4fdd85d..917cbea51a 100644 --- a/test/dartdoc_options_test.dart +++ b/test/dartdoc_options_test.dart @@ -498,7 +498,14 @@ dartdoc: errorMessage, equals( 'Field dartdoc.fileOptionList from ${pathLib.canonicalize(dartdocOptionsTwo.path)}, set to [existing.dart, thing/that/does/not/exist], resolves to missing path: ' - '"${pathLib.joinAll([pathLib.canonicalize(secondDir.path), 'thing', 'that', 'does', 'not', 'exist'])}"')); + '"${pathLib.joinAll([ + pathLib.canonicalize(secondDir.path), + 'thing', + 'that', + 'does', + 'not', + 'exist' + ])}"')); // It doesn't matter that this fails. expect( dartdocOptionSetFiles['nonCriticalFileOption'].valueAt(firstDir), @@ -519,7 +526,10 @@ dartdoc: errorMessage, equals( 'Field dartdoc.fileOption from ${pathLib.canonicalize(dartdocOptionsTwo.path)}, set to not existing, resolves to missing path: ' - '"${pathLib.joinAll([pathLib.canonicalize(secondDir.path), "not existing"])}"')); + '"${pathLib.joinAll([ + pathLib.canonicalize(secondDir.path), + "not existing" + ])}"')); }); test('DartdocOptionSetFile works for directory options', () { diff --git a/test/model_test.dart b/test/model_test.dart index bd3077ec76..ca44c08f80 100644 --- a/test/model_test.dart +++ b/test/model_test.dart @@ -1693,7 +1693,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, new File(pathLib.join(utils.testPackageDir.path, "crossdart.json")); crossDartFile.writeAsStringSync(""" {"$fakePath": - {"references":[{"offset":${offset},"end":${offset+3},"remotePath":"http://www.example.com/fake.dart"}]}} + {"references":[{"offset":${offset},"end":${offset + 3},"remotePath":"http://www.example.com/fake.dart"}]}} """); // Indirectly load the file. crossdartPackageGraph.crossdartJson; diff --git a/test/src/utils.dart b/test/src/utils.dart index a2dc71dad0..688677cc86 100644 --- a/test/src/utils.dart +++ b/test/src/utils.dart @@ -44,8 +44,8 @@ Future generatorContextFromArgv( /// Convenience factory to build a [DartdocOptionContext] and associate it with a /// [DartdocOptionSet] based on the current working directory. Future contextFromArgv(List argv) async { - DartdocOptionSet optionSet = await DartdocOptionSet - .fromOptionGenerators('dartdoc', [createDartdocOptions]); + DartdocOptionSet optionSet = await DartdocOptionSet.fromOptionGenerators( + 'dartdoc', [createDartdocOptions]); optionSet.parseArguments(argv); return new DartdocOptionContext(optionSet, Directory.current); } diff --git a/tool/doc_packages.dart b/tool/doc_packages.dart index 0c31e56c52..ade349f48f 100644 --- a/tool/doc_packages.dart +++ b/tool/doc_packages.dart @@ -196,8 +196,7 @@ Future _exec(String command, List args, {String cwd, bool quiet: false, Duration timeout: const Duration(seconds: 60)}) { - return Process - .start(command, args, workingDirectory: cwd) + return Process.start(command, args, workingDirectory: cwd) .then((Process process) { if (!quiet) { process.stdout.listen((bytes) => _log(utf8.decode(bytes))); From 34d133871a0654342980c6353a22b45bead68cf6 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 23 Jul 2018 15:12:35 -0700 Subject: [PATCH 2/9] Fix crash in angular, rearrange special object handling, and test angular doc builds --- .travis.yml | 3 +- analysis_options.yaml | 2 - lib/src/model.dart | 93 +++++++++++------------------ lib/src/special_elements.dart | 108 ++++++++++++++++++++++++++++++++++ pubspec.lock | 2 +- test/model_test.dart | 3 +- tool/grind.dart | 17 ++++-- tool/travis.sh | 3 + 8 files changed, 161 insertions(+), 70 deletions(-) create mode 100644 lib/src/special_elements.dart diff --git a/.travis.yml b/.travis.yml index 794905e56d..111f9b8d74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,7 @@ dart: - "dev/raw/latest" env: - DARTDOC_BOT=main - # TODO(devoncarew): add angulardart support - #- DARTDOC_BOT=angular + - DARTDOC_BOT=packages - DARTDOC_BOT=flutter - DARTDOC_BOT=sdk-docs script: ./tool/travis.sh diff --git a/analysis_options.yaml b/analysis_options.yaml index ee60de8645..83921c5cdf 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,7 +1,5 @@ analyzer: - strong-mode: true language: - enableGenericMethods: true enablePreviewDart2: true enableSuperMixins: true exclude: diff --git a/lib/src/model.dart b/lib/src/model.dart index 58c8437746..141f8a583e 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -44,6 +44,7 @@ import 'package:dartdoc/src/logging.dart'; import 'package:dartdoc/src/markdown_processor.dart' show Documentation; import 'package:dartdoc/src/model_utils.dart'; import 'package:dartdoc/src/package_meta.dart' show PackageMeta, FileContents; +import 'package:dartdoc/src/special_elements.dart'; import 'package:dartdoc/src/utils.dart'; import 'package:dartdoc/src/warnings.dart'; import 'package:front_end/src/byte_store/byte_store.dart'; @@ -180,18 +181,17 @@ abstract class Inheritable implements ModelElement { List get inheritance { List inheritance = []; inheritance.addAll((enclosingElement as Class).inheritanceChain); + Class object = packageGraph.specialClasses[SpecialClass.object]; if (!inheritance.contains(definingEnclosingElement) && definingEnclosingElement != null) { - assert(definingEnclosingElement == packageGraph.objectElement); + assert(definingEnclosingElement == object); } // Unless the code explicitly extends dart-core's Object, we won't get // an entry here. So add it. - if (inheritance.last != packageGraph.objectElement && - packageGraph.objectElement != null) { - inheritance.add(packageGraph.objectElement); + if (inheritance.last != object && object != null) { + inheritance.add(object); } - assert( - inheritance.where((e) => e == packageGraph.objectElement).length == 1); + assert(inheritance.where((e) => e == object).length == 1); return inheritance; } } @@ -2587,21 +2587,7 @@ abstract class ModelElement extends Canonicalization if (e is ClassElement) { if (!e.isEnum) { newModelElement = new Class(e, library, packageGraph); - if (newModelElement.name == 'Object' && - newModelElement.library.name == 'dart:core') { - // We've found Object. This is an important object, so save it in the package. - assert( - newModelElement.library.packageGraph._objectElement == null); - newModelElement.library.packageGraph._objectElement = - newModelElement; - } - if (newModelElement.name == 'Interceptor' && - newModelElement.library.name == 'dart:_interceptors') { - // We've found Interceptor. Another important object. - assert(!newModelElement.library.packageGraph._interceptorUsed); - newModelElement.library.packageGraph.interceptor = - newModelElement; - } + } else { newModelElement = new Enum(e, library, packageGraph); } @@ -4017,7 +4003,12 @@ class PackageGraph { // TODO(jcollins-g): This constructor is convoluted. Clean this up by // building Libraries and adding them to Packages, then adding Packages // to this graph. - PackageGraph(Iterable libraryElements, this.config, + + /// Construct a package graph. + /// [libraryElements] - Libraries to be documented. + /// [specialLibraryElements] - Any libraries that may not be documented, but + /// contain required [SpecialClass]es. + PackageGraph(Iterable libraryElements, Iterable specialLibraryElements, this.config, this.packageMeta, this._packageWarningOptions, this.driver, this.sdk) { assert(_allConstructedModelElements.isEmpty); assert(allLibraries.isEmpty); @@ -4042,11 +4033,19 @@ class PackageGraph { new Package.fromPackageMeta(packageMeta, this); allLibrariesAdded = true; + // [findOrCreateLibraryFor] already adds to the proper structures. + specialLibraryElements.forEach((element) { + findOrCreateLibraryFor(element); + }); + // Go through docs of every ModelElement in package to pre-build the macros // index. allLocalModelElements.forEach((m) => m.documentationLocal); _macrosAdded = true; + // Scan all model elements to insure that interceptor and other special + // objects are found. + specialClasses = new SpecialClasses(this); // After the allModelElements traversal to be sure that all packages // are picked up. documentedPackages.toList().forEach((package) { @@ -4059,6 +4058,8 @@ class PackageGraph { allImplementorsAdded = true; } + SpecialClasses specialClasses; + /// It is safe to cache values derived from the _implementors table if this /// is true. bool allImplementorsAdded = false; @@ -4497,31 +4498,6 @@ class PackageGraph { return _localPublicLibraries; } - // Written from ModelElement.from. - ModelElement _objectElement; - - // Return the element for "Object". - ModelElement get objectElement { - assert(_objectElement != null); - return _objectElement; - } - - // Don't let this be used for canonicalization before we find it. - bool _interceptorUsed = false; - Class _interceptor; - - /// Return the element for "Interceptor", a Dart implementation class intended - /// to function the same as Object. - Class get interceptor { - _interceptorUsed = true; - return _interceptor; - } - - set interceptor(Class newInterceptor) { - assert(_interceptorUsed == false); - _interceptor = newInterceptor; - } - // Return the set of [Class]es objects should inherit through if they // show up in the inheritance chain. Do not call before interceptorElement is // found. Add classes here if they are similar to Interceptor in that they @@ -4531,7 +4507,7 @@ class PackageGraph { Set get inheritThrough { if (_inheritThrough == null) { _inheritThrough = new Set(); - _inheritThrough.add(interceptor); + _inheritThrough.add(specialClasses[SpecialClass.interceptor]); } return _inheritThrough; } @@ -4746,16 +4722,16 @@ class PackageGraph { return foundLibrary; } - List _allModelElements; + List _allLocalModelElements; Iterable get allLocalModelElements { assert(allLibrariesAdded); - if (_allModelElements == null) { - _allModelElements = []; + if (_allLocalModelElements == null) { + _allLocalModelElements = []; this.localLibraries.forEach((library) { - _allModelElements.addAll(library.allModelElements); + _allLocalModelElements.addAll(library.allModelElements); }); } - return _allModelElements; + return _allLocalModelElements; } List _allCanonicalModelElements; @@ -5512,8 +5488,10 @@ class PackageBuilder { if (packageMeta.needsPubGet) { packageMeta.runPubGet(); } - Set libraries = await getLibraries(getFiles); - return new PackageGraph(libraries, config, config.topLevelPackageMeta, + Set libraries = new Set(); + Set specialLibraries = new Set(); + await getLibraries(libraries, specialLibraries, getFiles, specialLibraryFiles(sdk).toSet()); + return new PackageGraph(libraries, specialLibraries, config, config.topLevelPackageMeta, getWarningOptions(), driver, sdk); } @@ -5824,9 +5802,9 @@ class PackageBuilder { return new Set.from(files.map((s) => new File(s).absolute.path)); } - Future> getLibraries(Set files) async { - Set libraries = new Set(); + Future getLibraries(Set libraries, Set specialLibraries, Set files, Set specialFiles) async { libraries.addAll(await _parseLibraries(files)); + specialLibraries.addAll(await _parseLibraries(specialFiles.difference(files))); if (config.include.isNotEmpty) { Iterable knownLibraryNames = libraries.map((l) => l.name); Set notFound = new Set.from(config.include) @@ -5838,7 +5816,6 @@ class PackageBuilder { } libraries.removeWhere((lib) => !config.include.contains(lib.name)); } - return libraries; } /// If [dir] contains both a `lib` directory and a `pubspec.yaml` file treat diff --git a/lib/src/special_elements.dart b/lib/src/special_elements.dart new file mode 100644 index 0000000000..51328cfae8 --- /dev/null +++ b/lib/src/special_elements.dart @@ -0,0 +1,108 @@ +// 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. + +/// Handling for special elements within Dart. When identified these +/// may alter the interpretation and documentation generated for other +/// [ModelElement]s. +/// +/// Finding these must not depend on canonicalization. +library dartdoc.special_elements; + +import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/src/generated/sdk.dart'; +import 'package:dartdoc/src/model.dart'; + +/// Which of the [SpecialClasses] to get. +enum SpecialClass { + /// From dart:core, Object + object, + /// From dart:_interceptors, Interceptor + interceptor, +} + +/// A declaration of a special [Class] and how to find it. +class _SpecialClassDefinition { + /// Which specialElement this is. + final SpecialClass specialClass; + /// Name of the ModelElement. + final String name; + /// The library name for the [LibraryElement] in which this [ModelElement] + /// can be found. + final String libraryName; + /// The package name in which this [ModelElement] can be found. + final String packageName; + /// The URI for the library in which this [ModelElement] is defined. + final String specialFileUri; + /// If true, require this element to exist in the packageGraph when + /// calling the [SpecialClasses] constructor. + final bool required; + _SpecialClassDefinition(this.specialClass, this.name, this.libraryName, this.specialFileUri, {this.required = true, this.packageName = 'Dart'}) { + assert(packageName == 'Dart', 'Packages other than SDK not yet supported in special element detection'); + } + + /// Get the filename for the Dart Library where this [specialClass] is + /// declared. + String getSpecialFilename(DartSdk sdk) => sdk.mapDartUri(specialFileUri).fullName; + + bool matchesClass(Class modelClass) { + return modelClass.name == name && + modelClass.library.element.name == libraryName && + modelClass.package.name == packageName; + } +} + +/// List all special classes we need to find here. +final List<_SpecialClassDefinition> _specialClassDefinitions = [ + new _SpecialClassDefinition(SpecialClass.object, 'Object', 'dart.core', 'dart:core'), + new _SpecialClassDefinition(SpecialClass.interceptor, 'Interceptor', '_interceptors', 'dart:_interceptors'), +]; + +/// Given a SDK, resolve URIs for the libraries containing our special +/// clases. +Set specialLibraryFiles(DartSdk sdk) => _specialClassDefinitions.map((_SpecialClassDefinition d) => d.getSpecialFilename(sdk)).toSet(); + +Set __specialLibraryNames; +/// These library names can be checked against the [LibraryElement] names +/// to avoid traversing libraries we don't need to. +Set get _specialLibraryNames { + if (__specialLibraryNames == null) { + __specialLibraryNames = _specialClassDefinitions.map((_SpecialClassDefinition d) => d.libraryName).toSet(); + } + return __specialLibraryNames; +} + +/// Class for managing special [Class] objects inside Dartdoc. +class SpecialClasses { + final PackageGraph packageGraph; + final Map _specialClass = {}; + + SpecialClasses(this.packageGraph) { + Set doneKeys = new Set(); + Set keysToDo = new Set.from(packageGraph.allLibraries.keys); + // Loops because traversing the libraries can instantiate additional + // libraries, and does so in this manner to avoid running into iterable + // modification exceptions. + while (keysToDo.isNotEmpty) { + keysToDo.forEach((LibraryElement e) { + if (_specialLibraryNames.contains(e.name)) { + packageGraph.allLibraries[e].allClasses.forEach((Class aClass) { + _specialClassDefinitions.forEach((_SpecialClassDefinition d) { + if (d.matchesClass(aClass)) { + assert (!_specialClass.containsKey(d.specialClass) || _specialClass[d.specialClass] == aClass); + _specialClass[d.specialClass] = aClass; + } + }); + }); + } + doneKeys.add(e); + }); + keysToDo = new Set.from(packageGraph.allLibraries.keys.where((LibraryElement e) => !doneKeys.contains(e))); + } + _specialClassDefinitions.forEach((_SpecialClassDefinition d) { + if (d.required) assert(_specialClass.containsKey(d.specialClass)); + }); + } + + Class operator[](SpecialClass specialClass) => _specialClass[specialClass]; +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index fc126f7a76..990285f900 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -492,4 +492,4 @@ packages: source: hosted version: "2.1.13" sdks: - dart: ">=2.0.0-dev.59.0 <=2.0.0-dev.69.1" + dart: ">=2.0.0-dev.59.0 <=2.0.0-dev.69.0" diff --git a/test/model_test.dart b/test/model_test.dart index ca44c08f80..77af6e500b 100644 --- a/test/model_test.dart +++ b/test/model_test.dart @@ -8,6 +8,7 @@ import 'dart:io'; import 'package:dartdoc/dartdoc.dart'; import 'package:dartdoc/src/model.dart'; +import 'package:dartdoc/src/special_elements.dart'; import 'package:dartdoc/src/warnings.dart'; import 'package:path/path.dart' as pathLib; import 'package:test/test.dart'; @@ -305,7 +306,7 @@ void main() { htmlLibrary.allClasses.singleWhere((c) => c.name == 'EventTarget'); Field hashCode = EventTarget.allPublicInstanceProperties .singleWhere((f) => f.name == 'hashCode'); - Class objectModelElement = sdkAsPackageGraph.objectElement; + Class objectModelElement = sdkAsPackageGraph.specialClasses[SpecialClass.object]; // If this fails, EventTarget might have been changed to no longer // inherit from Interceptor. If that's true, adjust test case to // another class that does. diff --git a/tool/grind.dart b/tool/grind.dart index 3cb61045e0..657487a3b8 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -586,7 +586,7 @@ Future> _buildFlutterDocs( } /// Returns the directory in which we generated documentation. -Future _buildPubPackageDocs(String pubPackageName, +Future _buildPubPackageDocs(String pubPackageName, List dartdocParameters, [String version, String label]) async { Map env = _createThrowawayPubCache(); var launcher = new SubprocessLauncher( @@ -609,19 +609,24 @@ Future _buildPubPackageDocs(String pubPackageName, pathLib.join(Directory.current.absolute.path, 'bin', 'dartdoc.dart'), '--json', '--show-progress', - ]..addAll(extraDartdocParameters), + ]..addAll(dartdocParameters), workingDirectory: pubPackageDir.absolute.path); return pathLib.join(pubPackageDir.absolute.path, 'doc', 'api'); } @Task( - 'Serve an arbitrary pub package based on PACKAGE_NAME and PACKAGE_VERSION environment variables') -servePubPackage() async { + 'Build an arbitrary pub package based on PACKAGE_NAME and PACKAGE_VERSION environment variables') +Future buildPubPackage() async { assert(Platform.environment.containsKey('PACKAGE_NAME')); String packageName = Platform.environment['PACKAGE_NAME']; String version = Platform.environment['PACKAGE_VERSION']; - _serveDocsFrom(await _buildPubPackageDocs(packageName, version), 9000, - 'serve-pub-package'); + return _buildPubPackageDocs(packageName, extraDartdocParameters, version); +} + +@Task( + 'Serve an arbitrary pub package based on PACKAGE_NAME and PACKAGE_VERSION environment variables') +servePubPackage() async { + _serveDocsFrom(await buildPubPackage(), 9000, 'serve-pub-package'); } @Task('Checks that CHANGELOG mentions current version') diff --git a/tool/travis.sh b/tool/travis.sh index 6f4cceb121..a88429b516 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -20,6 +20,9 @@ if [ "$DARTDOC_BOT" = "sdk-docs" ]; then elif [ "$DARTDOC_BOT" = "flutter" ]; then echo "Running flutter dartdoc bot" pub run grinder validate-flutter-docs +elif [ "$DARTDOC_BOT" = "packages" ]; then + echo "Running packages dartdoc bot" + PACKAGE_NAME=angular PACKAGE_VERSION=">=5.0.0-beta" DARTDOC_PARAMS="--include=angular,angular.security" grind build-pub-package else echo "Running main dartdoc bot" pub run grinder buildbot From 9bbc45b29ac3ef7b8b047b89cea2a68c0ddc199f Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 23 Jul 2018 15:12:54 -0700 Subject: [PATCH 3/9] dartfmt --- lib/src/model.dart | 27 ++++++++++++++------- lib/src/special_elements.dart | 45 +++++++++++++++++++++++++---------- test/model_test.dart | 3 ++- tool/grind.dart | 3 ++- 4 files changed, 55 insertions(+), 23 deletions(-) diff --git a/lib/src/model.dart b/lib/src/model.dart index 141f8a583e..d842990679 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -2587,7 +2587,6 @@ abstract class ModelElement extends Canonicalization if (e is ClassElement) { if (!e.isEnum) { newModelElement = new Class(e, library, packageGraph); - } else { newModelElement = new Enum(e, library, packageGraph); } @@ -4008,8 +4007,14 @@ class PackageGraph { /// [libraryElements] - Libraries to be documented. /// [specialLibraryElements] - Any libraries that may not be documented, but /// contain required [SpecialClass]es. - PackageGraph(Iterable libraryElements, Iterable specialLibraryElements, this.config, - this.packageMeta, this._packageWarningOptions, this.driver, this.sdk) { + PackageGraph( + Iterable libraryElements, + Iterable specialLibraryElements, + this.config, + this.packageMeta, + this._packageWarningOptions, + this.driver, + this.sdk) { assert(_allConstructedModelElements.isEmpty); assert(allLibraries.isEmpty); _packageWarningCounter = new PackageWarningCounter(_packageWarningOptions); @@ -5490,9 +5495,10 @@ class PackageBuilder { } Set libraries = new Set(); Set specialLibraries = new Set(); - await getLibraries(libraries, specialLibraries, getFiles, specialLibraryFiles(sdk).toSet()); - return new PackageGraph(libraries, specialLibraries, config, config.topLevelPackageMeta, - getWarningOptions(), driver, sdk); + await getLibraries(libraries, specialLibraries, getFiles, + specialLibraryFiles(sdk).toSet()); + return new PackageGraph(libraries, specialLibraries, config, + config.topLevelPackageMeta, getWarningOptions(), driver, sdk); } DartSdk _sdk; @@ -5802,9 +5808,14 @@ class PackageBuilder { return new Set.from(files.map((s) => new File(s).absolute.path)); } - Future getLibraries(Set libraries, Set specialLibraries, Set files, Set specialFiles) async { + Future getLibraries( + Set libraries, + Set specialLibraries, + Set files, + Set specialFiles) async { libraries.addAll(await _parseLibraries(files)); - specialLibraries.addAll(await _parseLibraries(specialFiles.difference(files))); + specialLibraries + .addAll(await _parseLibraries(specialFiles.difference(files))); if (config.include.isNotEmpty) { Iterable knownLibraryNames = libraries.map((l) => l.name); Set notFound = new Set.from(config.include) diff --git a/lib/src/special_elements.dart b/lib/src/special_elements.dart index 51328cfae8..694ac075d8 100644 --- a/lib/src/special_elements.dart +++ b/lib/src/special_elements.dart @@ -17,6 +17,7 @@ import 'package:dartdoc/src/model.dart'; enum SpecialClass { /// From dart:core, Object object, + /// From dart:_interceptors, Interceptor interceptor, } @@ -25,49 +26,65 @@ enum SpecialClass { class _SpecialClassDefinition { /// Which specialElement this is. final SpecialClass specialClass; + /// Name of the ModelElement. final String name; + /// The library name for the [LibraryElement] in which this [ModelElement] /// can be found. final String libraryName; + /// The package name in which this [ModelElement] can be found. final String packageName; + /// The URI for the library in which this [ModelElement] is defined. final String specialFileUri; + /// If true, require this element to exist in the packageGraph when /// calling the [SpecialClasses] constructor. final bool required; - _SpecialClassDefinition(this.specialClass, this.name, this.libraryName, this.specialFileUri, {this.required = true, this.packageName = 'Dart'}) { - assert(packageName == 'Dart', 'Packages other than SDK not yet supported in special element detection'); + _SpecialClassDefinition( + this.specialClass, this.name, this.libraryName, this.specialFileUri, + {this.required = true, this.packageName = 'Dart'}) { + assert(packageName == 'Dart', + 'Packages other than SDK not yet supported in special element detection'); } /// Get the filename for the Dart Library where this [specialClass] is /// declared. - String getSpecialFilename(DartSdk sdk) => sdk.mapDartUri(specialFileUri).fullName; + String getSpecialFilename(DartSdk sdk) => + sdk.mapDartUri(specialFileUri).fullName; bool matchesClass(Class modelClass) { return modelClass.name == name && - modelClass.library.element.name == libraryName && - modelClass.package.name == packageName; + modelClass.library.element.name == libraryName && + modelClass.package.name == packageName; } } /// List all special classes we need to find here. final List<_SpecialClassDefinition> _specialClassDefinitions = [ - new _SpecialClassDefinition(SpecialClass.object, 'Object', 'dart.core', 'dart:core'), - new _SpecialClassDefinition(SpecialClass.interceptor, 'Interceptor', '_interceptors', 'dart:_interceptors'), + new _SpecialClassDefinition( + SpecialClass.object, 'Object', 'dart.core', 'dart:core'), + new _SpecialClassDefinition(SpecialClass.interceptor, 'Interceptor', + '_interceptors', 'dart:_interceptors'), ]; /// Given a SDK, resolve URIs for the libraries containing our special /// clases. -Set specialLibraryFiles(DartSdk sdk) => _specialClassDefinitions.map((_SpecialClassDefinition d) => d.getSpecialFilename(sdk)).toSet(); +Set specialLibraryFiles(DartSdk sdk) => _specialClassDefinitions + .map((_SpecialClassDefinition d) => d.getSpecialFilename(sdk)) + .toSet(); Set __specialLibraryNames; + /// These library names can be checked against the [LibraryElement] names /// to avoid traversing libraries we don't need to. Set get _specialLibraryNames { if (__specialLibraryNames == null) { - __specialLibraryNames = _specialClassDefinitions.map((_SpecialClassDefinition d) => d.libraryName).toSet(); + __specialLibraryNames = _specialClassDefinitions + .map((_SpecialClassDefinition d) => d.libraryName) + .toSet(); } return __specialLibraryNames; } @@ -89,7 +106,8 @@ class SpecialClasses { packageGraph.allLibraries[e].allClasses.forEach((Class aClass) { _specialClassDefinitions.forEach((_SpecialClassDefinition d) { if (d.matchesClass(aClass)) { - assert (!_specialClass.containsKey(d.specialClass) || _specialClass[d.specialClass] == aClass); + assert(!_specialClass.containsKey(d.specialClass) || + _specialClass[d.specialClass] == aClass); _specialClass[d.specialClass] = aClass; } }); @@ -97,12 +115,13 @@ class SpecialClasses { } doneKeys.add(e); }); - keysToDo = new Set.from(packageGraph.allLibraries.keys.where((LibraryElement e) => !doneKeys.contains(e))); + keysToDo = new Set.from(packageGraph.allLibraries.keys + .where((LibraryElement e) => !doneKeys.contains(e))); } _specialClassDefinitions.forEach((_SpecialClassDefinition d) { if (d.required) assert(_specialClass.containsKey(d.specialClass)); }); } - Class operator[](SpecialClass specialClass) => _specialClass[specialClass]; -} \ No newline at end of file + Class operator [](SpecialClass specialClass) => _specialClass[specialClass]; +} diff --git a/test/model_test.dart b/test/model_test.dart index 77af6e500b..ca93b774a0 100644 --- a/test/model_test.dart +++ b/test/model_test.dart @@ -306,7 +306,8 @@ void main() { htmlLibrary.allClasses.singleWhere((c) => c.name == 'EventTarget'); Field hashCode = EventTarget.allPublicInstanceProperties .singleWhere((f) => f.name == 'hashCode'); - Class objectModelElement = sdkAsPackageGraph.specialClasses[SpecialClass.object]; + Class objectModelElement = + sdkAsPackageGraph.specialClasses[SpecialClass.object]; // If this fails, EventTarget might have been changed to no longer // inherit from Interceptor. If that's true, adjust test case to // another class that does. diff --git a/tool/grind.dart b/tool/grind.dart index 657487a3b8..99d3b1afb8 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -586,7 +586,8 @@ Future> _buildFlutterDocs( } /// Returns the directory in which we generated documentation. -Future _buildPubPackageDocs(String pubPackageName, List dartdocParameters, +Future _buildPubPackageDocs( + String pubPackageName, List dartdocParameters, [String version, String label]) async { Map env = _createThrowawayPubCache(); var launcher = new SubprocessLauncher( From 7783b7b27a4a1a220da5cfe21ad17cc30e2d91e5 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 23 Jul 2018 15:21:51 -0700 Subject: [PATCH 4/9] Pin to .69 until other changes go through --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 111f9b8d74..d4b915b711 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: dart sudo: false dart: - - "dev/raw/latest" + - "dev/raw/2.0.0-dev.69.0" env: - DARTDOC_BOT=main - DARTDOC_BOT=packages From 4c7ffdfb1895fccce8803bdf3d7f75c63bf21dcb Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 23 Jul 2018 15:25:38 -0700 Subject: [PATCH 5/9] Pin appveyor too --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index d4bd319f99..5f8ae534c8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,7 @@ # BSD-style license that can be found in the LICENSE file. install: - - ps: wget https://storage.googleapis.com/dart-archive/channels/dev/raw/latest/sdk/dartsdk-windows-x64-release.zip -OutFile dart-sdk.zip + - ps: wget https://storage.googleapis.com/dart-archive/channels/dev/raw/2.0.0-dev-69.0/sdk/dartsdk-windows-x64-release.zip -OutFile dart-sdk.zip - cmd: echo "Unzipping dart-sdk..." - cmd: 7z x dart-sdk.zip -o"C:\tools" -y > nul - set PATH=%PATH%;C:\tools\dart-sdk\bin From 27369f2847a446859c668929925dd1da91db764c Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 23 Jul 2018 15:44:54 -0700 Subject: [PATCH 6/9] Fix CI typos --- appveyor.yml | 2 +- tool/travis.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5f8ae534c8..8cd0e1539e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,7 @@ # BSD-style license that can be found in the LICENSE file. install: - - ps: wget https://storage.googleapis.com/dart-archive/channels/dev/raw/2.0.0-dev-69.0/sdk/dartsdk-windows-x64-release.zip -OutFile dart-sdk.zip + - ps: wget https://storage.googleapis.com/dart-archive/channels/dev/raw/2.0.0-dev.69.0/sdk/dartsdk-windows-x64-release.zip -OutFile dart-sdk.zip - cmd: echo "Unzipping dart-sdk..." - cmd: 7z x dart-sdk.zip -o"C:\tools" -y > nul - set PATH=%PATH%;C:\tools\dart-sdk\bin diff --git a/tool/travis.sh b/tool/travis.sh index a88429b516..1445fb0877 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -22,7 +22,7 @@ elif [ "$DARTDOC_BOT" = "flutter" ]; then pub run grinder validate-flutter-docs elif [ "$DARTDOC_BOT" = "packages" ]; then echo "Running packages dartdoc bot" - PACKAGE_NAME=angular PACKAGE_VERSION=">=5.0.0-beta" DARTDOC_PARAMS="--include=angular,angular.security" grind build-pub-package + PACKAGE_NAME=angular PACKAGE_VERSION=">=5.0.0-beta" DARTDOC_PARAMS="--include=angular,angular.security" pub run grinder build-pub-package else echo "Running main dartdoc bot" pub run grinder buildbot From 6f470118cc2ec3c911804a9a97d1c3ee9c774989 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 23 Jul 2018 16:20:25 -0700 Subject: [PATCH 7/9] Fix problem with embeddeders that don't provide Interceptor (mark it optional) --- lib/src/model.dart | 6 +++++- lib/src/special_elements.dart | 11 +++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/src/model.dart b/lib/src/model.dart index d842990679..f3b9eec99f 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -5495,8 +5495,12 @@ class PackageBuilder { } Set libraries = new Set(); Set specialLibraries = new Set(); + DartSdk findSpecialsSdk = sdk; + if (embedderSdk.urlMappings.isNotEmpty) { + findSpecialsSdk = embedderSdk; + } await getLibraries(libraries, specialLibraries, getFiles, - specialLibraryFiles(sdk).toSet()); + specialLibraryFiles(findSpecialsSdk).toSet()); return new PackageGraph(libraries, specialLibraries, config, config.topLevelPackageMeta, getWarningOptions(), driver, sdk); } diff --git a/lib/src/special_elements.dart b/lib/src/special_elements.dart index 694ac075d8..ec727226f9 100644 --- a/lib/src/special_elements.dart +++ b/lib/src/special_elements.dart @@ -45,15 +45,12 @@ class _SpecialClassDefinition { final bool required; _SpecialClassDefinition( this.specialClass, this.name, this.libraryName, this.specialFileUri, - {this.required = true, this.packageName = 'Dart'}) { - assert(packageName == 'Dart', - 'Packages other than SDK not yet supported in special element detection'); - } + {this.required = true, this.packageName = 'Dart'}); /// Get the filename for the Dart Library where this [specialClass] is /// declared. String getSpecialFilename(DartSdk sdk) => - sdk.mapDartUri(specialFileUri).fullName; + sdk.mapDartUri(specialFileUri)?.fullName; bool matchesClass(Class modelClass) { return modelClass.name == name && @@ -67,13 +64,15 @@ final List<_SpecialClassDefinition> _specialClassDefinitions = [ new _SpecialClassDefinition( SpecialClass.object, 'Object', 'dart.core', 'dart:core'), new _SpecialClassDefinition(SpecialClass.interceptor, 'Interceptor', - '_interceptors', 'dart:_interceptors'), + '_interceptors', 'dart:_interceptors', + required: false), ]; /// Given a SDK, resolve URIs for the libraries containing our special /// clases. Set specialLibraryFiles(DartSdk sdk) => _specialClassDefinitions .map((_SpecialClassDefinition d) => d.getSpecialFilename(sdk)) + .where((String s) => s != null) .toSet(); Set __specialLibraryNames; From b84c9292f8659bfbe52739bd1d14694fd7f5c5f9 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 23 Jul 2018 16:50:02 -0700 Subject: [PATCH 8/9] Fix Flutter analysis errors from forced-load Interceptor attempt --- lib/src/model.dart | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/src/model.dart b/lib/src/model.dart index f3b9eec99f..58ebd80591 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -5699,7 +5699,8 @@ class PackageBuilder { return metas; } - Future> _parseLibraries(Set files) async { + Future> _parseLibraries(Set files, + {bool throwErrors = true}) async { Set libraries = new Set(); Set originalSources; Set sources = new Set(); @@ -5735,7 +5736,7 @@ class PackageBuilder { } } while (!lastPass.containsAll(current)); - await logAnalysisErrors(originalSources); + if (throwErrors) await logAnalysisErrors(originalSources); return libraries.toList(); } @@ -5818,8 +5819,12 @@ class PackageBuilder { Set files, Set specialFiles) async { libraries.addAll(await _parseLibraries(files)); - specialLibraries - .addAll(await _parseLibraries(specialFiles.difference(files))); + + /// Flutter doesn't seem to like being given the Interceptor library. + /// But it doesn't need it, either. So just skip reporting errors here. + specialLibraries.addAll(await _parseLibraries( + specialFiles.difference(files), + throwErrors: false)); if (config.include.isNotEmpty) { Iterable knownLibraryNames = libraries.map((l) => l.name); Set notFound = new Set.from(config.include) From 13e670d226f3075cf93b31ce3a67a1dd361fcf21 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 23 Jul 2018 16:57:25 -0700 Subject: [PATCH 9/9] Check for null embedder sdk --- lib/src/model.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/model.dart b/lib/src/model.dart index 58ebd80591..7ed5a5da34 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -5496,7 +5496,7 @@ class PackageBuilder { Set libraries = new Set(); Set specialLibraries = new Set(); DartSdk findSpecialsSdk = sdk; - if (embedderSdk.urlMappings.isNotEmpty) { + if (embedderSdk != null && embedderSdk.urlMappings.isNotEmpty) { findSpecialsSdk = embedderSdk; } await getLibraries(libraries, specialLibraries, getFiles,