Rakefile 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. #
  2. # Copyright (c) 2008-2017 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. require 'pathname'
  23. require 'json'
  24. require 'yaml'
  25. ### Tasks for general users ###
  26. # Usage: rake scaffolding dir=/path/to/new/project/root [project=Scaffolding] [target=Main]
  27. desc 'Create a new project using Urho3D as external library'
  28. task :scaffolding do
  29. abort 'Usage: rake scaffolding dir=/path/to/new/project/root [project=Scaffolding] [target=Main]' unless ENV['dir']
  30. project = ENV['project'] || 'Scaffolding'
  31. target = ENV['target'] || 'Main'
  32. abs_path = scaffolding ENV['dir'], project, target
  33. puts "\nNew project created in #{abs_path}.\n\n"
  34. puts "In order to configure and generate your project build tree you may need to first set"
  35. puts "'URHO3D_HOME' environment variable or use 'URHO3D_HOME' build option to point to the"
  36. puts "Urho3D project build tree or custom Urho3D SDK installation location.\n\n"
  37. puts "Please see https://urho3d.github.io/documentation/HEAD/_using_library.html for more detail.\nFor example:\n\n"
  38. puts "$ cd #{abs_path}\n$ rake cmake URHO3D_HOME=/path/to/Urho3D/build-tree\n$ rake make\n\n"
  39. end
  40. # Usage: rake cmake [<generator>] [<platform>] [<option>=<value> [<option>=<value>]] [[<platform>_]build_tree=/path/to/build-tree] [fix_scm]
  41. # e.g.: rake cmake clean android; or rake cmake android URHO3D_LIB_TYPE=SHARED; or rake cmake ios URHO3D_LUA=1 build_tree=~/ios-Build
  42. #
  43. # To avoid repeating the customized build tree locations, you can set and export them as environment variables.
  44. # e.g.: export native_build_tree=~/custom-native-Build android_build_tree=~/custom-android-Build mingw_build_tree=~/custom-mingw-Build rpi_build_tree=~/custom-rpi-Build
  45. # rake cmake rpi URHO3D_LUAJIT=1 URHO3D_LUAJIT_AMALG=1 && rake make rpi
  46. # The RPI build tree will be generated in the ~/custom-rpi-Build and then build from there
  47. desc 'Invoke one of the build scripts with the build tree location predetermined based on the target platform'
  48. task :cmake do
  49. script = 'cmake_generic'
  50. platform = 'native'
  51. build_options = ''
  52. # TODO: Need to find a way to automatically populate the array with all the Urho3D supported build options, at the moment it only contains those being used in CI
  53. ['URHO3D_64BIT', 'URHO3D_LIB_TYPE', 'URHO3D_STATIC_RUNTIME', 'URHO3D_PCH', 'URHO3D_BINDINGS', 'URHO3D_OPENGL', 'URHO3D_D3D11', 'URHO3D_TESTING', 'URHO3D_TEST_TIMEOUT', 'URHO3D_UPDATE_SOURCE_TREE', 'URHO3D_TOOLS', 'URHO3D_DEPLOYMENT_TARGET', 'URHO3D_USE_LIB64_RPM', 'CMAKE_BUILD_TYPE', 'CMAKE_OSX_DEPLOYMENT_TARGET', 'IOS', 'IPHONEOS_DEPLOYMENT_TARGET', 'TVOS', 'APPLETVOS_DEPLOYMENT_TARGET', 'WIN32', 'MINGW', 'DIRECTX_INC_SEARCH_PATHS', 'DIRECTX_LIB_SEARCH_PATHS', 'ANDROID', 'ANDROID_ABI', 'ANDROID_NATIVE_API_LEVEL', 'ANDROID_TOOLCHAIN_NAME', 'RPI', 'RPI_ABI', 'ARM', 'ARM_ABI_FLAGS', 'WEB', 'EMSCRIPTEN_SHARE_DATA', 'EMSCRIPTEN_WASM', 'EMSCRIPTEN_EMRUN_BROWSER'].each { |var|
  54. ARGV << "#{var}=\"#{ENV[var]}\"" if ENV[var] && !ARGV.find { |arg| /#{var}=/ =~ arg }
  55. }
  56. ARGV.each { |option|
  57. task option.to_sym do ; end; Rake::Task[option].clear # No-op hack
  58. case option
  59. when 'cmake', 'generic'
  60. # do nothing
  61. when 'clean', 'codeblocks', 'codelite', 'eclipse', 'ninja', 'vs2008', 'vs2010', 'vs2012', 'vs2013', 'vs2015', 'xcode'
  62. script = "cmake_#{option}" unless script == 'cmake_clean'
  63. when 'android', 'arm', 'ios', 'tvos', 'mingw', 'rpi', 'web'
  64. platform = option
  65. build_options = "#{build_options} -D#{option == 'mingw' ? 'WIN32' : option.upcase}=1" unless script == 'cmake_clean'
  66. script = 'cmake_xcode' if /(?:i|tv)os/ =~ option && script != 'cmake_clean'
  67. script = 'cmake_mingw' if option == 'mingw' && ENV['OS'] && script != 'cmake_clean'
  68. when 'fix_scm'
  69. build_options = "#{build_options} --fix-scm" if script == 'cmake_eclipse'
  70. else
  71. build_options = "#{build_options} -D#{option}" unless /build_tree=.*/ =~ option || script == 'cmake_clean'
  72. end
  73. }
  74. build_tree = ENV["#{platform}_build_tree"] || ENV['build_tree'] || "../#{platform}-Build"
  75. if ENV['OS']
  76. # CMake claims mingw32-make does not build correctly with MSYS shell in the PATH env-var and prevents build tree generation if so
  77. # Our CI on Windows host requires MSYS shell, so we cannot just simply remove it from the PATH globally
  78. # Instead, we modify the PATH env-var locally here just before invoking the CMake generator
  79. ENV['PATH'] = ENV['PATH'].gsub /Git\\usr\\bin/, 'GoAway'
  80. else
  81. ccache_envvar = ENV['CCACHE_SLOPPINESS'] ? '' : 'CCACHE_SLOPPINESS=pch_defines,time_macros' # Only attempt to do the right thing when user hasn't done it
  82. ccache_envvar = "#{ccache_envvar} CCACHE_COMPRESS=1" unless ENV['CCACHE_COMPRESS']
  83. end
  84. system "#{ccache_envvar} ./#{script}#{ENV['OS'] ? '.bat' : '.sh'} \"#{build_tree}\" #{build_options}" or abort
  85. end
  86. # Usage: rake make [<platform>] [<option>=<value> [<option>=<value>]] [[<platform>_]build_tree=/path/to/build-tree] [numjobs=n] [clean_first] [unfilter]
  87. # e.g.: rake make android; or rake make android doc; or rake make ios config=Debug sdk=iphonesimulator build_tree=~/ios-Build
  88. desc 'Build the generated project in its corresponding build tree'
  89. task :make do
  90. numjobs = ENV['numjobs'] || ''
  91. platform = 'native'
  92. cmake_build_options = ''
  93. build_options = ''
  94. unfilter = false
  95. ['config', 'target', 'sdk', 'ARCHS', 'ARGS', 'unfilter', 'verbosity'].each { |var|
  96. ARGV << "#{var}=\"#{ENV[var]}\"" if ENV[var] && !ARGV.find { |arg| /#{var}=/ =~ arg }
  97. }
  98. ARGV.each { |option|
  99. task option.to_sym do ; end; Rake::Task[option].clear # No-op hack
  100. case option
  101. when 'codeblocks', 'codelite', 'eclipse', 'generic', 'make', 'ninja', 'vs2008', 'vs2010', 'vs2012', 'vs2013', 'vs2015', 'xcode'
  102. # do nothing
  103. when 'android', 'arm', 'ios', 'tvos', 'mingw', 'rpi', 'web'
  104. platform = option
  105. when 'clean_first'
  106. cmake_build_options = "#{cmake_build_options} --clean-first"
  107. when 'unfilter'
  108. unfilter = true
  109. else
  110. if /(?:config|target)=.*/ =~ option
  111. cmake_build_options = "#{cmake_build_options} --#{option.gsub(/=/, ' ')}"
  112. elsif /(?:ARCHS|ARGS)=.*/ =~ option
  113. # The ARCHS option is only applicable for xcodebuild, useful to specify a non-default arch to build when in Debug build configuration where ONLY_ACTIVE_ARCH is set to YES
  114. # The ARGS option is only applicable for make, useful to pass extra arguments while building a specific target, e.g. ARGS=-VV when the target is 'test' to turn on extra verbose mode
  115. build_options = "#{build_options} #{option}"
  116. elsif /unfilter=\W*?(?<unfilter_value>\w+)/ =~ option
  117. unfilter = !(/(?:true|yes|1)/i =~ unfilter_value).nil?
  118. elsif /verbosity=.*/ =~ option
  119. # The verbosity option is only applicable for msbuild when building RUN_TESTS, useful to specify the verbosity of the test output
  120. if ARGV.include?('target=RUN_TESTS')
  121. build_options = "#{build_options} /#{option.gsub(/=/, ':')}"
  122. unfilter = true
  123. end
  124. elsif /(?:build_tree|numjobs)=.*/ !~ option
  125. build_options = "#{build_options} #{/=/ =~ option ? '-' + option.gsub(/=/, ' ') : option}"
  126. end
  127. end
  128. }
  129. build_tree = ENV["#{platform}_build_tree"] || ENV['build_tree'] || "../#{platform}-Build"
  130. if ENV['OS']
  131. # While calling mingw-32-make itself does not require the PATH to be altered (as long as it is not inside an MSYS shell),
  132. # we have to do it again here because our build system invokes CMake internally to generate things on-the-fly as part of the build process
  133. ENV['PATH'] = ENV['PATH'].gsub /Git\\usr\\bin/, 'GoAway'
  134. else
  135. ccache_envvar = ENV['CCACHE_SLOPPINESS'] ? '' : 'CCACHE_SLOPPINESS=pch_defines,time_macros' # Only attempt to do the right thing when user hasn't done it
  136. ccache_envvar = "#{ccache_envvar} CCACHE_COMPRESS=1" unless ENV['CCACHE_COMPRESS']
  137. end
  138. if !Dir.glob("#{build_tree}/*.xcodeproj").empty?
  139. # xcodebuild
  140. if !numjobs.empty?
  141. build_options = "-jobs #{numjobs}#{build_options}"
  142. end
  143. filter = !unfilter && !ARGV.include?('target=RUN_TESTS') && system('xcpretty -v >/dev/null 2>&1') ? '|xcpretty -c && exit ${PIPESTATUS[0]}' : ''
  144. elsif !Dir.glob("#{build_tree}\\*.sln".gsub(/\\/, '/')).empty?
  145. # msbuild
  146. numjobs = ":#{numjobs}" unless numjobs.empty?
  147. build_options = "/maxcpucount#{numjobs}#{build_options}"
  148. filter = unfilter ? '' : '/nologo /verbosity:minimal'
  149. filter = filter + ' /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"' if ENV['APPVEYOR']
  150. elsif !Dir.glob("#{build_tree}/*.ninja").empty?
  151. # ninja
  152. if !numjobs.empty?
  153. build_options = "-j#{numjobs}#{build_options}"
  154. end
  155. filter = ''
  156. else
  157. # make
  158. if numjobs.empty?
  159. case RUBY_PLATFORM
  160. when /linux/
  161. numjobs = (platform == 'web' ? `grep 'core id' /proc/cpuinfo |sort |uniq |wc -l` : `grep -c processor /proc/cpuinfo`).chomp
  162. when /darwin/
  163. numjobs = `sysctl -n hw.#{platform == 'web' ? 'physical' : 'logical'}cpu`.chomp
  164. when /win32|mingw|mswin/
  165. require 'win32ole'
  166. WIN32OLE.connect('winmgmts://').ExecQuery("select NumberOf#{platform == 'web' ? '' : 'Logical'}Processors from Win32_ComputerSystem").each { |out| numjobs = platform == 'web' ? out.NumberOfProcessors : out.NumberOfLogicalProcessors }
  167. else
  168. numjobs = 1
  169. end
  170. end
  171. build_options = "-j#{numjobs}#{build_options}"
  172. filter = ''
  173. end
  174. system "cd \"#{build_tree}\" && #{ccache_envvar} cmake --build . #{cmake_build_options} -- #{build_options} #{filter}" or abort
  175. end
  176. # Usage: rake android [parameter='--es pickedLibrary Urho3DPlayer:Scripts/NinjaSnowWar.as'] [intent=.SampleLauncher] [package=com.github.urho3d] [success_indicator='Initialized engine'] [payload='sleep 30'] [api=21] [abi=armeabi-v7a] [avd=test_#{api}_#{abi}] [retries=10] [retry_interval=10] [install]
  177. desc 'Test run APK in Android (virtual) device, default to Urho3D Samples APK if no parameter is given'
  178. task :android do
  179. parameter = ENV['parameter'] || '--es pickedLibrary Urho3DPlayer:Scripts/NinjaSnowWar.as'
  180. intent = ENV['intent'] || '.SampleLauncher'
  181. package = ENV['package'] || 'com.github.urho3d'
  182. success_indicator = ENV['success_indicator'] || 'Initialized engine'
  183. payload = ENV['payload'] || 'sleep 30'
  184. api = ENV['api'] || 21
  185. abi = ENV['abi'] || 'armeabi-v7a'
  186. avd = ENV['avd'] || "test_#{api}_#{abi}"
  187. retries = ENV['retries'] || 10 # minutes
  188. retry_interval = ENV['retry_interval'] || 10 # seconds
  189. build_tree = ENV['android_build_tree'] || ENV['build_tree'] || '../android-Build'
  190. install = false
  191. ARGV.each { |option|
  192. task option.to_sym do ; end; Rake::Task[option].clear # No-op hack
  193. case option
  194. when 'install'
  195. install = true
  196. end
  197. }
  198. android_prepare_device api, abi, avd or abort 'Failed to prepare Android (virtual) device for test run'
  199. if install
  200. system 'rake make android' or abort 'Failed to build shared library using Android NDK'
  201. Dir.chdir build_tree do
  202. system 'android update project -p .' unless File.exist? 'local.properties'
  203. system 'ant debug' or abort 'Failed to generate APK using Android SDK'
  204. end
  205. end
  206. android_wait_for_device retries, retry_interval or abort 'Failed to start Android (virtual) device'
  207. if install
  208. system "cd \"#{build_tree}\" && ant -Dadb.device.arg='-s #{$specific_device}' installd" or abort 'Failed to install APK'
  209. end
  210. android_test_run parameter, intent, package, success_indicator, payload or abort "Failed to test run #{package}/#{intent}"
  211. end
  212. ### Tasks for Urho3D maintainers ###
  213. # Usage: rake git remote_add|sync|subtree
  214. desc 'Collections of convenience git commands, multiple git commands may be executed in one rake command'
  215. task :git do
  216. success = true
  217. consumed = false
  218. ARGV.each_with_index { |command, index|
  219. task command.to_sym do ; end; Rake::Task[command].clear # No-op hack
  220. next if consumed
  221. case command
  222. when 'remote_add', 'sync', 'subtree'
  223. success = system "rake git_#{ARGV[index, ARGV.length - index].delete_if { |arg| /=/ =~ arg }.join ' '}"
  224. consumed = true
  225. else
  226. abort 'Usage: rake git remote_add|sync|subtree' unless command == 'git' && ARGV.length > 1
  227. end
  228. }
  229. abort unless success
  230. end
  231. # Usage: rake git remote_add [remote=<local-name>] url=<remote-url>'
  232. desc 'Add a new remote and configure it so that its tags will be fetched into a unique namespace'
  233. task :git_remote_add do
  234. abort 'Usage: rake git remote_add [remote=<name>] url=<remote-url>' unless ENV['url']
  235. remote = ENV['remote'] || /\/(.*?)\.git/.match(ENV['url'])[1]
  236. system "git remote add #{remote} #{ENV['url']} && git config --add remote.#{remote}.fetch +refs/tags/*:refs/tags/#{remote}/* && git config remote.#{remote}.tagopt --no-tags && git fetch #{remote}" or abort
  237. end
  238. # Usage: rake git sync [master=master] [upstream=upstream]
  239. desc "Fetch and merge an upstream's remote branch to a fork's local branch then pushing the local branch to the fork's corresponding remote branch"
  240. task :git_sync do
  241. master = ENV['master'] || 'master'
  242. upstream = ENV['upstream'] || 'upstream'
  243. system "git fetch #{upstream} && git checkout #{master} && git merge -m 'Sync at #{Time.now.localtime}.' #{upstream}/#{master} && git push && git checkout -" or abort
  244. end
  245. # Usage: rake git subtree split|rebase|add|push|pull
  246. desc 'Misc. sub-commands for git subtree operations'
  247. task :git_subtree do
  248. ARGV.each { |subcommand|
  249. task subcommand.to_sym do ; end; Rake::Task[subcommand].clear # No-op hack
  250. case subcommand
  251. when 'split'
  252. abort 'Usage: rake git subtree split subdir=</path/to/subdir/to/be/split> [split_branch=<name>]' unless ENV['subdir']
  253. ENV['split_branch'] = "#{Pathname.new(ENV['subdir']).basename}-split" unless ENV['split_branch']
  254. system "git subtree split --prefix #{ENV['subdir']} -b #{ENV['split_branch']}" or abort
  255. when 'rebase'
  256. abort 'Usage: rake git subtree rebase baseline=<commit|branch|tag> split_branch=<name>' unless ENV['baseline'] && ENV['split_branch']
  257. ENV['rebased_branch'] = "#{Pathname.new(ENV['baseline']).basename}-#{ENV['rebased_branch_suffix'] || 'modified-for-urho3d'}"
  258. head = `git log --pretty=format:'%H' #{ENV['split_branch']} |head -1`.chomp
  259. tail = `git log --reverse --pretty=format:'%H' #{ENV['split_branch']} |head -1`.chomp
  260. system "git rebase --onto #{ENV['baseline']} #{tail} #{head} && git checkout -b #{ENV['rebased_branch']}" or abort "After resolving all the conflicts, issue this command manually:\ngit checkout -b #{ENV['rebased_branch']}"
  261. when 'add'
  262. abort 'Usage: rake git subtree add subdir=</path/to/subdir/to/be/split> remote=<name> baseline=<commit|branch|tag>' unless ENV['subdir'] && ENV['remote'] && ENV['baseline']
  263. ENV['rebased_branch'] = "#{Pathname.new(ENV['baseline']).basename}-#{ENV['rebased_branch_suffix'] || 'modified-for-urho3d'}"
  264. system "git push -u #{ENV['remote']} #{ENV['rebased_branch']} && git rm -r #{ENV['subdir']} && git commit -qm 'Replace #{ENV['subdir']} subdirectory with subtree.' && git subtree add --prefix #{ENV['subdir']} #{ENV['remote']} #{ENV['rebased_branch']} --squash" or abort
  265. when 'push'
  266. abort 'Usage: rake git subtree push subdir=</path/to/subdir/to/be/split> remote=<name> baseline=<commit|branch|tag>' unless ENV['subdir'] && ENV['remote'] && ENV['baseline']
  267. ENV['rebased_branch'] = "#{Pathname.new(ENV['baseline']).basename}-#{ENV['rebased_branch_suffix'] || 'modified-for-urho3d'}"
  268. system "git subtree push --prefix #{ENV['subdir']} #{ENV['remote']} #{ENV['rebased_branch']}" or abort
  269. when 'pull'
  270. abort 'Usage: rake git subtree pull subdir=</path/to/subdir/to/be/split> remote=<name> baseline=<commit|branch|tag>' unless ENV['subdir'] && ENV['remote'] && ENV['baseline']
  271. ENV['rebased_branch'] = "#{Pathname.new(ENV['baseline']).basename}-#{ENV['rebased_branch_suffix'] || 'modified-for-urho3d'}"
  272. system "git subtree pull --prefix #{ENV['subdir']} #{ENV['remote']} #{ENV['rebased_branch']} --squash" or abort
  273. else
  274. abort 'Usage: rake git subtree split|rebase|add|push|pull' unless subcommand == 'git_subtree' && ARGV.length > 1
  275. end
  276. }
  277. end
  278. ### Tasks for CI builds and tests ###
  279. # Usage: NOT intended to be used manually
  280. desc 'Build and run the Annotate tool (temporary)'
  281. task :ci_annotate do
  282. system 'rake cmake URHO3D_CLANG_TOOLS=1 && rake make annotate' or abort 'Failed to annotate'
  283. system "git config user.name $GIT_NAME && git config user.email $GIT_EMAIL && git remote set-url --push origin https://[email protected]/$TRAVIS_REPO_SLUG.git && if git fetch origin clang-tools:clang-tools 2>/dev/null; then git push -qf origin --delete clang-tools; fi && git checkout -B clang-tools && git stash -q && git reset --hard HEAD~ && git stash pop -q && sed -i \"s/SF_DEFAULT/URHO3D_PCH=0 URHO3D_BINDINGS=1 SF_DEFAULT/g\" .travis.yml && git add -A .travis.yml Source/Urho3D && if git commit -qm 'Result of Annotator tool. [skip appveyor] [ci only: clang-tools]'; then git push -q -u origin clang-tools >/dev/null 2>&1; fi" or abort 'Failed to push clang-tools branch'
  284. end
  285. # Usage: NOT intended to be used manually
  286. desc 'Push the generated binding source files to clang-tools branch (temporary)'
  287. task :ci_push_bindings do
  288. abort "Skipped pushing to #{ENV['TRAVIS_BRANCH']} branch due to moving HEAD" unless `git fetch -qf origin #{ENV['TRAVIS_PULL_REQUEST'] == 'false' ? ENV['TRAVIS_BRANCH'] : %Q{+refs/pull/#{ENV['TRAVIS_PULL_REQUEST']}/head'}}; git log -1 --pretty=format:'%H' FETCH_HEAD` == ENV['TRAVIS_COMMIT']
  289. system "rm -rf fastcomp-clang && git config user.name $GIT_NAME && git config user.email $GIT_EMAIL && git remote set-url --push origin https://[email protected]/$TRAVIS_REPO_SLUG.git && git add -A Source/Urho3D && if git commit -qm 'Result of AutoBinder tool. [ci skip]'; then git push -q origin HEAD:#{ENV['TRAVIS_BRANCH']} >/dev/null 2>&1; fi" or abort "Failed to push #{ENV['TRAVIS_BRANCH']} branch"
  290. end
  291. # Usage: NOT intended to be used manually
  292. desc 'Configure, build, and test Urho3D project'
  293. task :ci do
  294. next if timeup # Measure the VM overhead
  295. # Skip if only performing CI for selected branches and the current branch is not in the list
  296. unless ENV['RELEASE_TAG']
  297. next if ENV['TRAVIS'] && /\[skip travis\]/ =~ ENV['COMMIT_MESSAGE'] # For feature parity with AppVeyor's [skip appveyor]
  298. matched = /\[ci only:(.*?)\]/.match(ENV['COMMIT_MESSAGE'])
  299. next if matched && !matched[1].split(/[ ,]/).reject!(&:empty?).map { |i| /#{i}/ =~ (ENV['TRAVIS_BRANCH'] || ENV['APPVEYOR_REPO_BRANCH']) }.any?
  300. end
  301. # Obtain our custom data, if any
  302. if ENV['APPVEYOR']
  303. # AppVeyor does not provide job number environment variable in the same semantics as TRAVIS_JOB_NUMBER nor it supports custom data in its .appveyor.yml document
  304. if ENV['included_sample'] || ENV['excluded_sample'] # Inclusion has higher precedence
  305. pairs = (ENV['included_sample'] || ENV['excluded_sample']).split
  306. samples = pairs.pop.split ','
  307. matched = true
  308. pairs.each { |pair|
  309. kv = pair.split '='
  310. matched = false if ENV[kv.first] != kv.last
  311. }
  312. samples.each { |name| ENV["#{ENV['included_sample'] ? 'INCLUDED' : 'EXCLUDED'}_SAMPLE_#{name}"] = '1' } if matched
  313. end
  314. else
  315. data = YAML::load(File.open('.travis.yml'))['data']
  316. data['excluded_sample']["##{ENV['TRAVIS_JOB_NUMBER'].split('.').last}"].each { |name| ENV["EXCLUDED_SAMPLE_#{name}"] = '1' } if data && data['excluded_sample'] && data['excluded_sample']["##{ENV['TRAVIS_JOB_NUMBER'].split('.').last}"]
  317. end
  318. # Unshallow the clone's history when necessary
  319. if ENV['CI'] && ENV['PACKAGE_UPLOAD'] && !ENV['RELEASE_TAG']
  320. system 'git fetch --unshallow' or abort 'Failed to unshallow cloned repository'
  321. puts; $stdout.flush
  322. end
  323. # CMake/Emscripten toolchain file does not show this information yet
  324. if ENV['WEB']
  325. system 'clang --version && emcc --version' or abort 'Failed to find Emscripten compiler toolchain'
  326. end
  327. # Show CMake version
  328. system 'cmake --version' or abort 'Failed to find CMake'
  329. puts; $stdout.flush
  330. # Using out-of-source build tree when using Travis-CI; 'build_tree' environment variable is already set when on AppVeyor
  331. ENV['build_tree'] = '../Build' unless ENV['APPVEYOR']
  332. # Always use a same build configuration to keep ccache's cache size small; single-config generator needs the option when configuring, while multi-config when building
  333. ENV[ENV['XCODE'] ? 'config' : 'CMAKE_BUILD_TYPE'] = 'Release' if ENV['USE_CCACHE']
  334. # Currently we don't have the infra to test run all the platforms; also skip when doing packaging build due to time constraint
  335. ENV['URHO3D_TESTING'] = '1' if (((ENV['LINUX'] && !ENV['URHO3D_64BIT']) || (ENV['OSX'] && !ENV['IOS'] && !ENV['TVOS']) || ENV['APPVEYOR']) && !ENV['PACKAGE_UPLOAD']) || ENV['WEB']
  336. # When not explicitly specified then use generic generator
  337. generator = ENV['XCODE'] ? 'xcode' : (ENV['APPVEYOR'] && !ENV['MINGW'] ? 'vs2015' : '')
  338. # LuaJIT on MinGW build is not possible on Travis-CI with Ubuntu 14.04 LTS still as its GCC cross-compiler does not have native exception handling
  339. # LuaJIT on Web platform is not possible
  340. jit = (ENV['WIN32'] && ENV['TRAVIS']) || ENV['WEB'] ? '' : 'JIT=1 URHO3D_LUAJIT_AMALG='
  341. system "rake cmake #{generator} URHO3D_LUA#{jit}=1 URHO3D_DATABASE_SQLITE=1 URHO3D_EXTRAS=1" or abort 'Failed to configure Urho3D library build'
  342. next if timeup # Measure the CMake configuration overhead
  343. if ENV['AVD'] && !ENV['PACKAGE_UPLOAD'] # Skip APK test run when packaging
  344. # Prepare a new AVD in another process to avoid busy waiting
  345. android_prepare_device ENV['AVD'], ENV['ANDROID_ABI'] or abort 'Failed to prepare Android (virtual) device for test run'
  346. end
  347. # Temporarily put the logic here for clang-tools migration until everything else are in their places
  348. if ENV['URHO3D_BINDINGS']
  349. system 'rake make' or abort 'Failed to build or test Urho3D library with annotated source files'
  350. system 'rake ci_push_bindings' or abort
  351. next
  352. end
  353. if !wait_for_block { Thread.current[:subcommand_to_kill] = 'xcodebuild'; system 'rake make' }
  354. abort 'Failed to build Urho3D library' unless File.exists?('already_timeup.log')
  355. $stderr.puts "Skipped the rest of the CI processes due to insufficient time"
  356. next
  357. end
  358. if ENV['URHO3D_TESTING'] && !ENV['WEB'] && !timeup
  359. # Multi-config CMake generators use different test target name than single-config ones for no good reason
  360. test = "rake make target=#{(ENV['OS'] && !ENV['MINGW']) || ENV['XCODE'] ? 'RUN_TESTS' : 'test'}"
  361. system "#{test}" or abort 'Failed to test Urho3D library'
  362. test = "&& echo#{ENV['OS'] ? '.' : ''} && #{test}"
  363. else
  364. test = ''
  365. end
  366. # Skip scaffolding test when time up or packaging for iOS, tvOS, and Web platform
  367. unless ENV['CI'] && (ENV['IOS'] || ENV['TVOS'] || ENV['WEB']) && ENV['PACKAGE_UPLOAD'] || ENV['XCODE_64BIT_ONLY'] || timeup
  368. # Staged-install Urho3D SDK when on Travis-CI; normal install when on AppVeyor
  369. ENV['DESTDIR'] = ENV['HOME'] || Dir.home unless ENV['APPVEYOR']
  370. if !wait_for_block("Installing Urho3D SDK to #{ENV['DESTDIR'] ? "#{ENV['DESTDIR']}/usr/local" : 'default system-wide location'}...") { Thread.current[:subcommand_to_kill] = 'xcodebuild'; system "rake make target=install >#{ENV['OS'] ? 'nul' : '/dev/null'}" }
  371. abort 'Failed to install Urho3D SDK' unless File.exists?('already_timeup.log')
  372. $stderr.puts "Skipped the rest of the CI processes due to insufficient time"
  373. next
  374. end
  375. # Alternate to use in-the-source build tree for test coverage
  376. ENV['build_tree'] = '.' unless ENV['APPVEYOR']
  377. # Ensure the following variables are auto-discovered during scaffolding test
  378. ENV['URHO3D_64BIT'] = nil unless ENV['APPVEYOR'] # AppVeyor uses VS generator which always requires URHO3D_64BIT as input variable
  379. ['URHO3D_LIB_TYPE', 'URHO3D_STATIC_RUNTIME', 'URHO3D_OPENGL', 'URHO3D_D3D11', 'URHO3D_SSE', 'URHO3D_DATABASE_ODBC', 'URHO3D_DATABASE_SQLITE', 'URHO3D_LUAJIT', 'URHO3D_TESTING'].each { |var| ENV[var] = nil }
  380. # Alternate the scaffolding location between Travis CI and AppVeyor for test coverage; Travis CI uses build tree while AppVeyor using source tree
  381. # First scaffolding test uses absolute path while second test uses relative path, also for test converage
  382. # First test - create a new project on the fly that uses newly installed Urho3D SDK
  383. org = (ENV['TRAVIS_REPO_SLUG'] || ENV['APPVEYOR_PROJECT_SLUG']).split('/').first
  384. Dir.chdir scaffolding "#{ENV['APPVEYOR'] ? "C:/projects/#{org}/" : (ENV['TRAVIS'] ? "#{ENV['HOME']}/build/#{org}/Build/" : '../Build/')}UsingSDK" do # The last rel path is for non-CI users, just in case
  385. puts "\nConfiguring downstream project using Urho3D SDK...\n\n"; $stdout.flush
  386. # SDK installation to a system-wide location does not need URHO3D_HOME to be defined, staged-installation does
  387. system "#{ENV['DESTDIR'] ? 'URHO3D_HOME=~/usr/local' : ''} rake cmake #{generator} URHO3D_LUA=1 && rake make #{test}" or abort 'Failed to configure/build/test temporary downstream project using Urho3D as external library'
  388. end
  389. next if timeup
  390. # Second test - create a new project on the fly that uses newly built Urho3D library in the build tree
  391. Dir.chdir scaffolding "#{ENV['APPVEYOR'] ? '' : '../Build/'}UsingBuildTree" do
  392. puts "Configuring downstream project using Urho3D library in its build tree...\n\n"; $stdout.flush
  393. system "rake cmake #{generator} URHO3D_HOME=#{ENV['APPVEYOR'] ? "../../#{ENV['build_tree']}" : '..'} URHO3D_LUA=1 && rake make #{test}" or abort 'Failed to configure/build/test temporary downstream project using Urho3D as external library'
  394. end
  395. end
  396. # Make, deploy, and test run Android APK in an Android (virtual) device
  397. if ENV['AVD'] && !ENV['PACKAGE_UPLOAD'] && !timeup
  398. puts "\nTest deploying and running Urho3D Samples APK..."
  399. Dir.chdir '../Build' do
  400. system 'android update project -p . && ant debug' or abort 'Failed to make Urho3D Samples APK'
  401. if android_wait_for_device
  402. system "ant -Dadb.device.arg='-s #{$specific_device}' installd" or abort 'Failed to deploy Urho3D Samples APK'
  403. android_test_run or abort 'Failed to test run Urho3D Samples APK'
  404. else
  405. puts 'Skipped test running Urho3D Samples APK as emulator failed to start in time'
  406. end
  407. end
  408. end
  409. end
  410. # Usage: NOT intended to be used manually
  411. desc 'Setup build cache'
  412. task :ci_setup_cache do
  413. clear = /\[cache clear\]/ =~ ENV['COMMIT_MESSAGE']
  414. # AppVeyor on Windows host has different kind of cache mechanism, not based on ccache
  415. if ENV['APPVEYOR']
  416. system "bash -c 'rm -rf #{ENV['build_tree']}'" if clear
  417. if File.exists?("#{ENV['build_tree']}/.commits")
  418. # Find the last valid commit SHA because the recorded commit SHAs may no longer be valid due to git reset/forced push
  419. last_commit = File.read("#{ENV['build_tree']}/.commits").split.find { |sha| system "git cat-file -e #{sha}" }
  420. # AppVeyor prefers CMD's FIND over MSYS's find, so we have to use fully qualified path to the MSYS's find
  421. system "bash -c '/c/Program\\ Files/Git/usr/bin/find CMakeLists.txt CMake Docs Source |xargs touch -r #{ENV['build_tree']}/CMakeCache.txt && touch $(git diff --name-only #{last_commit} #{ENV['APPVEYOR_REPO_COMMIT']})'"
  422. end
  423. next
  424. # Use internal cache store instead of using Travis CI one (this is a workaround for using ccache on Travis CI legacy build infra)
  425. elsif ENV['USE_CCACHE'].to_i == 2
  426. puts 'Setting up build cache'
  427. job_number = ".#{ENV['TRAVIS_JOB_NUMBER'].split('.').last}"
  428. repo_slug = "#{ENV['TRAVIS_REPO_SLUG'].split('/').first}/cache-store.git"
  429. matched = /.*-([^-]+-[^-]+)$/.match(ENV['TRAVIS_BRANCH'])
  430. base_mirror = matched ? matched[1] : nil
  431. # Do not abort even when it fails here
  432. system "if ! `git clone -q --depth 1 --branch #{ENV['TRAVIS_BRANCH']}#{job_number} https://github.com/#{repo_slug} ~/.ccache 2>/dev/null`; then if ! [ #{base_mirror} ] || ! `git clone -q --depth 1 --branch #{base_mirror}#{job_number} https://github.com/#{repo_slug} ~/.ccache 2>/dev/null`; then git clone -q --depth 1 https://github.com/#{repo_slug} ~/.ccache 2>/dev/null; fi && cd ~/.ccache && git checkout -qf -b #{ENV['TRAVIS_BRANCH']}#{job_number}; fi"
  433. # Preserving .git directory before clearing the cache on Linux host system (ccache on Mac OSX does not have this problem)
  434. `mv ~/.ccache/.git /tmp` if clear && ENV['OSX'].to_i != 1
  435. end
  436. # Clear ccache on demand
  437. system "ccache -z -M #{ENV['CCACHE_MAXSIZE']} #{clear ? '-C' : ''}"
  438. # Restoring .git directory if its backup exists
  439. `if [ -e /tmp/.git ]; then mv /tmp/.git ~/.ccache; fi`
  440. end
  441. # Usage: NOT intended to be used manually
  442. desc 'Teardown build cache'
  443. task :ci_teardown_cache do
  444. # AppVeyor on Windows host has different kind of cache mechanism, not based on ccache
  445. if ENV['APPVEYOR']
  446. # Keep the last 10 commit SHAs
  447. commits = (File.exists?("#{ENV['build_tree']}/.commits") ? File.read("#{ENV['build_tree']}/.commits").split : []).unshift(`git rev-parse #{ENV['APPVEYOR_REPO_COMMIT']}`.chomp).take 10
  448. File.open("#{ENV['build_tree']}/.commits", 'w') { |file| file.puts commits } if Dir.exist?(ENV['build_tree'])
  449. # Exclude build artifacts from being cached due to cache size limitation
  450. system "bash -c 'rm -f #{ENV['build_tree']}/bin/*.{exe,dll}'"
  451. next
  452. # Upload cache to internal cache store if it is our own
  453. elsif ENV['USE_CCACHE'].to_i == 2
  454. puts 'Storing build cache'
  455. job_number = ".#{ENV['TRAVIS_JOB_NUMBER'].split('.').last}"
  456. repo_slug = "#{ENV['TRAVIS_REPO_SLUG'].split('/').first}/cache-store.git"
  457. # Do not abort even when it fails here
  458. system "cd ~/.ccache && git config user.name $GIT_NAME && git config user.email $GIT_EMAIL && git remote set-url --push origin https://[email protected]/#{repo_slug} && git add -A . && git commit --amend -qm 'Travis CI: cache update at #{Time.now.utc}.' && git push -qf -u origin #{ENV['TRAVIS_BRANCH']}#{job_number} >/dev/null 2>&1"
  459. end
  460. system 'ccache -s'
  461. end
  462. # Usage: NOT intended to be used manually
  463. desc 'Update site on GitHub Pages (and source tree on GitHub while we are at it)'
  464. task :ci_site_update do
  465. # Skip when :ci rake task was skipped
  466. next unless File.exist?('../Build/CMakeCache.txt')
  467. next if timeup
  468. puts "Updating site...\n\n"
  469. system 'git clone --depth 1 -q https://github.com/urho3d/urho3d.github.io.git ../urho3d.github.io' or abort 'Failed to clone urho3d/urho3d.github.io'
  470. # Update credits from README.md to about.yml
  471. system "ruby -lne 'BEGIN { credits = false }; puts $_ if credits; credits = true if /bugfixes by:/; credits = false if /^$/' README.md |ruby -i -le 'credits = STDIN.read; puts ARGF.read.gsub(/(?<=contributors:\n).*?\n\n/m, credits)' ../urho3d.github.io/_data/about.yml" or abort 'Failed to update credits'
  472. # Setup doxygen to use minimal theme
  473. system "ruby -i -pe 'BEGIN { a = {%q{HTML_HEADER} => %q{minimal-header.html}, %q{HTML_FOOTER} => %q{minimal-footer.html}, %q{HTML_STYLESHEET} => %q{minimal-doxygen.css}, %q{HTML_COLORSTYLE_HUE} => 200, %q{HTML_COLORSTYLE_SAT} => 0, %q{HTML_COLORSTYLE_GAMMA} => 20, %q{DOT_IMAGE_FORMAT} => %q{svg}, %q{INTERACTIVE_SVG} => %q{YES}, %q{COLS_IN_ALPHA_INDEX} => 3} }; a.each {|k, v| gsub(/\#{k}\s*?=.*?\n/, %Q{\#{k} = \#{v}\n}) }' ../Build/Docs/generated/Doxyfile" or abort 'Failed to setup doxygen configuration file'
  474. system 'cp ../urho3d.github.io/_includes/Doxygen/minimal-* ../Build/Docs' or abort 'Failed to copy minimal-themed template'
  475. release = ENV['RELEASE_TAG'] || 'HEAD'
  476. unless release == 'HEAD'
  477. system "mkdir -p ../urho3d.github.io/documentation/#{release}" or abort 'Failed to create directory for new document version'
  478. system "ruby -i -pe 'gsub(/HEAD/, %q{#{release}})' ../Build/Docs/minimal-header.html" or abort 'Failed to update document version in YAML Front Matter block'
  479. append_new_release release or abort 'Failed to add new release to document data file'
  480. end
  481. # Generate and sync doxygen pages
  482. system "cd ../Build && make -j$numjobs doc >/dev/null 2>&1 && ruby -i -pe 'gsub(/(<\\/?h)3([^>]*?>)/, %q{\\14\\2}); gsub(/(<\\/?h)2([^>]*?>)/, %q{\\13\\2}); gsub(/(<\\/?h)1([^>]*?>)/, %q{\\12\\2})' Docs/html/_*.html && rsync -a --delete Docs/html/ ../urho3d.github.io/documentation/#{release}" or abort 'Failed to generate/rsync doxygen pages'
  483. # Supply GIT credentials to push site documentation changes to urho3d/urho3d.github.io.git
  484. system "cd ../urho3d.github.io && git config user.name $GIT_NAME && git config user.email $GIT_EMAIL && git remote set-url --push origin https://[email protected]/urho3d/urho3d.github.io.git && git add -A . && if git commit -qm \"Travis CI: site documentation update at #{Time.now.utc}.\n\nCommit: https://github.com/$TRAVIS_REPO_SLUG/commit/$TRAVIS_COMMIT\n\nMessage: $COMMIT_MESSAGE\"; then git push -q >/dev/null 2>&1 && echo Site updated successfully; fi" or abort 'Failed to update site'
  485. next if timeup
  486. # Skip detecting source tree changes when HEAD has moved or it is too late already as a release tag has just been pushed
  487. unless ENV['RELEASE_TAG'] || `git fetch -qf origin #{ENV['TRAVIS_BRANCH']}; git log -1 --pretty=format:'%H' FETCH_HEAD` != ENV['TRAVIS_COMMIT']
  488. puts "Updating source tree...\n\n"
  489. # Supply GIT credentials to push source tree changes to urho3d/Urho3D.git
  490. system 'git config user.name $GIT_NAME && git config user.email $GIT_EMAIL && git remote set-url --push origin https://[email protected]/$TRAVIS_REPO_SLUG.git'
  491. system "git add Source && git commit -qm 'Travis CI: source tree update at #{Time.now.utc}.' >/dev/null 2>&1" # Use extra quiet mode as there could be no changes at all
  492. if /2008-([0-9]{4}) the Urho3D project/.match(File.read('Rakefile'))[1].to_i != Time.now.year
  493. # Automatically bump copyright when crossing a new year and give instruction to clear the cache if so since the cache is of no use anyway because of massive changes
  494. system "git add #{bump_copyright_year.join ' '} && if git commit -qm 'Travis CI: bump copyright to #{Time.now.year}.\n[cache clear]'; then git push origin HEAD:#{ENV['TRAVIS_BRANCH']} -q >/dev/null 2>&1 && echo Bumped copyright - Happy New Year!; fi" or abort "Failed to push copyright update for #{ENV['TRAVIS_BRANCH']}"
  495. ['urho3d.github.io master', 'android-ndk ndk-update-trigger', 'armhf-sysroot sysroot-update-trigger', 'arm64-sysroot sysroot-update-trigger', 'rpi-sysroot sysroot-update-trigger', 'emscripten-sdk sdk-update-trigger'].each { |var| pair = var.split; system "if [ ! -d ../#{pair.first} ]; then git clone -q --depth 1 --branch #{pair.last} https://github.com/urho3d/#{pair.first} ../#{pair.first}; fi" or abort "Failed to clone urho3d/#{pair.first}"; system "cd ../#{pair.first} && git config user.name $GIT_NAME && git config user.email $GIT_EMAIL && git remote set-url --push origin https://[email protected]/urho3d/#{pair.first} && git add #{bump_copyright_year("../#{pair.first}").join ' '} 2>/dev/null && git add #{bump_copyright_year("../#{pair.first}", '2014-[0-9]{4} Yao').join ' '} 2>/dev/null && if git commit -qm 'Travis CI: bump copyright to #{Time.now.year}.\n[ci skip]'; then git push -q >/dev/null 2>&1; fi" or abort "Failed to push copyright update for urho3d/#{pair.first}"; }
  496. elsif system("git add Docs/*API* && git commit -qm 'Test commit to detect API documentation changes'")
  497. # Automatically give instruction to do packaging when API has changed, unless the instruction is already given in this commit
  498. bump_soversion 'Source/Urho3D/.soversion' or abort 'Failed to bump soversion'
  499. system "git add Source/Urho3D/.soversion && git commit --amend -qm \"Travis CI: API documentation update at #{Time.now.utc}.\n#{ENV['PACKAGE_UPLOAD'] ? '' : '[ci package]'}\n\nCommit: https://github.com/$TRAVIS_REPO_SLUG/commit/$TRAVIS_COMMIT\n\nMessage: #{ENV['COMMIT_MESSAGE'].gsub(/\[.*\]/, '')}\" && echo Source tree updated successfully" or abort 'Failed to commit API documentation'
  500. end
  501. else
  502. puts 'Skipped detecting source tree changes due to moving HEAD' unless ENV['RELEASE_TAG']
  503. end
  504. end
  505. # Usage: NOT intended to be used manually
  506. desc 'Update web samples to GitHub Pages'
  507. task :ci_emscripten_samples_update do
  508. next if timeup
  509. puts 'Updating Web samples in main website...'
  510. system 'git clone --depth 1 -q https://github.com/urho3d/urho3d.github.io.git ../urho3d.github.io' or abort 'Failed to clone urho3d/urho3d.github.io'
  511. system "rsync -a --delete --exclude tool --exclude *.pak --exclude index.md ../Build/bin/ ../urho3d.github.io/samples" or abort 'Failed to rsync Web samples'
  512. Dir.chdir('../urho3d.github.io/samples') {
  513. next unless system 'git diff --quiet Urho3D.js.data'
  514. uuid = `git diff --color=never --word-diff-regex='\\w+' --word-diff=porcelain Urho3D.js`.split.grep(/^[+-]\w+-/).map { |it| it[0] = ''; it }
  515. system %Q(ruby -i.bak -pe "gsub '#{uuid.last}', '#{uuid.first}'" Urho3D.js)
  516. if system 'git diff --quiet Urho3D.js'
  517. File.unlink 'Urho3D.js.bak'
  518. Dir['*.js'].each { |file| system %Q(ruby -i -pe "gsub '#{uuid.last}', '#{uuid.first}'" #{file}) }
  519. else
  520. File.rename 'Urho3D.js.bak', 'Urho3D.js'
  521. end
  522. }
  523. update_web_samples_data or abort 'Failed to update Web json data file'
  524. root_commit, _ = get_root_commit_and_recipients
  525. system "cd ../urho3d.github.io && git config user.name $GIT_NAME && git config user.email $GIT_EMAIL && git remote set-url --push origin https://[email protected]/urho3d/urho3d.github.io.git && git add -A . && ( git commit -qm \"Travis CI: Web samples update at #{Time.now.utc}.\n\nCommit: https://github.com/$TRAVIS_REPO_SLUG/commit/#{root_commit}\n\nMessage: #{`git log --format=%B -n 1 #{root_commit}`}\" || true) && git push -q >/dev/null 2>&1" or abort 'Failed to update Web samples'
  526. end
  527. # Usage: NOT intended to be used manually
  528. desc 'Create all CI mirror branches'
  529. task :ci_create_mirrors do
  530. # Skip all CI branches creation if there are more commits externally
  531. abort 'Skipped creating mirror branches due to moving remote HEAD' unless `git fetch -qf origin #{ENV['TRAVIS_PULL_REQUEST'] == 'false' ? ENV['TRAVIS_BRANCH'] : %Q{+refs/pull/#{ENV['TRAVIS_PULL_REQUEST']}/head'}}; git log -1 --pretty=format:'%H' FETCH_HEAD` == ENV['TRAVIS_COMMIT'] # This HEAD movement detection logic is more complex than usual as the original intention was to allow mirror creation on PR, however, we have scaled it back for now
  532. # Skip non-mandatory branches if there are pending commits internally
  533. head = `git log -1 --pretty=format:'%H' HEAD`
  534. head_moved = head != ENV['TRAVIS_COMMIT'] # Local head may be moved because of API documentation update
  535. # Reset the head to the original commit position for mirror creation
  536. system 'git checkout -qf $TRAVIS_COMMIT' if head_moved
  537. system 'git config user.name $GIT_NAME && git config user.email $GIT_EMAIL && git remote set-url --push origin https://[email protected]/$TRAVIS_REPO_SLUG.git' or abort 'Failed to re-checkout commit'
  538. # Limit the scanning to only master branch
  539. scan = ENV['TRAVIS_BRANCH'] == 'master'
  540. # Check if it is time to generate annotation
  541. annotate = ENV['TRAVIS_BRANCH'] == 'master' && (ENV['PACKAGE_UPLOAD'] || /\[ci annotate\]/ =~ ENV['COMMIT_MESSAGE']) && /\[ci only:.*?\]/ !~ ENV['COMMIT_MESSAGE']
  542. # Determine which CI mirror branches to be auto created
  543. unless ENV['RELEASE_TAG']
  544. skip_travis = /\[skip travis\]/ =~ ENV['COMMIT_MESSAGE'] # For feature parity with AppVeyor's [skip appveyor]
  545. matched = /\[ci only:(.*?)\]/.match(ENV['COMMIT_MESSAGE'])
  546. ci_only = matched ? matched[1].split(/[ ,]/).reject!(&:empty?) : nil
  547. else
  548. ci_only = nil
  549. end
  550. # Escape double quotes in the commit message so they do not interfere with the string interpolation below
  551. escaped_commit_message = ENV['COMMIT_MESSAGE'].gsub(/"/, '\"')
  552. # Obtain the whole stream and process the rest of documents except the first one since travis-build does not do that at the moment
  553. stream = YAML::load_stream(File.open('.travis.yml'))
  554. notifications = stream[0]['notifications']
  555. notifications['email']['recipients'] = get_root_commit_and_recipients().last unless notifications['email']['recipients']
  556. preset = stream[0]['data']['stages'] || {}
  557. stage = stream[0]['stage'] || 'test'
  558. # Install Travis CLI Ruby gem to interface with Travis
  559. system 'gem install travis >/dev/null 2>&1'
  560. stream.drop(1).each { |doc| branch = doc.delete('branch'); ci = branch['name']; ci_branch = ENV['RELEASE_TAG'] || (ENV['TRAVIS_BRANCH'] == 'master' && ENV['TRAVIS_PULL_REQUEST'] == 'false') ? ci : (ENV['TRAVIS_PULL_REQUEST'] == 'false' ? "#{ENV['TRAVIS_BRANCH']}-#{ci}" : "PR ##{ENV['TRAVIS_PULL_REQUEST']}-#{ci}"); is_appveyor_ci = branch['appveyor']; next if skip_travis && !is_appveyor_ci; unless (branch['mandatory'] || !head_moved) && ((ci_only && ci_only.map { |i| /#{i}/ =~ ci }.any?) || (!ci_only && (branch['active'] || (scan && /Scan/ =~ ci) || (annotate && /Annotate/ =~ ci)))); system "if git fetch origin #{ci_branch}:#{ci_branch} 2>/dev/null; then git push -qf origin --delete #{ci_branch}; fi"; puts "Skipped creating #{ci_branch} mirror branch due to moving HEAD" if !ci_only && branch['active'] && head_moved; next; end; unless is_appveyor_ci; doc['notifications'] = notifications unless doc['notifications']; doc['matrix']['include'].delete_if { |build| build['condition'] && !ENV[build['condition']] } && doc['matrix']['include'].each_with_index { |build, index| stage = build['stage'] || stage; build['before_script'].flatten! if build['before_script']; doc['matrix']['include'][index].merge! preset[stage] if preset[stage] } if doc['matrix'] && doc['matrix']['include']; doc_name = '.travis.yml'; else doc_name = '.appveyor.yml'; end; File.open("#{doc_name}.new", 'w') { |file| file.write doc.to_yaml }; puts "Creating #{ci_branch} mirror branch..."; alt = system("travis branches --org --no-interactive -r #{ENV['TRAVIS_REPO_SLUG']} |grep ^#{ci_branch}: |grep -cqP 'started|created'") ? '-alt' : nil; system "git checkout -qB #{ci_branch} && rm .appveyor.yml .travis.yml && mv #{doc_name}.new #{doc_name} && git add -A . && git commit -qm \"#{escaped_commit_message}\" && git push -qf -u origin #{ci_branch}:#{ci_branch}#{alt} >/dev/null 2>&1 && git checkout -q - && sleep 5" or abort "Failed to create #{ci_branch} mirror branch" }
  561. # Push pending commits if any
  562. system "git push origin #{head}:#{ENV['TRAVIS_BRANCH']} -q >/dev/null 2>&1" or abort "Failed to push pending commits to #{ENV['TRAVIS_BRANCH']}" if head_moved
  563. end
  564. # Usage: NOT intended to be used manually
  565. desc 'Delete CI mirror branch'
  566. task :ci_delete_mirror do
  567. # Skip when we are performing a release (in case we need to rerun the job to recreate the package)
  568. if ENV['RELEASE_TAG']
  569. # Do not use "abort" here because AppVeyor, unlike Travis, also handles the exit status of the processes invoked in the "on_finish" section of the .appveyor.yml
  570. # Using "abort" may incorrectly (or correctly, depends on your POV) report the whole CI as failed when the CI mirror branch deletion is being skipped
  571. $stderr.puts "Skipped deleting #{ENV['TRAVIS_BRANCH'] || ENV['APPVEYOR_REPO_BRANCH']} mirror branch"
  572. next
  573. end
  574. system "bash -c 'git config user.name #{ENV['GIT_NAME']} && git config user.email #{ENV['GIT_EMAIL']} && git remote set-url --push origin https://#{ENV['GH_TOKEN']}@github.com/#{ENV['TRAVIS_REPO_SLUG'] || ENV['APPVEYOR_REPO_NAME']}.git'"
  575. system "bash -c 'git push -qf origin --delete #{ENV['TRAVIS_BRANCH'] || ENV['APPVEYOR_REPO_BRANCH']} >/dev/null 2>&1'" or abort "Failed to delete #{ENV['TRAVIS_BRANCH'] || ENV['APPVEYOR_REPO_BRANCH']} mirror branch"
  576. end
  577. # Usage: NOT intended to be used manually
  578. desc 'Make binary package and upload it to a designated central hosting server'
  579. task :ci_package_upload do
  580. # Using out-of-source build tree when using Travis-CI; 'build_tree' environment variable is already set when on AppVeyor
  581. ENV['build_tree'] = '../Build' unless ENV['APPVEYOR']
  582. # Always use Release build configuration when using Xcode; 'config' environment variable is already set when on AppVeyor
  583. ENV['config'] = 'Release' if ENV['XCODE']
  584. # Skip when :ci rake task was skipped
  585. next unless File.exist?("#{ENV['build_tree']}/CMakeCache.txt")
  586. next if timeup
  587. # Generate the documentation if necessary
  588. if ENV['SITE_UPDATE']
  589. if File.exist?('.site_updated')
  590. # Skip if site is already updated before
  591. ENV['SITE_UPDATE'] = nil
  592. end
  593. elsif !File.exists?("#{ENV['build_tree']}/Docs/html/index.html")
  594. puts "Generating documentation...\n"; $stdout.flush
  595. # Ignore the exit status from 'make doc' on Windows host system because Doxygen may not return exit status correctly on Windows
  596. system "rake make target=doc >#{ENV['OS'] ? 'nul' : '/dev/null'}" or ENV['OS'] or abort 'Failed to generate documentation'
  597. next if timeup
  598. end
  599. # Make the package
  600. puts "Packaging artifacts...\n\n"; $stdout.flush
  601. if ENV['IOS'] || ENV['TVOS']
  602. # TODO: There is a bug in CMake/CPack that causes the 'package' target failed to build for iOS and tvOS platforms, workaround by calling cpack directly; CMake 3.4 runs the target successfully, however, the result tarball is incomplete (somehow it misses packaging the library itself, another bug?)
  603. system 'cd ../Build && cpack -G TGZ 2>/dev/null' or abort 'Failed to make binary package'
  604. else
  605. if ENV['ANDROID']
  606. if !ENV['NO_SDK_SYSIMG']
  607. system 'cd ../Build && android update project -p . && ant debug' or abort 'Failed to make Urho3D Samples APK'
  608. end
  609. end
  610. if ENV['URHO3D_USE_LIB64_RPM']
  611. system 'rake cmake' or abort 'Failed to reconfigure to generate 64-bit RPM package'
  612. system "rm #{ENV['build_tree']}/Urho3D-*" or abort 'Failed to remove previously generated artifacts' # This task can be invoked more than one time
  613. end
  614. system "#{!ENV['OS'] && (ENV['URHO3D_64BIT'] || ENV['RPI'] || ENV['ARM']) ? 'setarch i686' : ''} rake make target=package" or abort 'Failed to make binary package'
  615. end
  616. next if timeup
  617. # Determine the upload location
  618. puts "Uploading artifacts...\n\n"; $stdout.flush
  619. setup_digital_keys
  620. repo = ENV[ENV['TRAVIS'] ? 'TRAVIS_REPO_SLUG' : 'APPVEYOR_REPO_NAME']
  621. unless ENV['RELEASE_TAG']
  622. upload_dir = "/home/frs/project/#{repo}/Snapshots"
  623. if ENV['SITE_UPDATE']
  624. # Download source packages from GitHub
  625. system "export SNAPSHOT_VER=$(git describe $TRAVIS_COMMIT |ruby -pe 'gsub(/-(?!g)/, %q{.})'); wget -q https://github.com/$TRAVIS_REPO_SLUG/tarball/$TRAVIS_COMMIT -O Urho3D-$SNAPSHOT_VER-Source-snapshot.tar.gz && wget -q https://github.com/$TRAVIS_REPO_SLUG/zipball/$TRAVIS_COMMIT -O Urho3D-$SNAPSHOT_VER-Source-snapshot.zip" or abort 'Failed to get source packages'
  626. # Only keep the snapshots from the last 30 revisions
  627. system "for v in $(sftp [email protected] <<EOF |tr ' ' '\n' |grep Urho3D- |cut -d '-' -f1,2 |uniq |tail -n +11
  628. cd #{upload_dir}
  629. ls -1t
  630. bye
  631. EOF
  632. ); do echo rm #{upload_dir}/${v}-*; done |sftp -b - [email protected] >/dev/null 2>&1" or abort 'Failed to housekeep snapshots'
  633. end
  634. else
  635. upload_dir = "/home/frs/project/#{repo}/#{ENV['RELEASE_TAG']}"
  636. if ENV['SITE_UPDATE']
  637. # Download source packages from GitHub
  638. system 'wget -q https://github.com/$TRAVIS_REPO_SLUG/archive/$RELEASE_TAG.tar.gz -O Urho3D-$RELEASE_TAG-Source.tar.gz && wget -q https://github.com/$TRAVIS_REPO_SLUG/archive/$RELEASE_TAG.zip -O Urho3D-$RELEASE_TAG-Source.zip' or abort 'Failed to get source packages'
  639. end
  640. # Make sure the release directory exists remotely, do this in all the build jobs as we don't know which one would start uploading first
  641. system "bash -c 'sftp [email protected] <<EOF >/dev/null 2>&1
  642. mkdir #{upload_dir}
  643. bye
  644. EOF'" or abort 'Failed to create release directory remotely'
  645. end
  646. if ENV['SITE_UPDATE']
  647. # Upload the source package
  648. system "scp Urho3D-* [email protected]:#{upload_dir}" or abort 'Failed to upload source package'
  649. if ENV['RELEASE_TAG']
  650. # Mark the source tarball as default download for host systems other than Windows/Mac/Linux
  651. system "curl -H 'Accept: application/json' -X PUT -d 'default=bsd&default=solaris&default=others' -d \"api_key=$SF_API\" https://sourceforge.net/projects/%s/files/%s/#{ENV['RELEASE_TAG']}/Urho3D-#{ENV['RELEASE_TAG']}-Source.tar.gz" % ENV['TRAVIS_REPO_SLUG'].split('/') or abort 'Failed to set source tarball as default download'
  652. end
  653. # Sync readme and license files, just in case they are updated in the repo
  654. system 'for f in README.md LICENSE; do mtime=$(git log --format=%ai -n1 $f); touch -d "$mtime" $f; done' or abort 'Failed to acquire file modified time'
  655. system 'rsync -e ssh -az README.md LICENSE [email protected]:/home/frs/project/$TRAVIS_REPO_SLUG' or abort 'Failed to sync readme and license files'
  656. # Mark that the site has been updated
  657. File.open('.site_updated', 'w') {}
  658. end
  659. # Upload the binary package
  660. system "bash -c 'scp #{ENV['build_tree']}/Urho3D-* [email protected]:#{upload_dir}'" or abort 'Failed to upload binary package'
  661. if ENV['RELEASE_TAG'] && ENV['SF_DEFAULT']
  662. # Mark the corresponding binary package as default download for each Windows/Mac/Linux host systems
  663. system "bash -c \"curl -H 'Accept: application/json' -X PUT -d 'default=%s' -d \"api_key=$SF_API\" https://sourceforge.net/projects/%s/files/%s/#{ENV['RELEASE_TAG']}/Urho3D-#{ENV['RELEASE_TAG']}-%s\"" % ENV['SF_DEFAULT'].split(':').insert(1, repo.split('/')).flatten or abort 'Failed to set binary tarball/zip as default download'
  664. end
  665. end
  666. # Usage: NOT intended to be used manually
  667. desc 'Start/stop the timer'
  668. task :ci_timer do
  669. timeup
  670. end
  671. # Always call this function last in the multiple conditional check so that the checkpoint message does not being echoed unnecessarily
  672. def timeup quiet = false, cutoff_time = 40.0
  673. unless File.exists?('start_time.log')
  674. system 'touch start_time.log split_time.log'
  675. return nil
  676. end
  677. current_time = Time.now
  678. elapsed_time = (current_time - File.atime('start_time.log')) / 60.0
  679. unless quiet
  680. lap_time = (current_time - File.atime('split_time.log')) / 60.0
  681. system 'touch split_time.log'
  682. puts "\n=== elapsed time: #{elapsed_time.to_i} minutes #{((elapsed_time - elapsed_time.to_i) * 60.0).round} seconds, lap time: #{lap_time.to_i} minutes #{((lap_time - lap_time.to_i) * 60.0).round} seconds ===\n\n" unless File.exists?('already_timeup.log'); $stdout.flush
  683. end
  684. return system('touch already_timeup.log') if elapsed_time > cutoff_time
  685. end
  686. def scaffolding dir, project = 'Scaffolding', target = 'Main'
  687. begin
  688. dir = Pathname.new(dir).realdirpath.to_s
  689. rescue
  690. abort "Failed to scaffolding due to invalid parent directory in '#{dir}'"
  691. end
  692. dir.gsub!(/\//, '\\') if ENV['OS']
  693. build_script = <<EOF
  694. # Set CMake minimum version and CMake policy required by UrhoCommon module
  695. cmake_minimum_required (VERSION 3.2.3)
  696. if (COMMAND cmake_policy)
  697. # Libraries linked via full path no longer produce linker search paths
  698. cmake_policy (SET CMP0003 NEW)
  699. # INTERFACE_LINK_LIBRARIES defines the link interface
  700. cmake_policy (SET CMP0022 NEW)
  701. # Disallow use of the LOCATION target property - so we set to OLD as we still need it
  702. cmake_policy (SET CMP0026 OLD)
  703. # MACOSX_RPATH is enabled by default
  704. cmake_policy (SET CMP0042 NEW)
  705. # Honor the visibility properties for SHARED target types only
  706. cmake_policy (SET CMP0063 OLD)
  707. endif ()
  708. # Set project name
  709. project (#{project})
  710. # Set CMake modules search path
  711. set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
  712. # Include UrhoCommon.cmake module after setting project name
  713. include (UrhoCommon)
  714. # Define target name
  715. set (TARGET_NAME #{target})
  716. # Define source files
  717. define_source_files ()
  718. # Setup target with resource copying
  719. setup_main_executable ()
  720. # Setup test cases
  721. if (URHO3D_ANGELSCRIPT)
  722. setup_test (NAME ExternalLibAS OPTIONS Scripts/12_PhysicsStressTest.as -w)
  723. endif ()
  724. if (URHO3D_LUA)
  725. setup_test (NAME ExternalLibLua OPTIONS LuaScripts/12_PhysicsStressTest.lua -w)
  726. endif ()
  727. EOF
  728. # TODO: Rewrite in pure Ruby when it supports symlink creation on Windows platform and avoid forward/backward slash conversion
  729. if ENV['OS']
  730. system("@echo off && mkdir \"#{dir}\"\\bin && copy Source\\Tools\\Urho3DPlayer\\Urho3DPlayer.* \"#{dir}\" >nul && (for %f in (*.bat Rakefile) do mklink \"#{dir}\"\\%f %cd%\\%f >nul) && mklink /D \"#{dir}\"\\CMake %cd%\\CMake && (for %d in (Autoload,CoreData,Data) do mklink /D \"#{dir}\"\\bin\\%d %cd%\\bin\\%d >nul)") && File.write("#{dir}/CMakeLists.txt", build_script) or abort 'Failed to scaffolding'
  731. else
  732. system("bash -c \"mkdir -p '#{dir}'/bin && cp Source/Tools/Urho3DPlayer/Urho3DPlayer.* '#{dir}' && for f in {.,}*.sh Rakefile CMake; do ln -sf `pwd`/\\$f '#{dir}'; done && ln -sf `pwd`/bin/{Autoload,CoreData,Data} '#{dir}'/bin\"") && File.write("#{dir}/CMakeLists.txt", build_script) or abort 'Failed to scaffolding'
  733. end
  734. return dir
  735. end
  736. def get_root_commit_and_recipients
  737. # Root commit is a commit submitted by human
  738. root_commit = `git show -s --format='%H' #{ENV['TRAVIS_COMMIT']}`.rstrip
  739. recipients = `git show -s --format='%ae %ce' #{root_commit}`.chomp.split.uniq
  740. if recipients.include? '[email protected]'
  741. matched = /Commit:.*commit\/(.*?)\n/.match(ENV['COMMIT_MESSAGE'])
  742. if (matched)
  743. root_commit = matched[1]
  744. recipients = `git show -s --format='%ae %ce' #{root_commit}`.chomp.split.uniq
  745. end
  746. end
  747. return root_commit, recipients
  748. end
  749. def android_find_device api = nil, abi = nil
  750. # Return the previously found matching device or if not found yet then try to find the matching device now
  751. return $specific_device if $specific_device
  752. $specific_api = api.to_s if api
  753. $specific_abi = abi.to_s if abi
  754. loop do
  755. for i in `adb devices |tail -n +2`.split "\n"
  756. device = i.split.first
  757. if `adb -s #{device} wait-for-device shell getprop ro.build.version.sdk`.chomp == $specific_api && `adb -s #{device} shell getprop ro.product.cpu.abi`.chomp == $specific_abi
  758. return $specific_device = device
  759. end
  760. end
  761. break if api
  762. end
  763. nil
  764. end
  765. def android_prepare_device api, abi = 'armeabi-v7a', name = 'test'
  766. system 'if ! ps |grep -cq adb; then adb start-server; fi'
  767. if !android_find_device api, abi
  768. # Don't have any matching (virtual) device attached, try to attach the named device (create the named device as AVD if necessary)
  769. if !system "android list avd |grep -cq 'Name: #{name}$'"
  770. system "echo 'no' |android create avd -n #{name} -t android-#{api} --abi #{abi}" or abort "Failed to create '#{name}' Android virtual device"
  771. end
  772. system "if [ $CI ]; then export OPTS='-no-skin -no-audio -no-window -no-boot-anim -gpu off'; else export OPTS='-gpu on'; fi; emulator -avd #{name} $OPTS &"
  773. end
  774. return 0
  775. end
  776. def android_wait_for_device retries = -1, retry_interval = 10, package = 'android.process.acore' # Waiting for HOME by default
  777. # Wait until the indicator process is running or it is killed externally by user via Ctrl+C or when it exceeds the number of retries (if the retries parameter is provided)
  778. str = "\nWaiting for device..."
  779. thread = Thread.new { android_find_device }; sleep 0.5
  780. process_ready = false
  781. retries = retries * 60 / retry_interval unless retries == -1
  782. until retries == 0
  783. if thread.status == false
  784. thread.join
  785. break if process_ready
  786. process_ready = thread = Thread.new { `adb -s #{$specific_device} shell 'until ps |grep -c #{package} >/dev/null; do sleep #{retry_interval}; done; while ps |grep -c bootanimation >/dev/null; do sleep 1; done'` }; sleep 0.5
  787. next
  788. end
  789. print str; str = '.'; $stdout.flush # Flush the standard output stream in case it is buffered to prevent Travis-CI into thinking that the build/test has stalled
  790. sleep retry_interval
  791. retries -= 1 if retries > 0
  792. end
  793. puts "\n\n" if str == '.'; $stdout.flush
  794. return retries == 0 ? nil : 0
  795. end
  796. def android_test_run parameter = '--es pickedLibrary Urho3DPlayer:Scripts/NinjaSnowWar.as', intent = '.SampleLauncher', package = 'com.github.urho3d', success_indicator = 'Added resource path /apk/', payload = 'sleep 30'
  797. # The device should have been found at this point
  798. return nil unless $specific_device
  799. # Capture adb's stdout and interpret it because adb neither uses stderr nor returns proper exit code on error
  800. begin
  801. IO.popen("adb -s #{$specific_device} shell <<EOF
  802. # Try to unlock the device just in case it is locked
  803. input keyevent 82; input keyevent 4
  804. # Clear the log
  805. logcat -c
  806. # Start the app
  807. am start -a android.intent.action.MAIN -n #{package}/#{intent} #{parameter}
  808. # Wait until the process is running
  809. until ps |grep -c #{package} 1>/dev/null; do sleep 1; done
  810. # Execute the payload
  811. #{payload}
  812. # Exit and stop the app
  813. input keyevent 4 && am force-stop #{package}
  814. # Dump the log
  815. logcat -d
  816. # Bye bye
  817. exit
  818. ##
  819. EOF") { |stdout| echo = false; while output = stdout.gets do if echo && /#\s#/ !~ output then puts output else echo = true if /^##/ =~ output end; return nil if /^error/i =~ output end }
  820. # Result of the test run is determined based on the presence of the success indicator string in the log
  821. system "adb -s #{$specific_device} logcat -d |grep -cq '#{success_indicator}'"
  822. rescue
  823. nil
  824. end
  825. end
  826. # Usage: wait_for_block('This is a long function call...') { call_a_func } or abort
  827. # wait_for_block('This is a long system call...') { system 'do_something' } or abort
  828. def wait_for_block comment = '', retries = -1, retry_interval = 60
  829. # When not using Xcode, execute the code block in full speed
  830. unless ENV['XCODE']
  831. puts comment; $stdout.flush
  832. return yield
  833. end
  834. # Wait until the code block is completed or it is killed externally by user via Ctrl+C or when it exceeds the number of retries (if the retries parameter is provided)
  835. thread = Thread.new { rc = yield; Thread.main.wakeup; rc }
  836. thread.priority = 1 # Make the worker thread has higher priority than the main thread
  837. str = comment
  838. retries = retries * 60 / retry_interval unless retries == -1
  839. until thread.status == false
  840. if retries == 0 || timeup(true)
  841. thread.kill
  842. # Also kill the child subproceses spawned by the worker thread if specified
  843. system "killall #{thread[:subcommand_to_kill]}" if thread[:subcommand_to_kill]
  844. sleep 5
  845. break
  846. end
  847. print str; str = '.'; $stdout.flush # Flush the standard output stream in case it is buffered to prevent Travis-CI into thinking that the build/test has stalled
  848. retries -= 1 if retries > 0
  849. sleep retry_interval
  850. end
  851. puts "\n" if str == '.'; $stdout.flush
  852. thread.join
  853. return thread.value
  854. end
  855. def append_new_release release, filename = '../urho3d.github.io/_data/urho3d.json'
  856. begin
  857. urho3d_hash = JSON.parse File.read filename
  858. unless urho3d_hash['releases'].last == release
  859. urho3d_hash['releases'] << release
  860. end
  861. File.open(filename, 'w') { |file| file.puts urho3d_hash.to_json }
  862. return 0
  863. rescue
  864. nil
  865. end
  866. end
  867. def update_web_samples_data dir = '../urho3d.github.io/samples', filename = '../urho3d.github.io/_data/web.json'
  868. begin
  869. web = { 'samples' => {} }
  870. Dir.chdir(dir) { web['samples']['Native'] = Dir['*.html'].sort }
  871. web['player'] = web['samples']['Native'].pop # Assume the last sample after sorting is the Urho3DPlayer.html
  872. {'AngelScript' => 'Scripts', 'Lua' => 'LuaScripts'}.each { |lang, subdir|
  873. Dir.chdir("bin/Data/#{subdir}") {
  874. script_samples = Dir['[0-9]*'].sort
  875. deleted_samples = [] # Delete samples that do not have their native counterpart
  876. script_samples.each { |sample| deleted_samples.push sample unless web['samples']['Native'].include? "#{sample.split('.').first}.html" }
  877. web['samples'][lang] = (script_samples - deleted_samples).map { |sample| "#{subdir}/#{sample}" }
  878. }
  879. }
  880. File.open(filename, 'w') { |file| file.puts web.to_json }
  881. return 0
  882. rescue
  883. nil
  884. end
  885. end
  886. def bump_copyright_year dir='.', regex='2008-[0-9]{4} the Urho3D project'
  887. begin
  888. Dir.chdir dir do
  889. copyrighted = `git grep -El '#{regex}'`.split
  890. copyrighted.each { |filename|
  891. replaced_content = File.read(filename).gsub(/#{regex}/, regex.gsub('[0-9]{4}', Time.now.year.to_s))
  892. File.open(filename, 'w') { |file| file.puts replaced_content }
  893. }
  894. return copyrighted
  895. end
  896. rescue
  897. abort 'Failed to bump copyright year'
  898. end
  899. end
  900. def bump_soversion filename
  901. begin
  902. version = File.read(filename).split '.'
  903. bump_version version, 2
  904. File.open(filename, 'w') { |file| file.puts version.join '.' }
  905. return 0
  906. rescue
  907. nil
  908. end
  909. end
  910. def bump_version version, index
  911. if index > 0 && version[index].to_i == 255
  912. version[index] = 0
  913. bump_version version, index - 1
  914. else
  915. version[index] = version[index].to_i + 1
  916. end
  917. end
  918. def setup_digital_keys
  919. system "bash -c 'mkdir -p ~/.ssh && chmod 700 ~/.ssh'" or abort 'Failed to create ~/.ssh directory'
  920. system "bash -c 'ssh-keyscan frs.sourceforge.net >>~/.ssh/known_hosts 2>/dev/null'" or abort 'Failed to append frs.sourceforge.net server public key to known_hosts'
  921. # Workaround travis encryption key size limitation. Rather than using the solution in their FAQ (using AES to encrypt/decrypt the file and check in the encrypted file into repo), our solution is more pragmatic. The private key below is incomplete. Only the missing portion is encrypted. Much less secure than the original 2048-bit RSA has to offer but good enough for our case.
  922. system "bash -c 'cat <<EOF >~/.ssh/id_rsa
  923. -----BEGIN RSA PRIVATE KEY-----
  924. MIIEpQIBAAKCAQEAnZGzFEypdXKY3KDT0Q3NLY4Bv74yKgJ4LIgbXothx8w4CfM0
  925. VeWBL/AE2iRISEWGB07LruM9y+U/wt58WlCVu001GuJuvXwWenlljsvH8qQlErYi
  926. oXlCwAeVVeanILGL8CPS7QlyzOwwnVF6NdcmfDJjTthBVFbvHrWGo5if86zcZyMR
  927. 2BB5QVEr5fU0yOPFp0+2p7J3cA6HQSKwjUiDtJ+lM62UQp7InCCT3qeh5KYHQcYb
  928. KVJTyj5iycVuBujHDwNAivLq82ojG7LcKjP+Ia8fblardCOQyFk6pSDM79NJJ2Dg
  929. 3ZbYIJeUmqSqFhRW/13Bro7Z1aNGrdh/XZkkHwIDAQABAoIBACHcBFJxYtzVIloO
  930. yVWcFKIcaO3OLjNu0monWVJIu1tW3BfvRijLJ6aoejJyJ4I4RmPdn9FWDZp6CeiT
  931. LL+vn21fWvELBWb8ekwZOCSmT7IpaboKn4h5aUmgl4udA/73iC2zVQkQxbWZb5zu
  932. vEdDk4aOwV5ZBDjecYX01hjjnEOdZHGJlF/H/Xs0hYX6WDG3/r9QCJJ0nfd1/Fk2
  933. zdbZRtAbyRz6ZHiYKnFQ441qRRaEbzunkvTBEwu9iqzlE0s/g49LJL0mKEp7rt/J
  934. 4iS3LZTQbJNx5J0ti8ZJKHhvoWb5RJxNimwKvVHC0XBZKTiLMrhnADmcpjLz53F8
  935. $SF_KEY
  936. sx27yCaeBeKXV0tFOeZmgK664VM9EgesjIX4sVOJ5mA3xBJBOtz9n66LjoIlIM58
  937. dvsAnJt7MUBdclL/RBHEjbUxgGBDcazfWSuJe0sGczhnXMN94ox4MSECgYEAx5cv
  938. cs/2KurjtWPanDGSz71LyGNdL/xQrAud0gi49H0tyYr0XmzNoe2CbZ/T5xGSZB92
  939. PBcz4rnHQ/oujo/qwjNpDD0xVLEU70Uy/XiY5/v2111TFC4clfE/syZPywKAztt3
  940. y2l5z+QdsNigRPDhKw+7CFYaAnYBEISxR6nabT8CgYEAqHrM8fdn2wsCNE6XvkZQ
  941. O7ZANHNIKVnaRqW/8HW7EFAWQrlQTgzFbtR4uNBIqAtPsvwSx8Pk652+OR1VKfSv
  942. ya3dtqY3rY/ErXWyX0nfPQEbYj/oh8LbS6zPw75yIorP3ACIwMw3GRNWIvkdAGTn
  943. BMUgpWHUDLWWpWRrSzNi90ECgYEAkxxzQ6vW5OFGv17/NdswO+BpqCTc/c5646SY
  944. ScRWFxbhFclOvv5xPqYiWYzRkmIYRaYO7tGnU7jdD9SqVjfrsAJWrke4QZVYOdgG
  945. cl9eTLchxLGr15b5SOeNrQ1TCO4qZM3M6Wgv+bRI0h2JW+c0ABpTIBzehOvXcwZq
  946. 6MhgD98CgYEAtOPqc4aoIRUy+1oijpWs+wU7vAc8fe4sBHv5fsv7naHuPqZgyQYY
  947. 32a54xZxlsBw8T5P4BDy40OR7fu+6miUfL+WxUdII4fD3grlIPw6bpNE0bCDykv5
  948. RLq28S11hDrKf/ZetXNuIprfTlhl6ISBy+oWQibhXmFZSxEiXNV6hCQ=
  949. -----END RSA PRIVATE KEY-----
  950. EOF'" or abort 'Failed to create user private key to id_rsa'
  951. system "bash -c 'chmod 600 ~/.ssh/id_rsa'" or abort 'Failed to change id_rsa file permission'
  952. end
  953. # Load custom rake scripts
  954. Dir['.rake/*.rake'].each { |r| load r }
  955. # vi: set ts=2 sw=2 expandtab: