Generate bench/Android.mk from gyp.

For now, remove json functionality and do not depend on json. This
allows us to build and run until solving skbug.com/2448.

bench/DeferredSurfaceCopyBench.cpp:
Include GrRenderTarget last, so SK_SUPPORT_GPU will be set properly.

bench/ResultsWriter.h:
bench/benchmain.cpp:
Remove JSONResultsWriter when SK_BUILD_JSON_WRITER is not defined,
which is the case for the Android framework build.

gyp/bench.gyp:
Depend on skia and cutils (for android_atomic_inc etc).

gyp/common_conditions.gypi:
Define SK_BUILD_JSON_WRITER when skia_build_json_writer is set.

gyp/common_variables.gypi:
Add a flag for skia_build_json_writer, and set it only when
skia_android_framework is not set.

gyp/jsoncpp.gyp:
Do not build jsoncpp when skia_build_json_writer is not defined.
include/utils/SkJSONCPP.h:
Do not include json headers when SK_BUILD_JSON_WRITER is not defined.

platform_tools/android/bin/gyp_to_android.py:
Generate bench/Android.mk.

platform_tools/android/gyp_gen/gypd_parser.py:
Skip dest_dir when checking for include_dirs.

platform_tools/android/gyp_gen/makefile_writer.py:
Build bench/Android.mk when building external/skia.

platform_tools/android/gyp_gen/tool_makefile_writer.py:
Add a parameter for putting the binary into /data/local/tmp.

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

Author: scroggo@google.com

Review URL: https://codereview.chromium.org/282053002

git-svn-id: http://skia.googlecode.com/svn/trunk@14760 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/bench/DeferredSurfaceCopyBench.cpp b/bench/DeferredSurfaceCopyBench.cpp
index fcc19d4..6449b61 100644
--- a/bench/DeferredSurfaceCopyBench.cpp
+++ b/bench/DeferredSurfaceCopyBench.cpp
@@ -6,14 +6,14 @@
  * found in the LICENSE file.
  */
 
-#if SK_SUPPORT_GPU
-#include "GrRenderTarget.h"
-#endif
 #include "SkBenchmark.h"
 #include "SkDeferredCanvas.h"
 #include "SkDevice.h"
 #include "SkImage.h"
 #include "SkSurface.h"
+#if SK_SUPPORT_GPU
+#include "GrRenderTarget.h"
+#endif
 
 class DeferredSurfaceCopyBench : public SkBenchmark {
     enum {
diff --git a/bench/ResultsWriter.h b/bench/ResultsWriter.h
index 29d3d1d..12c968a 100644
--- a/bench/ResultsWriter.h
+++ b/bench/ResultsWriter.h
@@ -77,6 +77,7 @@
     const char* fTimeFormat;
 };
 
+#ifdef SK_BUILD_JSON_WRITER
 /**
  * This ResultsWriter handles writing out the results in JSON.
  *
@@ -133,6 +134,7 @@
     Json::Value* fConfig;
 };
 
+#endif // SK_BUILD_JSON_WRITER
 /**
  * This ResultsWriter writes out to multiple ResultsWriters.
  */
diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp
index e2cc9c1..25c552c 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -267,8 +267,9 @@
 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,
@@ -301,11 +302,15 @@
     LoggerResultsWriter logWriter(logger, FLAGS_timeFormat[0]);
     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.
     CallEnd<MultiResultsWriter> ender(writer);
diff --git a/gyp/bench.gyp b/gyp/bench.gyp
index 9e8d1d7..553c0e7 100644
--- a/gyp/bench.gyp
+++ b/gyp/bench.gyp
@@ -33,6 +33,14 @@
             ],
           },
         ],
+        ['skia_android_framework == 1',
+          {
+            'libraries': [
+              '-lskia',
+              '-lcutils',
+            ],
+          },
+        ],
       ],
       'includes': [
         'bench.gypi',
diff --git a/gyp/common_conditions.gypi b/gyp/common_conditions.gypi
index 6a800b4..4a60cd0 100644
--- a/gyp/common_conditions.gypi
+++ b/gyp/common_conditions.gypi
@@ -639,6 +639,12 @@
       ],
     }],
 
+    [ '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 b6d4e76..033073f 100644
--- a/gyp/common_variables.gypi
+++ b/gyp/common_variables.gypi
@@ -60,9 +60,13 @@
         [ '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_os%': '<(skia_os)',
           'skia_chrome_utils%': 1,
+          'skia_build_json_writer%': 1,
         }],
         [ 'skia_os == "win"', {
           'os_posix%': 0,
@@ -198,6 +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_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 1b5b784..0507ed0 100644
--- a/gyp/jsoncpp.gyp
+++ b/gyp/jsoncpp.gyp
@@ -19,38 +19,42 @@
     {
       'target_name': 'jsoncpp',
       'type': 'static_library',
-      'defines': [
-        'JSON_USE_EXCEPTION=0',
-      ],
-      'sources': [
-        '../third_party/externals/jsoncpp/include/json/assertions.h',
-        '../third_party/externals/jsoncpp/include/json/autolink.h',
-        '../third_party/externals/jsoncpp/include/json/config.h',
-        '../third_party/externals/jsoncpp/include/json/features.h',
-        '../third_party/externals/jsoncpp/include/json/forwards.h',
-        '../third_party/externals/jsoncpp/include/json/json.h',
-        '../third_party/externals/jsoncpp/include/json/reader.h',
-        '../third_party/externals/jsoncpp-chromium/overrides/include/json/value.h',
-        '../third_party/externals/jsoncpp/include/json/writer.h',
-        '../third_party/externals/jsoncpp/src/lib_json/json_batchallocator.h',
-        '../third_party/externals/jsoncpp/src/lib_json/json_reader.cpp',
-        '../third_party/externals/jsoncpp/src/lib_json/json_tool.h',
-        '../third_party/externals/jsoncpp-chromium/overrides/src/lib_json/json_value.cpp',
-        '../third_party/externals/jsoncpp/src/lib_json/json_writer.cpp',
-      ],
-      'include_dirs': [
-        '../third_party/externals/jsoncpp-chromium/overrides/include/',
-        '../third_party/externals/jsoncpp/include/',
-        '../third_party/externals/jsoncpp/src/lib_json/',
-      ],
-      'direct_dependent_settings': {
-        'include_dirs': [
-          '../third_party/externals/jsoncpp-chromium/overrides/include/',
-          '../third_party/externals/jsoncpp/include/',
-        ],
-      },
-      'cflags': [
-        '-w',
+      'conditions': [
+        ['skia_build_json_writer', {
+          'defines': [
+            'JSON_USE_EXCEPTION=0',
+          ],
+          'sources': [
+            '../third_party/externals/jsoncpp/include/json/assertions.h',
+            '../third_party/externals/jsoncpp/include/json/autolink.h',
+            '../third_party/externals/jsoncpp/include/json/config.h',
+            '../third_party/externals/jsoncpp/include/json/features.h',
+            '../third_party/externals/jsoncpp/include/json/forwards.h',
+            '../third_party/externals/jsoncpp/include/json/json.h',
+            '../third_party/externals/jsoncpp/include/json/reader.h',
+            '../third_party/externals/jsoncpp-chromium/overrides/include/json/value.h',
+            '../third_party/externals/jsoncpp/include/json/writer.h',
+            '../third_party/externals/jsoncpp/src/lib_json/json_batchallocator.h',
+            '../third_party/externals/jsoncpp/src/lib_json/json_reader.cpp',
+            '../third_party/externals/jsoncpp/src/lib_json/json_tool.h',
+            '../third_party/externals/jsoncpp-chromium/overrides/src/lib_json/json_value.cpp',
+            '../third_party/externals/jsoncpp/src/lib_json/json_writer.cpp',
+          ],
+          'include_dirs': [
+            '../third_party/externals/jsoncpp-chromium/overrides/include/',
+            '../third_party/externals/jsoncpp/include/',
+            '../third_party/externals/jsoncpp/src/lib_json/',
+          ],
+          'direct_dependent_settings': {
+            'include_dirs': [
+              '../third_party/externals/jsoncpp-chromium/overrides/include/',
+              '../third_party/externals/jsoncpp/include/',
+            ],
+          },
+          'cflags': [
+            '-w',
+          ],
+        }],
       ],
     },
   ],
diff --git a/include/utils/SkJSONCPP.h b/include/utils/SkJSONCPP.h
index 8dbb40c..966d064 100644
--- a/include/utils/SkJSONCPP.h
+++ b/include/utils/SkJSONCPP.h
@@ -10,6 +10,8 @@
 #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;
@@ -23,4 +25,6 @@
     #pragma warning(pop)
 #endif
 
-#endif
+#endif // SK_BUILD_JSON_WRITER
+
+#endif // SkJSONCPP_DEFINED
diff --git a/platform_tools/android/bin/gyp_to_android.py b/platform_tools/android/bin/gyp_to_android.py
index e885399..8994efd 100755
--- a/platform_tools/android/bin/gyp_to_android.py
+++ b/platform_tools/android/bin/gyp_to_android.py
@@ -135,14 +135,14 @@
                                        local_module_name='skia_test',
                                        local_module_tags=['eng', 'tests'])
 
-    # TODO (scroggo): Generate bench/Android.mk. See skbug.com/2448
-    #tool_makefile_writer.generate_tool(gyp_dir=tmp_folder,
-    #                                   target_file='bench.gyp',
-    #                                   skia_trunk=target_dir,
-    #                                   dest_dir='bench',
-    #                                   skia_lib_var_dict=common,
-    #                                   local_module_name='skia_bench',
-    #                                   local_module_tags=['tests'])
+    tool_makefile_writer.generate_tool(gyp_dir=tmp_folder,
+                                       target_file='bench.gyp',
+                                       skia_trunk=target_dir,
+                                       dest_dir='bench',
+                                       skia_lib_var_dict=common,
+                                       local_module_name='skia_bench',
+                                       local_module_tags=['tests'],
+                                       place_in_local_tmp=True)
 
     # Now that the defines have been written to SkUserConfig and they've been
     # used to skip adding them to the tools makefiles, they are not needed in
diff --git a/platform_tools/android/gyp_gen/gypd_parser.py b/platform_tools/android/gyp_gen/gypd_parser.py
index b0e1417..e992637 100644
--- a/platform_tools/android/gyp_gen/gypd_parser.py
+++ b/platform_tools/android/gyp_gen/gypd_parser.py
@@ -97,6 +97,9 @@
       # wants relative to dest_dir.
       rel_include = os.path.relpath(include, os.pardir)
       rel_include = os.path.relpath(rel_include, dest_dir)
+      # No need to include the base directory.
+      if rel_include is os.curdir:
+        continue
       rel_include = os.path.join('$(LOCAL_PATH)', rel_include)
 
     # Remove a trailing slash, if present.
diff --git a/platform_tools/android/gyp_gen/makefile_writer.py b/platform_tools/android/gyp_gen/makefile_writer.py
index 2129799..1c92760 100644
--- a/platform_tools/android/gyp_gen/makefile_writer.py
+++ b/platform_tools/android/gyp_gen/makefile_writer.py
@@ -117,7 +117,7 @@
 #
 
 # benchmark (timings)
-#include $(BASE_PATH)/bench/Android.mk
+include $(BASE_PATH)/bench/Android.mk
 
 # golden-master (fidelity / regression test)
 #include $(BASE_PATH)/gm/Android.mk
diff --git a/platform_tools/android/gyp_gen/tool_makefile_writer.py b/platform_tools/android/gyp_gen/tool_makefile_writer.py
index bdcd884..ac2a758 100644
--- a/platform_tools/android/gyp_gen/tool_makefile_writer.py
+++ b/platform_tools/android/gyp_gen/tool_makefile_writer.py
@@ -15,27 +15,37 @@
 import vars_dict_lib
 
 
-def write_tool_android_mk(target_dir, var_dict):
+def write_tool_android_mk(target_dir, var_dict, place_in_local_tmp):
   """Write Android.mk for a Skia tool.
 
   Args:
     target_dir: Destination for the makefile. Must not be None.
     var_dict: VarsDict containing variables for the makefile.
+    place_in_local_tmp: If True, the executable will be synced to
+      /data/local/tmp.
   """
   target_file = os.path.join(target_dir, 'Android.mk')
   with open(target_file, 'w') as f:
     f.write(makefile_writer.AUTOGEN_WARNING)
+
+    if place_in_local_tmp:
+      f.write('local_target_dir := $(TARGET_OUT_DATA)/local/tmp\n')
+
     makefile_writer.write_local_path(f)
     makefile_writer.write_clear_vars(f)
 
     makefile_writer.write_local_vars(f, var_dict, False, None)
 
+    if place_in_local_tmp:
+      f.write('LOCAL_MODULE_PATH := $(local_target_dir)\n')
+
     makefile_writer.write_include_stlport(f)
     f.write('include $(BUILD_EXECUTABLE)\n')
 
 
 def generate_tool(gyp_dir, target_file, skia_trunk, dest_dir,
-                  skia_lib_var_dict, local_module_name, local_module_tags):
+                  skia_lib_var_dict, local_module_name, local_module_tags,
+                  place_in_local_tmp=False):
   """Common steps for building one of the skia tools.
 
   Parse a gyp file and create an Android.mk for this tool.
@@ -52,6 +62,8 @@
       ensure we do not duplicate anything in this Android.mk.
     local_module_name: Name for this tool, to set as LOCAL_MODULE.
     local_module_tags: Tags to pass to LOCAL_MODULE_TAG.
+    place_in_local_tmp: If True, the executable will be synced to
+      /data/local/tmp.
   """
   result_file = android_framework_gyp.main(target_dir=gyp_dir,
                                            target_file=target_file,
@@ -89,4 +101,5 @@
   if not os.path.exists(full_dest):
     os.mkdir(full_dest)
 
-  write_tool_android_mk(target_dir=full_dest, var_dict=var_dict)
+  write_tool_android_mk(target_dir=full_dest, var_dict=var_dict,
+                        place_in_local_tmp=place_in_local_tmp)