require 'rake' require 'rake/clean' require 'json' include Rake::DSL require_relative './environment.rb' require_relative './commands.rb' require_relative './dependencies.rb' require_relative './console.rb' require_relative './timer.rb' require_relative './settings.rb' require_relative './text.rb' require_relative './svnexports.rb' require_relative './logger.rb' CLEAN.include('log','bin/**/*.pdb') CLOBBER.include('bin','obj','TestResults','*.gem','bin/**/*.exe') class DevTasks < Hash attr_accessor :timer def initialize @timer = Timer.new self[:name]=pwd.split('/').last#Rake.application.original_dir.split('/').last self[:svn_exports]=SvnExports.new self[:scm]=Environment.scm self[:scm_origin]=Environment.scm_origin self[:branch]=Environment.branch self[:task_order]=['pull','upgrade','setup','add','build','test','commit','push','verify','publish'] self[:relative_directory]=Environment.relative_directory self[:working_directory]=Environment.working_directory self[:context]=Environment.context self[:machine]=Environment.machine self[:platform]=RUBY_PLATFORM self[:dev_root]=Environment.dev_root self[:settings]=Settings.new self[:files]=Hash.new #self[:files][:source]=Rake::FileList.new("**/{*.{rb,feature,spec,gemspec,cs,c,m,cpp,cxx,h,hpp,i,jam,csproj,vcproj,snk,vcxproj,xcodeproj,plist,xib,sln,filters,xaml,yml,json,resx,settings,config},Jamfile,.semver,Gemfile,README,LICENSE}") self[:files][:source]=Rake::FileList.new("**/{*.{rb,feature,spec,gemspec}}") self[:files][:source].include('**/*.{cs,csproj,sln}') self[:files][:source].include('**/*.{cpp,cxx,h,hpp,i,c,vcproj,vcxproj,filters,resx,settings,config}') self[:files][:source].include('**/*.{m,xcodeproj,xib}') self[:files][:source].include('**/*.{xaml,xml,yaml,yml,json,md}') self[:files][:source].include('**/{Jamfile,.semver,Gemfile,README,LICENSE}') self[:files][:source].exclude("log/**/*.*") self[:files][:source].exclude("bin/**/*.*") self[:files][:source].exclude("obj/**/*.*") self[:files][:build]=Rake::FileList.new('**/*.{gemspec,sln}') self[:files][:artifact]=Rake::FileList.new("**/*.{gem,lib,dll,exe,h,hpp}") self[:commands]=Commands.new update end def add hash hash.each do |key,value| self[key]=value if !has_key?(key) end end def update self[:dependencies]=Dependencies.new if !has_key?(:dependencies) allartifactsexist = true self[:files][:artifact].each{|f| allartifactsexist=false if !File.exists?(f)} self[:newest_source_file]=self[:files][:source].max_by {|f| File.mtime(f)} self[:newest_artifact_file]=self[:files][:artifact].max_by { |f| File.mtime(f) } if allartifactsexist self[:commands]=Commands.new if !has_key?(:commands) #self[:commands].update self[:up_to_date] = false if(allartifactsexist && !self[:newest_artifact].nil? && !self[:newest_src_file].nil? && File.exists?(self[:newest_artifact]) && File.exists?(self[:newest_src_file])) if(File.mtime(self[:newest_artifact]) > File.mtime(self[:newest_src_file])) self[:task_order]=['upgrade'] if(File.mtime(self[:newest_artifact]) > File.mtime(self[:newest_src_file])) self[:up_to_date]=true end self[:newest_artifact_file_mtime]=File.mtime(self[:newest_artifact_file]).to_s self[:newest_source_file_mtime]=File.mtime(self[:newest_source_file]).to_s end update_tasks end def execute cmd self[:commands].execute_command cmd end def execute_task task self[:commands].execute_task task end def define_task task_name if(!Rake::Task.task_defined?(task_name)) ruby="desc '#{DevTasks.description(task_name)} ';task :#{task_name} do;DEV_TASKS.execute_task '#{task_name}';end" eval(ruby) end end def self.description task_name descriptions={ "add"=>"add untracked files to revision control system", "build"=>"executes build commands", "test"=>"executes test commands", "setup"=>"executes setup commands", "commit"=>"commit changes to revision control system" } if descriptions.has_key?(task_name.to_s) descriptions[task_name.to_s] else "#{task_name} task" end end def update_tasks dev_task_defaults=Array.new self[:commands].each do |key,array| #if(array.length > 0) define_task key dev_task_defaults << key #end end update_task_dependencies end def update_task_dependencies eval('task :build=>[:setup]') if Rake::Task.task_defined?(:setup) && Rake::Task.task_defined?(:build) eval('task :test=>[:build]') if Rake::Task.task_defined?(:build) && Rake::Task.task_defined?(:test) end def setup_svn_export(uri,dir) DEV_TASKS[:commands][:setup] << "svn export #{uri} #{dir}" if(!File.exists?(dir)) end def setup_copy(src,dest) if(File.exists?(src)) FileUtils.mkdir_p(File.dirname(dest)) if(!File.exists?(File.dirname(dest))) if(!File.exists?(dest)) DEV_TASKS[:commands][:setup] << "<%FileUtils.cp('#{src}','#{dest}')%>" end else if(src.kind_of?(Array)) src.each{|s|setup_copy(s,dest)} end end end def self.svn_export(dep_dir,uri) if(!File.exists?("#{Environment.dev_root}/dep/#{dep_dir}")) dest="#{Environment.dev_root}/dep/#{dep_dir}" Environment.execute "svn export #{uri} #{Environment.dev_root}/dep/#{dep_dir}" if !dest.include?("@") Environment.execute "svn export #{uri} #{Environment.dev_root}/dep/#{dep_dir}@" if dest.include?("@") end end end DEV_TASKS=DevTasks.new DEV=DEV_TASKS desc 'executes tasks in order of task_order, if they are defined' task :dev_tasks_default do DEV_TASKS.update DEV_TASKS[:task_order].each{|c| Rake::Task[c].invoke if(Rake::Task.task_defined?(c)) } puts "Total Time " + DEV_TASKS.timer.elapsed_str end desc 'dev_tasks default' task :default do Rake::Task[:dev_tasks_default].invoke Logger.finalize end desc 'displays information about current rake directory' task :info do DEV_TASKS.update Console.print_hash("",DEV_TASKS) end desc 'displays help for dev_task' task :help do puts "use rake -T to see available tasks" end #desc 'rake projects defined in DEV_TASKS[:dependencies][:projects]' task :rake_dependencies_projects do Console.announce_task_start "rake_dependencies_projects" DEV_TASKS[:dependencies][:projects].each{|project| dir=Environment.dev_root + "/wrk/" + project Environment.rake(dir,"default",true) if File.exists?(dir) } end #desc 'clobber projects defined in DEV_TASKS[:dependencies][:projects]' task :clobber_dependencies_projects do Console.announce_task_start "clobber_dependencies_projects" DEV_TASKS[:dependencies][:projects].each{|project| dir=Environment.dev_root + "/wrk/" + project Environment.rake(dir,"clobber",true) if File.exists?(dir) } end #desc 'clean projects defined in DEV_TASKS[:dependencies][:projects]' task :clean_dependencies_projects do Console.announce_task_start "clean_dependencies_projects" DEV_TASKS[:dependencies][:projects].each{|project| dir=Environment.dev_root + "/wrk/" + project Environment.rake(dir,"clean",true) if File.exists?(dir) } end