omnibus 3.2.2 → 4.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (302) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +140 -10
  3. data/CHANGELOG.md +181 -8
  4. data/README.md +63 -35
  5. data/Rakefile +1 -1
  6. data/docs/omnibus-build-cache.md b/data/docs/Build → Cache.md +0 -0
  7. data/docs/Building on Debian.md +59 -0
  8. data/docs/Building on OSX.md +61 -35
  9. data/docs/Building on RHEL.md +74 -0
  10. data/docs/Building on Windows.md +40 -81
  11. data/features/commands/build.feature +1 -2
  12. data/features/commands/clean.feature +1 -1
  13. data/lib/omnibus.rb +111 -204
  14. data/lib/omnibus/build_version.rb +3 -20
  15. data/lib/omnibus/build_version_dsl.rb +2 -3
  16. data/lib/omnibus/builder.rb +103 -211
  17. data/lib/omnibus/cleaner.rb +5 -7
  18. data/lib/omnibus/cli.rb +1 -4
  19. data/lib/omnibus/cli/base.rb +9 -16
  20. data/lib/omnibus/compressor.rb +60 -0
  21. data/{spec/data/complicated/config/software/version-manifest.rb → lib/omnibus/compressors/base.rb} +17 -12
  22. data/lib/omnibus/compressors/dmg.rb +312 -0
  23. data/lib/omnibus/{null_builder.rb → compressors/null.rb} +10 -4
  24. data/lib/omnibus/compressors/tgz.rb +141 -0
  25. data/lib/omnibus/config.rb +89 -83
  26. data/lib/omnibus/core_extensions.rb +1 -0
  27. data/lib/omnibus/core_extensions/open_uri.rb +58 -0
  28. data/lib/omnibus/digestable.rb +9 -3
  29. data/lib/omnibus/exceptions.rb +116 -175
  30. data/lib/omnibus/fetcher.rb +97 -138
  31. data/lib/omnibus/fetchers/git_fetcher.rb +130 -165
  32. data/lib/omnibus/fetchers/net_fetcher.rb +205 -164
  33. data/lib/omnibus/fetchers/{s3_cache_fetcher.rb → null_fetcher.rb} +27 -17
  34. data/lib/omnibus/fetchers/path_fetcher.rb +74 -32
  35. data/lib/omnibus/file_syncer.rb +149 -0
  36. data/lib/omnibus/generator.rb +103 -32
  37. data/lib/omnibus/generator_files/.kitchen.yml.erb +5 -1
  38. data/lib/omnibus/generator_files/Gemfile.erb +13 -7
  39. data/lib/omnibus/generator_files/config/projects/project.rb.erb +28 -0
  40. data/lib/omnibus/generator_files/config/software/zlib.rb.erb +55 -0
  41. data/lib/omnibus/generator_files/omnibus.rb.erb +5 -7
  42. data/lib/omnibus/git_cache.rb +11 -13
  43. data/lib/omnibus/logger.rb +76 -22
  44. data/lib/omnibus/logging.rb +1 -1
  45. data/lib/omnibus/metadata.rb +264 -0
  46. data/lib/omnibus/ohai.rb +0 -51
  47. data/lib/omnibus/package.rb +4 -228
  48. data/lib/omnibus/packager.rb +71 -0
  49. data/lib/omnibus/packagers/base.rb +118 -176
  50. data/lib/omnibus/packagers/bff.rb +136 -0
  51. data/lib/omnibus/packagers/deb.rb +389 -0
  52. data/lib/omnibus/packagers/makeself.rb +114 -0
  53. data/lib/omnibus/packagers/msi.rb +346 -0
  54. data/lib/omnibus/packagers/pkg.rb +278 -0
  55. data/lib/omnibus/packagers/rpm.rb +438 -0
  56. data/lib/omnibus/packagers/solaris.rb +110 -0
  57. data/lib/omnibus/project.rb +263 -666
  58. data/lib/omnibus/publisher.rb +3 -3
  59. data/lib/omnibus/s3_cache.rb +21 -30
  60. data/lib/omnibus/software.rb +132 -271
  61. data/lib/omnibus/templating.rb +66 -0
  62. data/lib/omnibus/thread_pool.rb +109 -0
  63. data/lib/omnibus/util.rb +137 -15
  64. data/lib/omnibus/version.rb +1 -1
  65. data/omnibus.gemspec +2 -2
  66. data/resources/bff/gen.template.erb +22 -0
  67. data/resources/bff/postinstall.sh +0 -0
  68. data/resources/bff/unpostinstall.sh +0 -0
  69. data/resources/deb/conffiles.erb +3 -0
  70. data/resources/deb/control.erb +25 -0
  71. data/resources/deb/md5sums.erb +3 -0
  72. data/{lib/omnibus/generator_files/mac_dmg → resources/dmg}/background.png +0 -0
  73. data/resources/dmg/create_dmg.osascript.erb +17 -0
  74. data/{lib/omnibus/generator_files/mac_dmg → resources/dmg}/icon.png +0 -0
  75. data/{bin → resources/makeself}/makeself-header.sh +0 -0
  76. data/{bin → resources/makeself}/makeself.sh +0 -0
  77. data/{lib/omnibus/generator_files/package_scripts/makeselfinst.erb → resources/makeself/post_extract.sh.erb} +4 -4
  78. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/LICENSE.rtf +0 -0
  79. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/banner_background.bmp +0 -0
  80. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/dialog_background.bmp +0 -0
  81. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project.ico +0 -0
  82. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project_16x16.ico +0 -0
  83. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project_32x32.ico +0 -0
  84. data/{spec/fixtures/sample/files/windows_msi/Resources/localization-en-us.wxl → resources/msi/localization-en-us.wxl.erb} +3 -4
  85. data/resources/msi/parameters.wxi.erb +9 -0
  86. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/source.wxs.erb +14 -15
  87. data/{lib/omnibus/generator_files/mac_pkg → resources/pkg}/background.png +0 -0
  88. data/resources/pkg/distribution.xml.erb +21 -0
  89. data/resources/pkg/license.html.erb +3 -0
  90. data/resources/pkg/welcome.html.erb +7 -0
  91. data/resources/rpm/rpmmacros.erb +3 -0
  92. data/resources/rpm/signing.erb +40 -0
  93. data/resources/rpm/spec.erb +70 -0
  94. data/spec/functional/builder_spec.rb +90 -111
  95. data/spec/functional/fetchers/git_fetcher_spec.rb +130 -0
  96. data/spec/functional/fetchers/net_fetcher_spec.rb +110 -0
  97. data/spec/functional/fetchers/path_fetcher_spec.rb +97 -0
  98. data/spec/functional/file_syncer_spec.rb +206 -0
  99. data/spec/functional/templating_spec.rb +73 -0
  100. data/spec/spec_helper.rb +31 -94
  101. data/spec/support/env_helpers.rb +20 -0
  102. data/spec/support/examples.rb +56 -0
  103. data/spec/support/file_helpers.rb +46 -0
  104. data/spec/support/git_helpers.rb +107 -0
  105. data/spec/support/logging_helpers.rb +33 -0
  106. data/spec/support/matchers.rb +36 -0
  107. data/spec/support/ohai_helpers.rb +22 -0
  108. data/spec/support/path_helpers.rb +19 -0
  109. data/spec/support/shell_helpers.rb +14 -0
  110. data/spec/unit/build_version_dsl_spec.rb +0 -17
  111. data/spec/unit/build_version_spec.rb +1 -19
  112. data/spec/unit/builder_spec.rb +158 -46
  113. data/spec/unit/compressor_spec.rb +45 -0
  114. data/spec/unit/compressors/base_spec.rb +26 -0
  115. data/spec/unit/compressors/dmg_spec.rb +291 -0
  116. data/spec/unit/compressors/null_spec.rb +23 -0
  117. data/spec/unit/compressors/tgz_spec.rb +67 -0
  118. data/spec/unit/config_spec.rb +27 -34
  119. data/spec/unit/digestable_spec.rb +4 -4
  120. data/spec/unit/fetchers/git_fetcher_spec.rb +110 -39
  121. data/spec/unit/fetchers/net_fetcher_spec.rb +182 -72
  122. data/spec/unit/fetchers/path_fetcher_spec.rb +111 -0
  123. data/spec/unit/generator_spec.rb +137 -0
  124. data/spec/unit/git_cache_spec.rb +24 -34
  125. data/spec/unit/library_spec.rb +21 -82
  126. data/spec/unit/metadata_spec.rb +207 -0
  127. data/spec/unit/ohai_spec.rb +0 -7
  128. data/spec/unit/omnibus_spec.rb +41 -36
  129. data/spec/unit/package_spec.rb +1 -216
  130. data/spec/unit/packagers/base_spec.rb +76 -190
  131. data/spec/unit/packagers/bff_spec.rb +160 -0
  132. data/spec/unit/packagers/deb_spec.rb +324 -0
  133. data/spec/unit/packagers/makeself_spec.rb +80 -0
  134. data/spec/unit/packagers/msi_spec.rb +267 -0
  135. data/spec/unit/packagers/pkg_spec.rb +219 -0
  136. data/spec/unit/packagers/rpm_spec.rb +328 -0
  137. data/spec/unit/project_spec.rb +217 -80
  138. data/spec/unit/publisher_spec.rb +6 -2
  139. data/spec/unit/publishers/artifactory_publisher_spec.rb +1 -1
  140. data/spec/unit/publishers/s3_publisher_spec.rb +1 -1
  141. data/spec/unit/s3_cacher_spec.rb +22 -5
  142. data/spec/unit/software_spec.rb +89 -232
  143. data/spec/unit/util_spec.rb +188 -0
  144. metadata +159 -402
  145. data/features/commands/_deprecated.feature +0 -84
  146. data/lib/omnibus/cleanroom.rb +0 -141
  147. data/lib/omnibus/cli/deprecated.rb +0 -132
  148. data/lib/omnibus/generator_files/mac_pkg/license.html.erb +0 -1
  149. data/lib/omnibus/generator_files/mac_pkg/welcome.html.erb +0 -9
  150. data/lib/omnibus/generator_files/project.rb.erb +0 -20
  151. data/lib/omnibus/generator_files/software/c-example.rb.erb +0 -42
  152. data/lib/omnibus/generator_files/software/erlang-example.rb.erb +0 -38
  153. data/lib/omnibus/generator_files/software/ruby-example.rb.erb +0 -24
  154. data/lib/omnibus/generator_files/windows_msi/localization-en-us.wxl.erb +0 -20
  155. data/lib/omnibus/generator_files/windows_msi/parameters.wxi.erb +0 -9
  156. data/lib/omnibus/packagers/mac_dmg.rb +0 -235
  157. data/lib/omnibus/packagers/mac_pkg.rb +0 -176
  158. data/lib/omnibus/packagers/windows_msi.rb +0 -109
  159. data/spec/data/complicated/config/patches/bzip2/makefile_take_env_vars.patch +0 -15
  160. data/spec/data/complicated/config/patches/couchdb/patch_for_couchjs_stack.patch +0 -19
  161. data/spec/data/complicated/config/patches/gd/gd-2.0.33-configure-libpng.patch +0 -100
  162. data/spec/data/complicated/config/patches/keepalived/keepalived-1.2.9_opscode_centos_5.patch +0 -15
  163. data/spec/data/complicated/config/patches/libedit/freebsd-vi-fix.patch +0 -24
  164. data/spec/data/complicated/config/patches/libiconv/libiconv-1.14_srclib_stdio.in.h-remove-gets-declarations.patch +0 -29
  165. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-makefile-dest-fix.patch +0 -35
  166. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-malloc-fix.patch +0 -13
  167. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-shared_lib_plus_plus-1.patch +0 -1035
  168. data/spec/data/complicated/config/patches/logrotate/logrotate_basedir_override.patch +0 -12
  169. data/spec/data/complicated/config/patches/ncurses/ncurses-5.9-solaris-xopen_source_extended-detection.patch +0 -11
  170. data/spec/data/complicated/config/patches/ncurses/ncurses-clang.patch +0 -42
  171. data/spec/data/complicated/config/patches/ncurses/patch-aa +0 -23
  172. data/spec/data/complicated/config/patches/ncurses/patch-ab +0 -44
  173. data/spec/data/complicated/config/patches/ncurses/patch-ac +0 -40
  174. data/spec/data/complicated/config/patches/ncurses/patch-ad +0 -12
  175. data/spec/data/complicated/config/patches/ncurses/patch-aix-configure +0 -23
  176. data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesf.h +0 -22
  177. data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesm.h +0 -22
  178. data/spec/data/complicated/config/patches/nrpe/fix_for_runit.patch +0 -64
  179. data/spec/data/complicated/config/patches/openssl/openssl-1.0.1f-do-not-build-docs.patch +0 -101
  180. data/spec/data/complicated/config/patches/postgresql/postgresql-9.1.2-configure-ncurses-fix.patch +0 -12
  181. data/spec/data/complicated/config/patches/ruby/patch-configure +0 -103
  182. data/spec/data/complicated/config/patches/ruby/ruby-aix-configure.patch +0 -10
  183. data/spec/data/complicated/config/patches/ruby/ruby-openssl-1.0.1c.patch +0 -42
  184. data/spec/data/complicated/config/patches/ruby/ruby_aix_1_9_3_448_ssl_EAGAIN.patch +0 -57
  185. data/spec/data/complicated/config/patches/ruby/rvm-cflags.patch +0 -27
  186. data/spec/data/complicated/config/projects/angrychef.rb +0 -32
  187. data/spec/data/complicated/config/projects/chef-windows.rb +0 -32
  188. data/spec/data/complicated/config/projects/chef.rb +0 -32
  189. data/spec/data/complicated/config/projects/chefdk-windows.rb +0 -41
  190. data/spec/data/complicated/config/projects/chefdk.rb +0 -44
  191. data/spec/data/complicated/config/software/appbundler.rb +0 -25
  192. data/spec/data/complicated/config/software/autoconf.rb +0 -35
  193. data/spec/data/complicated/config/software/automake.rb +0 -39
  194. data/spec/data/complicated/config/software/berkshelf.rb +0 -44
  195. data/spec/data/complicated/config/software/bundler.rb +0 -25
  196. data/spec/data/complicated/config/software/bzip2.rb +0 -46
  197. data/spec/data/complicated/config/software/cacerts.rb +0 -44
  198. data/spec/data/complicated/config/software/chef-client-msi.rb +0 -87
  199. data/spec/data/complicated/config/software/chef-gem.rb +0 -26
  200. data/spec/data/complicated/config/software/chef-vault.rb +0 -43
  201. data/spec/data/complicated/config/software/chef-windows.rb +0 -158
  202. data/spec/data/complicated/config/software/chef.rb +0 -170
  203. data/spec/data/complicated/config/software/chefdk.rb +0 -103
  204. data/spec/data/complicated/config/software/couchdb.rb +0 -53
  205. data/spec/data/complicated/config/software/curl.rb +0 -48
  206. data/spec/data/complicated/config/software/erlang.rb +0 -65
  207. data/spec/data/complicated/config/software/expat.rb +0 -21
  208. data/spec/data/complicated/config/software/fcgi.rb +0 -56
  209. data/spec/data/complicated/config/software/fcgiwrap.rb +0 -41
  210. data/spec/data/complicated/config/software/gd.rb +0 -56
  211. data/spec/data/complicated/config/software/gdbm.rb +0 -40
  212. data/spec/data/complicated/config/software/gecode.rb +0 -48
  213. data/spec/data/complicated/config/software/git.rb +0 -40
  214. data/spec/data/complicated/config/software/help2man.rb +0 -30
  215. data/spec/data/complicated/config/software/icu.rb +0 -40
  216. data/spec/data/complicated/config/software/jre.rb +0 -48
  217. data/spec/data/complicated/config/software/keepalived.rb +0 -43
  218. data/spec/data/complicated/config/software/libarchive.rb +0 -50
  219. data/spec/data/complicated/config/software/libedit.rb +0 -69
  220. data/spec/data/complicated/config/software/libffi.rb +0 -71
  221. data/spec/data/complicated/config/software/libgcc.rb +0 -39
  222. data/spec/data/complicated/config/software/libiconv.rb +0 -55
  223. data/spec/data/complicated/config/software/libjpeg.rb +0 -39
  224. data/spec/data/complicated/config/software/libpng.rb +0 -38
  225. data/spec/data/complicated/config/software/libtool.rb +0 -52
  226. data/spec/data/complicated/config/software/libwrap.rb +0 -50
  227. data/spec/data/complicated/config/software/libxml2.rb +0 -51
  228. data/spec/data/complicated/config/software/libxslt.rb +0 -52
  229. data/spec/data/complicated/config/software/libyaml-windows.rb +0 -43
  230. data/spec/data/complicated/config/software/libyaml.rb +0 -62
  231. data/spec/data/complicated/config/software/logrotate.rb +0 -41
  232. data/spec/data/complicated/config/software/makedepend.rb +0 -73
  233. data/spec/data/complicated/config/software/mysql2.rb +0 -42
  234. data/spec/data/complicated/config/software/nagios-plugins.rb +0 -53
  235. data/spec/data/complicated/config/software/nagios.rb +0 -66
  236. data/spec/data/complicated/config/software/ncurses.rb +0 -149
  237. data/spec/data/complicated/config/software/nginx.rb +0 -40
  238. data/spec/data/complicated/config/software/nodejs.rb +0 -44
  239. data/spec/data/complicated/config/software/nokogiri.rb +0 -55
  240. data/spec/data/complicated/config/software/nrpe.rb +0 -61
  241. data/spec/data/complicated/config/software/ohai.rb +0 -64
  242. data/spec/data/complicated/config/software/omnibus-ctl.rb +0 -34
  243. data/spec/data/complicated/config/software/openresty.rb +0 -67
  244. data/spec/data/complicated/config/software/openssl.rb +0 -158
  245. data/spec/data/complicated/config/software/pcre.rb +0 -42
  246. data/spec/data/complicated/config/software/perl-extutils-embed.rb +0 -15
  247. data/spec/data/complicated/config/software/perl-extutils-makemaker.rb +0 -15
  248. data/spec/data/complicated/config/software/perl.rb +0 -48
  249. data/spec/data/complicated/config/software/perl_pg_driver.rb +0 -12
  250. data/spec/data/complicated/config/software/php.rb +0 -41
  251. data/spec/data/complicated/config/software/pip.rb +0 -30
  252. data/spec/data/complicated/config/software/pkg-config.rb +0 -66
  253. data/spec/data/complicated/config/software/popt.rb +0 -47
  254. data/spec/data/complicated/config/software/postgresql.rb +0 -51
  255. data/spec/data/complicated/config/software/preparation.rb +0 -30
  256. data/spec/data/complicated/config/software/pygments.rb +0 -25
  257. data/spec/data/complicated/config/software/python.rb +0 -49
  258. data/spec/data/complicated/config/software/rabbitmq.rb +0 -36
  259. data/spec/data/complicated/config/software/rebar.rb +0 -36
  260. data/spec/data/complicated/config/software/redis.rb +0 -33
  261. data/spec/data/complicated/config/software/rsync.rb +0 -48
  262. data/spec/data/complicated/config/software/ruby-windows-devkit.rb +0 -30
  263. data/spec/data/complicated/config/software/ruby-windows.rb +0 -30
  264. data/spec/data/complicated/config/software/ruby.rb +0 -162
  265. data/spec/data/complicated/config/software/rubygems-customization.rb +0 -57
  266. data/spec/data/complicated/config/software/rubygems.rb +0 -37
  267. data/spec/data/complicated/config/software/runit.rb +0 -118
  268. data/spec/data/complicated/config/software/server-jre.rb +0 -46
  269. data/spec/data/complicated/config/software/setuptools.rb +0 -30
  270. data/spec/data/complicated/config/software/spawn-fcgi.rb +0 -40
  271. data/spec/data/complicated/config/software/sphinx.rb +0 -26
  272. data/spec/data/complicated/config/software/spidermonkey.rb +0 -60
  273. data/spec/data/complicated/config/software/sqitch.rb +0 -24
  274. data/spec/data/complicated/config/software/test-kitchen.rb +0 -39
  275. data/spec/data/complicated/config/software/unicorn.rb +0 -27
  276. data/spec/data/complicated/config/software/util-macros.rb +0 -46
  277. data/spec/data/complicated/config/software/xproto.rb +0 -46
  278. data/spec/data/complicated/config/software/yajl.rb +0 -30
  279. data/spec/data/complicated/config/software/zlib.rb +0 -67
  280. data/spec/data/overrides/bad_line.overrides +0 -3
  281. data/spec/data/overrides/good.overrides +0 -5
  282. data/spec/data/overrides/with_dupes.overrides +0 -4
  283. data/spec/data/projects/chefdk.rb +0 -41
  284. data/spec/data/projects/sample.rb +0 -13
  285. data/spec/data/software/erchef.rb +0 -42
  286. data/spec/data/software/zlib.rb +0 -67
  287. data/spec/fixtures/sample/files/mac_dmg/Resources/background.png +0 -0
  288. data/spec/fixtures/sample/files/mac_dmg/Resources/icon.png +0 -0
  289. data/spec/fixtures/sample/files/mac_pkg/Resources/background.png +0 -0
  290. data/spec/fixtures/sample/files/mac_pkg/Resources/license.html +0 -1
  291. data/spec/fixtures/sample/files/mac_pkg/Resources/welcome.html +0 -9
  292. data/spec/fixtures/sample/files/windows_msi/Resources/assets/LICENSE.rtf +0 -8
  293. data/spec/fixtures/sample/files/windows_msi/Resources/assets/banner_background.bmp +0 -0
  294. data/spec/fixtures/sample/files/windows_msi/Resources/assets/dialog_background.bmp +0 -0
  295. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project.ico +0 -0
  296. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_16x16.ico +0 -0
  297. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_32x32.ico +0 -0
  298. data/spec/fixtures/sample/files/windows_msi/Resources/parameters.wxi.erb +0 -9
  299. data/spec/fixtures/sample/files/windows_msi/Resources/source.wxs +0 -74
  300. data/spec/integration/packagers/mac_spec.rb +0 -58
  301. data/spec/integration/packagers/windows_spec.rb +0 -70
  302. data/spec/unit/packagers/mac_pkg_spec.rb +0 -151
@@ -14,174 +14,133 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- require 'pp'
18
-
19
17
  module Omnibus
20
- # Base class for classes that fetch project sources from the internet.
21
- #
22
- # @abstract Subclass and override the {#clean}, {#description},
23
- # {#fetch}, {#fetch_required?}, and {#version_guid} methods
24
- #
25
- # @todo Is this class supposed to be abstract or not? Pretty sure
26
- # it's supposed to be abstract
27
18
  class Fetcher
28
- # Given an error and a fetcher that generated the error, print a
29
- # formatted report of the error and stacktrace, along with fetcher
30
- # details to stderr.
31
- #
32
- # @note Does not rethrow the error; that must currently be done manually.
33
- #
34
- # @todo Since this is always called from within a fetcher, and
35
- # since the fetcher always passes itself in in the {#initialize}
36
- # method, this really ought to be encapsulated in a method call on
37
- # {Omnibus::Fetcher}.
38
- # @todo Also, since we always 'raise' after calling {#explain}, we
39
- # should just go ahead and exit from here. No need to raise,
40
- # since we're already outputting the real error and stacktrace
41
- # here.
42
- class ErrorReporter
43
- def initialize(error, fetcher)
44
- @error, @fetcher = error, fetcher
45
- end
46
-
47
- # @todo Why not just make an attribute for error?
48
- #
49
- # @todo And for that matter, why not make an attribute for the
50
- # fetcher as well? Or why not just use `@error` like we use
51
- # `@fetcher`?
52
- def e
53
- @error
54
- end
55
-
56
- # @todo If {Omnibus::Fetcher#description} is meant to show
57
- # parameters (presumably the kind of fetcher and the software it
58
- # is fetching?),
59
- # @todo make this use the logger
60
- def explain(why)
61
- $stderr.puts '* ' * 40
62
- $stderr.puts why
63
- $stderr.puts 'Fetcher params:'
64
- $stderr.puts indent(@fetcher.description, 2)
65
- $stderr.puts 'Exception:'
66
- $stderr.puts indent("#{e.class}: #{e.message.strip}", 2)
67
- Array(e.backtrace).each { |l| $stderr.puts indent(l, 4) }
68
- $stderr.puts '* ' * 40
69
- end
70
-
71
- private
72
-
73
- # Indent each line of a string with `n` spaces.
74
- #
75
- # Splits the string at `\n` characters and then pads the left
76
- # side with `n` spaces. Rejoins them all again with `\n`.
77
- #
78
- # @param string [String] the string to indent
79
- # @param n [Fixnum] the number of " " characters to indent each line.
80
- # @return [String]
81
- def indent(string, n)
82
- string.split("\n").map { |l| ' '.rjust(n) << l }.join("\n")
83
- end
84
- end
85
-
86
- class UnsupportedSourceLocation < ArgumentError
87
- end
88
-
89
- NULL_ARG = Object.new
90
-
91
- # Returns an implementation of {Fetcher} that can retrieve the
92
- # given software.
93
- #
94
- # @param software [Omnibus::Software] the software the Fetcher should fetch
95
- # @return [Omnibus::Fetcher]
96
- def self.for(software)
97
- if software.source
98
- if software.source[:url] && Config.use_s3_caching
99
- S3CacheFetcher.new(software)
100
- else
101
- without_caching_for(software)
102
- end
103
- else
104
- Fetcher.new(software)
105
- end
106
- end
107
-
108
- # @param software [Omnibus::Software] the software to fetch
109
- # @raise [UnsupportedSourceLocation] if the software's source is not
110
- # one of `:url`, `:git`, or `:path`
111
- # @see Omnibus::Software#source
112
- # @todo Define an enumeration of the acceptable software types
113
- # @todo This probably ought to be folded into {#for} method above.
114
- # It looks like this is called explicitly in
115
- # {Omnibus::S3Cache#fetch}, but that could be handled by having a
116
- # second optional parameter that always disables caching.
117
- # @todo Since the software determines what fetcher must be used to
118
- # fetch it, perhaps this should be a method on {Omnibus::Software}
119
- # instead.
120
- def self.without_caching_for(software)
121
- if software.source[:url]
122
- NetFetcher.new(software)
123
- elsif software.source[:git]
124
- GitFetcher.new(software)
125
- elsif software.source[:path]
126
- PathFetcher.new(software)
127
- else
128
- raise UnsupportedSourceLocation, "Don't know how to fetch software project #{software}"
129
- end
130
- end
131
-
19
+ include Digestable
132
20
  include Logging
133
21
  include Util
134
22
 
135
- attr_reader :name
136
-
137
- # @todo What is this? It doesn't appear to be used anywhere
138
- attr_reader :source_timefile
23
+ #
24
+ # The software for this fetcher.
25
+ #
26
+ # @return [Software]
27
+ #
28
+ attr_reader :software
139
29
 
30
+ #
31
+ # Create a new Fetcher object from the given software.
32
+ #
33
+ # @param [Software] software
34
+ # the software to create this fetcher
35
+ #
140
36
  def initialize(software)
141
37
  @software = software
142
38
  end
143
39
 
144
- # @!group Methods for Subclasses to Implement
145
-
146
- # @todo All extenders of this class override this method. Since
147
- # this class appears to be intended as an abstract one, this
148
- # should raise a NotImplementedError
149
- def description
150
- # Not as pretty as we'd like, but it's a sane default:
151
- inspect
152
- end
40
+ #
41
+ # @!group Abstract methods
42
+ #
43
+ # The following methods are all abstract and should be overriden in child
44
+ # classes.
45
+ # --------------------------------------------------
153
46
 
154
- # @todo All extenders of this class override this method. Since
155
- # this class appears to be intended as an abstract one, this
156
- # should raise a NotImplementedError
47
+ #
48
+ # @abstract
49
+ #
157
50
  def fetch_required?
158
- false
51
+ raise NotImplementedError
159
52
  end
160
53
 
161
- # @todo Empty method is very suspicious; raise NotImplementedError instead.
54
+ #
55
+ # @abstract
56
+ #
162
57
  def clean
58
+ raise NotImplementedError
163
59
  end
164
60
 
165
- # @todo Empty method is very suspicious; raise NotImplementedError instead.
61
+ #
62
+ # @abstract
63
+ #
166
64
  def fetch
65
+ raise NotImplementedError
167
66
  end
168
67
 
169
- # @todo Empty method is very suspicious; raise NotImplementedError instead.
68
+ #
69
+ # @abstract
70
+ #
170
71
  def version_guid
72
+ raise NotImplementedError
171
73
  end
172
74
 
173
- # Returns the version to be used during build caching.
174
- # By default fetchers don't override the versions.
75
+ #
76
+ # @abstract
77
+ #
175
78
  def version_for_cache
176
- nil
79
+ raise NotImplementedError
177
80
  end
178
81
 
82
+ #
83
+ # @!endgroup
84
+ # --------------------------------------------------
85
+
179
86
  private
180
87
 
88
+ #
89
+ # The "source" for this software, with applied overrides.
90
+ #
91
+ # @return [Hash]
92
+ #
93
+ def source
94
+ software.source
95
+ end
96
+
97
+ #
98
+ # The path where extracted software should live.
99
+ #
100
+ # @see Software#project_dir
101
+ #
102
+ # @return [String]
103
+ #
104
+ def project_dir
105
+ software.project_dir
106
+ end
107
+
108
+ #
109
+ # The version for this sfotware, with applied overrides.
110
+ #
111
+ # @return [String]
112
+ #
113
+ def version
114
+ software.version
115
+ end
116
+
117
+ #
118
+ # Override the +log_key+ for this fetcher to include the name of the
119
+ # software during the fetch.
120
+ #
121
+ # @return [String]
122
+ #
181
123
  def log_key
182
- @log_key ||= "#{super}: #{@software.name}"
124
+ @log_key ||= "#{super}: #{software.name}"
183
125
  end
184
126
 
185
- # !@endgroup
127
+
128
+ #
129
+ # Idempotently create the required directories for building/downloading.
130
+ # Fetchers should call this method before performing any operations that
131
+ # manipulate the filesystem.
132
+ #
133
+ # @return [void]
134
+ #
135
+ def create_required_directories
136
+ [
137
+ Config.cache_dir,
138
+ Config.source_dir,
139
+ software.build_dir,
140
+ software.project_dir,
141
+ ].each do |directory|
142
+ FileUtils.mkdir_p(directory) unless File.directory?(directory)
143
+ end
144
+ end
186
145
  end
187
146
  end
@@ -15,202 +15,167 @@
15
15
  #
16
16
 
17
17
  module Omnibus
18
- # Fetcher implementation for projects in git.
19
18
  class GitFetcher < Fetcher
20
- attr_reader :source
21
- attr_reader :project_dir
22
- attr_reader :version
23
-
24
- def initialize(software)
25
- @name = software.name
26
- @source = software.source
27
- @version = software.version
28
- @project_dir = software.project_dir
29
- super
30
- end
31
-
32
- def description
33
- <<-EOH.gsub(/^ {8}/, '').strip
34
- repo URI: #{@source[:git]}
35
- local location: #{@project_dir}
36
- EOH
19
+ #
20
+ # A fetch is required if the git repository is not cloned or if the local
21
+ # revision does not match the desired revision.
22
+ #
23
+ # @return [true, false]
24
+ #
25
+ def fetch_required?
26
+ !(cloned? && same_revision?)
37
27
  end
38
28
 
29
+ #
30
+ # The version identifier for this git location. This is computed using the
31
+ # current revision on disk.
32
+ #
33
+ # @return [String]
34
+ #
39
35
  def version_guid
40
- "git:#{current_revision}".chomp
41
- rescue
36
+ "git:#{current_revision}"
42
37
  end
43
38
 
39
+ #
40
+ # Clean the project directory by removing the contents from disk.
41
+ #
42
+ # @return [true, false]
43
+ # true if the project directory was removed, false otherwise
44
+ #
44
45
  def clean
45
- if existing_git_clone?
46
- log.info(log_key) { 'Cleaning existing build' }
47
- shellout!('git clean -fdx', cwd: project_dir)
46
+ if cloned?
47
+ log.info(log_key) { 'Cleaning existing clone' }
48
+ git('clean -fdx')
49
+ true
50
+ else
51
+ false
48
52
  end
49
- rescue Exception => e
50
- ErrorReporter.new(e, self).explain("Failed to clean git repository '#{@source[:git]}'")
51
- raise
52
- end
53
-
54
- def fetch_required?
55
- !existing_git_clone? || !current_rev_matches_target_rev?
56
53
  end
57
54
 
55
+ #
56
+ # Fetch (clone) or update (fetch) the remote git repository.
57
+ #
58
+ # @return [void]
59
+ #
58
60
  def fetch
59
- retries ||= 0
60
- if existing_git_clone?
61
- fetch_updates unless current_rev_matches_target_rev?
62
- else
63
- clone
64
- checkout
65
- end
66
- rescue Exception => e
67
- if retries >= 3
68
- ErrorReporter.new(e, self).explain("Failed to fetch git repository '#{@source[:git]}'")
69
- raise
61
+ log.info(log_key) { "Fetching from `#{source_url}'" }
62
+
63
+ create_required_directories
64
+
65
+ if cloned?
66
+ git_fetch unless same_revision?
70
67
  else
71
- # Deal with github failing all the time :(
72
- time_to_sleep = 5 * (2**retries)
73
- retries += 1
74
- log.warn(log_key) do
75
- "git clone/fetch failed for #{@source} #{retries} time(s). " \
76
- "Retrying in #{time_to_sleep}s..."
77
- end
78
- sleep(time_to_sleep)
79
- retry
68
+ git_clone
69
+ git_checkout
80
70
  end
81
71
  end
82
72
 
83
- # Return the target sha to be used during build caching
84
- # This overrides the cases where software.version is similar to
85
- # master, 11-stable etc..
73
+ #
74
+ # The version for this item in the cache. The is the parsed revision of the
75
+ # item on disk.
76
+ #
77
+ # @return [String]
78
+ #
86
79
  def version_for_cache
87
- target_revision
80
+ "revision:#{current_revision}"
88
81
  end
89
82
 
90
83
  private
91
84
 
92
- def clone
93
- log.info(log_key) { 'Cloning the source from git' }
94
- shellout!("git clone #{@source[:git]} #{project_dir}")
95
- end
96
-
97
- def checkout
98
- sha_ref = target_revision
99
- shellout!("git checkout #{sha_ref}", cwd: project_dir)
100
- end
101
-
102
- def fetch_updates
103
- log.info(log_key) do
104
- "Fetching updates and resetting to revision '#{target_revision}'"
105
- end
106
-
107
- fetch_cmd = "git fetch origin && " \
108
- "git fetch origin --tags && " \
109
- "git reset --hard #{target_revision}"
110
- shellout!(fetch_cmd, cwd: project_dir)
111
- end
112
-
113
- def existing_git_clone?
85
+ #
86
+ # The URL where the git source should be downloaded from.
87
+ #
88
+ # @return [String]
89
+ #
90
+ def source_url
91
+ source[:git]
92
+ end
93
+
94
+ #
95
+ # Determine if the clone exists.
96
+ #
97
+ # @return [true, false]
98
+ #
99
+ def cloned?
114
100
  File.exist?("#{project_dir}/.git")
115
101
  end
116
102
 
117
- def current_rev_matches_target_rev?
118
- current_revision && current_revision.strip.to_i(16) == target_revision.strip.to_i(16)
119
- end
120
-
103
+ #
104
+ # Clone the +source_url+ into the +project_dir+.
105
+ #
106
+ # @return [void]
107
+ #
108
+ def git_clone
109
+ git("clone #{source_url} .")
110
+ end
111
+
112
+ #
113
+ # Checkout the +target_revision+.
114
+ #
115
+ # @return [void]
116
+ #
117
+ def git_checkout
118
+ git("fetch --all")
119
+ git("checkout #{target_revision}")
120
+ end
121
+
122
+ #
123
+ # Fetch the remote tags and refs, and reset to +target_revision+.
124
+ #
125
+ # @return [void]
126
+ #
127
+ def git_fetch
128
+ git("fetch --all")
129
+ git("reset --hard #{target_revision}")
130
+ end
131
+
132
+ #
133
+ # The current revision for the cloned checkout.
134
+ #
135
+ # @return [String]
136
+ #
121
137
  def current_revision
122
- return @current_rev if @current_rev
123
-
124
- cmd = shellout!('git rev-parse HEAD', cwd: project_dir)
125
- stdout = cmd.stdout
126
-
127
- @current_rev = sha_hash?(stdout) ? stdout : nil
128
- @current_rev
138
+ @current_revision ||= git('rev-parse HEAD').stdout.strip
139
+ rescue CommandFailed
140
+ nil
129
141
  end
130
142
 
143
+ #
144
+ # The target revision from the user.
145
+ #
146
+ # @return [String]
147
+ #
131
148
  def target_revision
132
- @target_rev ||= if sha_hash?(version)
133
- version
134
- else
135
- revision_from_remote_reference(version)
136
- end
137
- end
138
-
139
- def sha_hash?(rev)
140
- rev =~ /^[0-9a-f]{40}$/
141
- end
142
-
143
- # Return the SHA corresponding to ref. If ref is an annotated tag,
144
- # return the SHA that was tagged not the SHA of the tag itself.
145
- def revision_from_remote_reference(ref)
146
- retries ||= 0
147
- # execute `git ls-remote` the trailing '*' does globbing. This
148
- # allows us to return the SHA of the tagged commit for annotated
149
- # tags. We take care to only return exact matches in
150
- # process_remote_list.
151
- cmd = shellout!("git ls-remote origin #{ref}*", cwd: project_dir)
152
- commit_ref = process_remote_list(cmd.stdout, ref)
153
-
154
- unless commit_ref
155
- raise UnresolvableGitReference.new("Could not resolve `#{ref}' to a SHA.")
156
- end
157
- commit_ref
158
- rescue UnresolvableGitReference => e # skip retries
159
- ErrorReporter.new(e, self).explain(<<-E)
160
- Command `#{cmd}' did not find a commit for reference `#{ref}'.
161
- The tag or branch you're looking for doesn't exist on the remote repo.
162
- If your project uses version tags like v1.2.3, include the 'v' in your
163
- software's version.
164
- E
165
- raise
166
- rescue Exception => e
167
- if retries >= 3
168
- ErrorReporter.new(e, self).explain("Failed to find any commits for the ref '#{ref}'")
169
- raise
149
+ @target_revision ||= git("rev-parse #{version}").stdout.strip
150
+ rescue CommandFailed => e
151
+ if e.message.include?('ambiguous argument')
152
+ @target_revision = git("rev-parse origin/#{version}").stdout.strip
153
+ @target_revision
170
154
  else
171
- # Deal with github failing all the time :(
172
- time_to_sleep = 5 * (2**retries)
173
- retries += 1
174
- log.warn(log_key) do
175
- "git ls-remote failed for #{@source} #{retries} time(s). " \
176
- "Retrying in #{time_to_sleep}s..."
177
- end
178
- sleep(time_to_sleep)
179
- retry
155
+ log.warn { 'Could not determine target revision!' }
156
+ nil
180
157
  end
181
158
  end
182
159
 
183
- def process_remote_list(stdout, ref)
184
- # Dereference annotated tags.
185
- #
186
- # Output will look like this:
187
- #
188
- # a2ed66c01f42514bcab77fd628149eccb4ecee28 refs/tags/rel-0.11.0
189
- # f915286abdbc1907878376cce9222ac0b08b12b8 refs/tags/rel-0.11.0^{}
190
- #
191
- # The SHA with ^{} is the commit pointed to by an annotated
192
- # tag. If ref isn't an annotated tag, there will not be a line
193
- # with trailing ^{}.
194
- #
195
- # We'll return the SHA corresponding to the ^{} which is the
196
- # commit pointed to by an annotated tag. If no such commit
197
- # exists (not an annotated tag) then we return the SHA of the
198
- # ref. If nothing matches, return "".
199
- lines = stdout.split("\n")
200
- matches = lines.map { |line| line.split("\t") }
201
- # first try for ^{} indicating the commit pointed to by an
202
- # annotated tag
203
- tagged_commit = matches.find { |m| m[1].end_with?("#{ref}^{}") }
204
- if tagged_commit
205
- tagged_commit[0]
206
- else
207
- found = matches.find { |m| m[1].end_with?("#{ref}") }
208
- if found
209
- found[0]
210
- else
211
- nil
212
- end
213
- end
160
+ #
161
+ # Determine if the given revision matches the current revision.
162
+ #
163
+ # @return [true, false]
164
+ #
165
+ def same_revision?
166
+ current_revision == target_revision
167
+ end
168
+
169
+ #
170
+ # Execute the given git command, inside the +project_dir+.
171
+ #
172
+ # @see Util#shellout!
173
+ #
174
+ # @return [Mixlib::ShellOut]
175
+ # the shellout object
176
+ #
177
+ def git(command)
178
+ shellout!("git #{command}", cwd: project_dir)
214
179
  end
215
180
  end
216
181
  end