Module: Hoe::Perforce
- Defined in:
- lib/hoe/perforce.rb
Overview
seattle.rb perforce projects are structured as:
project_name/
dev/
History.txt
Manifest.txt
README.txt
Rakefile
bin/
lib/
test/
...
1.0.0/...
1.0.1/...
...
Each release is a branch from project_name/dev to project_name/version. In perforce, branches can be explicit (created via a branch spec) or implicit (created by command-line). This structure can accommodate either but the code below is implicit.
Instance Method Summary collapse
- #define_perforce_tasks ⇒ Object
- #p4_integrate(from, to) ⇒ Object
- #p4_revert(dir) ⇒ Object
- #p4_submit(description) ⇒ Object
-
#p4sh(cmd) ⇒ Object
perforce has an annoying “feature” that reads PWD and chdir’s to it.
- #validate_manifest_file(manifest_dir) ⇒ Object
Instance Method Details
#define_perforce_tasks ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hoe/perforce.rb', line 29 def define_perforce_tasks warn :define_perforce_tasks if $DEBUG desc "branch the project from dev to version dir" task :branch do Dir.chdir ".." target_dir = File.directory?(version) ? version : "dev" branching = target_dir == "dev" pkg = File.basename(Dir.pwd) begin p4_integrate "dev", version if branching validate_manifest_file version p4_submit "Branching #{pkg} to version #{version}" if branching rescue => e p4_revert version raise e end Dir.chdir version end task :prerelease => :branch task :postrelease => :announce do system 'rake clean' end end |
#p4_integrate(from, to) ⇒ Object
107 108 109 110 111 |
# File 'lib/hoe/perforce.rb', line 107 def p4_integrate from, to opened = `p4 opened ... 2>&1` raise "You have files open" unless opened =~ /file\(s\) not opened/ p4sh "p4 integrate #{from}/... #{to}/..." end |
#p4_revert(dir) ⇒ Object
102 103 104 105 |
# File 'lib/hoe/perforce.rb', line 102 def p4_revert dir puts "reverting #{dir}" p4sh "p4 revert #{dir}/..." end |
#p4_submit(description) ⇒ Object
113 114 115 |
# File 'lib/hoe/perforce.rb', line 113 def p4_submit description p4sh "p4 submit -d #{description.inspect} ..." end |
#p4sh(cmd) ⇒ Object
perforce has an annoying “feature” that reads PWD and chdir’s to it. Without either mucking in ENV or forcing a different kind of system call, it’ll be in the original rake directory. I don’t want that for these recipes, so we tack on “;” in order to force the right type of exec.
66 67 68 |
# File 'lib/hoe/perforce.rb', line 66 def p4sh cmd sh "#{cmd};" end |
#validate_manifest_file(manifest_dir) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/hoe/perforce.rb', line 70 def validate_manifest_file manifest_dir manifest_file = "#{manifest_dir}/Manifest.txt" raise "#{manifest_file} does not exist" unless test ?f, manifest_file manifest = File.new(manifest_file).readlines.map { |x| x.strip } local_manifest = [] Dir.chdir manifest_dir do system 'rake clean' Find.find '.' do |f| local_manifest << f.sub(/^\.\//, '') if File.file? f end end extra_files = local_manifest - manifest missing_files = manifest - local_manifest msg = [] unless extra_files.empty? then msg << "You have files that are not in your manifest" msg << " #{extra_files.inspect}" end unless missing_files.empty? then msg << "You have files that are missing from your manifest" msg << " #{missing_files.inspect}" end raise msg.join("\n") unless msg.empty? end |