Rakefile 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_MAC = 'VLCKit.xcodeproj'
  25. SDK_SIM_IOS = 'iphonesimulator11.3'
  26. SDK_SIM_MAC = 'macosx10.13'
  27. SDK_SIM_DEST_IOS = "'platform=iOS Simulator,name=iPhone 7,OS=11.3'"
  28. SDK_SIM_DEST_MAC = "'platform=OS X,arch=x86_64'"
  29. SCHEME_IOS = 'MobileVLCKitTests'
  30. SCHEME_MAC = 'VLCKitTests'
  31. VLC_FLAGS_IOS = '-dva x86_64'
  32. VLC_FLAGS_MAC = '-dxs'
  33. DERIVED_DATA_PATH = 'DerivedData'
  34. COVERAGE_REPORT_PATH = 'Tests/Coverage'
  35. XCPRETTY = "xcpretty && exit ${PIPESTATUS[0]}"
  36. # ----------------------------------------------------------------- Tasks ------
  37. desc 'Build MobileVLCKit'
  38. task 'build:vlckit:ios' do
  39. puts 'Building MobileVLCKit'
  40. plugin_file = 'Resources/MobileVLCKit/vlc-plugins-iPhone.h'
  41. required_dirs = ['./libvlc/vlc/install-iPhoneSimulator', './libvlc/vlc/build-iPhoneSimulator']
  42. if File.exist?(plugin_file) && dirs_exist?(required_dirs)
  43. puts 'Found pre-existing build directory. Skipping build'
  44. else
  45. sh "./compileAndBuildVLCKit.sh #{VLC_FLAGS_IOS}"
  46. end
  47. end
  48. desc 'Build VLCKit (macOS)'
  49. task 'build:vlckit:mac' do
  50. puts 'Building VLCKit (macOS)'
  51. plugin_file = 'Resources/MobileVLCKit/vlc-plugins-MacOSX.xcconfig'
  52. required_dirs = ['./libvlc/vlc/install-MacOSX', './libvlc/vlc/build-MacOSX']
  53. if File.exist?(plugin_file) && dirs_exist?(required_dirs)
  54. puts 'Found pre-existing build directory. Skipping build'
  55. else
  56. sh "./compileAndBuildVLCKit.sh #{VLC_FLAGS_MAC}"
  57. end
  58. end
  59. desc 'Run MobileVLCKit tests'
  60. task 'test:ios' do
  61. puts 'Running tests for MobileVLCKit'
  62. 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}"
  63. end
  64. desc 'Run VLCKit tests'
  65. task 'test:mac' do
  66. puts 'Running tests for VLCKit'
  67. 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}"
  68. end
  69. desc 'Generate code coverage reports (MobileVLCKit)'
  70. task 'codecov:ios' do
  71. puts 'Generating code coverage reports (MobileVLCKit)'
  72. generate_coverage(SCHEME_IOS)
  73. end
  74. desc 'Generate code coverage reports (VLCKit macOS)'
  75. task 'codecov:mac' do
  76. puts 'Generating code coverage reports (VLCKit macOS)'
  77. generate_coverage(SCHEME_MAC)
  78. end
  79. # ------------------------------------------------------------- Functions ------
  80. def generate_coverage(scheme)
  81. report_name = "#{COVERAGE_REPORT_PATH}/#{scheme}_coverage.txt"
  82. scheme_derived_data = "#{DERIVED_DATA_PATH}/#{scheme}"
  83. if Dir.exist?(scheme_derived_data)
  84. sh "mkdir -p #{COVERAGE_REPORT_PATH}"
  85. sh "xcrun xccov view #{scheme_derived_data}/Logs/Test/*.xccovreport > #{report_name}"
  86. sh "cat #{report_name}"
  87. else
  88. puts "#{scheme} has not been tested yet. Please run its tests first"
  89. end
  90. end
  91. def dirs_exist?(directories)
  92. directories.each do |dir|
  93. return false unless Dir.exist?(dir)
  94. end
  95. end