Rakefile 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # Rakefile
  2. # Copyright (C) 2018 Mike JS Choi
  3. # Copyright (C) 2018 VLC authors and VideoLAN
  4. # $Id$
  5. #
  6. # Authors: Mike JS. Choi <mkchoi212 # icloud.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify it
  9. # under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation; either version 2.1 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License
  19. # along with this program; if not, write to the Free Software Foundation,
  20. # Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  21. #
  22. # ------------------------------------------------------------- Constants ------
  23. PROJECT_IOS = 'MobileVLCKit.xcodeproj'
  24. PROJECT_TV = 'MobileVLCKit.xcodeproj'
  25. PROJECT_MAC = 'VLCKit.xcodeproj'
  26. SDK_SIM_IOS = 'iphonesimulator11.3'
  27. SDK_SIM_TV = 'appletvsimulator11.3'
  28. SDK_SIM_MAC = 'macosx10.13'
  29. SDK_SIM_DEST_IOS = "'platform=iOS Simulator,name=iPhone 7,OS=11.3'"
  30. SDK_SIM_DEST_TV = "'platform=tvOS Simulator,name=Apple TV,OS=11.3'"
  31. SDK_SIM_DEST_MAC = "'platform=OS X,arch=x86_64'"
  32. SCHEME_IOS = 'MobileVLCKitTests'
  33. SCHEME_TV = 'TVVLCKitTests'
  34. SCHEME_MAC = 'VLCKitTests'
  35. VLC_FLAGS_IOS = '-dva x86_64'
  36. VLC_FLAGS_TV = '-st'
  37. VLC_FLAGS_MAC = '-dxs'
  38. DERIVED_DATA_PATH = 'DerivedData'
  39. COVERAGE_REPORT_PATH = 'Tests/Coverage'
  40. XCPRETTY = "xcpretty && exit ${PIPESTATUS[0]}"
  41. # ----------------------------------------------------------------- Tasks ------
  42. desc 'Build MobileVLCKit'
  43. task 'build:vlckit:ios' do
  44. puts 'Building MobileVLCKit'
  45. plugin_file = 'Resources/MobileVLCKit/vlc-plugins-iPhone.h'
  46. required_dirs = ['./libvlc/vlc/install-iPhoneSimulator', './libvlc/vlc/build-iPhoneSimulator']
  47. if File.exist?(plugin_file) && dirs_exist?(required_dirs)
  48. puts 'Found pre-existing build directory. Skipping build'
  49. else
  50. sh "./compileAndBuildVLCKit.sh #{VLC_FLAGS_IOS}"
  51. end
  52. end
  53. desc 'Build TVVLCKit'
  54. task 'build:vlckit:tv' do
  55. puts 'Building TVVLCKit'
  56. plugin_file = 'Resources/MobileVLCKit/vlc-plugins-AppleTV.xcconfig'
  57. required_dirs = ['./libvlc/vlc/install-AppleTVSimulator', './libvlc/vlc/build-AppleTVSimulator']
  58. if File.exist?(plugin_file) && dirs_exist?(required_dirs)
  59. puts 'Found pre-existing build directory. Skipping build'
  60. else
  61. sh "./compileAndBuildVLCKit.sh #{VLC_FLAGS_TV}"
  62. end
  63. end
  64. desc 'Build VLCKit (macOS)'
  65. task 'build:vlckit:mac' do
  66. puts 'Building VLCKit (macOS)'
  67. plugin_file = 'Resources/MobileVLCKit/vlc-plugins-MacOSX.xcconfig'
  68. required_dirs = ['./libvlc/vlc/install-MacOSX', './libvlc/vlc/build-MacOSX']
  69. if File.exist?(plugin_file) && dirs_exist?(required_dirs)
  70. puts 'Found pre-existing build directory. Skipping build'
  71. else
  72. sh "./compileAndBuildVLCKit.sh #{VLC_FLAGS_MAC}"
  73. end
  74. end
  75. desc 'Run MobileVLCKit tests'
  76. task 'test:ios' do
  77. puts 'Running tests for MobileVLCKit'
  78. sh "xcodebuild -derivedDataPath #{DERIVED_DATA_PATH}/#{SCHEME_IOS} -project #{PROJECT_IOS} -scheme #{SCHEME_IOS} -sdk #{SDK_SIM_IOS} -destination #{SDK_SIM_DEST_IOS} test | #{XCPRETTY}"
  79. end
  80. desc 'Run TVVLCKit tests'
  81. task 'test:tv' do
  82. puts 'Running tests for TVVLCKit'
  83. sh "xcodebuild -derivedDataPath #{DERIVED_DATA_PATH}/#{SCHEME_TV} -project #{PROJECT_TV} -scheme #{SCHEME_TV} -sdk #{SDK_SIM_TV} -destination #{SDK_SIM_DEST_TV} test | #{XCPRETTY}"
  84. end
  85. desc 'Run VLCKit tests'
  86. task 'test:mac' do
  87. puts 'Running tests for VLCKit'
  88. sh "xcodebuild -derivedDataPath #{DERIVED_DATA_PATH}/#{SCHEME_MAC} -project #{PROJECT_MAC} -scheme #{SCHEME_MAC} -sdk #{SDK_SIM_MAC} -destination #{SDK_SIM_DEST_MAC} test | #{XCPRETTY}"
  89. end
  90. desc 'Generate MobileVLCKit coverage reports'
  91. task 'codecov:ios' do
  92. puts 'Generating MobileVLCKit code coverage reports'
  93. generate_coverage(SCHEME_IOS)
  94. end
  95. desc 'Generate TVVLCKit code coverage reports'
  96. task 'codecov:tv' do
  97. puts 'Generating TVVLCKit code coverage reports'
  98. generate_coverage(SCHEME_TV)
  99. end
  100. desc 'Generate VLCKit (macOS) code coverage reports'
  101. task 'codecov:mac' do
  102. puts 'Generating VLCKit code coverage reports'
  103. generate_coverage(SCHEME_MAC)
  104. end
  105. # ------------------------------------------------------------- Functions ------
  106. def generate_coverage(scheme)
  107. report_name = "#{COVERAGE_REPORT_PATH}/#{scheme}_coverage.txt"
  108. scheme_derived_data = "#{DERIVED_DATA_PATH}/#{scheme}"
  109. if Dir.exist?(scheme_derived_data)
  110. sh "mkdir -p #{COVERAGE_REPORT_PATH}"
  111. sh "xcrun xccov view #{scheme_derived_data}/Logs/Test/*.xccovreport > #{report_name}"
  112. sh "cat #{report_name}"
  113. else
  114. puts "#{scheme} has not been tested yet. Please run its tests first"
  115. end
  116. end
  117. def dirs_exist?(directories)
  118. directories.each do |dir|
  119. return false unless Dir.exist?(dir)
  120. end
  121. end