git.rake revision 0f92c83be72626c93680facec849bb6ace681e2d
98N/Anamespace :git do
98N/A def reconfigure_cp_keys(source_file)
1600N/A data_root = Ontohub::Application.config.data_root
98N/A git_home = Ontohub::Application.config.git_home
98N/A
919N/A reconfigured_source = File.read(source_file).
919N/A sub(/^#define DATA_ROOT .*$/, "#define DATA_ROOT \"#{data_root}\"").
919N/A sub(/^#define GIT_HOME .*$/, "#define GIT_HOME \"#{git_home}\"")
919N/A
919N/A reconfigured_source_file = Tempfile.new(%w(cp_keys .c))
919N/A reconfigured_source_file.write(reconfigured_source)
919N/A reconfigured_source_file.close
919N/A puts "Copying #{source_file} to tempfile #{reconfigured_source_file.path}"
919N/A puts "Reconfiguring DATA_ROOT in this tempfile to #{data_root}"
919N/A puts "Reconfiguring GIT_HOME in this tempfile to #{git_home}"
919N/A
919N/A reconfigured_source_file
919N/A end
919N/A
919N/A def compile_gcc(source_path, target_path)
919N/A command = ['gcc', source_path, '-o', target_path]
919N/A puts "Compiling #{target_path.split('/').last} with"
98N/A puts command.map { |c| c.match(/\s/) ? "'#{c}'" : c }.join(' ')
98N/A system(*command)
98N/A end
98N/A
810N/A desc 'Compile cp_keys binary'
810N/A task :compile_cp_keys => :environment do
810N/A source_file = Rails.root.join('script', 'cp_keys.c')
810N/A target_path = Rails.root.join('bin', 'cp_keys').to_s
354N/A
354N/A reconfigured_source_tempfile = reconfigure_cp_keys(source_file)
354N/A compile_gcc(reconfigured_source_tempfile.path, target_path)
354N/A reconfigured_source_tempfile.unlink
354N/A end
354N/Aend
354N/A