Rakefile 4.85 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_TV = 'TVVLCKitTests'
Mike JS. Choi's avatar
Mike JS. Choi committed
38
SCHEME_MAC = 'VLCKitTests'
39 40

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

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

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

49 50
# ----------------------------------------------------------------- Tasks ------

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

  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

65 66 67 68 69 70 71 72 73 74 75 76 77 78
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
79 80 81 82 83 84 85 86 87 88 89 90 91 92
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

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

99 100 101 102 103 104
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
105 106 107 108
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
109 110
end

111
desc 'Generate MobileVLCKit coverage reports'
Mike JS. Choi's avatar
Mike JS. Choi committed
112
task 'codecov:ios' do
113
  puts 'Generating MobileVLCKit code coverage reports'
Mike JS. Choi's avatar
Mike JS. Choi committed
114
  generate_coverage(SCHEME_IOS)
115 116
end

117 118 119 120 121 122 123
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
124
task 'codecov:mac' do
125
  puts 'Generating VLCKit code coverage reports'
Mike JS. Choi's avatar
Mike JS. Choi committed
126 127 128
  generate_coverage(SCHEME_MAC)
end

129 130
# ------------------------------------------------------------- Functions ------

Mike JS. Choi's avatar
Mike JS. Choi committed
131 132 133 134 135 136 137 138 139 140 141 142 143
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

144 145 146 147 148
def dirs_exist?(directories)
  directories.each do |dir|
    return false unless Dir.exist?(dir)
  end
end