require 'p4util/tasks' require 'rake/clean' P4Util::Tasks.new do |p4util| p4util.basename = 'api_' p4util.version = 'r14.2' p4util.p4_init_dir = 'p4_web_api/clients/ruby/p4_web_api_client/spec/init.base' end P4Util::Tasks.new do |p4util| p4util.basename = 'proj_' p4util.version = 'r14.2' p4util.p4_init_dir = 'p4_project_services/clients/ruby/p4_project_services_client/spec/init' end desc 'Create a new config.ru in the work/ directory for launching the web apps' task 'work/config.ru' do Dir.mkdir('work') unless Dir.exist?('work') File.open('work/config.ru', 'w') do |f| f.puts <<-END.gsub(/^[ ]{4}/, '') require 'p4_web_api' require 'p4_project_services' # Avoid any environmental status pollution from your dev environment ENV.keys.select { |k| k =~ /^P4/ }.each { |k| ENV.delete(k) } api = P4WebAPI::App.new api.settings.p4 = { 'port' => 'localhost:1666', 'charset' => 'auto' } api.settings.token_path = '#{File.absolute_path('work/tokens')}' api.settings.workspace_folder = '#{File.absolute_path('work/workspaces')}' proj = P4ProjectServices::App.new proj.settings.p4 = { 'port' => 'localhost:1666', 'charset' => 'auto' } proj.settings.token_path = '#{File.absolute_path('work/tokens')}' proj.settings.p4_web_api_url = 'http://localhost:4567' proj.settings.p4_web_api_prefix = '/p4_web_api/v1' run Rack::URLMap.new( '/p4_web_api' => api, '/p4_project_services' => proj ) END end end desc 'Create the Unicorn config for testing' task 'work/unicorn.rb' do Dir.mkdir('work') unless Dir.exist?('work') File.open('work/unicorn.rb', 'w') do |f| f.puts <<-END.gsub(/^[ ]{4}/, '') pid '#{File.absolute_path('work/unicorn.pid')}' listen 4567 worker_processes 2 END end end desc 'Start p4_web_services unicorn instance (in background)' task :services_start => ['work/unicorn.rb', 'work/config.ru'] do pid = Process.spawn('bundle exec unicorn -c work/unicorn.rb work/config.ru') Process.detach(pid) File.open('work/p4_web_services.pid', 'w') do |f| f.puts(pid) end retries = 10 while !system('curl http://localhost:4567/') do sleep(0.25) retries -= 1 end system('curl http://localhost:4567') or fail 'did not start services' end desc 'Kills the spawned p4_web_services process (via the PID file)' task :services_stop do if File.exist?('work/unicorn.pid') pid = IO.read('work/unicorn.pid').to_i Process.kill('TERM', pid) end end begin require 'ci/reporter/rake/rspec' require 'rspec/core/rake_task' ENV['CI_REPORTS'] = 'spec-output' CLEAN.include('spec-output', 'coverage') RSpec::Core::RakeTask.new(:api_spec) do |t| t.pattern = 'p4_web_api/clients/ruby/p4_web_api_client/spec/*.rb' t.ruby_opts = ["-I#{File.absolute_path('p4_web_api/clients/ruby/p4_web_api_client/spec/lib')}"] end task api_spec: 'ci:setup:rspec' RSpec::Core::RakeTask.new(:proj_spec) do |t| t.pattern = 'p4_project_services/clients/ruby/p4_project_services_client/spec/*.rb' t.ruby_opts = ["-I#{File.absolute_path('p4_project_services/clients/ruby/p4_project_services_client/spec/lib')}"] end task proj_spec: 'ci:setup:rspec' rescue LoadError # no rspec available end desc 'Build all gems and copy them to our top-level pkg/ directory' task :build do system('cd p4_web_services_auth && rake build') or fail 'rake gem failed for p4_web_services_auth' system('cd p4_web_api/p4_web_api && rake package') or fail 'rake package failed for p4_web_api' system('cd p4_web_api/clients/ruby/p4_web_api_client && rake build') or fail 'rake build failed for p4_web_api_client' system('cd p4_project_services/p4_project_services_data && rake build') or fail 'rake build failed for p4_project_services_data' system('cd p4_project_services/p4_project_services && rake build') or fail 'rake build failed for p4_project_services' system('cd p4_project_services/clients/ruby/p4_project_services_client && rake build') or fail 'rake build failed for p4_project_services_client' system('cd p4_phoenix_services/p4_phoenix_services && rake build') or fail 'rake build failed for p4_phoenix_services' if Dir.exist?('build') `chmod -R +w build` end Dir.mkdir('build') unless Dir.exist?('build') Dir.mkdir('build/gem') unless Dir.exist?('build/gem') Dir.glob('**/pkg/*.gem').each do |f| FileUtils.copy(f, "build/gem/#{File.basename(f)}") end ['p4_project_services/clients/qt/p4_project_services_client', 'p4_phoenix_services/clients/qt/p4_phoenix_services_client'].each do |project| project_name = File.basename(project) Dir.glob("#{project}/**/*.h").each do |file| relative_path = file[(project.length+1)..-1] FileUtils.mkdir_p("build/include/#{File.dirname(relative_path)}") changelist=`p4 changes -m1 '//web-services/p4ws-main/...#have' | awk '{print $2}'`.strip contents = nil File.open(file, 'rb') do |f| contents = f.read.gsub('DEV', changelist) end File.open("build/include/#{relative_path}", 'wb') do |f| f.write(contents) end end end Dir.glob('') end CLEAN.include('**/pkg')