Skip to content

Commit

Permalink
Add output unit info to proto codec (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenVS authored and sigmundch committed Jun 22, 2018
1 parent 2a7c7f3 commit 0347b8f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
7 changes: 6 additions & 1 deletion info.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
syntax = "proto3";

option go_package = "dart2js_info";

package dart2js_info.proto;

message DependencyInfoPB {
Expand Down Expand Up @@ -49,8 +51,11 @@ message InfoPB {
/** How does this function or field depend on others. */
repeated DependencyInfoPB uses = 7;

/** The serialized_id of the output unit the element is generated into. */
string output_unit_id = 8;

/** Reserved tags for future common fields. */
reserved 8 to 99;
reserved 9 to 99;

/** The concrete info type. */
oneof concrete {
Expand Down
7 changes: 7 additions & 0 deletions lib/proto_info_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ class AllInfoToProtoConverter extends Converter<AllInfo, AllInfoPB> {
proto.coverageId = info.coverageId;
}

if (info is BasicInfo && info.outputUnit != null) {
// TODO(lorenvs): Similar to the JSON codec, omit this for the default
// output unit. At the moment, there is no easy way to identify which
// output unit is the default on [OutputUnitInfo].
proto.outputUnitId = info.outputUnit.serializedId;
}

if (info is CodeInfo) {
proto.uses.addAll(info.uses.map(_convertToDependencyInfoPB));
}
Expand Down
41 changes: 25 additions & 16 deletions lib/src/proto/info.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class InfoPB extends GeneratedMessage {
..aOS(6, 'parentId')
..pp<DependencyInfoPB>(7, 'uses', PbFieldType.PM,
DependencyInfoPB.$checkItem, DependencyInfoPB.create)
..aOS(8, 'outputUnitId')
..a<LibraryInfoPB>(100, 'libraryInfo', PbFieldType.OM,
LibraryInfoPB.getDefault, LibraryInfoPB.create)
..a<ClassInfoPB>(101, 'classInfo', PbFieldType.OM, ClassInfoPB.getDefault,
Expand Down Expand Up @@ -252,68 +253,76 @@ class InfoPB extends GeneratedMessage {

List<DependencyInfoPB> get uses => $_getList(6);

LibraryInfoPB get libraryInfo => $_getN(7);
String get outputUnitId => $_getS(7, '');
set outputUnitId(String v) {
$_setString(7, v);
}

bool hasOutputUnitId() => $_has(7);
void clearOutputUnitId() => clearField(8);

LibraryInfoPB get libraryInfo => $_getN(8);
set libraryInfo(LibraryInfoPB v) {
setField(100, v);
}

bool hasLibraryInfo() => $_has(7);
bool hasLibraryInfo() => $_has(8);
void clearLibraryInfo() => clearField(100);

ClassInfoPB get classInfo => $_getN(8);
ClassInfoPB get classInfo => $_getN(9);
set classInfo(ClassInfoPB v) {
setField(101, v);
}

bool hasClassInfo() => $_has(8);
bool hasClassInfo() => $_has(9);
void clearClassInfo() => clearField(101);

FunctionInfoPB get functionInfo => $_getN(9);
FunctionInfoPB get functionInfo => $_getN(10);
set functionInfo(FunctionInfoPB v) {
setField(102, v);
}

bool hasFunctionInfo() => $_has(9);
bool hasFunctionInfo() => $_has(10);
void clearFunctionInfo() => clearField(102);

FieldInfoPB get fieldInfo => $_getN(10);
FieldInfoPB get fieldInfo => $_getN(11);
set fieldInfo(FieldInfoPB v) {
setField(103, v);
}

bool hasFieldInfo() => $_has(10);
bool hasFieldInfo() => $_has(11);
void clearFieldInfo() => clearField(103);

ConstantInfoPB get constantInfo => $_getN(11);
ConstantInfoPB get constantInfo => $_getN(12);
set constantInfo(ConstantInfoPB v) {
setField(104, v);
}

bool hasConstantInfo() => $_has(11);
bool hasConstantInfo() => $_has(12);
void clearConstantInfo() => clearField(104);

OutputUnitInfoPB get outputUnitInfo => $_getN(12);
OutputUnitInfoPB get outputUnitInfo => $_getN(13);
set outputUnitInfo(OutputUnitInfoPB v) {
setField(105, v);
}

bool hasOutputUnitInfo() => $_has(12);
bool hasOutputUnitInfo() => $_has(13);
void clearOutputUnitInfo() => clearField(105);

TypedefInfoPB get typedefInfo => $_getN(13);
TypedefInfoPB get typedefInfo => $_getN(14);
set typedefInfo(TypedefInfoPB v) {
setField(106, v);
}

bool hasTypedefInfo() => $_has(13);
bool hasTypedefInfo() => $_has(14);
void clearTypedefInfo() => clearField(106);

ClosureInfoPB get closureInfo => $_getN(14);
ClosureInfoPB get closureInfo => $_getN(15);
set closureInfo(ClosureInfoPB v) {
setField(107, v);
}

bool hasClosureInfo() => $_has(14);
bool hasClosureInfo() => $_has(15);
void clearClosureInfo() => clearField(107);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/src/proto/info.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const InfoPB$json = const {
'6': '.dart2js_info.proto.DependencyInfoPB',
'10': 'uses'
},
const {'1': 'output_unit_id', '3': 8, '4': 1, '5': 9, '10': 'outputUnitId'},
const {
'1': 'library_info',
'3': 100,
Expand Down Expand Up @@ -152,7 +153,7 @@ const InfoPB$json = const {
const {'1': 'concrete'},
],
'9': const [
const {'1': 8, '2': 100},
const {'1': 9, '2': 100},
],
};

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dart2js_info
version: 0.5.8+1
version: 0.5.9
description: >
Libraries and tools to process data produced when running dart2js with
--dump-info.
Expand Down
18 changes: 18 additions & 0 deletions test/json_to_proto_deferred_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ main() {
expect(import.prefix, 'deferred_import');
expect(import.files, hasLength(1));
expect(import.files.first, 'hello_world_deferred.js_1.part.js');

// Dart protobuf doesn't support maps, translate the info list into
// a map for associative verifications.
final infoMap = <String, InfoPB>{};
infoMap.addEntries(proto.allInfos.map(
(entry) => new MapEntry<String, InfoPB>(entry.key, entry.value)));

final entrypoint = infoMap[proto.program.entrypointId];
expect(entrypoint, isNotNull);
expect(entrypoint.hasFunctionInfo(), isTrue);
expect(entrypoint.outputUnitId, isNotNull);

// The output unit of the entrypoint function should be the default
// entrypoint, which should have no imports.
final defaultOutputUnit = infoMap[entrypoint.outputUnitId];
expect(defaultOutputUnit, isNotNull);
expect(defaultOutputUnit.hasOutputUnitInfo(), isTrue);
expect(defaultOutputUnit.outputUnitInfo.imports, isEmpty);
});
});
}

0 comments on commit 0347b8f

Please sign in to comment.