omnibus 3.1.1 → 3.2.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -0
  3. data/Gemfile +0 -7
  4. data/README.md +108 -36
  5. data/Rakefile +1 -5
  6. data/docs/omnibus-build-cache.md +5 -5
  7. data/features/commands/_deprecated.feature +21 -3
  8. data/features/step_definitions/generator_steps.rb +7 -7
  9. data/lib/omnibus.rb +232 -171
  10. data/lib/omnibus/build_version.rb +2 -2
  11. data/lib/omnibus/builder.rb +38 -19
  12. data/lib/omnibus/cleaner.rb +5 -5
  13. data/lib/omnibus/cleanroom.rb +141 -0
  14. data/lib/omnibus/cli.rb +6 -9
  15. data/lib/omnibus/cli/base.rb +2 -1
  16. data/lib/omnibus/cli/cache.rb +15 -21
  17. data/lib/omnibus/cli/deprecated.rb +40 -4
  18. data/lib/omnibus/cli/publish.rb +61 -0
  19. data/lib/omnibus/config.rb +350 -189
  20. data/lib/omnibus/digestable.rb +131 -0
  21. data/lib/omnibus/exceptions.rb +163 -83
  22. data/lib/omnibus/fetcher.rb +1 -1
  23. data/lib/omnibus/fetchers/net_fetcher.rb +19 -13
  24. data/lib/omnibus/fetchers/path_fetcher.rb +8 -1
  25. data/lib/omnibus/fetchers/s3_cache_fetcher.rb +16 -7
  26. data/lib/omnibus/generator.rb +2 -2
  27. data/lib/omnibus/generator_files/Gemfile.erb +4 -1
  28. data/lib/omnibus/generator_files/README.md.erb +10 -0
  29. data/lib/omnibus/generator_files/{omnibus.rb.example.erb → omnibus.rb.erb} +20 -11
  30. data/lib/omnibus/generator_files/package_scripts/makeselfinst.erb +1 -1
  31. data/lib/omnibus/generator_files/project.rb.erb +2 -2
  32. data/lib/omnibus/generator_files/windows_msi/localization-en-us.wxl.erb +3 -3
  33. data/lib/omnibus/git_cache.rb +192 -0
  34. data/lib/omnibus/health_check.rb +171 -116
  35. data/lib/omnibus/library.rb +4 -2
  36. data/lib/omnibus/logger.rb +60 -1
  37. data/lib/omnibus/null_argumentable.rb +51 -0
  38. data/lib/omnibus/ohai.rb +29 -8
  39. data/lib/omnibus/package.rb +240 -0
  40. data/lib/omnibus/packagers/base.rb +21 -42
  41. data/lib/omnibus/packagers/mac_dmg.rb +5 -5
  42. data/lib/omnibus/packagers/mac_pkg.rb +20 -19
  43. data/lib/omnibus/packagers/windows_msi.rb +7 -7
  44. data/lib/omnibus/project.rb +969 -486
  45. data/lib/omnibus/publisher.rb +76 -0
  46. data/lib/omnibus/publishers/artifactory_publisher.rb +168 -0
  47. data/lib/omnibus/publishers/null_publisher.rb +23 -0
  48. data/lib/omnibus/publishers/s3_publisher.rb +99 -0
  49. data/lib/omnibus/s3_cache.rb +150 -63
  50. data/lib/omnibus/software.rb +749 -321
  51. data/lib/omnibus/{sugar.rb → sugarable.rb} +11 -6
  52. data/lib/omnibus/version.rb +1 -1
  53. data/omnibus.gemspec +8 -8
  54. data/spec/data/complicated/config/projects/angrychef.rb +1 -1
  55. data/spec/data/complicated/config/projects/chef-windows.rb +1 -1
  56. data/spec/data/complicated/config/projects/chef.rb +1 -1
  57. data/spec/data/complicated/config/projects/chefdk-windows.rb +1 -1
  58. data/spec/data/complicated/config/projects/chefdk.rb +1 -1
  59. data/spec/data/complicated/config/software/cacerts.rb +1 -1
  60. data/spec/data/complicated/config/software/chef-client-msi.rb +1 -1
  61. data/spec/data/complicated/config/software/libgcc.rb +1 -1
  62. data/spec/data/complicated/config/software/libiconv.rb +0 -11
  63. data/spec/data/complicated/config/software/libpng.rb +2 -2
  64. data/spec/data/complicated/config/software/openssl.rb +1 -1
  65. data/spec/data/complicated/config/software/ruby.rb +1 -1
  66. data/spec/data/complicated/config/software/runit.rb +4 -4
  67. data/spec/data/projects/chefdk.rb +1 -1
  68. data/spec/data/projects/sample.rb +1 -1
  69. data/spec/data/software/erchef.rb +3 -1
  70. data/spec/functional/packagers/mac_spec.rb +25 -24
  71. data/spec/functional/packagers/windows_spec.rb +21 -20
  72. data/spec/spec_helper.rb +43 -4
  73. data/spec/unit/build_version_spec.rb +14 -16
  74. data/spec/unit/cleanroom_spec.rb +63 -0
  75. data/spec/unit/config_spec.rb +36 -30
  76. data/spec/unit/digestable_spec.rb +38 -0
  77. data/spec/unit/fetchers/net_fetcher_spec.rb +98 -87
  78. data/spec/unit/{install_path_cache_spec.rb → git_cache_spec.rb} +67 -56
  79. data/spec/unit/health_check_spec.rb +73 -0
  80. data/spec/unit/library_spec.rb +166 -159
  81. data/spec/unit/ohai_spec.rb +19 -0
  82. data/spec/unit/omnibus_spec.rb +43 -41
  83. data/spec/unit/package_spec.rb +178 -0
  84. data/spec/unit/packagers/base_spec.rb +17 -47
  85. data/spec/unit/packagers/mac_pkg_spec.rb +104 -126
  86. data/spec/unit/project_spec.rb +176 -25
  87. data/spec/unit/publisher_spec.rb +49 -0
  88. data/spec/unit/publishers/artifactory_publisher_spec.rb +80 -0
  89. data/spec/unit/publishers/s3_publisher_spec.rb +120 -0
  90. data/spec/unit/s3_cacher_spec.rb +84 -19
  91. data/spec/unit/software_spec.rb +397 -170
  92. data/spec/unit/sugarable_spec.rb +43 -0
  93. metadata +62 -50
  94. data/Guardfile +0 -10
  95. data/lib/omnibus/artifact.rb +0 -165
  96. data/lib/omnibus/cli/release.rb +0 -40
  97. data/lib/omnibus/generator_files/Vagrantfile.erb +0 -75
  98. data/lib/omnibus/install_path_cache.rb +0 -105
  99. data/lib/omnibus/overrides.rb +0 -88
  100. data/lib/omnibus/package_release.rb +0 -154
  101. data/lib/omnibus/software_s3_urls.rb +0 -50
  102. data/spec/unit/artifact_spec.rb +0 -91
  103. data/spec/unit/overrides_spec.rb +0 -102
  104. data/spec/unit/package_release_spec.rb +0 -180
  105. data/spec/unit/sugar_spec.rb +0 -17
@@ -62,7 +62,7 @@ module Omnibus
62
62
  # Create a new BuildVersion
63
63
  #
64
64
  # @param [String] path Path from which to read git version information
65
- def initialize(path = Omnibus.project_root)
65
+ def initialize(path = Config.project_root)
66
66
  @path = path
67
67
  end
68
68
 
@@ -81,7 +81,7 @@ module Omnibus
81
81
  #
82
82
  # By default, a timestamp is incorporated into the build component of
83
83
  # version string (see {Omnibus::BuildVersion::TIMESTAMP_FORMAT}). This
84
- # option is configurable via the {Omnibus::Config}.
84
+ # option is configurable via the {Config}.
85
85
  #
86
86
  # @example 11.0.0-alpha.1+20121218164140.git.207.694b062
87
87
  # @return [String]
@@ -37,7 +37,7 @@ module Omnibus
37
37
  def_delegator :@builder, :rake
38
38
  def_delegator :@builder, :block
39
39
  def_delegator :@builder, :name
40
- def_delegator :@builder, :project_root
40
+ def_delegator :@builder, :max_build_jobs
41
41
 
42
42
  def initialize(builder, software)
43
43
  @builder, @software = builder, software
@@ -122,13 +122,10 @@ module Omnibus
122
122
  def patch(*args)
123
123
  args = args.dup.pop
124
124
 
125
- # we'll search for a patch file in the project root AND
126
- # the omnibus-software gem
127
- candidate_roots = [Omnibus.project_root]
128
- candidate_roots << Omnibus.omnibus_software_root if Omnibus.omnibus_software_root
129
-
130
- candidate_paths = candidate_roots.map do |root|
131
- File.expand_path("#{root}/config/patches/#{name}/#{args[:source]}")
125
+ # Search for patches just like we search for software
126
+ candidate_paths = Omnibus.software_dirs.map do |directory|
127
+ patches = directory.sub(Config.software_dir, 'config/patches')
128
+ "#{patches}/#{name}/#{args[:source]}"
132
129
  end
133
130
 
134
131
  source = candidate_paths.find { |path| File.exist?(path) }
@@ -151,10 +148,10 @@ module Omnibus
151
148
  def erb(*args)
152
149
  args = args.dup.pop
153
150
 
154
- source_path = File.expand_path("#{Omnibus.project_root}/config/templates/#{name}/#{args[:source]}")
151
+ source_path = File.expand_path("#{Config.project_root}/config/templates/#{name}/#{args[:source]}")
155
152
 
156
153
  unless File.exist?(source_path)
157
- raise MissingTemplate.new(args[:source], "#{Omnibus.project_root}/config/templates/#{name}")
154
+ raise MissingTemplate.new(args[:source], "#{Config.project_root}/config/templates/#{name}")
158
155
  end
159
156
 
160
157
  block do
@@ -190,14 +187,32 @@ module Omnibus
190
187
  @build_commands << rb_block
191
188
  end
192
189
 
190
+ #
191
+ # @deprecated Use {Config.project_root} instead
192
+ #
193
193
  def project_root
194
- Omnibus.project_root
194
+ Omnibus.logger.deprecated(log_key) do
195
+ 'project_root (DSL). Please use Config.project_root instead.'
196
+ end
197
+
198
+ Config.project_root
195
199
  end
196
200
 
197
201
  def project_dir
198
202
  @software.project_dir
199
203
  end
200
204
 
205
+ #
206
+ # @deprecated Use {install_path} instead
207
+ #
208
+ def install_path
209
+ log.deprecated(log_key) do
210
+ 'install_path (DSL). Please use install_dir instead.'
211
+ end
212
+
213
+ install_dir
214
+ end
215
+
201
216
  def install_dir
202
217
  @software.install_dir
203
218
  end
@@ -228,6 +243,14 @@ module Omnibus
228
243
  end
229
244
  end
230
245
 
246
+ def max_build_jobs
247
+ if Ohai['cpu'] && Ohai['cpu']['total'] && Ohai['cpu']['total'].to_s =~ /^\d+$/
248
+ Ohai['cpu']['total'].to_i + 1
249
+ else
250
+ 3
251
+ end
252
+ end
253
+
231
254
  private
232
255
 
233
256
  def execute_proc(cmd)
@@ -239,10 +262,6 @@ module Omnibus
239
262
  raise
240
263
  end
241
264
 
242
- def build_retries
243
- Omnibus.config[:build_retries]
244
- end
245
-
246
265
  def execute_sh(cmd)
247
266
  retries ||= 0
248
267
  shell = nil
@@ -262,7 +281,7 @@ module Omnibus
262
281
  cmd_string = cmd_args[0..-2].join(' ')
263
282
  cmd_opts_for_display = to_kv_str(cmd_args.last)
264
283
 
265
- log.debug(log_key) do
284
+ log.info(log_key) do
266
285
  "Executing: `#{cmd_string}` with #{cmd_opts_for_display}"
267
286
  end
268
287
 
@@ -275,17 +294,17 @@ module Omnibus
275
294
  shell.error!
276
295
  end
277
296
  rescue Exception => e
278
- raise if build_retries.nil? || build_retries == 0
297
+ raise if Config.build_retries.nil? || Config.build_retries == 0
279
298
  # Getting lots of errors from github, particularly with erlang/rebar
280
299
  # projects fetching tons of deps via git all the time. This isn't a
281
300
  # particularly elegant way to solve that problem. But it should work.
282
- if retries >= build_retries
301
+ if retries >= Config.build_retries
283
302
  ErrorReporter.new(e, self).explain("Failed to build #{name} while running `#{cmd_string}` with #{cmd_opts_for_display}")
284
303
  raise
285
304
  else
286
305
  time_to_sleep = 5 * (2**retries)
287
306
  retries += 1
288
- log.debug(log_key) do
307
+ log.info(log_key) do
289
308
  "Failed to execute cmd `#{cmd}` #{retries} time(s). " \
290
309
  "Retrying in #{time_to_sleep}s."
291
310
  end
@@ -41,26 +41,26 @@ module Omnibus
41
41
  end
42
42
 
43
43
  def clean_source_dir
44
- Dir.glob("#{Omnibus.config.source_dir}/**/*").each(&method(:remove_file))
44
+ Dir.glob("#{Config.source_dir}/**/*").each(&method(:remove_file))
45
45
  end
46
46
 
47
47
  def clean_build_dir
48
- Dir.glob("#{Omnibus.config.build_dir}/**/*").each(&method(:remove_file))
48
+ Dir.glob("#{Config.build_dir}/**/*").each(&method(:remove_file))
49
49
  end
50
50
 
51
51
  def clean_package_dir
52
52
  return unless purge?
53
- Dir.glob("#{Omnibus.config.package_dir}/**/*").each(&method(:remove_file))
53
+ Dir.glob("#{Config.package_dir}/**/*").each(&method(:remove_file))
54
54
  end
55
55
 
56
56
  def clean_cache_dir
57
57
  return unless purge?
58
- Dir.glob("#{Omnibus.config.cache_dir}/**/*").each(&method(:remove_file))
58
+ Dir.glob("#{Config.cache_dir}/**/*").each(&method(:remove_file))
59
59
  end
60
60
 
61
61
  def clean_install_dir
62
62
  return unless purge?
63
- remove_file(@project.install_path)
63
+ remove_file(@project.install_dir)
64
64
  end
65
65
 
66
66
  private
@@ -0,0 +1,141 @@
1
+ #
2
+ # Copyright 2014 Chef Software, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Omnibus
18
+ module Cleanroom
19
+ #
20
+ # Callback for when this module is included.
21
+ #
22
+ # @param [Class] base
23
+ #
24
+ def self.included(base)
25
+ base.send(:extend, ClassMethods)
26
+ base.send(:include, InstanceMethods)
27
+ end
28
+
29
+ #
30
+ # Class methods
31
+ #
32
+ module ClassMethods
33
+ #
34
+ # Evaluate the file in the context of the cleanroom.
35
+ #
36
+ # @param [Class] instance
37
+ # the instance of the class to evaluate against
38
+ # @param [String] filepath
39
+ # the path of the file to evaluate
40
+ #
41
+ def evaluate_file(instance, filepath)
42
+ absolute_path = File.expand_path(filepath)
43
+ file_contents = IO.read(absolute_path)
44
+ evaluate(instance, file_contents, absolute_path, 1)
45
+ end
46
+
47
+ #
48
+ # Evaluate the string or block in the context of the cleanroom.
49
+ #
50
+ # @param [Class] instance
51
+ # the instance of the class to evaluate against
52
+ # @param [Array<String>] args
53
+ # the args to +instance_eval+
54
+ # @param [Proc] block
55
+ # the block to +instance_eval+
56
+ #
57
+ def evaluate(instance, *args, &block)
58
+ cleanroom.new(instance).instance_eval(*args, &block)
59
+ end
60
+
61
+ #
62
+ # Expose the given method to the DSL.
63
+ #
64
+ # @param [Symbol] name
65
+ #
66
+ def expose(name)
67
+ unless public_method_defined?(name)
68
+ raise NameError, "undefined method `#{name}' for class `#{self.name}'"
69
+ end
70
+
71
+ exposed[name] = true
72
+ end
73
+
74
+ private
75
+
76
+ #
77
+ # The list of exposed methods.
78
+ #
79
+ # @return [Hash]
80
+ #
81
+ def exposed
82
+ @exposed ||= {}
83
+ end
84
+
85
+ #
86
+ # The cleanroom instance for this class. This method is intentionally
87
+ # NOT cached!
88
+ #
89
+ # @return [Class]
90
+ #
91
+ def cleanroom
92
+ exposed_methods = exposed.keys
93
+ parent = self.name
94
+
95
+ Class.new do
96
+ define_method(:initialize) do |instance|
97
+ @instance = instance
98
+ end
99
+
100
+ exposed_methods.each do |exposed_method|
101
+ define_method(exposed_method) do |*args, &block|
102
+ @instance.send(exposed_method, *args, &block)
103
+ end
104
+ end
105
+
106
+ define_method(:inspect) do
107
+ "#<#{parent} (Cleanroom)>"
108
+ end
109
+ alias_method :to_s, :inspect
110
+ end
111
+ end
112
+ end
113
+
114
+ #
115
+ # Instance Mehtods
116
+ #
117
+ module InstanceMethods
118
+ #
119
+ # Evaluate the file against the current instance.
120
+ #
121
+ # @param (see Cleanroom.evaluate_file)
122
+ # @return [self]
123
+ #
124
+ def evaluate_file(filepath)
125
+ self.class.evaluate_file(self, filepath)
126
+ self
127
+ end
128
+
129
+ #
130
+ # Evaluate the contents against the current instance.
131
+ #
132
+ # @param (see Cleanroom.evaluate_file)
133
+ # @return [self]
134
+ #
135
+ def evaluate(*args, &block)
136
+ self.class.evaluate(self, *args, &block)
137
+ self
138
+ end
139
+ end
140
+ end
141
+ end
@@ -40,14 +40,11 @@ module Omnibus
40
40
 
41
41
  Omnibus::CLI.start(@argv)
42
42
  @kernel.exit(0)
43
- rescue => e
43
+ rescue Omnibus::Error => e
44
44
  error = Omnibus.ui.set_color(e.message, :red)
45
+ backtrace = Omnibus.ui.set_color("\n" + e.backtrace.join("\n "), :red)
45
46
  Omnibus.ui.error(error)
46
-
47
- if log.debug?
48
- backtrace = Omnibus.ui.set_color("\n" + e.backtrace.join("\n "), :red)
49
- Omnibus.ui.error(backtrace)
50
- end
47
+ Omnibus.ui.error(backtrace)
51
48
 
52
49
  if e.respond_to?(:status_code)
53
50
  @kernel.exit(e.status_code)
@@ -119,10 +116,10 @@ module Omnibus
119
116
  #
120
117
  # Publish Omnibus package(s) to a backend.
121
118
  #
122
- # $ omnibus release --project chefdk
119
+ # $ omnibus publish s3 pkg/*chef*
123
120
  #
124
- register(Command::Release, 'release', 'release', 'Publish Omnibus packages')
125
- CLI.tasks['clean'].options = Command::Release.class_options
121
+ register(Command::Publish, 'publish', 'publish [COMMAND]', 'Publish Omnibus packages to a backend')
122
+ CLI.tasks['publish'].options = Command::Publish.class_options
126
123
 
127
124
  #
128
125
  # Display version information.
@@ -26,7 +26,8 @@ module Omnibus
26
26
  # Handle the case where Thor thinks a trailing --help is actually an
27
27
  # argument and blows up...
28
28
  if args.length > 1 && !(args & Thor::HELP_MAPPINGS).empty?
29
- args.unshift('help')
29
+ args = args - Thor::HELP_MAPPINGS
30
+ args.insert(-2, 'help')
30
31
  end
31
32
 
32
33
  super
@@ -19,20 +19,20 @@ module Omnibus
19
19
  namespace :cache
20
20
 
21
21
  #
22
- # List the existing source packages in the cache.
22
+ # List the existing software packages in the cache.
23
23
  #
24
24
  # $ omnibus cache existing
25
25
  #
26
- desc 'existing', 'List source packages which exist in the cache'
26
+ desc 'existing', 'List software packages which exist in the cache'
27
27
  def existing
28
- result = cache.list
28
+ result = S3Cache.list
29
29
 
30
30
  if result.empty?
31
31
  say('There are no packages in the cache!')
32
32
  else
33
33
  say('The following packages are in the cache:')
34
- result.each do |source|
35
- say(" * #{source.name}")
34
+ result.each do |software|
35
+ say(" * #{software.name}-#{software.version}")
36
36
  end
37
37
  end
38
38
  end
@@ -44,7 +44,7 @@ module Omnibus
44
44
  #
45
45
  desc 'list', 'List all cached files (by S3 key)'
46
46
  def list
47
- result = cache.list_by_key
47
+ result = S3Cache.keys
48
48
 
49
49
  if result.empty?
50
50
  say('There is nothing in the cache!')
@@ -57,33 +57,33 @@ module Omnibus
57
57
  end
58
58
 
59
59
  #
60
- # List missing source packages.
60
+ # List missing software packages.
61
61
  #
62
62
  # $ omnibus cache missing
63
63
  #
64
- desc 'missing', 'Lists source packages that are required but not yet cached'
64
+ desc 'missing', 'Lists software packages that are required but not yet cached'
65
65
  def missing
66
- result = cache.missing
66
+ result = S3Cache.missing
67
67
 
68
68
  if result.empty?
69
69
  say('There are no missing packages in the cache.')
70
70
  else
71
71
  say('The following packages are missing from the cache:')
72
- result.each do |source|
73
- say(source.name)
72
+ result.each do |software|
73
+ say(" * #{software.name}-#{software.version}")
74
74
  end
75
75
  end
76
76
  end
77
77
 
78
78
  #
79
- # Fetch missing source packages locally
79
+ # Fetch missing software packages locally
80
80
  #
81
81
  # $ omnibus cache fetch
82
82
  #
83
- desc 'fetch', 'Fetches missing source packages locally'
83
+ desc 'fetch', 'Fetches missing software packages locally'
84
84
  def fetch
85
85
  say('Fetching missing packages...')
86
- cache.fetch_missing
86
+ S3Cache.fetch_missing
87
87
  end
88
88
 
89
89
  #
@@ -94,13 +94,7 @@ module Omnibus
94
94
  desc 'populate', 'Populate the S3 Cache'
95
95
  def populate
96
96
  say('Populating the cache...')
97
- cache.populate
98
- end
99
-
100
- private
101
-
102
- def cache
103
- @cache ||= S3Cache.new
97
+ S3Cache.populate
104
98
  end
105
99
  end
106
100
  end