wwtd 0.3.3 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6047caedac1a829700e28ccff419fe44d1c88b1a
4
- data.tar.gz: fa353d441fa565d52944d724818dd27aaabe3708
3
+ metadata.gz: aaf173c438b057ddc0fde8ff1b335f076f2ffdcf
4
+ data.tar.gz: de324a6c925e15d68c9710236e8d23f20a9af746
5
5
  SHA512:
6
- metadata.gz: 5cc29527b8312b0ab1f27e2f91183e6ae5bfd140352cc179572f83c25668167af90aab50dc607e62f58206964d784dbf489926caa62a1abebbf7203f395063e4
7
- data.tar.gz: 3dc6001dc74d8634a9bce4733b71220b3685674a8627e5112399835fbdefcfee50c4d07b7ef89f6fed0acc7daf358ad1a59fe5b1bbc42e720134dbe7c7f7077f
6
+ metadata.gz: 401234f4b9e42a343b34ef6c44f115f84bb247c8977fbfba06b2096773ccb015627bc4a16db5f6a24d7cedc6077b8b1202e9dce0e96b41498f94dca9dafe1e45
7
+ data.tar.gz: dae16e6defcbbea3e9aba080565a0aaed888b8d53f03068c59935b6d053780a8702fed63ce8b27d686b882f40ffeef1c11a38446c5ef1d52416e818fc932cc4f
Binary file
data.tar.gz.sig CHANGED
@@ -1 +1,2 @@
1
- ��DU���OT<��7�C.�5���������@�����%����W2��|OG0�0�HiG�߻�@�N�\�7-�����:���t�Db��GP
1
+ *dvͺ��)�%HK���.��lg����_oǹ�k�����
2
+ ��ӈy"M�"P�|.J��y&�V
@@ -2,11 +2,12 @@ require "wwtd/version"
2
2
  require "optparse"
3
3
  require "yaml"
4
4
  require "shellwords"
5
- require "parallel"
6
5
  require "tempfile"
7
6
  require "tmpdir"
8
7
  require "wwtd/ruby"
8
+ require "wwtd/run"
9
9
  require "wwtd/cli"
10
+ require "open3"
10
11
 
11
12
  module WWTD
12
13
  CONFIG = ".travis.yml"
@@ -23,37 +24,24 @@ module WWTD
23
24
  end
24
25
 
25
26
  def run(matrix, options, &block)
26
- run_in_parallel(matrix, options) do |config, lock|
27
- state = if Ruby.available?(config["rvm"])
28
- yield(:start, config, matrix)
29
- result = run_config(config, lock)
30
- result ? :success : :failure
31
- else
32
- :missing
33
- end
34
-
35
- yield(state, config)
36
-
37
- [state, config]
38
- end
39
- end
40
-
41
- private
42
-
43
- def run_in_parallel(matrix, options)
44
27
  results = nil
45
28
  with_clean_dot_bundle do
46
- Dir.mktmpdir do |lock| # does not return values in ruby 1.8
47
- results = Parallel.map(matrix.each_with_index, :in_processes => options[:parallel].to_i) do |config, i|
48
- # set env as parallel_tests does to reuse existing infrastructure
49
- ENV["TEST_ENV_NUMBER"] = (i == 0 ? "" : (i + 1).to_s) if options[:parallel]
50
- yield config, lock
29
+ with_clean_env do
30
+ Dir.mktmpdir do |lock| # does not return values in ruby 1.8
31
+ results = in_multiple_threads(matrix.each_with_index, options[:parallel]) do |config, i|
32
+ # set env as parallel_tests does to reuse existing infrastructure
33
+ env = {}
34
+ env["TEST_ENV_NUMBER"] = (i == 0 ? "" : (i + 1).to_s) if options[:parallel]
35
+ Run.new(config, env, lock).execute(&block)
36
+ end
51
37
  end
52
38
  end
53
39
  end
54
40
  results
55
41
  end
56
42
 
43
+ private
44
+
57
45
  def with_clean_dot_bundle
58
46
  had_old = File.exist?(".bundle")
59
47
  Dir.mktmpdir do |dir|
@@ -84,61 +72,16 @@ module WWTD
84
72
  matrix.map! { |c| config.merge(c) }
85
73
  end
86
74
 
87
- def run_config(config, lock)
88
- with_clean_env do
89
- Shellwords.split(config["env"] || "").each do |part|
90
- name, value = part.split("=", 2)
91
- ENV[name] = value
92
- end
93
-
94
- if gemfile = config["gemfile"]
95
- ENV["BUNDLE_GEMFILE"] = gemfile
96
- end
97
- wants_bundle = gemfile || File.exist?(DEFAULT_GEMFILE)
98
-
99
- switch_ruby = Ruby.switch_statement(config["rvm"])
100
-
101
- if wants_bundle
102
- flock("#{lock}/#{config["rvm"] || "rvm"}") do
103
- default_bundler_args = "--deployment --path #{Dir.pwd}/vendor/bundle" if committed?("#{gemfile || DEFAULT_GEMFILE}.lock")
104
- bundle_command = "#{switch_ruby}bundle install #{config["bundler_args"] || default_bundler_args}"
105
- return false unless sh "#{bundle_command.strip} --quiet"
106
- end
107
- end
108
-
109
- default_command = (wants_bundle ? "bundle exec rake" : "rake")
110
- command = config["script"] || default_command
111
- command = "#{switch_ruby}#{command}"
112
-
113
- sh(command)
114
- end
115
- end
116
-
117
- def committed?(file)
118
- @committed_files ||= (File.exist?(".git") && `git ls-files`.split("\n")) || []
119
- @committed_files.include?(file)
120
- end
121
-
122
- def flock(file)
123
- File.open(file, "w") do |f|
124
- begin
125
- f.flock(File::LOCK_EX)
126
- yield
127
- ensure
128
- f.flock(File::LOCK_UN)
129
- end
130
- end
131
- end
132
-
133
75
  # http://grosser.it/2010/12/11/sh-without-rake/
134
- def sh(cmd)
76
+ def sh(env, cmd=nil)
77
+ cmd, env = env, {} unless cmd
135
78
  puts cmd
136
- IO.popen(cmd) do |pipe|
137
- while str = pipe.gets
79
+ Open3.popen2(env, cmd) do |stdin, stdout, wait|
80
+ while str = stdout.gets
138
81
  puts str
139
82
  end
83
+ wait.value.success?
140
84
  end
141
- $?.success?
142
85
  end
143
86
 
144
87
  def with_clean_env(&block)
@@ -148,5 +91,19 @@ module WWTD
148
91
  yield
149
92
  end
150
93
  end
94
+
95
+ def in_multiple_threads(data, count)
96
+ data = data.to_a.dup
97
+ threads = [count || 1, data.size].min
98
+ results = []
99
+ (0...threads).to_a.map do
100
+ Thread.new do
101
+ while slice = data.shift
102
+ results << yield(slice)
103
+ end
104
+ end
105
+ end.each(&:join)
106
+ results
107
+ end
151
108
  end
152
109
  end
@@ -37,7 +37,7 @@ module WWTD
37
37
 
38
38
  Options:
39
39
  BANNER
40
- opts.on("-p", "--parallel [PROCESSES]", Integer, "Run in parallel") { |c| options[:parallel] = c || Parallel.processor_count }
40
+ opts.on("-p", "--parallel [COUNT]", Integer, "Run in parallel") { |c| options[:parallel] = c || 4 }
41
41
  opts.on("-h", "--help", "Show this.") { puts opts; exit }
42
42
  opts.on("-v", "--version", "Show Version"){ puts WWTD::VERSION; exit}
43
43
  end.parse!(argv)
@@ -5,6 +5,9 @@ module WWTD
5
5
  !version || switch_statement(version)
6
6
  end
7
7
 
8
+ # - rvm: "rvm xxx do"
9
+ # - others: env hash
10
+ # - unknown: nil
8
11
  def switch_statement(version)
9
12
  return unless version
10
13
  version = normalize_ruby_version(version)
@@ -13,23 +16,25 @@ module WWTD
13
16
  command if cache_command("#{command} ruby -v")
14
17
  else
15
18
  if ruby_root = ENV["RUBY_ROOT"] # chruby or RUBY_ROOT set
16
- switch_path(File.dirname(ruby_root), version)
19
+ switch_via_env(File.dirname(ruby_root), version)
17
20
  elsif rbenv_executable
18
21
  rubies_root = cache_command("which rbenv").sub(%r{/(\.?rbenv)/.*}, "/\\1") + "/versions"
19
- switch_path(rubies_root, version)
22
+ switch_via_env(rubies_root, version)
20
23
  end
21
24
  end
22
25
  end
23
26
 
24
27
  private
25
28
 
26
- def switch_path(rubies_root, version)
27
- extract_jruby_rbenv_options!(version)
29
+ def switch_via_env(rubies_root, version)
30
+ base = extract_jruby_rbenv_options!(version)
28
31
  if ruby_root = ruby_root(rubies_root, version)
29
32
  gem_home = Dir["#{ruby_root}/lib/ruby/gems/*"].first
30
- ENV["PATH"] = "#{ruby_root}/bin:#{ENV["PATH"]}"
31
- ENV["GEM_HOME"] = ENV["GEM_PATH"] = gem_home
32
- ""
33
+ base.merge(
34
+ "PATH" => "#{ruby_root}/bin:#{ENV["PATH"]}",
35
+ "GEM_HOME" => gem_home,
36
+ "GEM_PATH" => gem_home
37
+ )
33
38
  end
34
39
  end
35
40
 
@@ -64,11 +69,12 @@ module WWTD
64
69
 
65
70
  # set ruby-opts for jruby flavors
66
71
  def extract_jruby_rbenv_options!(version)
67
- if version.sub!("-d19", "")
68
- ENV["JRUBY_OPTS"] = "--1.9"
72
+ flag = if version.sub!("-d19", "")
73
+ "--1.9"
69
74
  elsif version.sub!("-d18", "")
70
- ENV["JRUBY_OPTS"] = "--1.8"
75
+ "--1.8"
71
76
  end
77
+ { "JRUBY_OPTS" => flag }
72
78
  end
73
79
 
74
80
  def capture(command)
@@ -0,0 +1,87 @@
1
+ module WWTD
2
+ class Run
3
+ def initialize(config, env, lock)
4
+ @config, @env, @lock = config, env, lock
5
+ add_env_from_config
6
+ @switch = build_switch_statement
7
+ end
8
+
9
+ def execute(&block)
10
+ state = if Ruby.available?(config["rvm"])
11
+ yield(:start, config)
12
+ success? ? :success : :failure
13
+ else
14
+ :missing
15
+ end
16
+
17
+ yield(state, config)
18
+
19
+ [state, config]
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :config, :env, :lock, :switch
25
+
26
+ def success?
27
+ if wants_bundle?
28
+ flock File.join(lock, config["rvm"] || "rvm") do
29
+ default_bundler_args = "--deployment --path #{Dir.pwd}/vendor/bundle" if committed?("#{gemfile || DEFAULT_GEMFILE}.lock")
30
+ bundle_command = "#{switch}bundle install #{config["bundler_args"] || default_bundler_args}"
31
+ return false unless sh(env, "#{bundle_command.strip} --quiet")
32
+ end
33
+ end
34
+
35
+ default_command = (wants_bundle? ? "bundle exec rake" : "rake")
36
+ command = config["script"] || default_command
37
+ command = "#{switch}#{command}"
38
+
39
+ sh(env, command)
40
+ end
41
+
42
+ def wants_bundle?
43
+ gemfile || File.exist?(DEFAULT_GEMFILE)
44
+ end
45
+
46
+ def gemfile
47
+ config["gemfile"]
48
+ end
49
+
50
+ def build_switch_statement
51
+ switch_ruby = Ruby.switch_statement(config["rvm"])
52
+ if switch_ruby.is_a?(Hash)
53
+ env.merge!(switch_ruby)
54
+ switch_ruby = nil
55
+ end
56
+ switch_ruby
57
+ end
58
+
59
+ def add_env_from_config
60
+ Shellwords.split(config["env"] || "").each do |part|
61
+ name, value = part.split("=", 2)
62
+ env[name] = value
63
+ end
64
+ env["BUNDLE_GEMFILE"] = gemfile if gemfile
65
+ end
66
+
67
+ def committed?(file)
68
+ @committed_files ||= (File.exist?(".git") && `git ls-files`.split("\n")) || []
69
+ @committed_files.include?(file)
70
+ end
71
+
72
+ def flock(file)
73
+ File.open(file, "w") do |f|
74
+ begin
75
+ f.flock(File::LOCK_EX)
76
+ yield
77
+ ensure
78
+ f.flock(File::LOCK_UN)
79
+ end
80
+ end
81
+ end
82
+
83
+ def sh(*args)
84
+ ::WWTD.send(:sh, *args)
85
+ end
86
+ end
87
+ end
@@ -1,3 +1,3 @@
1
1
  module WWTD
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wwtd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -30,21 +30,7 @@ cert_chain:
30
30
  ycwMXfl0
31
31
  -----END CERTIFICATE-----
32
32
  date: 2013-11-23 00:00:00.000000000 Z
33
- dependencies:
34
- - !ruby/object:Gem::Dependency
35
- name: parallel
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- type: :runtime
42
- prerelease: false
43
- version_requirements: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
33
+ dependencies: []
48
34
  description:
49
35
  email: michael@grosser.it
50
36
  executables:
@@ -56,6 +42,7 @@ files:
56
42
  - lib/wwtd.rb
57
43
  - lib/wwtd/cli.rb
58
44
  - lib/wwtd/ruby.rb
45
+ - lib/wwtd/run.rb
59
46
  - lib/wwtd/tasks.rb
60
47
  - lib/wwtd/version.rb
61
48
  homepage: http://github.com/grosser/wwtd
metadata.gz.sig CHANGED
Binary file