summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-18 01:51:37 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-18 01:51:37 +0000
commitddc6d877066d01a136e1b40c86865760d8cf414a (patch)
tree35b8c1ca59daebf2cf2c8770943fed28206ea094
parent0a57c025d1e88036c4ae01b3293a74fc84834d04 (diff)
downloadchromium_src-ddc6d877066d01a136e1b40c86865760d8cf414a.zip
chromium_src-ddc6d877066d01a136e1b40c86865760d8cf414a.tar.gz
chromium_src-ddc6d877066d01a136e1b40c86865760d8cf414a.tar.bz2
Generate shim headers for libpng
BUG=165264 Review URL: https://codereview.chromium.org/11470020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173618 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xbuild/gyp_chromium1
-rw-r--r--build/shim_headers.gypi45
-rw-r--r--third_party/libpng/libpng.gyp13
-rwxr-xr-xtools/generate_shim_headers/generate_shim_headers.py66
-rw-r--r--ui/gfx/codec/png_codec.cc4
-rw-r--r--ui/gfx/codec/png_codec_unittest.cc7
-rw-r--r--webkit/support/webkit_support_gfx.cc4
7 files changed, 123 insertions, 17 deletions
diff --git a/build/gyp_chromium b/build/gyp_chromium
index 499fa5c..ee5b3f3 100755
--- a/build/gyp_chromium
+++ b/build/gyp_chromium
@@ -21,6 +21,7 @@ sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
import gyp
# Add paths so that pymod_do_main(...) can import files.
+sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers'))
sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))
sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build'))
diff --git a/build/shim_headers.gypi b/build/shim_headers.gypi
new file mode 100644
index 0000000..cf0914d
--- /dev/null
+++ b/build/shim_headers.gypi
@@ -0,0 +1,45 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This file is meant to be included into a target to handle shim headers
+# in a consistent manner. To use this the following variables need to be
+# defined:
+# headers_root_path: string: path to directory containing headers
+# header_filenames: list: list of header file names
+
+{
+ 'variables': {
+ 'shim_headers_path': '<(INTERMEDIATE_DIR)/shim_headers',
+ },
+ 'direct_dependent_settings': {
+ 'include_dirs+': [
+ '<(shim_headers_path)',
+ ],
+ },
+ 'actions': [
+ {
+ 'variables': {
+ 'generator_path': '<(DEPTH)/tools/generate_shim_headers/generate_shim_headers.py',
+ 'generator_args': [
+ '--headers-root', '<(headers_root_path)',
+ '--output-directory', '<(shim_headers_path)',
+ '<@(header_filenames)',
+ ],
+ },
+ 'action_name': 'generate_<(_target_name)_shim_headers',
+ 'inputs': [
+ '<(generator_path)',
+ ],
+ 'outputs': [
+ '<!@pymod_do_main(generate_shim_headers <@(generator_args) --outputs)',
+ ],
+ 'action': ['python',
+ '<(generator_path)',
+ '<@(generator_args)',
+ '--generate',
+ ],
+ 'message': 'Generating <(_target_name) shim headers.',
+ },
+ ],
+}
diff --git a/third_party/libpng/libpng.gyp b/third_party/libpng/libpng.gyp
index 634c0e3..2a20b6b 100644
--- a/third_party/libpng/libpng.gyp
+++ b/third_party/libpng/libpng.gyp
@@ -109,9 +109,6 @@
'cflags': [
'<!@(<(pkg-config) --cflags libpng)',
],
- 'defines': [
- 'USE_SYSTEM_LIBPNG',
- ],
},
'link_settings': {
'ldflags': [
@@ -121,6 +118,16 @@
'<!@(<(pkg-config) --libs-only-l libpng)',
],
},
+ 'variables': {
+ 'headers_root_path': '.',
+ 'header_filenames': [
+ 'png.h',
+ 'pngconf.h',
+ ],
+ },
+ 'includes': [
+ '../../build/shim_headers.gypi',
+ ],
},
],
}],
diff --git a/tools/generate_shim_headers/generate_shim_headers.py b/tools/generate_shim_headers/generate_shim_headers.py
new file mode 100755
index 0000000..068a2ac
--- /dev/null
+++ b/tools/generate_shim_headers/generate_shim_headers.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Generates shim headers that mirror the directory structure of bundled headers,
+but just forward to the system ones.
+
+This allows seamless compilation against system headers with no changes
+to our source code.
+"""
+
+
+import optparse
+import os.path
+import sys
+
+
+SHIM_TEMPLATE = """
+#if defined(OFFICIAL_BUILD)
+#error shim headers must not be used in official builds!
+#endif
+
+#include <%s>
+"""
+
+
+def GeneratorMain(argv):
+ parser = optparse.OptionParser()
+ parser.add_option('--headers-root')
+ parser.add_option('--output-directory')
+ parser.add_option('--outputs', action='store_true')
+ parser.add_option('--generate', action='store_true')
+
+ options, args = parser.parse_args(argv)
+
+ if not options.headers_root:
+ parser.error('Missing --headers-root parameter.')
+ if not options.output_directory:
+ parser.error('Missing --output-directory parameter.')
+ if not args:
+ parser.error('Missing arguments - header file names.')
+
+ source_tree_root = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), '..', '..'))
+
+ target_directory = os.path.join(
+ options.output_directory,
+ os.path.relpath(options.headers_root, source_tree_root))
+ if options.generate and not os.path.exists(target_directory):
+ os.makedirs(target_directory)
+ for header_filename in args:
+ if options.outputs:
+ yield os.path.join(target_directory, header_filename)
+ if options.generate:
+ with open(os.path.join(target_directory, header_filename), 'w') as f:
+ f.write(SHIM_TEMPLATE % header_filename)
+
+
+def DoMain(argv):
+ return '\n'.join(GeneratorMain(argv))
+
+
+if __name__ == '__main__':
+ DoMain(sys.argv[1:])
diff --git a/ui/gfx/codec/png_codec.cc b/ui/gfx/codec/png_codec.cc
index 474fbc9..e0dc4c6 100644
--- a/ui/gfx/codec/png_codec.cc
+++ b/ui/gfx/codec/png_codec.cc
@@ -14,11 +14,7 @@
#include "third_party/skia/include/core/SkColorPriv.h"
extern "C" {
-#if defined(USE_SYSTEM_LIBPNG)
-#include <png.h>
-#else
#include "third_party/libpng/png.h"
-#endif
#if defined(USE_SYSTEM_ZLIB)
#include <zlib.h>
diff --git a/ui/gfx/codec/png_codec_unittest.cc b/ui/gfx/codec/png_codec_unittest.cc
index 83f535e..ef21d38 100644
--- a/ui/gfx/codec/png_codec_unittest.cc
+++ b/ui/gfx/codec/png_codec_unittest.cc
@@ -2,17 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#if defined(USE_SYSTEM_LIBPNG)
-#include <png.h>
-#else
-#include "third_party/libpng/png.h"
-#endif
-
#include <algorithm>
#include <cmath>
#include "base/logging.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/libpng/png.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColorPriv.h"
#include "third_party/skia/include/core/SkUnPreMultiply.h"
diff --git a/webkit/support/webkit_support_gfx.cc b/webkit/support/webkit_support_gfx.cc
index 1471e29..1da7a34 100644
--- a/webkit/support/webkit_support_gfx.cc
+++ b/webkit/support/webkit_support_gfx.cc
@@ -9,11 +9,7 @@
#include <string.h>
extern "C" {
-#if defined(USE_SYSTEM_LIBPNG)
-#include <png.h>
-#else
#include "third_party/libpng/png.h"
-#endif
#if defined(USE_SYSTEM_ZLIB)
#include <zlib.h>