Allow running gyp_to_android without SkUserConfig.
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 21 Apr 2014 14:45:01 +0000 (14:45 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 21 Apr 2014 14:45:01 +0000 (14:45 +0000)
The old code requires that include/config/SkUserConfig.h exists,
to ensure that it gets copied into Android's
include/core/SkUserConfig.h when we do a merge. However, if a
developer wants to make changes and rerun the script, they
should not have to recreate include/config/SkUserConfig.h just
to rerun the script. By default, allow the original to not
exist and just skip the copy.

Update tests to pass. Also add tests to support this use case.

Make gyp_to_android.py executable.

R=robertphillips@google.com, halcanary@google.com

Author: scroggo@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@14273 2bbb7eff-a529-9590-31e7-b0007b416f81

platform_tools/android/bin/gyp_to_android.py [changed mode: 0644->0755]
platform_tools/android/gyp_gen/generate_user_config.py
platform_tools/android/tests/expectations/missing-filename.xxx [new file with mode: 0644]
platform_tools/android/tests/generate_user_config_tests.py

old mode 100644 (file)
new mode 100755 (executable)
index c8abfb6..f7199b8
@@ -64,12 +64,14 @@ def generate_var_dict(target_dir, target_file, skia_arch_type, have_neon):
   print '.',
   return var_dict
 
-def main(target_dir=None):
+def main(target_dir=None, require_sk_user_config=False):
   """
   Read gyp files and create Android.mk for the Android framework's
   external/skia.
   @param target_dir Directory in which to place 'Android.mk'. If None, the file
                     will be placed in skia's root directory.
+  @param require_sk_user_config If True, raise an AssertionError if
+                                SkUserConfig.h does not exist.
   """
   # Create a temporary folder to hold gyp and gypd files. Create it in SKIA_DIR
   # so that it is a sibling of gyp/, so the relationships between gyp files and
@@ -125,7 +127,8 @@ def main(target_dir=None):
       dst_dir = os.path.join(SKIA_DIR, 'include', 'core')
 
     generate_user_config.generate_user_config(
-        original_sk_user_config=user_config, target_dir=dst_dir,
+        original_sk_user_config=user_config,
+        require_sk_user_config=require_sk_user_config, target_dir=dst_dir,
         ordered_set=common.DEFINES)
 
     # Now that the defines have been written to SkUserConfig, they are not
index 1fafc1d..957c363 100644 (file)
@@ -8,6 +8,7 @@
 """Function for generating the SkUserConfig file, customized for Android."""
 
 import os
+import shutil
 
 
 AUTOGEN_WARNING = (
@@ -27,7 +28,8 @@ AUTOGEN_WARNING = (
 BUILD_GUARD = 'SkUserConfig_Android_DEFINED'
 
 
-def generate_user_config(original_sk_user_config, target_dir, ordered_set):
+def generate_user_config(original_sk_user_config, require_sk_user_config,
+                         target_dir, ordered_set):
   """Generate the SkUserConfig file specific to the Android framework.
 
   Android needs its #defines in its skia/include/core directory, so that other
@@ -39,6 +41,9 @@ def generate_user_config(original_sk_user_config, target_dir, ordered_set):
 
   Args:
       original_sk_user_config: Path to original SkUserConfig.h
+      require_sk_user_config: If True, raise an AssertionError if
+          SkUserConfig.h does not exist. Either way, if it does exist, copy it
+          into the new file.
       target_dir: Directory within which the modified SkUserConfig.h will be
           written. Its name will be the same basename as
           original_sk_user_config. If None, the new file will be written to the
@@ -50,7 +55,9 @@ def generate_user_config(original_sk_user_config, target_dir, ordered_set):
       AssertionError: If original_sk_user_config does not exist.
   """
 
-  assert os.path.exists(original_sk_user_config)
+  sk_user_config_exists = os.path.exists(original_sk_user_config)
+  if require_sk_user_config:
+    assert sk_user_config_exists
 
   dst_filename = os.path.basename(original_sk_user_config)
   if target_dir:
@@ -62,9 +69,9 @@ def generate_user_config(original_sk_user_config, target_dir, ordered_set):
     # Copy the original exactly. This is merely for reference. Many of the
     # defines written to the file below, either manually or generated from the
     # gyp files, have explanations in the original SkUserConfig.h
-    with open(original_sk_user_config, 'r') as original:
-      for line in original:
-        dst.write(line)
+    if sk_user_config_exists:
+      with open(original_sk_user_config, 'r') as original:
+        shutil.copyfileobj(original, dst)
 
     # Now add the defines specific to Android. Write a custom build guard to
     # ensure they don't get defined more than once.
diff --git a/platform_tools/android/tests/expectations/missing-filename.xxx b/platform_tools/android/tests/expectations/missing-filename.xxx
new file mode 100644 (file)
index 0000000..d0d70d7
--- /dev/null
@@ -0,0 +1,33 @@
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// THIS FILE IS AUTOGENERATED BY GYP_TO_ANDROID.PY. DO NOT EDIT.
+//
+// This file contains Skia's upstream include/config/SkUserConfig.h as a
+// reference, followed by the actual defines set for Android.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+// Android defines:
+#ifndef SkUserConfig_Android_DEFINED
+#define SkUserConfig_Android_DEFINED
+#ifdef ANDROID
+    #include <utils/misc.h>
+#endif
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+    #define SK_CPU_BENDIAN
+    #undef  SK_CPU_LENDIAN
+#else
+    #define SK_CPU_LENDIAN
+    #undef  SK_CPU_BENDIAN
+#endif
+
+#define SK_BUILD_FOR_ANDROID
+#define SK_BUILD_FOR_ANDROID_FRAMEWORK
+#define SK_SCALAR_IS_FLOAT
+#define foo
+#define bar
+
+#endif // SkUserConfig_Android_DEFINED
index 503a154..660757d 100644 (file)
@@ -24,13 +24,15 @@ from generate_user_config import generate_user_config as gen_config
 
 # Name of SkUserConfig file.
 USER_CONFIG_NAME = 'SkUserConfig-h.txt'
+MISSING_FILENAME = 'missing-filename.xxx'
 # Path to unchanging Dummy SkUserConfig file.
 FULL_DUMMY_PATH = os.path.join(os.path.dirname(__file__), 'inputs',
                                USER_CONFIG_NAME)
 REBASELINE_MSG = ('If you\'ve modified generate_user_config.py, run '
                   '"generate_user_config_tests.py --rebaseline" to rebaseline')
 
-def generate_dummy_user_config(original_sk_user_config, target_dir):
+def generate_dummy_user_config(original_sk_user_config,
+                               require_sk_user_config, target_dir):
   # Add an arbitrary set of defines
   defines = [ 'SK_BUILD_FOR_ANDROID',
               'SK_BUILD_FOR_ANDROID_FRAMEWORK',
@@ -38,6 +40,7 @@ def generate_dummy_user_config(original_sk_user_config, target_dir):
               'foo',
               'bar' ]
   gen_config(original_sk_user_config=original_sk_user_config,
+             require_sk_user_config=require_sk_user_config,
              target_dir=target_dir, ordered_set=defines)
 
 
@@ -45,18 +48,33 @@ class GenUserConfigTest(unittest.TestCase):
 
   def test_missing_sk_user_config(self):
     tmp = tempfile.mkdtemp()
-    original = os.path.join(tmp, 'filename')
+    original = os.path.join(tmp, MISSING_FILENAME)
     assert not os.path.exists(original)
 
+
+    # With require_sk_user_config set to True, an AssertionError will be
+    # thrown when original_sk_user_config is missing.
     with self.assertRaises(AssertionError):
       ordered_set = [ 'define' ]
-      gen_config(original_sk_user_config=original, target_dir=tmp,
-                 ordered_set=ordered_set)
+      gen_config(original_sk_user_config=original,
+                 require_sk_user_config=True,
+                 target_dir=tmp, ordered_set=ordered_set)
+
+    # With require_sk_user_config set to False, it is okay for
+    # original_sk_user_config to be missing.
+    generate_dummy_user_config(original_sk_user_config=original,
+                               require_sk_user_config=False, target_dir=tmp)
+    actual_name = os.path.join(tmp, MISSING_FILENAME)
+    utils.compare_to_expectation(actual_name=actual_name,
+                                 expectation_name=MISSING_FILENAME,
+                                 assert_true=self.assertTrue,
+                                 msg=REBASELINE_MSG)
+
     shutil.rmtree(tmp)
 
   def test_gen_config(self):
     tmp = tempfile.mkdtemp()
-    generate_dummy_user_config(FULL_DUMMY_PATH, tmp)
+    generate_dummy_user_config(FULL_DUMMY_PATH, True, tmp)
     actual_name = os.path.join(tmp, USER_CONFIG_NAME)
     utils.compare_to_expectation(actual_name=actual_name,
                         expectation_name=USER_CONFIG_NAME,
@@ -74,7 +92,8 @@ def main():
 
 
 def rebaseline():
-  generate_dummy_user_config(FULL_DUMMY_PATH, utils.EXPECTATIONS_DIR)
+  generate_dummy_user_config(FULL_DUMMY_PATH, True, utils.EXPECTATIONS_DIR)
+  generate_dummy_user_config(MISSING_FILENAME, False, utils.EXPECTATIONS_DIR)
 
 if __name__ == "__main__":
   parser = argparse.ArgumentParser()