[topaz][fuchsia][migration] Move protoc_gen_dart out of //topaz into
fuchsia.git.
Change-Id: I46672e271d44586b6327b803e71ef3be4858d766
Reviewed-on: https://fuchsia-review.googlesource.com/c/topaz/+/516361
Commit-Queue: Naud Ghebre <naudzghebre@google.com>
Reviewed-by: Chase Latta <chaselatta@google.com>
diff --git a/tools/protobuf/protoc_gen_dart/BUILD.gn b/tools/protobuf/protoc_gen_dart/BUILD.gn
deleted file mode 100644
index a3f5371..0000000
--- a/tools/protobuf/protoc_gen_dart/BUILD.gn
+++ /dev/null
@@ -1,14 +0,0 @@
-# Copyright 2018 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import("//build/dart/dart_tool.gni")
-
-# This is the protobuf plugin for dart we supply to the protoc compiler.
-dart_tool("protoc_gen_dart") {
- package_name = "protoc_gen_dart"
-
- main_dart = "lib/main.dart"
-
- deps = [ "//third_party/dart-pkg/pub/protoc_plugin" ]
-}
diff --git a/tools/protobuf/protoc_gen_dart/analysis_options.yaml b/tools/protobuf/protoc_gen_dart/analysis_options.yaml
deleted file mode 100644
index 48e8ec9..0000000
--- a/tools/protobuf/protoc_gen_dart/analysis_options.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-# Copyright 2018 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-include: ../../analysis_options.yaml
diff --git a/tools/protobuf/protoc_gen_dart/lib/main.dart b/tools/protobuf/protoc_gen_dart/lib/main.dart
deleted file mode 100644
index 34b1638..0000000
--- a/tools/protobuf/protoc_gen_dart/lib/main.dart
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2018 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-import 'dart:io';
-
-import 'package:path/path.dart' as path;
-import 'package:protoc_plugin/protoc.dart';
-
-/// This is the alternate plugin driver for dart protobuf bindings. This
-/// plugin driver is suppled into the `protoc` (or protoc_wrapper.py). This
-/// driver is used alongside GN, takes in a mapping of dart package name -> dart
-/// package paths, and uses these mappings to transform strictly file-based
-/// imports to package-based imports.
-///
-/// The plugin option passed to `protoc` end up here. The option format is:
-/// A semicolon-separated list of package name -> package directory mappings of
-/// the form `package_name|input_root`. `input_root` designates the directory
-/// relative to which input protos are located -- typically the root of the GN
-/// package, where the `BUILD.gn` file is located.
-///
-/// The options above are used in the following way:
-/// * Given a file-based import path in the .proto file, the generated dart
-/// import path is rebased to a package path if possible.
-/// * See [DartImportMappingOutputConfiguration.resolveImport] below.
-class DartImportMappingOptionParser extends SingleOptionParser {
- /// This is the option key we pass to protoc;
- static const String kImportOptionKey = 'PackagePaths';
-
- /// Output map of: package input root => package name
- final Map<String, String> packageMapping;
-
- DartImportMappingOptionParser(this.packageMapping);
-
- @override
- void parse(String name, String value, onError(String message)) {
- if (value == null) {
- onError('Invalid $kImportOptionKey option. Expected a non-empty value.');
- return;
- }
-
- for (var entry in value.split(';')) {
- var fields = entry.split('|');
- if (fields.length != 2) {
- onError('ERROR: expected package_name|input_root. Got: $entry');
- continue;
- }
- if (packageMapping.containsKey(fields[1])) {
- onError('ERROR: ${fields[1]} already exists.');
- continue;
- }
- packageMapping[fields[1]] = fields[0];
- }
- }
-}
-
-class DartImportMappingOutputConfiguration extends DefaultOutputConfiguration {
- /// Output map (package root) => package name
- final Map<String, String> packageMapping;
-
- DartImportMappingOutputConfiguration(this.packageMapping);
-
- /// Given a file-based import path ("a/b/c/d.proto"), this routine looks
- /// through the [packageMapping] to find a package that this import may fall
- /// under. If it can find one, it rebases the import path to the package
- /// input root in the generated import string.
- @override
- Uri resolveImport(Uri target, Uri source, String extension) {
- for (int i = target.pathSegments.length; i > 0; i--) {
- var candidatePath = target.pathSegments.sublist(0, i).join('/');
- if (packageMapping.containsKey(candidatePath)) {
- var packageName = packageMapping[candidatePath];
- var importPath = target.pathSegments
- .sublist(i, target.pathSegments.length)
- .join('/');
- var genImportPath = '${path.withoutExtension(importPath)}.pb.dart';
- return Uri.parse('package:$packageName/$genImportPath');
- }
- }
- return super.resolveImport(target, source, extension);
- }
-}
-
-void main() {
- var packageMapping = <String, String>{};
- CodeGenerator(stdin, stdout).generate(
- optionParsers: {
- DartImportMappingOptionParser.kImportOptionKey:
- DartImportMappingOptionParser(packageMapping),
- },
- config: DartImportMappingOutputConfiguration(packageMapping),
- );
-}
diff --git a/tools/protobuf/protoc_gen_dart/pubspec.yaml b/tools/protobuf/protoc_gen_dart/pubspec.yaml
deleted file mode 100644
index e69de29..0000000
--- a/tools/protobuf/protoc_gen_dart/pubspec.yaml
+++ /dev/null