Skip to content
This repository was archived by the owner on Jan 26, 2021. It is now read-only.

Commit 6abea8b

Browse files
committed
Fix up benchmark reporting
1 parent e7a3105 commit 6abea8b

File tree

2 files changed

+22
-67
lines changed

2 files changed

+22
-67
lines changed

benchmark/lib/report.dart

Lines changed: 17 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ library protoc.benchmark.report;
66

77
import 'dart:convert' show jsonEncode;
88

9+
import 'package:yaml/yaml.dart';
10+
911
import 'generated/benchmark.pb.dart' as pb;
1012

1113
pb.Response findUpdatedResponse(pb.Report beforeRep, pb.Report afterRep) {
@@ -67,75 +69,23 @@ pb.Packages createPackages(String pubspecYaml, String pubspecLock) {
6769
/// - assumes all other lines without a value except 'description'
6870
/// start a new package
6971
/// - only allows known keys within a package
70-
List<pb.PackageVersion> _parseLockFile(String contents) {
71-
var out = <pb.PackageVersion>[];
72-
73-
bool inPackages = false;
74-
bool inDescription = false;
75-
pb.PackageVersion pv = null;
76-
var lineNumber = 0;
77-
for (var line in contents.split("\n")) {
78-
lineNumber++;
79-
line = line.trim(); // ignore indentation
80-
if (line == "" || line.startsWith("#")) continue;
81-
82-
// find key and value
83-
var colon = line.indexOf(":");
84-
if (colon == -1) {
85-
throw "can't parse pubspec.lock at line $lineNumber";
86-
}
87-
var key = line.substring(0, colon).trim();
88-
var value = line.substring(colon + 1).trim();
89-
if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
90-
value = value.substring(1, value.length - 1);
91-
}
92-
93-
if (!inPackages) {
94-
if (key == "packages" && value == "") {
95-
inPackages = true;
96-
continue;
97-
}
98-
throw "can't parse pubspec.lock at line $lineNumber";
99-
}
100-
101-
if (value == "") {
102-
if (key == "description") {
103-
inDescription = true;
104-
continue;
105-
}
106-
if (pv != null) out.add(pv);
107-
pv = new pb.PackageVersion()..name = key;
108-
continue;
109-
}
110-
111-
if (pv == null) {
112-
throw "can't parse pubspec.lock at line $lineNumber - no value for $key";
113-
}
114-
115-
if (inDescription && (key == "name" || key == "url")) continue;
116-
inDescription = false;
117-
118-
switch (key) {
119-
case "description":
120-
break;
121-
case "source":
122-
pv.source = value;
123-
break;
124-
case "version":
125-
pv.version = value;
126-
break;
127-
case "path":
128-
pv.path = value;
129-
break;
130-
case "relative":
131-
break; // ignore
132-
case "sdk":
133-
break; // ignore
134-
default:
135-
throw "can't parse pubspec.lock at line $lineNumber - unknown key $key";
72+
Iterable<pb.PackageVersion> _parseLockFile(String contents) sync* {
73+
var yaml = loadYaml(contents) as YamlMap;
74+
var packages = yaml['packages'] as YamlMap;
75+
76+
for (var entry in packages.entries) {
77+
var map = entry.value as YamlMap;
78+
var pkgVersion = new pb.PackageVersion()
79+
..name = entry.key as String
80+
..source = map['source']
81+
..version = map['version'];
82+
83+
var path = (map['description'] as YamlMap)['path'];
84+
if (path != null) {
85+
pkgVersion.path = path;
13686
}
87+
yield pkgVersion;
13788
}
138-
return out;
13989
}
14090

14191
/// Encodes a report as nicely-formatted JSON.

pubspec.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ version: 0.10.2
33
author: Dart Team <misc@dartlang.org>
44
description: Protoc compiler plugin to generate Dart code
55
homepage: https://github.com/dart-lang/dart-protoc-plugin
6+
67
environment:
78
sdk: '>=2.0.0 <3.0.0'
9+
810
dependencies:
911
fixnum: ^0.10.5
1012
path: ^1.0.0
1113
protobuf: ^0.10.2
1214
dart_style: ^1.0.6
15+
1316
dev_dependencies:
1417
test: ^1.3.0
18+
yaml: ^2.1.15
19+
1520
executables:
1621
protoc-gen-dart: protoc_plugin

0 commit comments

Comments
 (0)