Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 81 lines (69 sloc) 2.24 kb
d1a7d24 @bcui6611 Automatically generate manifest files based on gerrit-refspec
bcui6611 authored
1 #!/usr/bin/env ruby
2
3 require 'rexml/document'
4 require 'rubygems'
5 require 'rake'
6 if ARGV.size < 4
7 puts "I need at least 4 arg: repo/manifest.xml newmanifest.xml ep-engine master"
8 exit 1
9 end
10
11 path = ARGV[0] # Required. Example: some/repo/manifest/default.xml
12 oxml = ARGV[1] # Example: output/build-manifest.xml -- usable as input to repo tool.
13 gerrit_project = ARGV[2] # Required.
14 gerrit_refspec = ARGV[3] # Required.
15
16 root = REXML::Document.new(File.new(path)).root
17
18 default = root.get_elements("//default")[0]
19 remotes = {}
20
21 root.each_element("//remote") do |remote|
22 remotes[remote.attributes['name']] = remote
23 end
24
25 projects = {}
26
27 root.each_element("//project") do |project|
28 projects[project.attributes['name']] = project
29 end
30
31 if oxml
32 # Emit a manifest.xml that can be used as input to
33 # the repo / fetch-manifest.rb tool.
34 #
35 File.open(oxml, 'w') do |o|
36 o.write "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
37 o.write "<manifest>\n"
38 remotes.keys.sort.each do |name|
39 remote = remotes[name]
40 o.write " <remote name=\"#{name}\" fetch=\"#{remote.attributes['fetch']}\"/>\n"
41 end
42 o.write "\n"
43 o.write " <default remote=\"#{default.attributes['remote']}\" revision=\"#{default.attributes['revision']}\"/>\n"
44 o.write "\n"
45 projects.keys.sort.each do |name|
46 project = projects[name]
47 remote = project.attributes['remote']
48 path = project.attributes['path'] || project.attributes['name']
49 curr = project.attributes['revision'] || default.attributes['revision']
50 if name == gerrit_project
51 curr = gerrit_refspec
52 end
53 Dir.chdir(path) do
54 #curr = `git rev-parse HEAD`.chomp
55 o.write " <project name=\"#{name}\" path=\"#{path}\" revision=\"#{curr}\""
56 if remote
57 o.write "\n"
58 o.write " remote=\"#{remote}\""
59 end
60
61 has_body = false
62
63 project.each_element do |child|
64 o.write(">\n") unless has_body
65 o.write(" ")
66 o.write(child)
67 o.write("\n")
68 has_body = true
69 end
70
71 if has_body
72 o.write " </project>\n"
73 else
74 o.write "/>\n"
75 end
76 end
77 end
78 o.write "</manifest>\n"
79 end
80 end
Something went wrong with that request. Please try again.