You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2015/11/28 00:59:30 UTC

thrift git commit: THRIFT-3448 Add a Dart generator argument for overriding the thrift library dependency in generated pubspec.yaml files.

Repository: thrift
Updated Branches:
  refs/heads/master e841b3dac -> b0526d524


THRIFT-3448 Add a Dart generator argument for overriding the thrift library dependency in generated pubspec.yaml files.


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/b0526d52
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/b0526d52
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/b0526d52

Branch: refs/heads/master
Commit: b0526d5243c18855940846a99e2ca5254b0828f2
Parents: e841b3d
Author: Mark Erickson <ma...@workiva.com>
Authored: Wed Nov 25 14:15:55 2015 -0600
Committer: Roger Meier <ro...@apache.org>
Committed: Sat Nov 28 00:58:31 2015 +0100

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_dart_generator.cc | 40 +++++++++++++++++++---
 1 file changed, 35 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/b0526d52/compiler/cpp/src/generate/t_dart_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_dart_generator.cc b/compiler/cpp/src/generate/t_dart_generator.cc
index f48559b..e404476 100644
--- a/compiler/cpp/src/generate/t_dart_generator.cc
+++ b/compiler/cpp/src/generate/t_dart_generator.cc
@@ -75,6 +75,13 @@ public:
       library_name_ = "";
     }
 
+    iter = parsed_options.find("pubspec_lib");
+    if (iter != parsed_options.end()) {
+      pubspec_lib_ = (iter->second);
+    } else {
+      pubspec_lib_ = "";
+    }
+
     out_dir_base_ = "gen-dart";
   }
 
@@ -240,12 +247,23 @@ public:
            || ttype->is_string();
   }
 
+  vector<std::string> split(const string& s, char delim) {
+    vector<std::string> elems;
+    stringstream ss(s);
+    string item;
+    while (getline(ss, item, delim)) {
+      elems.push_back(item);
+    }
+    return elems;
+  }
+
   std::string constant_name(std::string name);
 
 private:
   std::ofstream f_service_;
 
   std::string library_name_;
+  std::string pubspec_lib_;
 
   std::string base_dir_;
   std::string src_dir_;
@@ -374,10 +392,19 @@ void t_dart_generator::generate_dart_pubspec() {
 
   indent(f_pubspec) << "dependencies:" << endl;
   indent_up();
-  indent(f_pubspec) << "thrift:  # ^" << dart_thrift_version << endl;
-  indent_up();
-  indent(f_pubspec) << "path: ../../../../lib/dart" << endl;
-  indent_down();
+
+  if (pubspec_lib_.empty()) {
+    // default to relative path within working directory, which works for tests
+    indent(f_pubspec) << "thrift:  # ^" << dart_thrift_version << endl;
+    indent_up();
+    indent(f_pubspec) << "path: ../../../../lib/dart" << endl;
+    indent_down();
+  } else {
+    const vector<std::string> lines = split(pubspec_lib_, '|');
+    for (size_t line_index = 0; line_index < lines.size(); line_index++) {
+      indent(f_pubspec) << lines[line_index] << endl;
+    }
+  }
 
   // add included thrift files as dependencies
   const vector<t_program*>& includes = program_->get_includes();
@@ -2364,5 +2391,8 @@ std::string t_dart_generator::get_enum_class_name(t_type* type) {
 THRIFT_REGISTER_GENERATOR(
     dart,
     "Dart",
-    "    library_name=my_library    Optional override for library name.\n"
+    "    library_name:    Optional override for library name.\n"
+    "    pubspec_lib:     Optional override for thrift lib dependency in pubspec.yaml,\n"
+    "                     e.g. \"thrift: 0.x.x\".  Use a pipe delimiter to separate lines,\n"
+    "                     e.g. \"thrift:|  git:|    url: git@foo.com\"\n"
 )