OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library serialization.elements; | 5 library serialization.elements; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 * format that clients might need to be aware of (such as adding a kind of | 130 * format that clients might need to be aware of (such as adding a kind of |
131 * data that was previously not summarized), this value should be incremented | 131 * data that was previously not summarized), this value should be incremented |
132 * by 1. | 132 * by 1. |
133 */ | 133 */ |
134 static const int currentMinorVersion = 0; | 134 static const int currentMinorVersion = 0; |
135 | 135 |
136 final List<String> _linkedLibraryUris = <String>[]; | 136 final List<String> _linkedLibraryUris = <String>[]; |
137 final List<LinkedLibraryBuilder> _linkedLibraries = <LinkedLibraryBuilder>[]; | 137 final List<LinkedLibraryBuilder> _linkedLibraries = <LinkedLibraryBuilder>[]; |
138 final List<String> _unlinkedUnitUris = <String>[]; | 138 final List<String> _unlinkedUnitUris = <String>[]; |
139 final List<UnlinkedUnitBuilder> _unlinkedUnits = <UnlinkedUnitBuilder>[]; | 139 final List<UnlinkedUnitBuilder> _unlinkedUnits = <UnlinkedUnitBuilder>[]; |
140 final List<String> _unlinkedUnitHashes = <String>[]; | 140 final List<String> _unlinkedUnitHashes; |
| 141 final bool _excludeHashes; |
| 142 |
| 143 /** |
| 144 * Create a [PackageBundleAssembler]. If [excludeHashes] is `true`, hash |
| 145 * computation will be skipped. |
| 146 */ |
| 147 PackageBundleAssembler({bool excludeHashes: false}) |
| 148 : _excludeHashes = excludeHashes, |
| 149 _unlinkedUnitHashes = excludeHashes ? null : <String>[]; |
141 | 150 |
142 /** | 151 /** |
143 * Add a fallback library to the package bundle, corresponding to the library | 152 * Add a fallback library to the package bundle, corresponding to the library |
144 * whose defining compilation unit is located at [source]. Caller must also | 153 * whose defining compilation unit is located at [source]. Caller must also |
145 * call [addFallbackUnit] for all compilation units contained in the library | 154 * call [addFallbackUnit] for all compilation units contained in the library |
146 * (including the defining compilation unit). | 155 * (including the defining compilation unit). |
147 */ | 156 */ |
148 void addFallbackLibrary(Source source) { | 157 void addFallbackLibrary(Source source) { |
149 String uri = source.uri.toString(); | 158 String uri = source.uri.toString(); |
150 _linkedLibraryUris.add(uri); | 159 _linkedLibraryUris.add(uri); |
(...skipping 10 matching lines...) Expand all Loading... |
161 _unlinkedUnits.add(new UnlinkedUnitBuilder( | 170 _unlinkedUnits.add(new UnlinkedUnitBuilder( |
162 fallbackModePath: path.relative(source.fullName))); | 171 fallbackModePath: path.relative(source.fullName))); |
163 } | 172 } |
164 | 173 |
165 void addLinkedLibrary(String uri, LinkedLibraryBuilder library) { | 174 void addLinkedLibrary(String uri, LinkedLibraryBuilder library) { |
166 _linkedLibraries.add(library); | 175 _linkedLibraries.add(library); |
167 _linkedLibraryUris.add(uri); | 176 _linkedLibraryUris.add(uri); |
168 } | 177 } |
169 | 178 |
170 void addUnlinkedUnit(Source source, UnlinkedUnitBuilder unit) { | 179 void addUnlinkedUnit(Source source, UnlinkedUnitBuilder unit) { |
171 addUnlinkedUnitWithHash(source.uri.toString(), unit, _hash(source.contents.d
ata)); | 180 addUnlinkedUnitWithHash(source.uri.toString(), unit, |
| 181 _excludeHashes ? null : _hash(source.contents.data)); |
172 } | 182 } |
173 | 183 |
174 void addUnlinkedUnitWithHash(String uri, UnlinkedUnitBuilder unit, String hash
) { | 184 void addUnlinkedUnitWithHash( |
| 185 String uri, UnlinkedUnitBuilder unit, String hash) { |
175 _unlinkedUnitUris.add(uri); | 186 _unlinkedUnitUris.add(uri); |
176 _unlinkedUnits.add(unit); | 187 _unlinkedUnits.add(unit); |
177 _unlinkedUnitHashes.add(hash); | 188 _unlinkedUnitHashes?.add(hash); |
178 } | 189 } |
179 | 190 |
180 /** | 191 /** |
181 * Assemble a new [PackageBundleBuilder] using the gathered information. | 192 * Assemble a new [PackageBundleBuilder] using the gathered information. |
182 */ | 193 */ |
183 PackageBundleBuilder assemble() { | 194 PackageBundleBuilder assemble() { |
184 return new PackageBundleBuilder( | 195 return new PackageBundleBuilder( |
185 linkedLibraryUris: _linkedLibraryUris, | 196 linkedLibraryUris: _linkedLibraryUris, |
186 linkedLibraries: _linkedLibraries, | 197 linkedLibraries: _linkedLibraries, |
187 unlinkedUnitUris: _unlinkedUnitUris, | 198 unlinkedUnitUris: _unlinkedUnitUris, |
(...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 exportNames.add(new LinkedExportNameBuilder( | 1659 exportNames.add(new LinkedExportNameBuilder( |
1649 name: name, | 1660 name: name, |
1650 dependency: serializeDependency(dependentLibrary), | 1661 dependency: serializeDependency(dependentLibrary), |
1651 unit: unit, | 1662 unit: unit, |
1652 kind: kind)); | 1663 kind: kind)); |
1653 } | 1664 } |
1654 pb.exportNames = exportNames; | 1665 pb.exportNames = exportNames; |
1655 return pb; | 1666 return pb; |
1656 } | 1667 } |
1657 } | 1668 } |
OLD | NEW |