check_no_module_imports.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright 2018 Google
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Fail if any source files contain Objective-C module @imports, excluding:
  15. # * Example sources
  16. # * Sample sources
  17. options=(
  18. -n # show line numbers
  19. -I # exclude binary files
  20. '^@import'
  21. )
  22. function exit_with_error {
  23. echo "ERROR: @import statement found in the files above. Please use #import instead."
  24. exit 1
  25. }
  26. git grep "${options[@]}" \
  27. -- ':(exclude,glob)**/Example/**' ':(exclude,glob)**/Sample/**' \
  28. ':(exclude)FirebaseAuth/Sources/Backend/FIRAuthBackend.m' \
  29. ':(exclude)FirebaseCore/Sources/Private/FirebaseCoreInternal.h' \
  30. ':(exclude)FirebaseInstallations/Source/Library/Private/FirebaseInstallationsInternal.h' \
  31. ':(exclude,glob)FirebaseStorage/**' \
  32. ':(exclude)Functions/FirebaseFunctions/FIRFunctions.m' \
  33. ':(exclude)GoogleUtilities/NSData+zlib/Private/GULNSDataInternal.h' \
  34. ':(exclude)GoogleUtilities/Logger/Private/GULLogger.h' \
  35. ':(exclude)HeadersImports.md' && exit_with_error
  36. # Tests are under the Example directory, so we have to separately grep them for
  37. # @import statements (otherwise they'd be excluded).
  38. git grep "${options[@]}" \
  39. -- ':(glob)**/Tests/**' ':(glob)**/TestUtils/**' ':(glob)**/IntegrationTests/**' && \
  40. exit_with_error
  41. # We need to explicitly exit 0, since we expect `git grep` to return an error
  42. # if no @import calls are found.
  43. exit 0