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
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
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
"""Function for generating the SkUserConfig file, customized for Android."""
import os
+import shutil
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
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
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:
# 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.
--- /dev/null
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// 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
# 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',
'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)
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,
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()