Skip to content

Commit

Permalink
add public headers checker
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-stripe committed Jul 22, 2016
1 parent 9a667a7 commit 6634e8e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -18,6 +18,7 @@ before_install:
script:
- open -a "simulator" --args -CurrentDeviceUDID $SIMULATOR_ID
- "./ci_scripts/check_version.rb"
- "./ci_scripts/check_public_headers.rb"
- '[ "$TEST_TYPE" != lint ] || ./ci_scripts/check_fauxpas.sh'
- '[ "$TEST_TYPE" != tests ] || ./ci_scripts/run_tests.sh'
- '[ "$TEST_TYPE" != installation_cocoapods ] || ./Tests/installation_tests/cocoapods/without_frameworks/test.sh'
Expand Down
3 changes: 3 additions & 0 deletions Stripe/PublicHeaders/Stripe.h
Expand Up @@ -34,3 +34,6 @@
#import "UINavigationBar+Stripe_Theme.h"
#import "STPUserInformation.h"
#import "STPImageLibrary.h"
#import "STPPaymentConfiguration.h"
#import "STPAPIResponseDecodable.h"
#import "STPFormEncodable.h"
46 changes: 46 additions & 0 deletions ci_scripts/check_public_headers.rb
@@ -0,0 +1,46 @@
#!/usr/bin/env ruby

begin
gem "xcodeproj"
rescue LoadError
system("gem install xcodeproj")
Gem.clear_paths
end

require 'xcodeproj'

puts "Checking headers..."

contents_of_stripe_dot_h = (File.readlines("Stripe/PublicHeaders/Stripe.h").map do |line|
/\#import \"(.*?)\"\n/.match(line)
end.compact.map do |match|
match.captures.first
end + ["Stripe.h"]).sort
contents_of_public_headers_dir = Dir.glob("Stripe/PublicHeaders/*.h").map { |h| File.basename(h) }.sort

if contents_of_public_headers_dir != contents_of_stripe_dot_h
likely_culprits = ([contents_of_stripe_dot_h - contents_of_public_headers_dir] + [contents_of_public_headers_dir - contents_of_stripe_dot_h]).uniq
abort("The contents of Stripe/PublicHeaders do not match what is #imported in Stripe/PublicHeaders/Stripe.h. Likely culprits: #{likely_culprits}.")
end

dynamic_framework_target = Xcodeproj::Project.open('Stripe.xcodeproj').targets.select { |t| t.name == 'StripeiOS' }.first
dynamic_framework_public_headers = dynamic_framework_target.headers_build_phase.files.select do |f|
f.settings && f.settings["ATTRIBUTES"] == ["Public"]
end.map(&:display_name).sort

if contents_of_public_headers_dir != dynamic_framework_public_headers
likely_culprits = ([dynamic_framework_public_headers - contents_of_public_headers_dir] + [contents_of_public_headers_dir - dynamic_framework_public_headers]).uniq
abort("The contents of Stripe/PublicHeaders do not match the public headers of the StripeiOS target. Likely culprits: #{likely_culprits}.")
end

static_library_target = Xcodeproj::Project.open('Stripe.xcodeproj').targets.select { |t| t.name == 'StripeiOSStatic' }.first
static_library_public_headers = static_library_target.headers_build_phase.files.select do |f|
f.settings && f.settings["ATTRIBUTES"] == ["Public"]
end.map(&:display_name).sort

if contents_of_public_headers_dir != static_library_public_headers
likely_culprits = ([static_library_public_headers - contents_of_public_headers_dir] + [contents_of_public_headers_dir - static_library_public_headers]).uniq
abort("The contents of Stripe/PublicHeaders do not match the public headers of the StripeiOSStatic target. Likely culprits: #{likely_culprits}.")
end

puts "Headers look good!"

0 comments on commit 6634e8e

Please sign in to comment.