From 03a7f5fe2de9b0c886be4063533c91720ced0bf9 Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Fri, 10 Feb 2017 09:06:38 -0500 Subject: [PATCH] Make header files idempotent; script to check Change-Id: I960ded854e6bc7cdee029a7393cac2a686c41754 Reviewed-on: https://skia-review.googlesource.com/8308 Commit-Queue: Hal Canary Reviewed-by: Mike Klein --- include/utils/SkFrontBufferedStream.h | 4 + samplecode/DecodeFile.h | 4 + src/android/SkBitmapRegionCodec.h | 4 + src/codec/SkBmpMaskCodec.h | 4 + src/codec/SkBmpRLECodec.h | 3 + src/codec/SkBmpStandardCodec.h | 3 + src/codec/SkCodecImageGenerator.h | 3 + src/codec/SkGifCodec.h | 3 + src/codec/SkIcoCodec.h | 3 + src/codec/SkPngCodec.h | 3 + src/core/SkColorSpacePriv.h | 3 + src/core/SkPictureCommon.h | 3 + src/core/SkRecordedDrawable.h | 3 + src/core/SkTraceEventCommon.h | 3 + src/effects/SkEmbossMask_Table.h | 4 +- src/images/transform_scanline.h | 3 + tests/CodecPriv.h | 3 + tests/PathOpsTSectDebug.h | 3 + tools/check-headers-self-sufficient | 107 +++++++++++++++++++++++ tools/skiaserve/urlhandlers/UrlHandler.h | 3 + 20 files changed, 168 insertions(+), 1 deletion(-) create mode 100755 tools/check-headers-self-sufficient diff --git a/include/utils/SkFrontBufferedStream.h b/include/utils/SkFrontBufferedStream.h index bfc2728ef0..3532fc5259 100644 --- a/include/utils/SkFrontBufferedStream.h +++ b/include/utils/SkFrontBufferedStream.h @@ -5,6 +5,9 @@ * found in the LICENSE file. */ +#ifndef SkFrontBufferedStream_DEFINED +#define SkFrontBufferedStream_DEFINED + #include "SkTypes.h" class SkStream; @@ -35,3 +38,4 @@ public: */ static SkStreamRewindable* Create(SkStream* stream, size_t minBufferSize); }; +#endif // SkFrontBufferedStream_DEFINED diff --git a/samplecode/DecodeFile.h b/samplecode/DecodeFile.h index 95f3e39983..450c1fb3d7 100644 --- a/samplecode/DecodeFile.h +++ b/samplecode/DecodeFile.h @@ -5,6 +5,9 @@ * found in the LICENSE file. */ +#ifndef DecodeFile_DEFINED +#define DecodeFile_DEFINED + #include "SkBitmap.h" #include "SkCodec.h" #include "SkData.h" @@ -36,3 +39,4 @@ static inline sk_sp decode_file(const char filename[]) { sk_sp data(SkData::MakeFromFileName(filename)); return data ? SkImage::MakeFromEncoded(data) : nullptr; } +#endif // DecodeFile_DEFINED diff --git a/src/android/SkBitmapRegionCodec.h b/src/android/SkBitmapRegionCodec.h index c59879b68d..b3b0637432 100644 --- a/src/android/SkBitmapRegionCodec.h +++ b/src/android/SkBitmapRegionCodec.h @@ -5,6 +5,9 @@ * found in the LICENSE file. */ +#ifndef SkBitmapRegionCodec_DEFINED +#define SkBitmapRegionCodec_DEFINED + #include "SkBitmap.h" #include "SkBitmapRegionDecoder.h" #include "SkAndroidCodec.h" @@ -35,3 +38,4 @@ private: typedef SkBitmapRegionDecoder INHERITED; }; +#endif // SkBitmapRegionCodec_DEFINED diff --git a/src/codec/SkBmpMaskCodec.h b/src/codec/SkBmpMaskCodec.h index 939a4d8adf..50e285dff3 100644 --- a/src/codec/SkBmpMaskCodec.h +++ b/src/codec/SkBmpMaskCodec.h @@ -5,6 +5,9 @@ * found in the LICENSE file. */ +#ifndef SkBmpMaskCodec_DEFINED +#define SkBmpMaskCodec_DEFINED + #include "SkBmpCodec.h" #include "SkImageInfo.h" #include "SkMaskSwizzler.h" @@ -58,3 +61,4 @@ private: typedef SkBmpCodec INHERITED; }; +#endif // SkBmpMaskCodec_DEFINED diff --git a/src/codec/SkBmpRLECodec.h b/src/codec/SkBmpRLECodec.h index 8ea3a86dba..030e82731f 100644 --- a/src/codec/SkBmpRLECodec.h +++ b/src/codec/SkBmpRLECodec.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef SkBmpRLECodec_DEFINED +#define SkBmpRLECodec_DEFINED #include "SkBmpCodec.h" #include "SkColorTable.h" @@ -114,3 +116,4 @@ private: typedef SkBmpCodec INHERITED; }; +#endif // SkBmpRLECodec_DEFINED diff --git a/src/codec/SkBmpStandardCodec.h b/src/codec/SkBmpStandardCodec.h index 61b2792404..740db8ead0 100644 --- a/src/codec/SkBmpStandardCodec.h +++ b/src/codec/SkBmpStandardCodec.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef SkBmpStandardCodec_DEFINED +#define SkBmpStandardCodec_DEFINED #include "SkBmpCodec.h" #include "SkColorTable.h" @@ -98,3 +100,4 @@ private: typedef SkBmpCodec INHERITED; }; +#endif // SkBmpStandardCodec_DEFINED diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h index e1aa2209dd..51086eb0a8 100644 --- a/src/codec/SkCodecImageGenerator.h +++ b/src/codec/SkCodecImageGenerator.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef SkCodecImageGenerator_DEFINED +#define SkCodecImageGenerator_DEFINED #include "SkCodec.h" #include "SkColorTable.h" @@ -47,3 +49,4 @@ private: typedef SkImageGenerator INHERITED; }; +#endif // SkCodecImageGenerator_DEFINED diff --git a/src/codec/SkGifCodec.h b/src/codec/SkGifCodec.h index 9e980abafa..67654d3b55 100644 --- a/src/codec/SkGifCodec.h +++ b/src/codec/SkGifCodec.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef SkGifCodec_DEFINED +#define SkGifCodec_DEFINED #include "SkCodec.h" #include "SkCodecAnimation.h" @@ -152,3 +154,4 @@ private: typedef SkCodec INHERITED; }; +#endif // SkGifCodec_DEFINED diff --git a/src/codec/SkIcoCodec.h b/src/codec/SkIcoCodec.h index e8dcc83f59..f9a14eb377 100644 --- a/src/codec/SkIcoCodec.h +++ b/src/codec/SkIcoCodec.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef SkIcoCodec_DEFINED +#define SkIcoCodec_DEFINED #include "SkCodec.h" #include "SkImageInfo.h" @@ -99,3 +101,4 @@ private: typedef SkCodec INHERITED; }; +#endif // SkIcoCodec_DEFINED diff --git a/src/codec/SkPngCodec.h b/src/codec/SkPngCodec.h index 7fdec01e11..7a2ebae210 100644 --- a/src/codec/SkPngCodec.h +++ b/src/codec/SkPngCodec.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef SkPngCodec_DEFINED +#define SkPngCodec_DEFINED #include "SkCodec.h" #include "SkColorSpaceXform.h" @@ -138,3 +140,4 @@ private: typedef SkCodec INHERITED; }; +#endif // SkPngCodec_DEFINED diff --git a/src/core/SkColorSpacePriv.h b/src/core/SkColorSpacePriv.h index 26ccd5e6ca..e1b01b707f 100644 --- a/src/core/SkColorSpacePriv.h +++ b/src/core/SkColorSpacePriv.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef SkColorSpacePriv_DEFINED +#define SkColorSpacePriv_DEFINED #include @@ -192,3 +194,4 @@ static inline bool named_to_parametric(SkColorSpaceTransferFn* coeffs, return false; } } +#endif // SkColorSpacePriv_DEFINED diff --git a/src/core/SkPictureCommon.h b/src/core/SkPictureCommon.h index 51724afcb5..6f6a9f1fcf 100644 --- a/src/core/SkPictureCommon.h +++ b/src/core/SkPictureCommon.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef SkPictureCommon_DEFINED +#define SkPictureCommon_DEFINED // Some shared code used by both SkBigPicture and SkMiniPicture. // SkTextHunter -- SkRecord visitor that returns true when the op draws text. @@ -138,3 +140,4 @@ struct SkPathCounter { int fNumSlowPathsAndDashEffects; }; +#endif // SkPictureCommon_DEFINED diff --git a/src/core/SkRecordedDrawable.h b/src/core/SkRecordedDrawable.h index de1fca5233..c7ba74143e 100644 --- a/src/core/SkRecordedDrawable.h +++ b/src/core/SkRecordedDrawable.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef SkRecordedDrawable_DEFINED +#define SkRecordedDrawable_DEFINED #include "SkBBoxHierarchy.h" #include "SkDrawable.h" @@ -39,3 +41,4 @@ private: std::unique_ptr fDrawableList; const SkRect fBounds; }; +#endif // SkRecordedDrawable_DEFINED diff --git a/src/core/SkTraceEventCommon.h b/src/core/SkTraceEventCommon.h index 57f67775e8..d066d903c2 100644 --- a/src/core/SkTraceEventCommon.h +++ b/src/core/SkTraceEventCommon.h @@ -1,6 +1,8 @@ // Copyright 2015 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. +#ifndef SkTraceEventCommon_DEFINED +#define SkTraceEventCommon_DEFINED // This header file defines the set of trace_event macros without specifying // how the events actually get collected and stored. If you need to expose trace @@ -1037,3 +1039,4 @@ #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g') #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p') #define TRACE_EVENT_SCOPE_NAME_THREAD ('t') +#endif // SkTraceEventCommon_DEFINED diff --git a/src/effects/SkEmbossMask_Table.h b/src/effects/SkEmbossMask_Table.h index b7073f302b..09fc348b38 100644 --- a/src/effects/SkEmbossMask_Table.h +++ b/src/effects/SkEmbossMask_Table.h @@ -4,7 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ - +#ifndef SkEmbossMask_Table_DEFINED +#define SkEmbossMask_Table_DEFINED #include "SkTypes.h" @@ -1035,3 +1036,4 @@ static const uint16_t gInvSqrtTable[128 * 128] = { 0x00C0, 0x00C0, 0x00BF, 0x00BE, 0x00BE, 0x00BD, 0x00BC, 0x00BC, 0x00BB, 0x00BA, 0x00BA, 0x00B9, 0x00B8, 0x00B8, 0x00B7, 0x00B6 }; #define kDeltaUsedToBuildTable 32 +#endif // SkEmbossMask_Table_DEFINED diff --git a/src/images/transform_scanline.h b/src/images/transform_scanline.h index d855964989..3c754275e0 100644 --- a/src/images/transform_scanline.h +++ b/src/images/transform_scanline.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef transform_scanline_DEFINED +#define transform_scanline_DEFINED /** * Functions to transform scanlines between packed-pixel formats. @@ -271,3 +273,4 @@ static inline void transform_scanline_F16_premul_to_8888(char* SK_RESTRICT dst, p.append(SkRasterPipeline::store_8888, (void**) &dst); p.run(0, width); } +#endif // transform_scanline_DEFINED diff --git a/tests/CodecPriv.h b/tests/CodecPriv.h index 515dbdec2a..50c205c16a 100644 --- a/tests/CodecPriv.h +++ b/tests/CodecPriv.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef CodecPriv_DEFINED +#define CodecPriv_DEFINED #include "SkBitmap.h" #include "SkCodec.h" @@ -32,3 +34,4 @@ inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) { bm->rowBytes(), nullptr, colorPtr, colorCountPtr); return result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput; } +#endif // CodecPriv_DEFINED diff --git a/tests/PathOpsTSectDebug.h b/tests/PathOpsTSectDebug.h index e18e0f89e6..209152104b 100644 --- a/tests/PathOpsTSectDebug.h +++ b/tests/PathOpsTSectDebug.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef PathOpsTSectDebug_DEFINED +#define PathOpsTSectDebug_DEFINED #include "SkPathOpsTSect.h" @@ -219,3 +221,4 @@ void SkTSpan::dumpID() const { SkDebugf("%c", cE); } } +#endif // PathOpsTSectDebug_DEFINED diff --git a/tools/check-headers-self-sufficient b/tools/check-headers-self-sufficient new file mode 100755 index 0000000000..8e5ced47dd --- /dev/null +++ b/tools/check-headers-self-sufficient @@ -0,0 +1,107 @@ +#!/bin/sh + +# Copyright 2017 Google Inc. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +cd "$(dirname "$0")/.." + +compile_header() { + # test each header for self-sufficiency and idempotency. + printf '#include "%s"\n#include "%s"\n' "$1" "$1" | \ + c++ --std=c++11 \ + -Iinclude/core \ + -Iinclude/config \ + -Iinclude/android \ + -Iinclude/c \ + -Iinclude/codec \ + -Iinclude/effects \ + -Iinclude/gpu \ + -Iinclude/gpu/gl \ + -Iinclude/pathops \ + -Iinclude/ports \ + -Iinclude/private \ + -Iinclude/svg \ + -Iinclude/utils \ + -Iinclude/utils/mac \ + -Iinclude/views \ + -Iinclude/xml \ + -Isrc/codec \ + -Isrc/core \ + -Isrc/effects \ + -Isrc/effects/gradients \ + -Isrc/fonts \ + -Isrc/gpu \ + -Isrc/image \ + -Isrc/images \ + -Isrc/lazy \ + -Isrc/opts \ + -Isrc/pathops \ + -Isrc/ports \ + -Isrc/sfnt \ + -Isrc/sksl \ + -Isrc/utils \ + -Isrc/utils/win \ + -Igm \ + -Itests \ + -Itools \ + -Itools/debugger \ + -Itools/flags \ + -Itools/gpu \ + -Itools/timer \ + -Ithird_party/etc1 \ + -Ithird_party/externals/jsoncpp/include \ + -Ithird_party/externals/sfntly/cpp/src \ + -Ithird_party/externals/zlib \ + -Ithird_party/gif \ + -o /dev/null -c -x c++ - +} + +FAIL=0 +for header in $(git ls-files | grep '\.h$'); do + # The following headers don't pass this test for one reason or another. + case $header in + */osmesa_wrapper.h) continue;; + debugger/QT/*) continue;; + example/*) continue;; + experimental/*) continue;; + include/config/*) continue;; + include/core/SkPostConfig.h) continue;; + include/gpu/vk/*) continue;; + include/ports/SkFontMgr_android.h) continue;; + include/ports/SkFontMgr_fontconfig.h) continue;; + include/ports/SkTypeface_win.h) continue;; + include/private/*_impl.h) continue;; + include/utils/mac/SkCGUtils.h) continue;; + include/views/SkOSWindow_*.h) continue;; + src/c/sk_c_from_to.h) continue;; + src/codec/SkJpegDecoderMgr.h) continue;; + src/codec/SkJpegUtility.h) continue;; + src/core/*Template.h) continue;; + src/core/SkBitmapProcState_*.h) continue;; + src/core/SkFDot6Constants.h) continue;; + src/core/SkLinearBitmapPipeline.h) continue;; + src/core/SkLinearBitmapPipeline_*.h) continue;; + src/core/SkUnPreMultiplyPriv.h) continue;; + src/gpu/vk/*.h) continue;; + src/images/SkJPEGWriteUtility.h) continue;; + src/opts/*_SSE2.h) continue;; + src/opts/*_SSSE3.h) continue;; + src/opts/*_neon.h) continue;; + src/opts/*_sse.h) continue;; + src/opts/Sk4px_*.h) continue;; + src/ports/*) continue;; + src/utils/*_win.h) continue;; + src/utils/win/*) continue;; + src/views/*) continue;; + third_party/*) continue;; + tools/fiddle/*) continue;; + tools/viewer/*) continue;; + esac + if ! compile_header "$header"; then + echo "FAILURE: $header" + FAIL=1 + fi +done +exit $FAIL diff --git a/tools/skiaserve/urlhandlers/UrlHandler.h b/tools/skiaserve/urlhandlers/UrlHandler.h index e86e7fca90..95fa47603a 100644 --- a/tools/skiaserve/urlhandlers/UrlHandler.h +++ b/tools/skiaserve/urlhandlers/UrlHandler.h @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef UrlHandler_DEFINED +#define UrlHandler_DEFINED #include "SkColor.h" @@ -162,3 +164,4 @@ public: const char* upload_data, size_t* upload_data_size) override; }; +#endif // UrlHandler_DEFINED