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.
- checksums.yaml +7 -0
- data/.gitignore +140 -10
- data/CHANGELOG.md +181 -8
- data/README.md +63 -35
- data/Rakefile +1 -1
- data/docs/omnibus-build-cache.md b/data/docs/Build → Cache.md +0 -0
- data/docs/Building on Debian.md +59 -0
- data/docs/Building on OSX.md +61 -35
- data/docs/Building on RHEL.md +74 -0
- data/docs/Building on Windows.md +40 -81
- data/features/commands/build.feature +1 -2
- data/features/commands/clean.feature +1 -1
- data/lib/omnibus.rb +111 -204
- data/lib/omnibus/build_version.rb +3 -20
- data/lib/omnibus/build_version_dsl.rb +2 -3
- data/lib/omnibus/builder.rb +103 -211
- data/lib/omnibus/cleaner.rb +5 -7
- data/lib/omnibus/cli.rb +1 -4
- data/lib/omnibus/cli/base.rb +9 -16
- data/lib/omnibus/compressor.rb +60 -0
- data/{spec/data/complicated/config/software/version-manifest.rb → lib/omnibus/compressors/base.rb} +17 -12
- data/lib/omnibus/compressors/dmg.rb +312 -0
- data/lib/omnibus/{null_builder.rb → compressors/null.rb} +10 -4
- data/lib/omnibus/compressors/tgz.rb +141 -0
- data/lib/omnibus/config.rb +89 -83
- data/lib/omnibus/core_extensions.rb +1 -0
- data/lib/omnibus/core_extensions/open_uri.rb +58 -0
- data/lib/omnibus/digestable.rb +9 -3
- data/lib/omnibus/exceptions.rb +116 -175
- data/lib/omnibus/fetcher.rb +97 -138
- data/lib/omnibus/fetchers/git_fetcher.rb +130 -165
- data/lib/omnibus/fetchers/net_fetcher.rb +205 -164
- data/lib/omnibus/fetchers/{s3_cache_fetcher.rb → null_fetcher.rb} +27 -17
- data/lib/omnibus/fetchers/path_fetcher.rb +74 -32
- data/lib/omnibus/file_syncer.rb +149 -0
- data/lib/omnibus/generator.rb +103 -32
- data/lib/omnibus/generator_files/.kitchen.yml.erb +5 -1
- data/lib/omnibus/generator_files/Gemfile.erb +13 -7
- data/lib/omnibus/generator_files/config/projects/project.rb.erb +28 -0
- data/lib/omnibus/generator_files/config/software/zlib.rb.erb +55 -0
- data/lib/omnibus/generator_files/omnibus.rb.erb +5 -7
- data/lib/omnibus/git_cache.rb +11 -13
- data/lib/omnibus/logger.rb +76 -22
- data/lib/omnibus/logging.rb +1 -1
- data/lib/omnibus/metadata.rb +264 -0
- data/lib/omnibus/ohai.rb +0 -51
- data/lib/omnibus/package.rb +4 -228
- data/lib/omnibus/packager.rb +71 -0
- data/lib/omnibus/packagers/base.rb +118 -176
- data/lib/omnibus/packagers/bff.rb +136 -0
- data/lib/omnibus/packagers/deb.rb +389 -0
- data/lib/omnibus/packagers/makeself.rb +114 -0
- data/lib/omnibus/packagers/msi.rb +346 -0
- data/lib/omnibus/packagers/pkg.rb +278 -0
- data/lib/omnibus/packagers/rpm.rb +438 -0
- data/lib/omnibus/packagers/solaris.rb +110 -0
- data/lib/omnibus/project.rb +263 -666
- data/lib/omnibus/publisher.rb +3 -3
- data/lib/omnibus/s3_cache.rb +21 -30
- data/lib/omnibus/software.rb +132 -271
- data/lib/omnibus/templating.rb +66 -0
- data/lib/omnibus/thread_pool.rb +109 -0
- data/lib/omnibus/util.rb +137 -15
- data/lib/omnibus/version.rb +1 -1
- data/omnibus.gemspec +2 -2
- data/resources/bff/gen.template.erb +22 -0
- data/resources/bff/postinstall.sh +0 -0
- data/resources/bff/unpostinstall.sh +0 -0
- data/resources/deb/conffiles.erb +3 -0
- data/resources/deb/control.erb +25 -0
- data/resources/deb/md5sums.erb +3 -0
- data/{lib/omnibus/generator_files/mac_dmg → resources/dmg}/background.png +0 -0
- data/resources/dmg/create_dmg.osascript.erb +17 -0
- data/{lib/omnibus/generator_files/mac_dmg → resources/dmg}/icon.png +0 -0
- data/{bin → resources/makeself}/makeself-header.sh +0 -0
- data/{bin → resources/makeself}/makeself.sh +0 -0
- data/{lib/omnibus/generator_files/package_scripts/makeselfinst.erb → resources/makeself/post_extract.sh.erb} +4 -4
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/LICENSE.rtf +0 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/banner_background.bmp +0 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/dialog_background.bmp +0 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project.ico +0 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project_16x16.ico +0 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project_32x32.ico +0 -0
- data/{spec/fixtures/sample/files/windows_msi/Resources/localization-en-us.wxl → resources/msi/localization-en-us.wxl.erb} +3 -4
- data/resources/msi/parameters.wxi.erb +9 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/source.wxs.erb +14 -15
- data/{lib/omnibus/generator_files/mac_pkg → resources/pkg}/background.png +0 -0
- data/resources/pkg/distribution.xml.erb +21 -0
- data/resources/pkg/license.html.erb +3 -0
- data/resources/pkg/welcome.html.erb +7 -0
- data/resources/rpm/rpmmacros.erb +3 -0
- data/resources/rpm/signing.erb +40 -0
- data/resources/rpm/spec.erb +70 -0
- data/spec/functional/builder_spec.rb +90 -111
- data/spec/functional/fetchers/git_fetcher_spec.rb +130 -0
- data/spec/functional/fetchers/net_fetcher_spec.rb +110 -0
- data/spec/functional/fetchers/path_fetcher_spec.rb +97 -0
- data/spec/functional/file_syncer_spec.rb +206 -0
- data/spec/functional/templating_spec.rb +73 -0
- data/spec/spec_helper.rb +31 -94
- data/spec/support/env_helpers.rb +20 -0
- data/spec/support/examples.rb +56 -0
- data/spec/support/file_helpers.rb +46 -0
- data/spec/support/git_helpers.rb +107 -0
- data/spec/support/logging_helpers.rb +33 -0
- data/spec/support/matchers.rb +36 -0
- data/spec/support/ohai_helpers.rb +22 -0
- data/spec/support/path_helpers.rb +19 -0
- data/spec/support/shell_helpers.rb +14 -0
- data/spec/unit/build_version_dsl_spec.rb +0 -17
- data/spec/unit/build_version_spec.rb +1 -19
- data/spec/unit/builder_spec.rb +158 -46
- data/spec/unit/compressor_spec.rb +45 -0
- data/spec/unit/compressors/base_spec.rb +26 -0
- data/spec/unit/compressors/dmg_spec.rb +291 -0
- data/spec/unit/compressors/null_spec.rb +23 -0
- data/spec/unit/compressors/tgz_spec.rb +67 -0
- data/spec/unit/config_spec.rb +27 -34
- data/spec/unit/digestable_spec.rb +4 -4
- data/spec/unit/fetchers/git_fetcher_spec.rb +110 -39
- data/spec/unit/fetchers/net_fetcher_spec.rb +182 -72
- data/spec/unit/fetchers/path_fetcher_spec.rb +111 -0
- data/spec/unit/generator_spec.rb +137 -0
- data/spec/unit/git_cache_spec.rb +24 -34
- data/spec/unit/library_spec.rb +21 -82
- data/spec/unit/metadata_spec.rb +207 -0
- data/spec/unit/ohai_spec.rb +0 -7
- data/spec/unit/omnibus_spec.rb +41 -36
- data/spec/unit/package_spec.rb +1 -216
- data/spec/unit/packagers/base_spec.rb +76 -190
- data/spec/unit/packagers/bff_spec.rb +160 -0
- data/spec/unit/packagers/deb_spec.rb +324 -0
- data/spec/unit/packagers/makeself_spec.rb +80 -0
- data/spec/unit/packagers/msi_spec.rb +267 -0
- data/spec/unit/packagers/pkg_spec.rb +219 -0
- data/spec/unit/packagers/rpm_spec.rb +328 -0
- data/spec/unit/project_spec.rb +217 -80
- data/spec/unit/publisher_spec.rb +6 -2
- data/spec/unit/publishers/artifactory_publisher_spec.rb +1 -1
- data/spec/unit/publishers/s3_publisher_spec.rb +1 -1
- data/spec/unit/s3_cacher_spec.rb +22 -5
- data/spec/unit/software_spec.rb +89 -232
- data/spec/unit/util_spec.rb +188 -0
- metadata +159 -402
- data/features/commands/_deprecated.feature +0 -84
- data/lib/omnibus/cleanroom.rb +0 -141
- data/lib/omnibus/cli/deprecated.rb +0 -132
- data/lib/omnibus/generator_files/mac_pkg/license.html.erb +0 -1
- data/lib/omnibus/generator_files/mac_pkg/welcome.html.erb +0 -9
- data/lib/omnibus/generator_files/project.rb.erb +0 -20
- data/lib/omnibus/generator_files/software/c-example.rb.erb +0 -42
- data/lib/omnibus/generator_files/software/erlang-example.rb.erb +0 -38
- data/lib/omnibus/generator_files/software/ruby-example.rb.erb +0 -24
- data/lib/omnibus/generator_files/windows_msi/localization-en-us.wxl.erb +0 -20
- data/lib/omnibus/generator_files/windows_msi/parameters.wxi.erb +0 -9
- data/lib/omnibus/packagers/mac_dmg.rb +0 -235
- data/lib/omnibus/packagers/mac_pkg.rb +0 -176
- data/lib/omnibus/packagers/windows_msi.rb +0 -109
- data/spec/data/complicated/config/patches/bzip2/makefile_take_env_vars.patch +0 -15
- data/spec/data/complicated/config/patches/couchdb/patch_for_couchjs_stack.patch +0 -19
- data/spec/data/complicated/config/patches/gd/gd-2.0.33-configure-libpng.patch +0 -100
- data/spec/data/complicated/config/patches/keepalived/keepalived-1.2.9_opscode_centos_5.patch +0 -15
- data/spec/data/complicated/config/patches/libedit/freebsd-vi-fix.patch +0 -24
- data/spec/data/complicated/config/patches/libiconv/libiconv-1.14_srclib_stdio.in.h-remove-gets-declarations.patch +0 -29
- data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-makefile-dest-fix.patch +0 -35
- data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-malloc-fix.patch +0 -13
- data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-shared_lib_plus_plus-1.patch +0 -1035
- data/spec/data/complicated/config/patches/logrotate/logrotate_basedir_override.patch +0 -12
- data/spec/data/complicated/config/patches/ncurses/ncurses-5.9-solaris-xopen_source_extended-detection.patch +0 -11
- data/spec/data/complicated/config/patches/ncurses/ncurses-clang.patch +0 -42
- data/spec/data/complicated/config/patches/ncurses/patch-aa +0 -23
- data/spec/data/complicated/config/patches/ncurses/patch-ab +0 -44
- data/spec/data/complicated/config/patches/ncurses/patch-ac +0 -40
- data/spec/data/complicated/config/patches/ncurses/patch-ad +0 -12
- data/spec/data/complicated/config/patches/ncurses/patch-aix-configure +0 -23
- data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesf.h +0 -22
- data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesm.h +0 -22
- data/spec/data/complicated/config/patches/nrpe/fix_for_runit.patch +0 -64
- data/spec/data/complicated/config/patches/openssl/openssl-1.0.1f-do-not-build-docs.patch +0 -101
- data/spec/data/complicated/config/patches/postgresql/postgresql-9.1.2-configure-ncurses-fix.patch +0 -12
- data/spec/data/complicated/config/patches/ruby/patch-configure +0 -103
- data/spec/data/complicated/config/patches/ruby/ruby-aix-configure.patch +0 -10
- data/spec/data/complicated/config/patches/ruby/ruby-openssl-1.0.1c.patch +0 -42
- data/spec/data/complicated/config/patches/ruby/ruby_aix_1_9_3_448_ssl_EAGAIN.patch +0 -57
- data/spec/data/complicated/config/patches/ruby/rvm-cflags.patch +0 -27
- data/spec/data/complicated/config/projects/angrychef.rb +0 -32
- data/spec/data/complicated/config/projects/chef-windows.rb +0 -32
- data/spec/data/complicated/config/projects/chef.rb +0 -32
- data/spec/data/complicated/config/projects/chefdk-windows.rb +0 -41
- data/spec/data/complicated/config/projects/chefdk.rb +0 -44
- data/spec/data/complicated/config/software/appbundler.rb +0 -25
- data/spec/data/complicated/config/software/autoconf.rb +0 -35
- data/spec/data/complicated/config/software/automake.rb +0 -39
- data/spec/data/complicated/config/software/berkshelf.rb +0 -44
- data/spec/data/complicated/config/software/bundler.rb +0 -25
- data/spec/data/complicated/config/software/bzip2.rb +0 -46
- data/spec/data/complicated/config/software/cacerts.rb +0 -44
- data/spec/data/complicated/config/software/chef-client-msi.rb +0 -87
- data/spec/data/complicated/config/software/chef-gem.rb +0 -26
- data/spec/data/complicated/config/software/chef-vault.rb +0 -43
- data/spec/data/complicated/config/software/chef-windows.rb +0 -158
- data/spec/data/complicated/config/software/chef.rb +0 -170
- data/spec/data/complicated/config/software/chefdk.rb +0 -103
- data/spec/data/complicated/config/software/couchdb.rb +0 -53
- data/spec/data/complicated/config/software/curl.rb +0 -48
- data/spec/data/complicated/config/software/erlang.rb +0 -65
- data/spec/data/complicated/config/software/expat.rb +0 -21
- data/spec/data/complicated/config/software/fcgi.rb +0 -56
- data/spec/data/complicated/config/software/fcgiwrap.rb +0 -41
- data/spec/data/complicated/config/software/gd.rb +0 -56
- data/spec/data/complicated/config/software/gdbm.rb +0 -40
- data/spec/data/complicated/config/software/gecode.rb +0 -48
- data/spec/data/complicated/config/software/git.rb +0 -40
- data/spec/data/complicated/config/software/help2man.rb +0 -30
- data/spec/data/complicated/config/software/icu.rb +0 -40
- data/spec/data/complicated/config/software/jre.rb +0 -48
- data/spec/data/complicated/config/software/keepalived.rb +0 -43
- data/spec/data/complicated/config/software/libarchive.rb +0 -50
- data/spec/data/complicated/config/software/libedit.rb +0 -69
- data/spec/data/complicated/config/software/libffi.rb +0 -71
- data/spec/data/complicated/config/software/libgcc.rb +0 -39
- data/spec/data/complicated/config/software/libiconv.rb +0 -55
- data/spec/data/complicated/config/software/libjpeg.rb +0 -39
- data/spec/data/complicated/config/software/libpng.rb +0 -38
- data/spec/data/complicated/config/software/libtool.rb +0 -52
- data/spec/data/complicated/config/software/libwrap.rb +0 -50
- data/spec/data/complicated/config/software/libxml2.rb +0 -51
- data/spec/data/complicated/config/software/libxslt.rb +0 -52
- data/spec/data/complicated/config/software/libyaml-windows.rb +0 -43
- data/spec/data/complicated/config/software/libyaml.rb +0 -62
- data/spec/data/complicated/config/software/logrotate.rb +0 -41
- data/spec/data/complicated/config/software/makedepend.rb +0 -73
- data/spec/data/complicated/config/software/mysql2.rb +0 -42
- data/spec/data/complicated/config/software/nagios-plugins.rb +0 -53
- data/spec/data/complicated/config/software/nagios.rb +0 -66
- data/spec/data/complicated/config/software/ncurses.rb +0 -149
- data/spec/data/complicated/config/software/nginx.rb +0 -40
- data/spec/data/complicated/config/software/nodejs.rb +0 -44
- data/spec/data/complicated/config/software/nokogiri.rb +0 -55
- data/spec/data/complicated/config/software/nrpe.rb +0 -61
- data/spec/data/complicated/config/software/ohai.rb +0 -64
- data/spec/data/complicated/config/software/omnibus-ctl.rb +0 -34
- data/spec/data/complicated/config/software/openresty.rb +0 -67
- data/spec/data/complicated/config/software/openssl.rb +0 -158
- data/spec/data/complicated/config/software/pcre.rb +0 -42
- data/spec/data/complicated/config/software/perl-extutils-embed.rb +0 -15
- data/spec/data/complicated/config/software/perl-extutils-makemaker.rb +0 -15
- data/spec/data/complicated/config/software/perl.rb +0 -48
- data/spec/data/complicated/config/software/perl_pg_driver.rb +0 -12
- data/spec/data/complicated/config/software/php.rb +0 -41
- data/spec/data/complicated/config/software/pip.rb +0 -30
- data/spec/data/complicated/config/software/pkg-config.rb +0 -66
- data/spec/data/complicated/config/software/popt.rb +0 -47
- data/spec/data/complicated/config/software/postgresql.rb +0 -51
- data/spec/data/complicated/config/software/preparation.rb +0 -30
- data/spec/data/complicated/config/software/pygments.rb +0 -25
- data/spec/data/complicated/config/software/python.rb +0 -49
- data/spec/data/complicated/config/software/rabbitmq.rb +0 -36
- data/spec/data/complicated/config/software/rebar.rb +0 -36
- data/spec/data/complicated/config/software/redis.rb +0 -33
- data/spec/data/complicated/config/software/rsync.rb +0 -48
- data/spec/data/complicated/config/software/ruby-windows-devkit.rb +0 -30
- data/spec/data/complicated/config/software/ruby-windows.rb +0 -30
- data/spec/data/complicated/config/software/ruby.rb +0 -162
- data/spec/data/complicated/config/software/rubygems-customization.rb +0 -57
- data/spec/data/complicated/config/software/rubygems.rb +0 -37
- data/spec/data/complicated/config/software/runit.rb +0 -118
- data/spec/data/complicated/config/software/server-jre.rb +0 -46
- data/spec/data/complicated/config/software/setuptools.rb +0 -30
- data/spec/data/complicated/config/software/spawn-fcgi.rb +0 -40
- data/spec/data/complicated/config/software/sphinx.rb +0 -26
- data/spec/data/complicated/config/software/spidermonkey.rb +0 -60
- data/spec/data/complicated/config/software/sqitch.rb +0 -24
- data/spec/data/complicated/config/software/test-kitchen.rb +0 -39
- data/spec/data/complicated/config/software/unicorn.rb +0 -27
- data/spec/data/complicated/config/software/util-macros.rb +0 -46
- data/spec/data/complicated/config/software/xproto.rb +0 -46
- data/spec/data/complicated/config/software/yajl.rb +0 -30
- data/spec/data/complicated/config/software/zlib.rb +0 -67
- data/spec/data/overrides/bad_line.overrides +0 -3
- data/spec/data/overrides/good.overrides +0 -5
- data/spec/data/overrides/with_dupes.overrides +0 -4
- data/spec/data/projects/chefdk.rb +0 -41
- data/spec/data/projects/sample.rb +0 -13
- data/spec/data/software/erchef.rb +0 -42
- data/spec/data/software/zlib.rb +0 -67
- data/spec/fixtures/sample/files/mac_dmg/Resources/background.png +0 -0
- data/spec/fixtures/sample/files/mac_dmg/Resources/icon.png +0 -0
- data/spec/fixtures/sample/files/mac_pkg/Resources/background.png +0 -0
- data/spec/fixtures/sample/files/mac_pkg/Resources/license.html +0 -1
- data/spec/fixtures/sample/files/mac_pkg/Resources/welcome.html +0 -9
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/LICENSE.rtf +0 -8
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/banner_background.bmp +0 -0
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/dialog_background.bmp +0 -0
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/project.ico +0 -0
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_16x16.ico +0 -0
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_32x32.ico +0 -0
- data/spec/fixtures/sample/files/windows_msi/Resources/parameters.wxi.erb +0 -9
- data/spec/fixtures/sample/files/windows_msi/Resources/source.wxs +0 -74
- data/spec/integration/packagers/mac_spec.rb +0 -58
- data/spec/integration/packagers/windows_spec.rb +0 -70
- data/spec/unit/packagers/mac_pkg_spec.rb +0 -151
data/lib/omnibus/fetcher.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
136
|
-
|
137
|
-
#
|
138
|
-
|
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
|
-
#
|
145
|
-
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
|
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
|
-
#
|
155
|
-
#
|
156
|
-
#
|
47
|
+
#
|
48
|
+
# @abstract
|
49
|
+
#
|
157
50
|
def fetch_required?
|
158
|
-
|
51
|
+
raise NotImplementedError
|
159
52
|
end
|
160
53
|
|
161
|
-
#
|
54
|
+
#
|
55
|
+
# @abstract
|
56
|
+
#
|
162
57
|
def clean
|
58
|
+
raise NotImplementedError
|
163
59
|
end
|
164
60
|
|
165
|
-
#
|
61
|
+
#
|
62
|
+
# @abstract
|
63
|
+
#
|
166
64
|
def fetch
|
65
|
+
raise NotImplementedError
|
167
66
|
end
|
168
67
|
|
169
|
-
#
|
68
|
+
#
|
69
|
+
# @abstract
|
70
|
+
#
|
170
71
|
def version_guid
|
72
|
+
raise NotImplementedError
|
171
73
|
end
|
172
74
|
|
173
|
-
#
|
174
|
-
#
|
75
|
+
#
|
76
|
+
# @abstract
|
77
|
+
#
|
175
78
|
def version_for_cache
|
176
|
-
|
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}: #{
|
124
|
+
@log_key ||= "#{super}: #{software.name}"
|
183
125
|
end
|
184
126
|
|
185
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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}"
|
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
|
46
|
-
log.info(log_key) { 'Cleaning existing
|
47
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
72
|
-
|
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
|
-
#
|
84
|
-
#
|
85
|
-
#
|
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
|
-
|
80
|
+
"revision:#{current_revision}"
|
88
81
|
end
|
89
82
|
|
90
83
|
private
|
91
84
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
123
|
-
|
124
|
-
|
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
|
-
@
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
172
|
-
|
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
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
#
|
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
|