Rakefile 5.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# Rakefile
# Copyright (C) 2018 Mike JS Choi
# Copyright (C) 2018 VLC authors and VideoLAN
# $Id$
#
# Authors: Mike JS. Choi <mkchoi212 # icloud.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
#
# ------------------------------------------------------------- Constants ------

Mike JS. Choi's avatar
Mike JS. Choi committed
24
PROJECT_IOS = 'MobileVLCKit.xcodeproj'
25
PROJECT_TV = 'MobileVLCKit.xcodeproj'
Mike JS. Choi's avatar
Mike JS. Choi committed
26
PROJECT_MAC = 'VLCKit.xcodeproj'
Mike JS. Choi's avatar
Mike JS. Choi committed
27 28

SDK_SIM_IOS = 'iphonesimulator11.3'
29
SDK_SIM_TV = 'appletvsimulator11.3'
Mike JS. Choi's avatar
Mike JS. Choi committed
30
SDK_SIM_MAC = 'macosx10.13'
Mike JS. Choi's avatar
Mike JS. Choi committed
31 32

SDK_SIM_DEST_IOS = "'platform=iOS Simulator,name=iPhone 7,OS=11.3'"
33
SDK_SIM_DEST_TV = "'platform=tvOS Simulator,name=Apple TV,OS=11.3'"
Mike JS. Choi's avatar
Mike JS. Choi committed
34
SDK_SIM_DEST_MAC = "'platform=OS X,arch=x86_64'"
35 36

SCHEME_IOS = 'MobileVLCKitTests'
37
SCHEME_IOS_DYNAMIC = 'DynamicMobileVLCKitTests'
38
SCHEME_TV = 'TVVLCKitTests'
Mike JS. Choi's avatar
Mike JS. Choi committed
39
SCHEME_MAC = 'VLCKitTests'
40 41

VLC_FLAGS_IOS = '-dva x86_64'
42
VLC_FLAGS_TV = '-st'
Mike JS. Choi's avatar
Mike JS. Choi committed
43
VLC_FLAGS_MAC = '-dxs'
44

Mike JS. Choi's avatar
Mike JS. Choi committed
45 46 47 48 49
DERIVED_DATA_PATH = 'DerivedData'
COVERAGE_REPORT_PATH = 'Tests/Coverage'

XCPRETTY = "xcpretty && exit ${PIPESTATUS[0]}"

50 51
# ----------------------------------------------------------------- Tasks ------

Mike JS. Choi's avatar
Mike JS. Choi committed
52
desc 'Build MobileVLCKit'
53
task 'build:vlckit:ios' do
Mike JS. Choi's avatar
Mike JS. Choi committed
54
  puts 'Building MobileVLCKit'
55 56 57 58 59 60 61 62 63 64 65

  plugin_file = 'Resources/MobileVLCKit/vlc-plugins-iPhone.h'
  required_dirs = ['./libvlc/vlc/install-iPhoneSimulator', './libvlc/vlc/build-iPhoneSimulator']

  if File.exist?(plugin_file) && dirs_exist?(required_dirs)
    puts 'Found pre-existing build directory. Skipping build'
  else
    sh "./compileAndBuildVLCKit.sh #{VLC_FLAGS_IOS}"
  end
end

66 67 68 69 70 71 72 73 74 75 76 77 78 79
desc 'Build TVVLCKit'
task 'build:vlckit:tv' do
  puts 'Building TVVLCKit'

  plugin_file = 'Resources/MobileVLCKit/vlc-plugins-AppleTV.xcconfig'
  required_dirs = ['./libvlc/vlc/install-AppleTVSimulator', './libvlc/vlc/build-AppleTVSimulator']

  if File.exist?(plugin_file) && dirs_exist?(required_dirs)
    puts 'Found pre-existing build directory. Skipping build'
  else
    sh "./compileAndBuildVLCKit.sh #{VLC_FLAGS_TV}"
  end
end

Mike JS. Choi's avatar
Mike JS. Choi committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93
desc 'Build VLCKit (macOS)'
task 'build:vlckit:mac' do
  puts 'Building VLCKit (macOS)'

  plugin_file = 'Resources/MobileVLCKit/vlc-plugins-MacOSX.xcconfig'
  required_dirs = ['./libvlc/vlc/install-MacOSX', './libvlc/vlc/build-MacOSX']

  if File.exist?(plugin_file) && dirs_exist?(required_dirs)
    puts 'Found pre-existing build directory. Skipping build'
  else
    sh "./compileAndBuildVLCKit.sh #{VLC_FLAGS_MAC}"
  end
end

94 95 96
desc 'Run MobileVLCKit tests'
task 'test:ios' do
  puts 'Running tests for MobileVLCKit'
Mike JS. Choi's avatar
Mike JS. Choi committed
97 98 99
  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}"
end

100 101 102 103 104 105
desc 'Run DynamicMobileVLCKit tests'
task 'test:ios_dynamic' do
  puts 'Running tests for DynamicMobileVLCKit'
  sh "xcodebuild -derivedDataPath #{DERIVED_DATA_PATH}/#{SCHEME_IOS_DYNAMIC} -project #{PROJECT_IOS} -scheme #{SCHEME_IOS_DYNAMIC} -sdk #{SDK_SIM_IOS} -destination #{SDK_SIM_DEST_IOS} -UseModernBuildSystem=NO test | #{XCPRETTY}"
end

106 107 108 109 110 111
desc 'Run TVVLCKit tests'
task 'test:tv' do
  puts 'Running tests for TVVLCKit'
  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}"
end

Mike JS. Choi's avatar
Mike JS. Choi committed
112 113 114 115
desc 'Run VLCKit tests'
task 'test:mac' do
  puts 'Running tests for VLCKit'
  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}"
Mike JS. Choi's avatar
Mike JS. Choi committed
116 117
end

118
desc 'Generate MobileVLCKit coverage reports'
Mike JS. Choi's avatar
Mike JS. Choi committed
119
task 'codecov:ios' do
120
  puts 'Generating MobileVLCKit code coverage reports'
Mike JS. Choi's avatar
Mike JS. Choi committed
121
  generate_coverage(SCHEME_IOS)
122 123
end

124 125 126 127 128 129
desc 'Generate DynamicMobileVLCKit coverage reports'
task 'codecov:ios_dynamic' do
  puts 'Generating DynamicMobileVLCKit code coverage reports'
  generate_coverage(SCHEME_IOS_DYNAMIC)
end

130 131 132 133 134 135 136
desc 'Generate TVVLCKit code coverage reports'
task 'codecov:tv' do
  puts 'Generating TVVLCKit code coverage reports'
  generate_coverage(SCHEME_TV)
end

desc 'Generate VLCKit (macOS) code coverage reports'
Mike JS. Choi's avatar
Mike JS. Choi committed
137
task 'codecov:mac' do
138
  puts 'Generating VLCKit code coverage reports'
Mike JS. Choi's avatar
Mike JS. Choi committed
139 140 141
  generate_coverage(SCHEME_MAC)
end

142 143
# ------------------------------------------------------------- Functions ------

Mike JS. Choi's avatar
Mike JS. Choi committed
144 145 146 147 148 149 150 151 152 153 154 155 156
def generate_coverage(scheme)
  report_name = "#{COVERAGE_REPORT_PATH}/#{scheme}_coverage.txt"
  scheme_derived_data = "#{DERIVED_DATA_PATH}/#{scheme}"

  if Dir.exist?(scheme_derived_data)
    sh "mkdir -p #{COVERAGE_REPORT_PATH}"
    sh "xcrun xccov view #{scheme_derived_data}/Logs/Test/*.xccovreport > #{report_name}"
    sh "cat #{report_name}"
  else
    puts "#{scheme} has not been tested yet. Please run its tests first"
  end
end

157 158 159 160 161
def dirs_exist?(directories)
  directories.each do |dir|
    return false unless Dir.exist?(dir)
  end
end