require 'rake/clean' require 'rake/packagetask' Rake::PackageTask.new('helix-web-services', :noversion) do |package| package.need_tar = true package.package_files.include('build/**/*') package.package_files.include('doc/**/*') package.package_files.include('helix_web_services/**/*') package.package_files.include('helix_web_services_client/**/*') package.package_files.include('packaging/**/*') package.package_files.include('Gemfile') package.package_files.include('Gemfile.lock') package.package_files.include('Rakefile') package.package_files.include('README.md') package.package_files.include('LICENSE') end namespace :nginx do desc 'Creates the nginx config in work/' task :config do Dir.mkdir('work') unless Dir.exist?('work') File.open('work/nginx.conf', 'w') do |f| f.puts <<-END.gsub(/^[ ]{8}/, '') pid #{File.absolute_path('work/nginx.pid')}; error_log #{File.absolute_path('work/nginx.errors.log')}; worker_processes 10; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] $status ' '"$request" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log #{File.absolute_path('work/nginx.access.log')} main; map $http_upgrade $connection_upgrade { default Upgrade; '' close; } server { listen 8080; location /hws { rewrite /hws/(.*) /$1 break; proxy_pass $scheme://127.0.0.1:9000; } location / { root #{File.absolute_path('helix_web_components')}; include /usr/local/etc/nginx/mime.types; } } } END end end desc 'Start nginx locally' task :start => :config do sh "nginx -c #{File.absolute_path('work/nginx.conf')}" or fail 'nginx failed' end desc 'Stop local nginx' task :stop do if File.exist?('work/nginx.pid') pid = IO.read('work/nginx.pid').to_i Process.kill('TERM', pid) end end end namespace :qt do desc 'Rebuild native tools in qt/work directory (please set CMAKE_PREFIX_PATH in environment)' task :build do FileUtils.rmtree('qt/work') if Dir.exist?('qt/work') FileUtils.mkdir('qt/work') system('cd qt/work && cmake .. && make') or fail('qt build failed') end CLEAN.include('qt/work') desc 'Run all qt tests' task :test do system('cd qt/work/p4_phoenix_services_client && ./PhoenixIntegrationTests') or fail('PhoenixIntegrationTests failed') end desc 'Archive Qt package in build/ directory' task :publish do if Dir.exist?('build') `chmod -R +w build` end Dir.mkdir('build') unless Dir.exist?('build') ['helix_web_services_client_qt'].each do |project| project_name = File.basename(project) puts "Preparing project #{project_name} from #{project}" Dir.glob("#{project}/**/*").each do |file| relative_path = file[(project.length+1)..-1] if File.file?(file) FileUtils.mkdir_p("build/#{project_name}/#{File.dirname(relative_path)}") changelist=`p4 changes -m1 ...#have | awk '{print $2}'`.strip contents = nil File.open(file, 'rb') do |f| contents = f.read.gsub('DEV', changelist) end File.open("build/#{project_name}/#{relative_path}", 'wb') do |f| f.write(contents) end end end end Dir.glob('') end end desc 'Rebuild the main ASCIIDoc documentation' task :asciidoc do system('bundle exec asciidoctor -o build/doc/p4ws.html doc/p4ws.asc') || fail('asciidoctor failed') end namespace :all do desc 'Rebuild documentation across system' task :doc => :asciidoc do system('cd helix_web_services_client && bundle exec rake yard') || fail('rake yard failed for helix_web_services_client') system('cd helix_web_services && bundle exec rake yard') || fail('rake yard failed for helix_web_services') end end desc 'Run unit and integrated tests against a local development server' task :test do error = initialize_p4d error ||= initialize_development_unicorn error ||= run_server_tests error ||= run_client_tests cleanup fail('tests failed, see output for details') if error end def initialize_p4d puts 'starting p4d' ok = system('cd helix_web_services_client && bundle exec p4util kill') return true unless ok if Dir.exist?('/tmp/p4util/p4droot') require 'fileutils' FileUtils.rmtree('/tmp/p4util/p4droot') end ok = system('cd helix_web_services_client && bundle exec p4util start') return true unless ok ok = system('cd helix_web_services_client && bundle exec p4util init') return true unless ok end def initialize_development_unicorn puts 'starting unicorn' begin ok = system( 'cd helix_web_services && ' + 'WORKSPACE_DIR=/tmp/tokens ' + 'UNICORN_PID=/tmp/unicorn.pid ' + 'HWS_STDOUT_PATH=/tmp/unicorn.out ' + 'HWS_STDERR_PATH=/tmp/unicorn.err ' + 'bundle exec unicorn -c config/unicorn.rb -D' ) return true unless ok while connect_to_server == false sleep(0.1) end return false rescue Exception => e puts "Error: #{e.message}" return true end end def connect_to_server require 'socket' begin s = TCPSocket.new 'localhost', 9000 s.close return true rescue Exception => e return false end end def run_server_tests ok = system('cd helix_web_services && bundle exec rake spec') return true unless ok end def run_client_tests ok = system('cd helix_web_services_client && bundle exec rake spec') return true unless ok end def cleanup ok = system('cd helix_web_services_client && bundle exec p4util kill') return true unless ok if Dir.exist?('/tmp/p4util/p4droot') require 'fileutils' FileUtils.rmtree('/tmp/p4util/p4droot') end if File.exist?('/tmp/unicorn.pid') unicorn_pid = IO.read('/tmp/unicorn.pid').to_i puts "killing pid: #{unicorn_pid}" Process.kill('TERM', unicorn_pid) File.unlink('/tmp/unicorn.pid') end end desc 'Create primary source deliverables' task :build => [:package]