packaging 0.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +17 -0
  3. data/README-Solaris.md +117 -0
  4. data/README.md +1031 -0
  5. data/lib/packaging.rb +32 -0
  6. data/lib/packaging/artifactory.rb +278 -0
  7. data/lib/packaging/config.rb +392 -0
  8. data/lib/packaging/config/params.rb +366 -0
  9. data/lib/packaging/deb.rb +28 -0
  10. data/lib/packaging/deb/repo.rb +263 -0
  11. data/lib/packaging/gem.rb +112 -0
  12. data/lib/packaging/ips.rb +57 -0
  13. data/lib/packaging/msi.rb +89 -0
  14. data/lib/packaging/nuget.rb +39 -0
  15. data/lib/packaging/osx.rb +36 -0
  16. data/lib/packaging/paths.rb +238 -0
  17. data/lib/packaging/platforms.rb +480 -0
  18. data/lib/packaging/repo.rb +55 -0
  19. data/lib/packaging/retrieve.rb +46 -0
  20. data/lib/packaging/rpm.rb +5 -0
  21. data/lib/packaging/rpm/repo.rb +257 -0
  22. data/lib/packaging/tar.rb +154 -0
  23. data/lib/packaging/util.rb +146 -0
  24. data/lib/packaging/util/date.rb +15 -0
  25. data/lib/packaging/util/execution.rb +85 -0
  26. data/lib/packaging/util/file.rb +125 -0
  27. data/lib/packaging/util/git.rb +174 -0
  28. data/lib/packaging/util/git_tags.rb +73 -0
  29. data/lib/packaging/util/gpg.rb +62 -0
  30. data/lib/packaging/util/jenkins.rb +95 -0
  31. data/lib/packaging/util/misc.rb +69 -0
  32. data/lib/packaging/util/net.rb +368 -0
  33. data/lib/packaging/util/os.rb +17 -0
  34. data/lib/packaging/util/platform.rb +40 -0
  35. data/lib/packaging/util/rake_utils.rb +111 -0
  36. data/lib/packaging/util/serialization.rb +19 -0
  37. data/lib/packaging/util/ship.rb +171 -0
  38. data/lib/packaging/util/tool.rb +41 -0
  39. data/lib/packaging/util/version.rb +326 -0
  40. data/spec/fixtures/config/ext/build_defaults.yaml +2 -0
  41. data/spec/fixtures/config/ext/project_data.yaml +2 -0
  42. data/spec/fixtures/config/params.yaml +2 -0
  43. data/spec/fixtures/configs/components/test_file.json +1 -0
  44. data/spec/fixtures/configs/components/test_file_2.json +0 -0
  45. data/spec/fixtures/configs/components/test_file_not_tagged.json +1 -0
  46. data/spec/fixtures/configs/components/test_file_wrong_ext.txt +0 -0
  47. data/spec/fixtures/configs/components/test_file_wrong_ext.wrong +0 -0
  48. data/spec/fixtures/util/pre_tasks.yaml +4 -0
  49. data/spec/lib/packaging/artifactory_spec.rb +171 -0
  50. data/spec/lib/packaging/config_spec.rb +556 -0
  51. data/spec/lib/packaging/deb/repo_spec.rb +148 -0
  52. data/spec/lib/packaging/deb_spec.rb +52 -0
  53. data/spec/lib/packaging/paths_spec.rb +153 -0
  54. data/spec/lib/packaging/platforms_spec.rb +153 -0
  55. data/spec/lib/packaging/repo_spec.rb +97 -0
  56. data/spec/lib/packaging/retrieve_spec.rb +61 -0
  57. data/spec/lib/packaging/rpm/repo_spec.rb +133 -0
  58. data/spec/lib/packaging/tar_spec.rb +122 -0
  59. data/spec/lib/packaging/util/execution_spec.rb +56 -0
  60. data/spec/lib/packaging/util/file_spec.rb +139 -0
  61. data/spec/lib/packaging/util/git_spec.rb +160 -0
  62. data/spec/lib/packaging/util/git_tag_spec.rb +36 -0
  63. data/spec/lib/packaging/util/gpg_spec.rb +64 -0
  64. data/spec/lib/packaging/util/jenkins_spec.rb +112 -0
  65. data/spec/lib/packaging/util/misc_spec.rb +31 -0
  66. data/spec/lib/packaging/util/net_spec.rb +239 -0
  67. data/spec/lib/packaging/util/os_spec.rb +31 -0
  68. data/spec/lib/packaging/util/rake_utils_spec.rb +70 -0
  69. data/spec/lib/packaging/util/ship_spec.rb +117 -0
  70. data/spec/lib/packaging/util/version_spec.rb +123 -0
  71. data/spec/lib/packaging_spec.rb +19 -0
  72. data/spec/spec_helper.rb +36 -0
  73. data/static_artifacts/PackageInfo.plist +3 -0
  74. data/tasks/00_utils.rake +216 -0
  75. data/tasks/30_metrics.rake +33 -0
  76. data/tasks/apple.rake +266 -0
  77. data/tasks/build.rake +12 -0
  78. data/tasks/clean.rake +5 -0
  79. data/tasks/config.rake +30 -0
  80. data/tasks/deb.rake +129 -0
  81. data/tasks/deb_repos.rake +28 -0
  82. data/tasks/deprecated.rake +130 -0
  83. data/tasks/doc.rake +20 -0
  84. data/tasks/education.rake +57 -0
  85. data/tasks/fetch.rake +57 -0
  86. data/tasks/gem.rake +146 -0
  87. data/tasks/jenkins.rake +494 -0
  88. data/tasks/jenkins_dynamic.rake +202 -0
  89. data/tasks/load_extras.rake +21 -0
  90. data/tasks/mock.rake +348 -0
  91. data/tasks/nightly_repos.rake +335 -0
  92. data/tasks/pe_deb.rake +12 -0
  93. data/tasks/pe_rpm.rake +13 -0
  94. data/tasks/pe_ship.rake +221 -0
  95. data/tasks/pe_sign.rake +13 -0
  96. data/tasks/pe_tar.rake +5 -0
  97. data/tasks/retrieve.rake +45 -0
  98. data/tasks/rpm.rake +66 -0
  99. data/tasks/rpm_repos.rake +29 -0
  100. data/tasks/ship.rake +752 -0
  101. data/tasks/sign.rake +226 -0
  102. data/tasks/tag.rake +8 -0
  103. data/tasks/tar.rake +34 -0
  104. data/tasks/update.rake +16 -0
  105. data/tasks/vanagon.rake +35 -0
  106. data/tasks/vendor_gems.rake +117 -0
  107. data/tasks/version.rake +33 -0
  108. data/tasks/z_data_dump.rake +65 -0
  109. data/templates/README +1 -0
  110. data/templates/downstream.xml.erb +47 -0
  111. data/templates/msi.xml.erb +197 -0
  112. data/templates/packaging.xml.erb +344 -0
  113. data/templates/repo.xml.erb +114 -0
  114. metadata +234 -0
@@ -0,0 +1,123 @@
1
+ # -*- ruby -*-
2
+ require 'spec_helper'
3
+
4
+ # Spec tests for Pkg::Util::Version
5
+ #
6
+ # rubocop:disable Metrics/BlockLength
7
+ describe 'Pkg::Util::Version' do
8
+ context '#versionbump' do
9
+ let(:version_file) { 'thing.txt' }
10
+ let(:version) { '1.2.3' }
11
+ let(:orig_contents) { "abcd\nVERSION = @DEVELOPMENT_VERSION@\n" }
12
+ let(:updated_contents) { "abcd\nVERSION = #{version}\n" }
13
+
14
+ it 'should update the version file contents accordingly' do
15
+ Pkg::Config.config_from_hash(project: 'foo', version_file: version_file)
16
+ allow(IO).to receive(:read).with(version_file) { orig_contents }
17
+ allow(Pkg::Config).to receive(:version) { version }
18
+ version_file_to_write = double('file')
19
+ expect(File).to receive(:open).with(version_file, 'w').and_yield(version_file_to_write)
20
+ expect(version_file_to_write).to receive(:write).with(updated_contents)
21
+ Pkg::Util::Version.versionbump
22
+ end
23
+ end
24
+
25
+ describe '#base_pkg_version' do
26
+ version_hash = {
27
+ '5.6' => ['5.6', '1'],
28
+ '1.0.0' => ['1.0.0', '1'],
29
+ '2017.6.5.3' => ['2017.6.5.3', '1'],
30
+ '4.99.0-22' => ['4.99.0.22', '0.1'],
31
+ '1.0.0-658-gabc1234' => ['1.0.0.658.gabc1234', '0.1'],
32
+ '5.0.0.master.SNAPSHOT.2017.05.16T1357' => ['5.0.0.master', '0.1SNAPSHOT.2017.05.16T1357'],
33
+ '5.9.7-rc4' => ['5.9.7', '0.1rc4'],
34
+ '5.9.7-rc4-65-gabc1234' => ['5.9.7.65.gabc1234', '0.1rc4'],
35
+ '5.9.7-rc4-65-gabc1234-dirty' => ['5.9.7.65.gabc1234', '0.1rc4dirty'],
36
+ '4.99.0-dirty' => ['4.99.0', '0.1dirty'],
37
+ '4.99.0-56-gabc1234-dirty' => ['4.99.0.56.gabc1234', '0.1dirty']
38
+ }
39
+ version_hash.each do |pre, post|
40
+ before do
41
+ allow(Pkg::Config).to receive(:version) { pre }
42
+ allow(Pkg::Config).to receive(:release) { '1' }
43
+ allow(Pkg::Config).to receive(:vanagon_project) { false }
44
+ end
45
+
46
+ it "transforms #{pre} to #{post}" do
47
+ expect(Pkg::Util::Version.base_pkg_version(pre)).to eq post
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#final?' do
53
+ final_versions = [
54
+ '1.0.0',
55
+ '2017.6.5.3',
56
+ '0.6.8',
57
+ '2068.532.6',
58
+ '96.5'
59
+ ]
60
+
61
+ non_final_versions = [
62
+ '4.99.0-22',
63
+ '1.0.0-658-gabc1234',
64
+ '5.0.0.master.SNAPSHOT.2017.05.16T1357',
65
+ '5.9.7-rc4',
66
+ '4.99.0-56-dirty'
67
+ ]
68
+
69
+ final_versions.each do |version|
70
+ it "returns true when given #{version}" do
71
+ allow(Pkg::Config).to receive(:version) { nil }
72
+ expect(Pkg::Util::Version.final?(version)).to be true
73
+ end
74
+ end
75
+
76
+ non_final_versions.each do |version|
77
+ it "returns false when given #{version}" do
78
+ allow(Pkg::Config).to receive(:version) { nil }
79
+ expect(Pkg::Util::Version.final?(version)).to be false
80
+ end
81
+ end
82
+
83
+ it 'correctly reads a final version from Pkg::Config.version' do
84
+ allow(Pkg::Config).to receive(:version) { '1.0.0' }
85
+ expect(Pkg::Util::Version.final?).to be true
86
+ end
87
+
88
+ it 'correctly reads a non-final version from Pkg::Config.version' do
89
+ allow(Pkg::Config).to receive(:version) { '4.99.0-56-dirty' }
90
+ expect(Pkg::Util::Version.final?).to be false
91
+ end
92
+
93
+ it 'classifies dirty versions as final when allow_dirty_tree is set' do
94
+ allow(Pkg::Config).to receive(:allow_dirty_tree).and_return true
95
+ allow(Pkg::Config).to receive(:version) { '1.0.0-dirty' }
96
+ expect(Pkg::Util::Version.final?).to be true
97
+ end
98
+
99
+ it 'classifies dirty nonfinal versions as not final even when allow_dirty_tree is set' do
100
+ allow(Pkg::Config).to receive(:allow_dirty_tree).and_return true
101
+ allow(Pkg::Config).to receive(:version) { '1.0.0-22-dirty' }
102
+ expect(Pkg::Util::Version.final?).to be false
103
+ end
104
+ end
105
+
106
+ context "#dash_version" do
107
+ versions = {
108
+ '5.3.0' => '5.3.0',
109
+ '5.3.0-18-gfbddc8f' => '5.3.0-18',
110
+ '5.3.0-18-gfbddc8f-dirty' => '5.3.0-18-dirty',
111
+ '0.7.0-rc1' => '0.7.0-rc1',
112
+ '0.7.0-rc1-63-g51ccc51' => '0.7.0-rc1-63',
113
+ '0.7.0-rc1-63-g51ccc51-dirty'=> '0.7.0-rc1-63-dirty',
114
+ }
115
+ versions.each do |describe, reformatted|
116
+ it "correctly returns #{reformatted} when #{describe} is the git describe version" do
117
+ allow(Pkg::Util::Git).to receive(:ref_type).and_return 'sha'
118
+ allow(Pkg::Util::Git).to receive(:describe).and_return describe
119
+ expect(Pkg::Util::Version.dash_version).to eq reformatted
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ # We load packaging.rb once, in spec_helper, to avoid reloading the library
4
+ # and issuing warnings about already defined constants.
5
+ describe "Pkg" do
6
+ it "should require the utilities module, Pkg::Util" do
7
+ Pkg::Util.should_not be_nil
8
+ end
9
+
10
+ it "should require the configuration module, Pkg::Config" do
11
+ Pkg::Config.should_not be_nil
12
+ end
13
+
14
+ it "should require the tar library, Pkg::Tar" do
15
+ Pkg::Tar.should_not be_nil
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'pathname'
4
+ require 'rake'
5
+
6
+ SPECDIR = Pathname(__FILE__).dirname
7
+ PROJECT_ROOT = File.expand_path(File.join(Pathname(__FILE__).dirname, ".."))
8
+ FIXTURES = File.join(SPECDIR, 'fixtures')
9
+
10
+ require File.join(SPECDIR, '..', 'lib', 'packaging.rb')
11
+
12
+ def load_task(name)
13
+ return false if (@loaded ||= {})[name]
14
+ load File.join(SPECDIR, '..', 'tasks', name)
15
+ @loaded[name] = true
16
+ end
17
+
18
+ def reset_env(keys)
19
+ keys.each do |key|
20
+ ENV[key] = nil
21
+ end
22
+ end
23
+
24
+ RSpec.configure do |config|
25
+ if Pkg::Util::OS.windows? && RUBY_VERSION =~ /^1\./
26
+ require 'win32console'
27
+ config.output_stream = $stdout
28
+ config.error_stream = $stderr
29
+
30
+ config.formatters.each do |f|
31
+ if not f.instance_variable_get(:@output).kind_of?(::File)
32
+ f.instance_variable_set(:@output, $stdout)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <pkg-info followSymLinks="true" minimumSystemVersion="10.6" auth="root"/>
3
+
@@ -0,0 +1,216 @@
1
+ #######################################################################
2
+ # #
3
+ # #
4
+ # #
5
+ # #
6
+ # #
7
+ # #
8
+ # ! DO NOT ADD TO THIS FILE ! #
9
+ # #
10
+ # Usage of this file to store utilities is deprecated. Any new #
11
+ # utilities should be added to new or existing classes in #
12
+ # lib/packaging/util. Any modified utilities should be migrated #
13
+ # to new or existing classes in lib/packaging/util as well. #
14
+ # #
15
+ # #
16
+ # #
17
+ # #
18
+ # #
19
+ # #
20
+ #######################################################################
21
+
22
+
23
+
24
+
25
+
26
+ # Utility methods used by the various rake tasks
27
+
28
+ #######################################################################
29
+ # #
30
+ # DEPRECATED METHODS: Please move any newly depreacted #
31
+ # methods into the following section so that we can easily #
32
+ # see what methods are left to librarify. #
33
+ # #
34
+ #######################################################################
35
+
36
+ def invoke_task(task, *args)
37
+ Pkg::Util.deprecate('invoke_task', 'Pkg::Util::RakeUtils.invoke_task')
38
+ Pkg::Util::RakeUtils.invoke_task(task, *args)
39
+ end
40
+
41
+ def rsync_to(*args)
42
+ Pkg::Util.deprecate('rsync_to', 'Pkg::Util::Net.rsync_to')
43
+ Pkg::Util::Net.rsync_to(args[0], args[1], args[2])
44
+ end
45
+
46
+ def rsync_from(*args)
47
+ Pkg::Util.deprecate('rsync_from', 'Pkg::Util::Net.rsync_from')
48
+ Pkg::Util::Net.rsync_from(args[0], args[1], args[2])
49
+ end
50
+
51
+ def mkdir_pr(*args)
52
+ Pkg::Util.deprecate('mkdir_pr', 'FileUtils.mkdir_p')
53
+ FileUtils.mkdir_p args
54
+ end
55
+
56
+ def ln(target, name)
57
+ Pkg::Util.deprecate('ln', 'FileUtils.ln')
58
+ FileUtils.ln(name, target, :force => true, :verbose => true)
59
+ end
60
+
61
+ def ln_sfT(src, dest)
62
+ Pkg::Util.deprecate('ln_sfT')
63
+ sh "ln -sfT #{src} #{dest}"
64
+ end
65
+
66
+ def git_commit_file(file, message = nil)
67
+ Pkg::Util.deprecate('git_commit_file', 'Pkg::Util::Git.git_commit_file')
68
+ Pkg::Util::Git.git_commit_file(file, message)
69
+ end
70
+
71
+ def git_bundle(treeish, appendix = nil, output_dir = nil)
72
+ Pkg::Util.deprecate('git_bundle', 'Pkg::Util::Git.git_bundle')
73
+ Pkg::Util::Git.git_bundle(treeish, appendix, output_dir)
74
+ end
75
+
76
+ def git_tag(version)
77
+ Pkg::Util.deprecate('git_tag', 'Pkg::Util::Git.git_tag')
78
+ Pkg::Util::Git.git_tag(version)
79
+ end
80
+
81
+ def git_pull(remote, branch)
82
+ Pkg::Util.deprecate('git_pull', 'Pkg::Util::Git.git_pull')
83
+ Pkg::Util::Git.git_pull(remote, branch)
84
+ end
85
+
86
+ def curl_form_data(uri, form_data = [], options = {})
87
+ Pkg::Util.deprecate("curl_form_data", "Pkg::Util::Net.curl_form_data")
88
+ Pkg::Util::Net.curl_form_data(uri, form_data, options)
89
+ end
90
+
91
+ def create_jenkins_job(name, xml_file)
92
+ Pkg::Util.deprecate("create_jenkins_job", "Pkg::Util::Jenkins.create_jenkins_job")
93
+ Pkg::Util::Jenkins.create_jenkins_job(name, xml_file)
94
+ end
95
+
96
+ def jenkins_job_exists?(name)
97
+ Pkg::Util.deprecate("jenkins_job_exists", "Pkg::Util::Jenkins.jenkins_job_exists?")
98
+ Pkg::Util::Jenkins.jenkins_job_exists?(name)
99
+ end
100
+
101
+ def print_url_info(url_string)
102
+ Pkg::Util.deprecate("print_url_info", "Pkg::Util::Net.print_url_info")
103
+ Pkg::Util::Net.print_url_info(url_string)
104
+ end
105
+
106
+ def retry_on_fail(args, &block)
107
+ Pkg::Util.deprecate("retry_on_fail", "Pkg::Util::Execution.retry_on_fail")
108
+ Pkg::Util::Execution.retry_on_fail(args, &block)
109
+ end
110
+
111
+ # ex combines the behavior of `%x{cmd}` and rake's `sh "cmd"`. `%x{cmd}` has
112
+ # the benefit of returning the standard out of an executed command, enabling us
113
+ # to query the file system, e.g. `contents = %x{ls}`. The drawback to `%x{cmd}`
114
+ # is that on failure of a command (something returned non-zero) the return of
115
+ # `%x{cmd}` is just an empty string. As such, we can't know if we succeeded.
116
+ # Rake's `sh "cmd"`, on the other hand, will raise a RuntimeError if a command
117
+ # does not return 0, but doesn't return any of the stdout from the command -
118
+ # only true or false depending on its success or failure. With `ex(cmd)` we
119
+ # purport to both return the results of the command execution (ala `%x{cmd}`)
120
+ # while also raising an exception if a command does not succeed (ala `sh "cmd"`).
121
+ def ex(command)
122
+ Pkg::Util.deprecate("ex", "Pkg::Util::Execution.ex")
123
+ Pkg::Util::Execution.ex(command)
124
+ end
125
+
126
+ def load_keychain
127
+ Pkg::Util.deprecate("load_keychain", "Pkg::Util::Gpg.load_keychain")
128
+ Pkg::Util::Gpg.load_keychain
129
+ end
130
+
131
+ def kill_keychain
132
+ Pkg::Util.deprecate("kill_keychain", "Pkg::Util::Gpg.kill_keychain")
133
+ Pkg::Util::Gpg.kill_keychain
134
+ end
135
+
136
+ def start_keychain
137
+ Pkg::Util.deprecate("start_keychain", "Pkg::Util::Gpg.start_keychain")
138
+ Pkg::Util::Gpg.start_keychain
139
+ end
140
+
141
+ def gpg_sign_file(file)
142
+ Pkg::Util.deprecate("gpg_sign_file", "Pkg::Util::Gpg.sign_file")
143
+ Pkg::Util::Gpg.sign_file(file)
144
+ end
145
+
146
+ def check_var(varname, var)
147
+ Pkg::Util.deprecate('check_var', 'Pkg::Util.check_var')
148
+ Pkg::Util.check_var(varname, var)
149
+ end
150
+
151
+ def rand_string
152
+ Pkg::Util.deprecate('invoke_task', 'Pkg::Util.rand_string')
153
+ Pkg::Util.rand_string
154
+ end
155
+
156
+ def escape_html(uri)
157
+ Pkg::Util.deprecate('escape_html', 'Pkg::Util::Net.escape_html')
158
+ Pkg::Util::Net.escape_html(uri)
159
+ end
160
+
161
+ def add_param_to_uri(uri, param)
162
+ Pkg::Util.deprecate('add_param_to_uri', 'Pkg::Util::Net.add_param_to_uri')
163
+ Pkg::Util::Net.add_param_to_uri(uri, param)
164
+ end
165
+
166
+ def cp_pr(src, dest, options = {})
167
+ Pkg::Util.deprecate('cp_pr', 'FileUtils.cp_r')
168
+ mandatory = { :preserve => true }
169
+ FileUtils.cp_r(src, dest, options.merge(mandatory))
170
+ end
171
+
172
+ def cp_p(src, dest, options = {})
173
+ Pkg::Util.deprecate('cp_p', 'FileUtils.cp')
174
+ mandatory = { :preserve => true }
175
+ FileUtils.cp(src, dest, options.merge(mandatory))
176
+ end
177
+
178
+ def remote_set_immutable(host, files)
179
+ Pkg::Util.deprecate('remote_set_immutable', 'Pkg::Util::Net.remote_set_immutable')
180
+ Pkg::Util::Net.remote_set_immutable(host, files)
181
+ end
182
+
183
+ def ask_yes_or_no
184
+ Pkg::Util.deprecate('ask_yes_or_no', 'Pkg::Util.ask_yes_or_no')
185
+ Pkg::Util.ask_yes_or_no
186
+ end
187
+
188
+ def confirm_ship(files)
189
+ Pkg::Util.deprecate('confirm_ship', 'Pkg::Util.confirm_ship')
190
+ Pkg::Util.confirm_ship(files)
191
+ end
192
+
193
+ def deprecate(old_cmd, new_cmd = nil)
194
+ Pkg::Util.deprecate('deprecate', 'Pkg::Util.deprecate')
195
+ Pkg::Util.deprecate(old_cmd, new_cmd)
196
+ end
197
+
198
+ def remote_bootstrap(host, treeish, tar_cmd = nil, tarball = nil)
199
+ Pkg::Util.deprecate('remote_bootstrap', 'Pkg::Util::Net.remote_bootstrap')
200
+ Pkg::Util::Net.remote_bootstrap(host, treeish, tar_cmd, tarball)
201
+ end
202
+
203
+ def remote_buildparams(host, build)
204
+ Pkg::Util.deprecate('remote_buildparams', 'Pkg::Util::Net.remote_buildparams')
205
+ Pkg::Util::Net.remote_buildparams(host, build)
206
+ end
207
+
208
+ def ship_gem(file)
209
+ Pkg::Util.deprecate('ship_gem', 'Pkg::Gem.ship')
210
+ Pkg::Gem.ship(file)
211
+ end
212
+
213
+ def set_cow_envs(cow)
214
+ Pkg::Util.deprecate('set_cow_envs', 'Pkg::Deb.set_cow_envs')
215
+ Pkg::Deb.set_cow_envs(cow)
216
+ end
@@ -0,0 +1,33 @@
1
+ @metrics = []
2
+ def add_shipped_metrics(args)
3
+ @metrics << {
4
+ :type => 'shipped',
5
+ :package => (args[:package] || Pkg::Config.project),
6
+ :version => (args[:version] || Pkg::Config.version),
7
+ :pe_version => (args[:pe_version] || Pkg::Config.pe_version),
8
+ :is_rc => (args[:is_rc] || false),
9
+ }
10
+ end
11
+
12
+ def post_shipped_metrics
13
+ require 'net/http'
14
+ @metrics.each do |metric|
15
+ type = metric[:type]
16
+ package = metric[:package]
17
+ version = metric[:version]
18
+ pe_version = metric[:pe_version]
19
+ is_rc = metric[:is_rc]
20
+
21
+ uri = URI(Pkg::Config.metrics_url)
22
+ res = Net::HTTP.post_form(
23
+ uri,
24
+ {
25
+ 'type' => type,
26
+ 'package' => package,
27
+ 'version' => version,
28
+ 'pe_version' => pe_version,
29
+ 'is_rc' => is_rc,
30
+ }
31
+ )
32
+ end
33
+ end
@@ -0,0 +1,266 @@
1
+ # Title: Rake task to build Apple packages for #{@project}.
2
+ # Author: Gary Larizza
3
+ # Date: 05/18/2012
4
+ # Description: This task will create a DMG-encapsulated package that will
5
+ # install a package on OS X systems. This happens by building
6
+ # a directory tree of files that will then be fed to the
7
+ # packagemaker binary (can be installed by installing the
8
+ # XCode Tools) which will create the .pkg file.
9
+ #
10
+
11
+ # Path to Binaries (Constants)
12
+ CP = '/bin/cp'
13
+ INSTALL = '/usr/bin/install'
14
+ DITTO = '/usr/bin/ditto'
15
+ PKGBUILD = '/usr/bin/pkgbuild'
16
+
17
+ # Setup task to populate all the variables
18
+ task :setup do
19
+ # Read the Apple file-mappings
20
+ begin
21
+ @source_files = Pkg::Util::Serialization.load_yaml('ext/osx/file_mapping.yaml')
22
+ rescue => e
23
+ fail "Could not load Apple file mappings from 'ext/osx/file_mapping.yaml'\n#{e}"
24
+ end
25
+ @package_name = Pkg::Config.project
26
+ @title = "#{Pkg::Config.project}-#{Pkg::Config.version}"
27
+ @reverse_domain = "com.#{Pkg::Config.packager}.#{@package_name}"
28
+ @package_major_version = Pkg::Config.version.split('.')[0]
29
+ @package_minor_version = Pkg::Config.version.split('.')[1] +
30
+ Pkg::Config.version.split('.')[2].split('-')[0].split('rc')[0]
31
+ @pm_restart = 'None'
32
+ @build_date = Time.new.strftime("%Y-%m-%dT%H:%M:%SZ")
33
+ @apple_bindir = File.join('/', @source_files['directories']['bin']['path'])
34
+ @apple_sbindir = '/usr/sbin'
35
+ @apple_libdir = File.join('/', @source_files['directories']['lib']['path'])
36
+ @apple_old_libdir = '/usr/lib/ruby/site_ruby/1.8'
37
+ @apple_docdir = '/usr/share/doc'
38
+ end
39
+
40
+ # method: make_directory_tree
41
+ # description: This method sets up the directory structure that packagemaker
42
+ # needs to build a package. A prototype.plist file (holding
43
+ # package-specific options) is built from an ERB template located
44
+ # in the ext/osx directory.
45
+ def make_directory_tree
46
+ project_tmp = "#{Pkg::Util::File.mktemp}/#{@package_name}"
47
+ @scratch = "#{project_tmp}/#{@title}"
48
+ @working_tree = {
49
+ 'scripts' => "#{@scratch}/scripts",
50
+ 'resources' => "#{@scratch}/resources",
51
+ 'working' => "#{@scratch}/root",
52
+ 'payload' => "#{@scratch}/payload",
53
+ }
54
+ puts "Cleaning Tree: #{project_tmp}"
55
+ rm_rf(project_tmp)
56
+ @working_tree.each do |key, val|
57
+ mkdir_p(val)
58
+ end
59
+
60
+ if File.exists?('ext/osx/postflight.erb')
61
+ Pkg::Util::File.erb_file 'ext/osx/postflight.erb', "#{@working_tree["scripts"]}/postinstall", false, :binding => binding
62
+ end
63
+
64
+ if File.exists?('ext/osx/preflight.erb')
65
+ Pkg::Util::File.erb_file 'ext/osx/preflight.erb', "#{@working_tree["scripts"]}/preinstall", false, :binding => binding
66
+ end
67
+
68
+ if File.exists?('ext/osx/prototype.plist.erb')
69
+ Pkg::Util::File.erb_file 'ext/osx/prototype.plist.erb', "#{@scratch}/prototype.plist", false, :binding => binding
70
+ end
71
+
72
+ if File.exists?('ext/packaging/static_artifacts/PackageInfo.plist')
73
+ cp 'ext/packaging/static_artifacts/PackageInfo.plist', "#{@scratch}/PackageInfo.plist"
74
+ end
75
+
76
+ end
77
+
78
+ # method: build_dmg
79
+ # description: This method builds a package from the directory structure in
80
+ # /tmp/#{@project} and puts it in the
81
+ # /tmp/#{@project}/#{@project}-#{version}/payload directory. A DMG is
82
+ # created, using hdiutil, based on the contents of the
83
+ # /tmp/#{@project}/#{@project}-#{version}/payload directory. The resultant
84
+ # DMG is placed in the pkg/apple directory.
85
+ #
86
+ def build_dmg
87
+ # Local Variables
88
+ dmg_format_code = 'UDZO'
89
+ zlib_level = '9'
90
+ dmg_format_option = "-imagekey zlib-level=#{zlib_level}"
91
+ dmg_format = "#{dmg_format_code} #{dmg_format_option}"
92
+ dmg_file = "#{@title}.dmg"
93
+ package_file = "#{@title}.pkg"
94
+
95
+ # Build .pkg file
96
+ system("sudo #{PKGBUILD} --root #{@working_tree['working']} \
97
+ --scripts #{@working_tree['scripts']} \
98
+ --identifier #{@reverse_domain} \
99
+ --version #{Pkg::Config.version} \
100
+ --install-location / \
101
+ --ownership preserve \
102
+ --info #{@scratch}/PackageInfo.plist \
103
+ #{@working_tree['payload']}/#{package_file}")
104
+
105
+ # Build .dmg file
106
+ system("sudo hdiutil create -volname #{@title} \
107
+ -srcfolder #{@working_tree['payload']} \
108
+ -uid 99 \
109
+ -gid 99 \
110
+ -ov \
111
+ -format #{dmg_format} \
112
+ #{dmg_file}")
113
+
114
+ if File.directory?("#{pwd}/pkg/apple")
115
+ sh "sudo mv #{pwd}/#{dmg_file} #{pwd}/pkg/apple/#{dmg_file}"
116
+ puts "moved: #{dmg_file} has been moved to #{pwd}/pkg/apple/#{dmg_file}"
117
+ else
118
+ mkdir_p("#{pwd}/pkg/apple")
119
+ sh "sudo mv #{pwd}/#{dmg_file} #{pwd}/pkg/apple/#{dmg_file}"
120
+ puts "moved: #{dmg_file} has been moved to #{pwd}/pkg/apple/#{dmg_file}"
121
+ end
122
+ end
123
+
124
+ # method: pack_source
125
+ # description: This method copies the #{@project} source into a directory
126
+ # structure in /tmp/#{@project}/#{@project}-#{version}/root mirroring the
127
+ # structure on the target system for which the package will be
128
+ # installed. Anything installed into /tmp/#{@project}/root will be
129
+ # installed as the package's payload.
130
+ #
131
+ def pack_source
132
+ work = "#{@working_tree['working']}"
133
+ source = pwd
134
+
135
+ # Make all necessary directories
136
+ @source_files.each_value do |files|
137
+ files.each_value do |params|
138
+ mkdir_p "#{work}/#{params['path']}"
139
+ end
140
+ end
141
+
142
+ # Install directory contents into place
143
+ unless @source_files['directories'].nil?
144
+ @source_files['directories'].each do |dir, params|
145
+ unless FileList["#{source}/#{dir}/*"].empty?
146
+ cmd = "#{DITTO} #{source}/#{dir}/ #{work}/#{params['path']}"
147
+ puts cmd
148
+ system(cmd)
149
+ end
150
+ end
151
+ end
152
+
153
+ # Setup a preinstall script and replace variables in the files with
154
+ # the correct paths.
155
+ if File.exists?("#{@working_tree['scripts']}/preinstall")
156
+ chmod(0755, "#{@working_tree['scripts']}/preinstall")
157
+ sh "sudo chown root:wheel #{@working_tree['scripts']}/preinstall"
158
+ end
159
+
160
+ # Setup a postinstall from from the erb created earlier
161
+ if File.exists?("#{@working_tree['scripts']}/postinstall")
162
+ chmod(0755, "#{@working_tree['scripts']}/postinstall")
163
+ sh "sudo chown root:wheel #{@working_tree['scripts']}/postinstall"
164
+ end
165
+
166
+ # Do a run through first setting the specified permissions then
167
+ # making sure 755 is set for all directories
168
+ unless @source_files['directories'].nil?
169
+ @source_files['directories'].each do |dir, params|
170
+ owner = params['owner']
171
+ group = params['group']
172
+ perms = params['perms']
173
+ path = params['path']
174
+ ##
175
+ # Before setting our default permissions for all subdirectories/files of
176
+ # each directory listed in directories, we have to get a list of the
177
+ # directories. Otherwise, when we set the default perms (most likely
178
+ # 0644) we'll lose traversal on subdirectories, and later when we want to
179
+ # ensure they're 755 we won't be able to find them.
180
+ #
181
+ directories = []
182
+ Dir["#{work}/#{path}/**/*"].each do |file|
183
+ directories << file if File.directory?(file)
184
+ end
185
+
186
+ ##
187
+ # Here we're setting the default permissions for all files as described
188
+ # in file_mapping.yaml. Since we have a listing of directories, it
189
+ # doesn't matter if we remove executable permission on directories, we'll
190
+ # reset it later.
191
+ #
192
+ sh "sudo chmod -R #{perms} #{work}/#{path}"
193
+
194
+ ##
195
+ # We know at least one directory, the one listed in file_mapping.yaml, so
196
+ # we set it executable.
197
+ #
198
+ sh "sudo chmod 0755 #{work}/#{path}"
199
+
200
+ ##
201
+ # Now that default perms are set, we go in and reset executable perms on
202
+ # directories
203
+ #
204
+ directories.each { |d| sh "sudo chmod 0755 #{d}" }
205
+
206
+ ##
207
+ # Finally we set the owner/group as described in file_mapping.yaml
208
+ #
209
+ sh "sudo chown -R #{owner}:#{group} #{work}/#{path}"
210
+ end
211
+ end
212
+
213
+ # Install any files
214
+ unless @source_files['files'].nil?
215
+ @source_files['files'].each do |file, params|
216
+ owner = params['owner']
217
+ group = params['group']
218
+ perms = params['perms']
219
+ dest = params['path']
220
+ # Allow for regexs like [A-Z]*
221
+ FileList[file].each do |f|
222
+ cmd = "sudo #{INSTALL} -o #{owner} -g #{group} -m #{perms} #{source}/#{f} #{work}/#{dest}"
223
+ puts cmd
224
+ system(cmd)
225
+ end
226
+ end
227
+ end
228
+
229
+ # Hackery here. Our packages were using /usr/bin/env ruby and installing to
230
+ # system ruby loadpath, which breaks horribly in a multi-ruby (rbenv, etc)
231
+ # environment. This goes into the workdir and looks for any files dropped in
232
+ # bin, and "seds" the shebang to /usr/bin/ruby. I would love to be using a
233
+ # ruby approach to this instead of shelling out to sed, but the problem is
234
+ # we've already set ownership on these files, almost exclusively to root, and
235
+ # thus we need to sudo out.
236
+ if @source_files['directories'] and @source_files['directories']['bin']
237
+ if bindir = @source_files['directories']['bin']['path']
238
+ Dir[File.join(work, bindir, '*')].each do |binfile|
239
+ sh "sudo /usr/bin/sed -E -i '' '1 s,^#![[:space:]]*/usr/bin/env[[:space:]]+ruby$,#!/usr/bin/ruby,' #{binfile}"
240
+ end
241
+ end
242
+ end
243
+ end
244
+
245
+ namespace :package do
246
+ desc "Task for building an Apple Package"
247
+ task :apple => [:setup] do
248
+ if Pkg::Config.build_dmg
249
+ bench = Benchmark.realtime do
250
+ # Test for pkgbuild binary
251
+ fail "pkgbuild must be installed." unless \
252
+ File.exists?(PKGBUILD)
253
+
254
+ make_directory_tree
255
+ pack_source
256
+ build_dmg
257
+ end
258
+ puts "Finished building in: #{bench}"
259
+ end
260
+ end
261
+ end
262
+
263
+ # An alias task to simplify our remote logic in jenkins.rake
264
+ namespace :pl do
265
+ task :dmg => "package:apple"
266
+ end