63
64
65
66
67
68
69
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/dr/gitpackage.rb', line 63
def build(branch=nil, force=false)
branch = @default_branch unless branch
version = nil
orig_rev, curr_rev = update_from_origin branch
if curr_rev != orig_rev || force
Dir.mktmpdir do |src_dir|
log :info, "Extracting the sources"
git_cmd ="git --git-dir #{@git_dir} archive " +
"--format tar #{branch} | tar x -C #{src_dir}"
ShellCmd.new git_cmd, :tag => "git", :show_out => true
version = PkgVersion.new get_version "#{src_dir}/debian/changelog"
log :info, "Source version: #{version}"
while build_exists? version
version.increment!
end
log :info, "Building version: #{version}"
log :info, "Updating changelog"
now = Time.new.strftime("%a, %-d %b %Y %T %z")
ch_entry = "#{@name} (#{version}) kano; urgency=low\n"
ch_entry << "\n"
ch_entry << " * Package rebuilt, updated to revision #{curr_rev[0..7]}.\n"
ch_entry << "\n"
ch_entry << " -- Team Kano <[email protected]> #{now}\n\n"
changelog = ""
File.open "#{src_dir}/debian/changelog", "r" do |f|
changelog = f.read
end
File.open "#{src_dir}/debian/changelog", "w" do |f|
f.write ch_entry
f.write changelog
end
repo_arches = @repo.get_architectures
pkg_arches = get_architectures("#{src_dir}/debian/control")
arches = case
when pkg_arches.include?("any") || pkg_arches.include?("all")
repo_arches
else
repo_arches & pkg_arches
end
arches.each do |arch|
@repo.buildroot(arch).open do |br|
log :info, "Building the #{@name.fg("blue")} package " +
"v#{version} for #{arch}"
build_dir_name = "#{@name}-#{version.upstream}"
build_dir = "#{br}/#{build_dir_name}"
FileUtils.cp_r src_dir, build_dir
log :info, "Creating orig source tarball"
tar = "tar cz -C #{build_dir} --exclude=debian " +
"-f #{br}/#{@name}_#{version.upstream}.orig.tar.gz " +
"`ls -1 #{build_dir}`"
ShellCmd.new tar, :tag => "tar"
apt = "sudo chroot #{br} apt-get update"
deps = <<-EOS
sudo chroot #{br} <<EOF
dpkg-source -b "/#{build_dir_name}"
mk-build-deps *.dsc -i -t "apt-get --no-install-recommends -y"
rm -rf #{@name}-build-deps_*
EOF
EOS
build = <<-EOS
sudo chroot #{br} <<EOF
cd /#{build_dir_name}
debuild -i -uc -us -b
EOF
EOS
log :info, "Updating the sources lists"
ShellCmd.new apt, :tag => "apt-get", :show_out => true
log :info, "Installing build dependencies"
ShellCmd.new deps, :tag => "mk-build-deps", :show_out => true
log :info, "Building the package"
ShellCmd.new build, :tag => "debuild", :show_out => true
debs = Dir["#{br}/*.deb"]
expected_pkgs = get_subpackage_names "#{src_dir}/debian/control"
expected_pkgs.each do |subpkg_name|
includes = debs.inject(false) do |r, n|
r || ((/^#{br}\/#{subpkg_name}_#{version}/ =~ n) != nil)
end
unless includes
log :err, "Subpackage #{subpkg_name} did not build properly"
raise "Building #{name} failed"
end
end
build_dir = "#{@repo.location}/packages/#{@name}/builds/#{version}"
FileUtils.mkdir_p build_dir
debs.each do |pkg|
FileUtils.cp pkg, build_dir
end
end
end
end
else
log :info, "There were no changes in the #{pkg.name.fg("blue")} package"
log :info, "Build stopped (add -f to build anyway)"
end
version
end
|