In Android framework, make tools depend on jsoncpp

Always build the tools with JSON, but either build our own
or use the system's.

Rename skia_build_json_writer to skia_use_system_jsoncpp,
since we now always build with JSON.

Remove SK_BUILD_JSON_WRITER, which was only there so
we could build without JSON it in the framework.

BUG=skia:2448
R=djsollen@google.com, reed@google.com

Author: scroggo@google.com

Review URL: https://codereview.chromium.org/303913002
diff --git a/bench/ResultsWriter.cpp b/bench/ResultsWriter.cpp
index 0bfcba8..08f11c1 100644
--- a/bench/ResultsWriter.cpp
+++ b/bench/ResultsWriter.cpp
@@ -9,8 +9,6 @@
 
 #include "ResultsWriter.h"
 
-#ifdef SK_BUILD_JSON_WRITER
-
 Json::Value* SkFindNamedNode(Json::Value* root, const char name[]) {
     Json::Value* search_results = NULL;
     for(Json::Value::iterator iter = root->begin();
@@ -30,4 +28,3 @@
     }
 }
 
-#endif // SK_BUILD_JSON_WRITER
diff --git a/bench/ResultsWriter.h b/bench/ResultsWriter.h
index c665938..e089d7f 100644
--- a/bench/ResultsWriter.h
+++ b/bench/ResultsWriter.h
@@ -77,7 +77,6 @@
     const char* fTimeFormat;
 };
 
-#ifdef SK_BUILD_JSON_WRITER
 /**
  * This ResultsWriter handles writing out the results in JSON.
  *
@@ -146,8 +145,6 @@
     Json::Value* fConfig;
 };
 
-#endif // SK_BUILD_JSON_WRITER
-
 /**
  * This ResultsWriter writes out to multiple ResultsWriters.
  */
diff --git a/bench/TimerData.cpp b/bench/TimerData.cpp
index d3dbf28..0cb0002 100644
--- a/bench/TimerData.cpp
+++ b/bench/TimerData.cpp
@@ -140,7 +140,6 @@
     return str;
 }
 
-#ifdef SK_BUILD_JSON_WRITER
 Json::Value TimerData::getJSON(uint32_t timerFlags,
                                Result result,
                                int itersPerTiming) {
@@ -223,4 +222,3 @@
     }
     return dataNode;
 }
-#endif  // SK_BUILD_JSON_WRITER
diff --git a/bench/TimerData.h b/bench/TimerData.h
index be6158b..fb84df1 100644
--- a/bench/TimerData.h
+++ b/bench/TimerData.h
@@ -68,11 +68,9 @@
                        const char* configName,
                        uint32_t timerFlags,
                        int itersPerTiming = 1);
-#ifdef SK_BUILD_JSON_WRITER
     Json::Value getJSON(uint32_t timerFlags,
                         Result result,
                         int itersPerTiming = 1);
-#endif // SK_BUILD_JSON_WRITER
 
 private:
     int fMaxNumTimings;
diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp
index af70878..6e18a8a 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -255,9 +255,7 @@
 DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops.");
 DEFINE_bool2(verbose, v, false, "Print more.");
 DEFINE_string2(resourcePath, i, "resources", "directory for test resources.");
-#ifdef SK_BUILD_JSON_WRITER
 DEFINE_string(outResultsFile, "", "If given, the results will be written to the file in JSON format.");
-#endif
 DEFINE_bool(dryRun, false, "Don't actually run the tests, just print what would have been done.");
 
 // Has this bench converged?  First arguments are milliseconds / loop iteration,
@@ -291,13 +289,11 @@
     MultiResultsWriter writer;
     writer.add(&logWriter);
 
-#ifdef SK_BUILD_JSON_WRITER
     SkAutoTDelete<JSONResultsWriter> jsonWriter;
     if (FLAGS_outResultsFile.count()) {
         jsonWriter.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0])));
         writer.add(jsonWriter.get());
     }
-#endif
 
     // Instantiate after all the writers have been added to writer so that we
     // call close() before their destructors are called on the way out.
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 8755598..776b642 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -38,16 +38,10 @@
 
 DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS.");
 DEFINE_int32(gpuThreads, 1, "Threads for GPU work.");
-#ifdef SK_BUILD_JSON_WRITER
 DEFINE_string2(expectations, r, "",
                "If a directory, compare generated images against images under this path. "
                "If a file, compare generated images against JSON expectations at this path."
 );
-#else
-DEFINE_string2(expectations, r, "",
-               "If a directory, compare generated images against images under this path. "
-);
-#endif
 DEFINE_string2(resources, i, "resources", "Path to resources directory.");
 DEFINE_string(match, "",  "[~][^]substring[$] [...] of GM name to run.\n"
                           "Multiple matches may be separated by spaces.\n"
@@ -249,9 +243,7 @@
             if (sk_isdir(path)) {
                 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
             } else {
-#ifdef SK_BUILD_JSON_WRITER
                 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
-#endif
             }
         }
     }
diff --git a/dm/DMExpectations.h b/dm/DMExpectations.h
index 5509709..238d1c5 100644
--- a/dm/DMExpectations.h
+++ b/dm/DMExpectations.h
@@ -19,7 +19,6 @@
     bool check(const Task&, SkBitmap) const SK_OVERRIDE { return true; }
 };
 
-#ifdef SK_BUILD_JSON_WRITER
 class JsonExpectations : public Expectations {
 public:
     explicit JsonExpectations(const char* path) : fGMExpectations(path) {}
@@ -41,7 +40,6 @@
 private:
     skiagm::JsonExpectationsSource fGMExpectations;
 };
-#endif
 
 }  // namespace DM
 
diff --git a/gm/gm_expectations.cpp b/gm/gm_expectations.cpp
index f0ccb3e..7089070 100644
--- a/gm/gm_expectations.cpp
+++ b/gm/gm_expectations.cpp
@@ -31,7 +31,6 @@
 
 namespace skiagm {
 
-#ifdef SK_BUILD_JSON_WRITER
     Json::Value CreateJsonTree(Json::Value expectedResults,
                                Json::Value actualResultsFailed,
                                Json::Value actualResultsFailureIgnored,
@@ -47,7 +46,6 @@
         root[kJsonKey_ExpectedResults] = expectedResults;
         return root;
     }
-#endif
 
     // GmResultDigest class...
 
@@ -55,7 +53,6 @@
         fIsValid = SkBitmapHasher::ComputeDigest(bitmap, &fHashDigest);
     }
 
-#ifdef SK_BUILD_JSON_WRITER
     GmResultDigest::GmResultDigest(const Json::Value &jsonTypeValuePair) {
         fIsValid = false;
         if (!jsonTypeValuePair.isArray()) {
@@ -80,7 +77,6 @@
             }
         }
     }
-#endif
 
     bool GmResultDigest::isValid() const {
         return fIsValid;
@@ -92,7 +88,6 @@
         return (this->fIsValid && other.fIsValid && (this->fHashDigest == other.fHashDigest));
     }
 
-#ifdef SK_BUILD_JSON_WRITER
     Json::Value GmResultDigest::asJsonTypeValuePair() const {
         // TODO(epoger): The current implementation assumes that the
         // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5
@@ -105,7 +100,6 @@
         }
         return jsonTypeValuePair;
     }
-#endif
 
     SkString GmResultDigest::getHashType() const {
         // TODO(epoger): The current implementation assumes that the
@@ -140,7 +134,6 @@
         fAllowedResultDigests.push_back(bitmapAndDigest.fDigest);
     }
 
-#ifdef SK_BUILD_JSON_WRITER
     Expectations::Expectations(Json::Value jsonElement) {
         if (jsonElement.empty()) {
             fIgnoreFailure = kDefaultIgnoreFailure;
@@ -173,7 +166,6 @@
             }
         }
     }
-#endif
 
     bool Expectations::match(GmResultDigest actualGmResultDigest) const {
         for (int i=0; i < this->fAllowedResultDigests.count(); i++) {
@@ -185,7 +177,6 @@
         return false;
     }
 
-#ifdef SK_BUILD_JSON_WRITER
     Json::Value Expectations::asJsonValue() const {
         Json::Value allowedDigestArray;
         if (!this->fAllowedResultDigests.empty()) {
@@ -199,7 +190,6 @@
         jsonExpectations[kJsonKey_ExpectedResults_IgnoreFailure]  = this->ignoreFailure();
         return jsonExpectations;
     }
-#endif
 
     // IndividualImageExpectationsSource class...
 
@@ -217,7 +207,6 @@
     }
 
 
-#ifdef SK_BUILD_JSON_WRITER
     // JsonExpectationsSource class...
 
     JsonExpectationsSource::JsonExpectationsSource(const char *jsonPath) {
@@ -247,5 +236,4 @@
         }
         return true;
     }
-#endif
 }
diff --git a/gm/gm_expectations.h b/gm/gm_expectations.h
index c69fafc..1cd6a1f 100644
--- a/gm/gm_expectations.h
+++ b/gm/gm_expectations.h
@@ -22,13 +22,11 @@
 
 namespace skiagm {
 
-#ifdef SK_BUILD_JSON_WRITER
     Json::Value CreateJsonTree(Json::Value expectedResults,
                                Json::Value actualResultsFailed,
                                Json::Value actualResultsFailureIgnored,
                                Json::Value actualResultsNoComparison,
                                Json::Value actualResultsSucceeded);
-#endif
     /**
      * The digest of a GM test result.
      *
@@ -42,14 +40,12 @@
          */
         explicit GmResultDigest(const SkBitmap &bitmap);
 
-#ifdef SK_BUILD_JSON_WRITER
         /**
          * Create a ResultDigest representing an allowed result
          * checksum within JSON expectations file, in the form
          * ["bitmap-64bitMD5", 12345].
          */
         explicit GmResultDigest(const Json::Value &jsonTypeValuePair);
-#endif
 
         /**
          * Returns true if this GmResultDigest was fully and successfully
@@ -63,13 +59,11 @@
          */
         bool equals(const GmResultDigest &other) const;
 
-#ifdef SK_BUILD_JSON_WRITER
         /**
          * Returns a JSON type/value pair representing this result,
          * such as ["bitmap-64bitMD5", 12345].
          */
         Json::Value asJsonTypeValuePair() const;
-#endif
 
         /**
          * Returns the hashtype, such as "bitmap-64bitMD5", as an SkString.
@@ -118,7 +112,6 @@
          */
         explicit Expectations(const BitmapAndDigest& bitmapAndDigest);
 
-#ifdef SK_BUILD_JSON_WRITER
         /**
          * Create Expectations from a JSON element as found within the
          * kJsonKey_ExpectedResults section.
@@ -127,7 +120,6 @@
          * don't have any expectations.
          */
         explicit Expectations(Json::Value jsonElement);
-#endif
 
         /**
          * Returns true iff we want to ignore failed expectations.
@@ -161,12 +153,10 @@
             return (kUnknown_SkColorType == fBitmap.colorType()) ? NULL : &fBitmap;
         }
 
-#ifdef SK_BUILD_JSON_WRITER
         /**
          * Return a JSON representation of the expectations.
          */
         Json::Value asJsonValue() const;
-#endif
 
     private:
         const static bool kDefaultIgnoreFailure = false;
@@ -209,7 +199,6 @@
         const SkString fRootDir;
     };
 
-#ifdef SK_BUILD_JSON_WRITER
     /**
      * Return Expectations based on JSON summary file.
      */
@@ -237,7 +226,6 @@
         Json::Value fJsonRoot;
         Json::Value fJsonExpectedResults;
     };
-#endif // SK_BUILD_JSON_WRITER
 
 }
 #endif
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 3723769..0be3454 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -869,7 +869,6 @@
                                             const GmResultDigest &actualResultDigest,
                                             ErrorCombination errors,
                                             bool ignoreFailure) {
-#ifdef SK_BUILD_JSON_WRITER
         Json::Value jsonActualResults = actualResultDigest.asJsonTypeValuePair();
         Json::Value *resultCollection = NULL;
 
@@ -901,7 +900,6 @@
         if (resultCollection) {
             (*resultCollection)[testName] = jsonActualResults;
         }
-#endif
     }
 
     /**
@@ -909,9 +907,7 @@
      */
     void add_expected_results_to_json_summary(const char testName[],
                                               Expectations expectations) {
-#ifdef SK_BUILD_JSON_WRITER
         this->fJsonExpectedResults[testName] = expectations.asJsonValue();
-#endif
     }
 
     /**
@@ -1271,14 +1267,12 @@
     // If unset, we don't do comparisons.
     SkAutoTUnref<ExpectationsSource> fExpectationsSource;
 
-#ifdef SK_BUILD_JSON_WRITER
     // JSON summaries that we generate as we go (just for output).
     Json::Value fJsonExpectedResults;
     Json::Value fJsonActualResults_Failed;
     Json::Value fJsonActualResults_FailureIgnored;
     Json::Value fJsonActualResults_NoComparison;
     Json::Value fJsonActualResults_Succeeded;
-#endif
 }; // end of GMMain class definition
 
 #if SK_SUPPORT_GPU
@@ -1475,9 +1469,7 @@
              "each test).");
 DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images, use checksum-"
             "based filenames, as rebaseline.py will use when downloading them from Google Storage");
-#ifdef SK_BUILD_JSON_WRITER
 DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file.");
-#endif
 DEFINE_string2(writePath, w, "",  "Write rendered images into this directory.");
 DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory.");
 DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, "
@@ -2201,12 +2193,10 @@
             gmmain->fExpectationsSource.reset(SkNEW_ARGS(
                 IndividualImageExpectationsSource, (readPath)));
         } else {
-#ifdef SK_BUILD_JSON_WRITER
             if (FLAGS_verbose) {
                 SkDebugf("reading expectations from JSON summary file %s\n", readPath);
             }
             gmmain->fExpectationsSource.reset(SkNEW_ARGS(JsonExpectationsSource, (readPath)));
-#endif
         }
     }
     return true;
@@ -2413,7 +2403,6 @@
     }
 #endif
 
-#ifdef SK_BUILD_JSON_WRITER
     if (FLAGS_writeJsonSummaryPath.count() == 1) {
         Json::Value root = CreateJsonTree(
             gmmain.fJsonExpectedResults,
@@ -2423,7 +2412,6 @@
         SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]);
         stream.write(jsonStdString.c_str(), jsonStdString.length());
     }
-#endif
 
 #if SK_SUPPORT_GPU
 
diff --git a/gyp/common_conditions.gypi b/gyp/common_conditions.gypi
index b908903..b131766 100644
--- a/gyp/common_conditions.gypi
+++ b/gyp/common_conditions.gypi
@@ -680,12 +680,6 @@
       ],
     }],
 
-    [ 'skia_build_json_writer', {
-      'defines': [
-        'SK_BUILD_JSON_WRITER',
-      ]
-    }],
-
   ], # end 'conditions'
   # The Xcode SYMROOT must be at the root. See build/common.gypi in chromium for more details
   'xcode_settings': {
diff --git a/gyp/common_variables.gypi b/gyp/common_variables.gypi
index f0c065f..c414c75 100644
--- a/gyp/common_variables.gypi
+++ b/gyp/common_variables.gypi
@@ -64,13 +64,11 @@
         [ 'skia_android_framework == 1', {
           'skia_os%': 'android',
           'skia_chrome_utils%': 0,
-          # FIXME (scroggo): JSON is disabled in Android framework until we
-          # solve skbug.com/2448
-          'skia_build_json_writer%': 0,
+          'skia_use_system_json%': 1,
         }, {
           'skia_os%': '<(skia_os)',
           'skia_chrome_utils%': 1,
-          'skia_build_json_writer%': 1,
+          'skia_use_system_json%': 0,
         }],
         [ 'skia_os == "win"', {
           'os_posix%': 0,
@@ -204,7 +202,7 @@
     'skia_mesa%': '<(skia_mesa)',
     'skia_stroke_path_rendering%': '<(skia_stroke_path_rendering)',
     'skia_android_framework%': '<(skia_android_framework)',
-    'skia_build_json_writer%': '<(skia_build_json_writer)',
+    'skia_use_system_json%': '<(skia_use_system_json)',
     'skia_android_path_rendering%': '<(skia_android_path_rendering)',
     'skia_resource_cache_mb_limit%': '<(skia_resource_cache_mb_limit)',
     'skia_resource_cache_count_limit%': '<(skia_resource_cache_count_limit)',
diff --git a/gyp/jsoncpp.gyp b/gyp/jsoncpp.gyp
index 0507ed0..337f716 100644
--- a/gyp/jsoncpp.gyp
+++ b/gyp/jsoncpp.gyp
@@ -18,9 +18,16 @@
   'targets': [
     {
       'target_name': 'jsoncpp',
-      'type': 'static_library',
       'conditions': [
-        ['skia_build_json_writer', {
+        ['skia_use_system_json', {
+          'type': 'none',
+          'direct_dependent_settings': {
+            'libraries': [
+              'jsoncpp.a',
+            ],
+          },
+        }, {
+          'type': 'static_library',
           'defines': [
             'JSON_USE_EXCEPTION=0',
           ],
diff --git a/include/utils/SkJSONCPP.h b/include/utils/SkJSONCPP.h
index 0582e8f..de82768 100644
--- a/include/utils/SkJSONCPP.h
+++ b/include/utils/SkJSONCPP.h
@@ -10,8 +10,6 @@
 #ifndef SkJSONCPP_DEFINED
 #define SkJSONCPP_DEFINED
 
-#ifdef SK_BUILD_JSON_WRITER
-
 #ifdef SK_BUILD_FOR_WIN
     // json includes xlocale which generates warning 4530 because we're
     // compiling without exceptions;
@@ -26,6 +24,4 @@
     #pragma warning(pop)
 #endif
 
-#endif // SK_BUILD_JSON_WRITER
-
 #endif // SkJSONCPP_DEFINED
diff --git a/tools/PictureResultsWriter.h b/tools/PictureResultsWriter.h
index 9aa33b5..272a50c 100644
--- a/tools/PictureResultsWriter.h
+++ b/tools/PictureResultsWriter.h
@@ -140,7 +140,6 @@
     SkString currentLine;
 };
 
-#ifdef SK_BUILD_JSON_WRITER
 /**
  * This PictureResultsWriter collects data in a JSON node
  *
@@ -227,6 +226,5 @@
     Json::Value *fCurrentTileSet;
     Json::Value *fCurrentTile;
 };
-#endif // SK_BUILD_JSON_WRITER
 
 #endif
diff --git a/tools/bench_pictures_main.cpp b/tools/bench_pictures_main.cpp
index c267c4c..6b76bfc 100644
--- a/tools/bench_pictures_main.cpp
+++ b/tools/bench_pictures_main.cpp
@@ -39,9 +39,7 @@
         "Specific flags are listed above.");
 DEFINE_string(logFile, "", "Destination for writing log output, in addition to stdout.");
 DEFINE_bool(logPerIter, false, "Log each repeat timer instead of mean.");
-#ifdef SK_BUILD_JSON_WRITER
 DEFINE_string(jsonLog, "", "Destination for writing JSON data.");
-#endif
 DEFINE_bool(min, false, "Print the minimum times (instead of average).");
 DECLARE_int32(multi);
 DECLARE_string(readPath);
@@ -419,14 +417,12 @@
         }
     }
 
-#ifdef SK_BUILD_JSON_WRITER
     SkAutoTDelete<PictureJSONResultsWriter> jsonWriter;
     if (FLAGS_jsonLog.count() == 1) {
         jsonWriter.reset(SkNEW(PictureJSONResultsWriter(FLAGS_jsonLog[0])));
         gWriter.add(jsonWriter.get());
     }
 
-#endif
     gWriter.add(&gLogWriter);