2
0
Эх сурвалжийг харах

For Travis CI - attempt to enable ccache on OSX CI build.
[ci only: OSX]

Yao Wei Tjong 姚伟忠 10 жил өмнө
parent
commit
f55d06bc6b

+ 3 - 3
.travis.yml

@@ -117,8 +117,8 @@ script: rake ci
 before_cache: ccache -s
 before_cache: ccache -s
 after_success:
 after_success:
   - if [ $SITE_UPDATE ]; then rake ci_site_update; fi
   - if [ $SITE_UPDATE ]; then rake ci_site_update; fi
-  - if [ ${TRAVIS_JOB_NUMBER##*.} == 1 ]; then rake ci_create_mirrors; fi
   - if [ $PACKAGE_UPLOAD ]; then rake ci_package_upload; if [ $LINUX ] && [ ! "$URHO3D_64BIT" == "0" ]; then rake ci_package_upload URHO3D_USE_LIB64_RPM=1; fi; fi
   - if [ $PACKAGE_UPLOAD ]; then rake ci_package_upload; if [ $LINUX ] && [ ! "$URHO3D_64BIT" == "0" ]; then rake ci_package_upload URHO3D_USE_LIB64_RPM=1; fi; fi
+after_script: if [ ${TRAVIS_JOB_NUMBER##*.} == 1 ]; then rake ci_create_mirrors; fi
 notifications: {email: {on_success: never, on_failure: change}}
 notifications: {email: {on_success: never, on_failure: change}}
 
 
 ---
 ---
@@ -273,7 +273,7 @@ env:
     - secure: AfoHc5tpnYoI2TVGUeE9Xdru+15pd5N4YzO7EWvwmMnrHtNO3retrmKOGpnIyfbP2BeWRTW/z+BI4G0RrfvubjHu2us4wRh6Jq8+UZohBBkM+ldTnyqYHX97q+6ScWBWZGg7dpthd1x/7fmds8dSRzustHUhI7RzPbWEMQH1DGI=
     - secure: AfoHc5tpnYoI2TVGUeE9Xdru+15pd5N4YzO7EWvwmMnrHtNO3retrmKOGpnIyfbP2BeWRTW/z+BI4G0RrfvubjHu2us4wRh6Jq8+UZohBBkM+ldTnyqYHX97q+6ScWBWZGg7dpthd1x/7fmds8dSRzustHUhI7RzPbWEMQH1DGI=
     - NUMJOBS=3
     - NUMJOBS=3
     - OSX=1
     - OSX=1
-    - USE_CCACHE=1
+    - USE_CCACHE=2
     - CCACHE_SLOPPINESS=pch_defines,time_macros
     - CCACHE_SLOPPINESS=pch_defines,time_macros
     - CCACHE_COMPRESS=1
     - CCACHE_COMPRESS=1
   matrix:
   matrix:
@@ -298,7 +298,7 @@ before_script:
   - travis_retry brew update >/dev/null && travis_retry brew install ccache
   - travis_retry brew update >/dev/null && travis_retry brew install ccache
   - if [ $PACKAGE_UPLOAD ]; then travis_retry brew install doxygen graphviz; fi
   - if [ $PACKAGE_UPLOAD ]; then travis_retry brew install doxygen graphviz; fi
   - export PATH=$(brew info ccache |grep -o '\S*lib\S*'):$PATH
   - export PATH=$(brew info ccache |grep -o '\S*lib\S*'):$PATH
-  - ccache -z -M 200M
+  - if [ $XCODE ]; then cp -p $(which ccache) $(dirname $(xcodebuild -find-executable clang)) && for compiler in clang clang++; do path=$(xcodebuild -find-executable $compiler); mv $path{,.orig} && sudo ln -sf $(dirname $path)/clang.orig /usr/bin/$compiler && ln -s ccache $path; done; fi
   - if [ $IOS ]; then export CI_START_TIME=$(date +%s); fi
   - if [ $IOS ]; then export CI_START_TIME=$(date +%s); fi
 script: rake ci
 script: rake ci
 after_success: if [ $PACKAGE_UPLOAD ]; then rake ci_package_upload; fi
 after_success: if [ $PACKAGE_UPLOAD ]; then rake ci_package_upload; fi

+ 7 - 2
CMake/Modules/Urho3D-CMake-common.cmake

@@ -1463,8 +1463,13 @@ elseif (EMSCRIPTEN)
     endif ()
     endif ()
 elseif (NOT CMAKE_CROSSCOMPILING AND NOT CMAKE_HOST_WIN32 AND "$ENV{USE_CCACHE}")
 elseif (NOT CMAKE_CROSSCOMPILING AND NOT CMAKE_HOST_WIN32 AND "$ENV{USE_CCACHE}")
     # Warn user if PATH environment variable has not been correctly set for using ccache
     # Warn user if PATH environment variable has not been correctly set for using ccache
-    execute_process (COMMAND whereis -b ccache COMMAND grep -o \\S*lib\\S* RESULT_VARIABLE EXIT_CODE OUTPUT_VARIABLE CCACHE_SYMLINK ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
-    if (EXIT_CODE EQUAL 0 AND NOT ${CMAKE_C_COMPILER} MATCHES ${CCACHE_SYMLINK})
+    if (APPLE)
+        set (WHEREIS brew info ccache)
+    else ()
+        set (WHEREIS whereis -b ccache)
+    endif ()
+    execute_process (COMMAND ${WHEREIS} COMMAND grep -o \\S*lib\\S* RESULT_VARIABLE EXIT_CODE OUTPUT_VARIABLE CCACHE_SYMLINK ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if (EXIT_CODE EQUAL 0 AND NOT $ENV{PATH} MATCHES "${CCACHE_SYMLINK}")  # Need to stringify because CCACHE_SYMLINK variable could be empty when the command failed
         message (WARNING "The lib directory containing the ccache symlinks (${CCACHE_SYMLINK}) has not been added in the PATH environment variable. "
         message (WARNING "The lib directory containing the ccache symlinks (${CCACHE_SYMLINK}) has not been added in the PATH environment variable. "
             "This is required to enable ccache support for native compiler toolchain. CMake has been configured to use the actual compiler toolchain instead of ccache. "
             "This is required to enable ccache support for native compiler toolchain. CMake has been configured to use the actual compiler toolchain instead of ccache. "
             "In order to rectify this, the build tree must be regenerated after the PATH environment variable has been adjusted accordingly.")
             "In order to rectify this, the build tree must be regenerated after the PATH environment variable has been adjusted accordingly.")

+ 19 - 3
Rakefile

@@ -187,7 +187,7 @@ desc 'Configure, build, and test Urho3D project'
 task :ci do
 task :ci do
   # Skip if only performing CI for selected branches and the current branch is not in the list
   # Skip if only performing CI for selected branches and the current branch is not in the list
   matched = /\[ci only:(.*?)\]/.match(ENV['COMMIT_MESSAGE'])
   matched = /\[ci only:(.*?)\]/.match(ENV['COMMIT_MESSAGE'])
-  next if matched && !matched[1].split(/[ ,]/).reject!(&:empty?).map { |i| /#{ENV['TRAVIS_BRANCH']}/ =~ i }.any?
+  next if matched && !matched[1].split(/[ ,]/).reject!(&:empty?).map { |i| /#{i}/ =~ ENV['TRAVIS_BRANCH'] }.any?
   # Obtain our custom data, if any
   # Obtain our custom data, if any
   data = YAML::load(File.open(".travis.yml"))['data']
   data = YAML::load(File.open(".travis.yml"))['data']
   data['excluded_sample'].each { |name| ENV["EXCLUDE_SAMPLE_#{name}"] = '1' } if data && data['excluded_sample']
   data['excluded_sample'].each { |name| ENV["EXCLUDE_SAMPLE_#{name}"] = '1' } if data && data['excluded_sample']
@@ -195,6 +195,16 @@ task :ci do
   if ENV['CI'] && ENV['PACKAGE_UPLOAD'] && !ENV['RELEASE_TAG']
   if ENV['CI'] && ENV['PACKAGE_UPLOAD'] && !ENV['RELEASE_TAG']
     system 'git fetch --unshallow' or abort 'Failed to unshallow cloned repository'
     system 'git fetch --unshallow' or abort 'Failed to unshallow cloned repository'
   end
   end
+  # Use internal cache store instead of using Travis CI one (this is a workaround for using ccache on Travis CI legacy build infra)
+  if ENV['USE_CCACHE'].to_i == 2
+    puts 'Setting up build cache'
+    job_number = ENV['TRAVIS_JOB_NUMBER'].split('.')[1]
+    job_number = ".#{job_number}" if job_number
+    repo_slug = "#{ENV['TRAVIS_REPO_SLUG'].split('/')[0]}/cache-store.git"
+    # Do not abort even when it fails here
+    system "time if `git clone -q --depth 1 --branch #{ENV['TRAVIS_BRANCH']}#{job_number} https://github.com/#{repo_slug} ~/.ccache`; then ccache -z; else git clone -q --depth 1 https://github.com/#{repo_slug} ~/.ccache && cd ~/.ccache && git -qf checkout -b #{ENV['TRAVIS_BRANCH']}#{job_number} && ccache -M 100M; fi"
+    puts "\n"
+  end
   # Clear ccache on demand
   # Clear ccache on demand
   system 'ccache -C' if /\[ccache clear\]/ =~ ENV['COMMIT_MESSAGE']
   system 'ccache -C' if /\[ccache clear\]/ =~ ENV['COMMIT_MESSAGE']
   # Packaging always use Release configuration
   # Packaging always use Release configuration
@@ -202,7 +212,7 @@ task :ci do
     $configuration = 'Release'
     $configuration = 'Release'
     $testing = 0
     $testing = 0
   else
   else
-    $configuration = ENV['CI'] && ENV['USE_CCACHE'].to_i == 1 ? 'Release' : 'Debug'  # Aways use a same build configuration to keep ccache's cache size small when on Travis CI
+    $configuration = ENV['CI'] && ENV['USE_CCACHE'].to_i > 0 ? 'Release' : 'Debug'  # Aways use a same build configuration to keep ccache's cache size small when on Travis CI
     # Only 64-bit Linux environment with virtual framebuffer X server support and not MinGW build; or OSX build environment and not iOS build; or Emscripten build environment are capable to run tests
     # Only 64-bit Linux environment with virtual framebuffer X server support and not MinGW build; or OSX build environment and not iOS build; or Emscripten build environment are capable to run tests
     $testing = (ENV['LINUX'] && !ENV['URHO3D_64BIT']) || (ENV['OSX'] && ENV['IOS'].to_i != 1) || ENV['EMSCRIPTEN'] ? 1 : 0
     $testing = (ENV['LINUX'] && !ENV['URHO3D_64BIT']) || (ENV['OSX'] && ENV['IOS'].to_i != 1) || ENV['EMSCRIPTEN'] ? 1 : 0
     if $testing
     if $testing
@@ -221,6 +231,12 @@ task :ci do
     # GCC or Clang
     # GCC or Clang
     makefile_ci
     makefile_ci
   end
   end
+  # Upload cache to internal cache store
+  if ENV['USE_CCACHE'].to_i == 2
+    puts "\nStoring build cache"
+    # Do not abort even when it fails here
+    system "time (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)"
+  end
 end
 end
 
 
 # Usage: NOT intended to be used manually
 # Usage: NOT intended to be used manually
@@ -286,7 +302,7 @@ task :ci_create_mirrors do
   stream = YAML::load_stream(File.open('.travis.yml'))
   stream = YAML::load_stream(File.open('.travis.yml'))
   notifications = stream[0]['notifications']
   notifications = stream[0]['notifications']
   notifications['email']['recipients'] = `git show -s --format='%ae %ce' #{ENV['TRAVIS_COMMIT']}`.chomp.split.uniq unless notifications['email']['recipients']
   notifications['email']['recipients'] = `git show -s --format='%ae %ce' #{ENV['TRAVIS_COMMIT']}`.chomp.split.uniq unless notifications['email']['recipients']
-  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}"); unless (ci_only && ci_only.map { |i| /#{ci}/ =~ i }.any?) || (!ci_only && (branch['active'] || (scan && /Scan/ =~ ci))); system "if git fetch origin #{ci_branch}:#{ci_branch} 2>/dev/null; then git push -qf origin --delete #{ci_branch}; fi"; next; end; lastjob = doc['matrix'] && doc['matrix']['include'] ? doc['matrix']['include'].length : (doc['env']['matrix'] ? doc['env']['matrix'].length : 1); doc['after_script'] = (lastjob == 1 ? '%s' : "if [ ${TRAVIS_JOB_NUMBER##*.} == #{lastjob} ]; then %s; fi") % 'rake ci_delete_mirror'; doc['notifications'] = notifications unless doc['notifications']; File.open('.travis.yml.doc', 'w') { |file| file.write doc.to_yaml }; system "git checkout -B #{ci_branch} && rm .travis.yml && mv .travis.yml.doc .travis.yml && git add -A . && git commit -qm '#{branch['description']}' && git push -qf -u origin #{ci_branch} >/dev/null 2>&1 && git checkout -q -" or abort "Failed to create #{ci_branch} mirror branch" }
+  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}"); unless (ci_only && ci_only.map { |i| /#{i}/ =~ ci }.any?) || (!ci_only && (branch['active'] || (scan && /Scan/ =~ ci))); system "if git fetch origin #{ci_branch}:#{ci_branch} 2>/dev/null; then git push -qf origin --delete #{ci_branch}; fi"; next; end; lastjob = doc['matrix'] && doc['matrix']['include'] ? doc['matrix']['include'].length : (doc['env']['matrix'] ? doc['env']['matrix'].length : 1); doc['after_script'] = [*doc['after_script']] << (lastjob == 1 ? '%s' : "if [ ${TRAVIS_JOB_NUMBER##*.} == #{lastjob} ]; then %s; fi") % 'rake ci_delete_mirror'; doc['notifications'] = notifications unless doc['notifications']; File.open('.travis.yml.doc', 'w') { |file| file.write doc.to_yaml }; system "git checkout -B #{ci_branch} && rm .travis.yml && mv .travis.yml.doc .travis.yml && git add -A . && git commit -qm '#{branch['description']}' && git push -qf -u origin #{ci_branch} >/dev/null 2>&1 && git checkout -q -" or abort "Failed to create #{ci_branch} mirror branch" }
 end
 end
 
 
 # Usage: NOT intended to be used manually
 # Usage: NOT intended to be used manually