processDeps function

Future<Set<String>> processDeps(
  1. String file,
  2. List<String> baseArguments
)

Implementation

Future<Set<String>> processDeps(String file, List<String> baseArguments) async {
  final work = <String>{};
  final tmpPath = path.join(baseDirectory.path, 'tmp.deps');
  final depsProcess = await Process.run(
    protoc,
    [
      '--dependency_out=$tmpPath',
      ...baseArguments,
      '--plugin=protoc-gen-dart=$dartPlugin',
      file,
    ],
    stdoutEncoding: utf8,
    stderrEncoding: utf8,
  );
  if (depsProcess.exitCode != 0) {
    stderr.writeln(depsProcess.stdout);
    stderr.writeln('error processing dependency: $file');
    stderr.writeln(depsProcess.stderr);
    throw 'error';
  }

  bool found = false;
  for (var line in LineSplitter.split(File(tmpPath).readAsStringSync())) {
    if (!found && line.contains(': ')) {
      found = true;
      var dep = line.split(': ')[1];
      if (dep.endsWith(r'\')) {
        dep = dep.substring(0, dep.length - 1);
      }
      work.add(dep.trim());
    } else if (found) {
      if (line.endsWith(r'\')) {
        line = line.substring(0, line.length - 1);
      }
      work.add(line.trim());
    }
  }
  return work;
}