kameleon-builder 2.1.0 → 2.1.1

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.
@@ -1,6 +1,14 @@
1
+ .. _`installation`:
2
+
1
3
  ------------
2
4
  Installation
3
5
  ------------
6
+
7
+ The easiest way to install and test Kameleon if you
8
+ are using a Debian based linux distribution is by using the deb package available at `kameleon_deb`_.
9
+
10
+ .. _kameleon_deb: http://kameleon.imag.fr/pkg/kameleon_2.1.0+20140612204940-1_amd64.deb
11
+
4
12
  .. note::
5
13
  On debian based distribution be sure to install the ``ruby-dev`` package first
6
14
 
@@ -0,0 +1,24 @@
1
+ - get_tau:
2
+ - exec_local: cd /tmp/
3
+ - exec_local: wget -q http://www.cs.uoregon.edu/research/tau/tau_releases/tau-2.22.2.tar.gz
4
+ - exec_local: wget -q http://www.cs.uoregon.edu/research/tau/pdt_releases/pdt-3.19.tar.gz
5
+ - local2in:
6
+ - /tmp/tau-2.22.2.tar.gz
7
+ - /tmp/tau-2.22.2.tar.gz
8
+ - local2in:
9
+ - /tmp/pdt-3.19.tar.gz
10
+ - /tmp/pdt-3.19.tar.gz
11
+ - pdt_install:
12
+ - exec_in: cd /tmp/
13
+ - exec_in: tar -xzf pdt-3.19.tar.gz
14
+ - exec_in: cd /tmp/pdtoolkit-3.19
15
+ - exec_in: ./configure -prefix=/usr/local/pdt-install
16
+ - exec_in: make clean install
17
+
18
+ - tau_install:
19
+ - exec_in: cd /tmp/
20
+ - exec_in: tar -xzf tau-2.22.2.tar.gz
21
+ - exec_in: cd /tmp/tau-2.22.2
22
+ # - exec_in: ./configure -prefix=/usr/local/tau-install -pdt=/usr/local/pdt-install/ -mpiinc=/usr/local/openmpi-install/include -mpilib=/usr/local/openmpi-install/lib
23
+ - exec_in: ./configure -prefix=/usr/local/tau-install -pdt=/usr/local/pdt-install/ -mpiinc=/usr/include/openmpi/ -mpilib=/usr/lib/openmpi/
24
+ - exec_in: make install
data/ext/mkrf_conf.rb ADDED
@@ -0,0 +1,58 @@
1
+ # Based on: http://www.programmersparadox.com/2012/05/21/gemspec-loading-dependent-gems-based-on-the-users-system/
2
+
3
+ # This file needs to be named mkrf_conf.rb
4
+ # so that rubygems will recognize it as a ruby extension
5
+ # file and not think it is a C extension file
6
+
7
+ jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)
8
+ rbx = defined?(RUBY_ENGINE) && 'rbx' == RUBY_ENGINE
9
+
10
+ def already_installed(dep)
11
+ !Gem::DependencyInstaller.new(:domain => :local).find_gems_with_sources(dep).empty? ||
12
+ !Gem::DependencyInstaller.new(:domain => :local,:prerelease => true).find_gems_with_sources(dep).empty?
13
+ end
14
+
15
+ # Load up the rubygem's dependency installer to
16
+ # installer the gems we want based on the version
17
+ # of Ruby the user has installed
18
+
19
+ unless jruby || rbx
20
+ require 'rubygems'
21
+ require 'rubygems/command.rb'
22
+ require 'rubygems/dependency.rb'
23
+ require 'rubygems/dependency_installer.rb'
24
+
25
+
26
+
27
+ begin
28
+ Gem::Command.build_args = ARGV
29
+ rescue NoMethodError
30
+ end
31
+
32
+ if RUBY_VERSION > "2.0"
33
+ dep = Gem::Dependency.new("syck", '> 0')
34
+ end
35
+
36
+ begin
37
+ puts "Installing base gem"
38
+ inst = Gem::DependencyInstaller.new
39
+ inst.install dep
40
+ rescue
41
+ inst = Gem::DependencyInstaller.new(:prerelease => true)
42
+ begin
43
+ inst.install dep
44
+ rescue Exception => e
45
+ puts e
46
+ puts e.backtrace.join "\n "
47
+ exit(1)
48
+ end
49
+ end unless dep.nil? || already_installed(dep)
50
+ end
51
+
52
+ # If this was C, rubygems would attempt to run make
53
+ # Since this is Ruby, rubygems will attempt to run rake
54
+ # If it doesn't find and successfully run a rakefile, it errors out
55
+ f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w")
56
+ f.write("task :default\n")
57
+ f.close
58
+
@@ -1,6 +1,4 @@
1
1
  # coding: utf-8
2
- RUBYONEX = RUBY_VERSION < "2.0"
3
-
4
2
  lib = File.expand_path('../lib', __FILE__)
5
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
4
  require 'kameleon/version'
@@ -26,18 +24,21 @@ Gem::Specification.new do |s|
26
24
  s.test_files = s.files.grep(%r{^(tests|s|features)/})
27
25
  s.require_paths = ["lib"]
28
26
 
29
- s.required_ruby_version = RUBYONEX ? '>= 1.9.3' : '>= 2.0.0'
30
-
31
27
  s.add_dependency 'childprocess', '~> 0.5'
32
28
  s.add_dependency 'thor', '~> 0.15'
33
29
  s.add_dependency 'table_print', '~> 1.5'
34
30
  s.add_dependency 'log4r-color', '~> 1.2'
35
- s.add_dependency 'syck', '~> 1.0.0' unless RUBYONEX
36
- s.add_dependency 'diffy', '~> 3.0.4'
31
+ s.add_dependency 'diffy', '~> 3.0'
32
+ # Syck is also a dependency for Ruby 2 environments.
33
+ # It is installed at install-time if necessary,
34
+ # via ext/mkrf_conf.rb
37
35
 
38
36
  s.add_development_dependency 'pry', '~> 0.9'
39
37
  s.add_development_dependency 'pry-debugger', '~> 0.2'
40
38
  s.add_development_dependency 'rake', '~> 10.1'
41
39
  s.add_development_dependency 'minitest', '~> 4.7'
42
40
  s.add_development_dependency 'coveralls', '~> 0.7'
41
+
42
+ # To allow installing the Syck gem when Ruby version is >2.0.0
43
+ s.extensions = ["ext/mkrf_conf.rb"]
43
44
  end
data/lib/kameleon.rb CHANGED
@@ -19,8 +19,12 @@ module Kameleon
19
19
  :FATAL)
20
20
 
21
21
  class << self
22
- attr_writer :logger, :env, :source_root, :templates_path, :templates_names,
23
- :templates_files
22
+ attr_writer :logger
23
+ attr_writer :env
24
+ attr_writer :source_root
25
+ attr_writer :templates_path
26
+ attr_writer :templates_names
27
+ attr_writer :templates_files
24
28
 
25
29
  # The source root is the path to the root directory of the kameleon gem.
26
30
  def source_root
@@ -1,7 +1,8 @@
1
1
  require 'securerandom'
2
2
  require 'yaml'
3
+ require 'syck'
3
4
 
4
- YAML::ENGINE.yamler = 'syck' if (defined?(Syck) || defined?(YAML::Syck)) && defined?(YAML::ENGINE)
5
+ YAML::ENGINE.yamler = 'syck' if defined?(YAML::ENGINE)
5
6
 
6
7
  if RUBY_VERSION < "1.9.3"
7
8
  # Backport of missing SecureRandom methods from 1.9
@@ -37,3 +38,24 @@ if RUBY_VERSION < "1.9.3"
37
38
  end
38
39
  end
39
40
  end
41
+
42
+
43
+ class Object
44
+ ##
45
+ # @person ? @person.name :nil
46
+ # vs
47
+ # @person.try(:name)
48
+ def try(method)
49
+ send method if respond_to? method
50
+ end
51
+ end
52
+
53
+ class Hash
54
+ def self.try_convert(obj)
55
+ obj.try(:to_hash)
56
+ end
57
+
58
+ def flatten
59
+ to_a.flatten!
60
+ end
61
+ end
@@ -3,7 +3,8 @@ require 'kameleon/shell'
3
3
  module Kameleon
4
4
  class Context
5
5
 
6
- attr_accessor :shell, :name
6
+ attr_accessor :shell
7
+ attr_accessor :name
7
8
 
8
9
  def initialize(name, cmd, workdir, exec_prefix, local_workdir)
9
10
  @name = name.downcase
@@ -80,10 +81,13 @@ module Kameleon
80
81
 
81
82
  def lazyload_shell()
82
83
  unless @shell.started?
84
+ @shell.restart
83
85
  # Start the shell process
84
- @shell.start
85
86
  execute("echo The '#{name}_context' has been initialized", :log_level => "info")
86
87
  end
88
+ rescue
89
+ @shell.stop
90
+ raise
87
91
  end
88
92
 
89
93
  def start_shell
@@ -91,6 +95,8 @@ module Kameleon
91
95
  lazyload_shell
92
96
  @logger.info("Starting interactive shell")
93
97
  @shell.fork_and_wait
98
+ rescue ShellError => e
99
+ e.message.split( /\r?\n/ ).each {|m| @logger.error m }
94
100
  end
95
101
 
96
102
  def closed?
@@ -5,7 +5,10 @@ require 'kameleon/persistent_cache'
5
5
  module Kameleon
6
6
 
7
7
  class Engine
8
- attr_accessor :recipe, :cwd, :build_recipe_path, :pretty_list_checkpoints
8
+ attr_accessor :recipe
9
+ attr_accessor :cwd
10
+ attr_accessor :build_recipe_path
11
+ attr_accessor :pretty_list_checkpoints
9
12
 
10
13
  def initialize(recipe, options)
11
14
  @options = options
@@ -250,9 +253,9 @@ module Kameleon
250
253
  raise AbortError, "Execution aborted..."
251
254
  elsif answer.eql? "c"
252
255
  ## resetting the exit status
253
- @in_context.execute("true")
254
- @out_context.execute("true")
255
- @local_context.execute("true")
256
+ @in_context.execute("true") unless @in_context.closed?
257
+ @out_context.execute("true") unless @out_context.closed?
258
+ @local_context.execute("true") unless @local_context.closed?
256
259
  return true
257
260
  elsif answer.eql? "r"
258
261
  @logger.notice("Retrying the previous command...")
@@ -331,24 +334,23 @@ module Kameleon
331
334
  do_steps(section)
332
335
  end
333
336
  clean
334
- rescue AbortError => e
335
- @logger.error("Aborted...")
336
- @logger.warn("Waiting for cleanup before exiting...")
337
- clean
338
- raise e
339
- rescue SystemExit, Interrupt => e
340
- @logger.error("Interrupted...")
341
- @out_context.reopen
342
- @in_context.reopen
343
- @local_context.reopen
337
+ rescue Exception => e
338
+ if e.is_a?(AbortError)
339
+ @logger.error("Aborted...")
340
+ elsif e.is_a?(SystemExit) || e.is_a?(Interrupt)
341
+ @logger.error("Interrupted...")
342
+ @out_context.reopen
343
+ @in_context.reopen
344
+ @local_context.reopen
345
+ else
346
+ @logger.fatal("fatal error...")
347
+ end
344
348
  @logger.warn("Waiting for cleanup before exiting...")
345
349
  clean
346
- raise e
347
- rescue Exception => e
348
350
  @out_context.close!
349
351
  @in_context.close!
350
352
  @local_context.close!
351
- raise e
353
+ raise
352
354
  end
353
355
  end
354
356
 
@@ -7,8 +7,14 @@ module Kameleon
7
7
  class Persistent_cache
8
8
 
9
9
  include Singleton
10
- attr_reader :polipo_env, :cache_dir,:polipo_port
11
- attr_writer :activated, :cwd, :polipo_path, :name
10
+ attr_reader :polipo_env
11
+ attr_reader :cache_dir
12
+ attr_reader :polipo_port
13
+ attr_writer :activated
14
+ attr_reader :cwd
15
+ attr_reader :polipo_path
16
+ attr_reader :name
17
+
12
18
  def initialize()
13
19
  @logger = Log4r::Logger.new("kameleon::[kameleon]")
14
20
  ## we must configure Polipo to be execute for the in and out context
@@ -25,7 +31,6 @@ module Kameleon
25
31
  :idleTime => "5",
26
32
  :chunkHighMark => "425165824",
27
33
  :proxyPort => @polipo_port,
28
- #:proxyOffline => "true"
29
34
  :relaxTransparency =>"true"
30
35
  }
31
36
 
@@ -61,7 +66,7 @@ module Kameleon
61
66
 
62
67
  if @polipo_path.nil? then
63
68
  @logger.error("Polipo binary not found, make sure it is in your current PATH")
64
- @logger.error("or use the option --proxy_path")
69
+ @logger.error("or use the option --proxy-path")
65
70
  raise BuildError, "Failed to use persistent cache"
66
71
  end
67
72
  end
@@ -77,7 +82,7 @@ module Kameleon
77
82
  end
78
83
 
79
84
  def create_cache_directory(step_name)
80
- @logger.notice("Creating cache directory #{step_name} for Polipo")
85
+ @logger.notice("Creating cache directory #{step_name} for Polipo")
81
86
  directory_name = @cache_dir + "/#{step_name}"
82
87
  FileUtils.mkdir_p directory_name
83
88
  directory_name
@@ -87,7 +92,7 @@ module Kameleon
87
92
  ## This function assumes that the cache directory has already been created by the engine
88
93
  ## Stopping first the previous proxy
89
94
  ## have to check if polipo is running
90
- @logger.notice("Starting web proxy Polipo in directory #{directory} using port: #{@polipo_port}")
95
+ @logger.debug("Starting web proxy Polipo in directory #{directory} using port: #{@polipo_port}")
91
96
  @polipo_process.stop unless @polipo_process.nil?
92
97
  command = ["#{@polipo_path}/polipo"]
93
98
  @polipo_cmd_options[:diskCacheRoot] = directory
@@ -4,8 +4,15 @@ require 'kameleon/step'
4
4
  module Kameleon
5
5
 
6
6
  class Recipe
7
- attr_accessor :path, :name, :global, :sections, :aliases, :aliases_path, \
8
- :checkpoint, :checkpoint_path, :metainfo
7
+ attr_accessor :path
8
+ attr_accessor :name
9
+ attr_accessor :global
10
+ attr_accessor :sections
11
+ attr_accessor :aliases
12
+ attr_accessor :aliases_path
13
+ attr_accessor :checkpoint
14
+ attr_accessor :checkpoint_path
15
+ attr_accessor :metainfo
9
16
 
10
17
  def initialize(path)
11
18
  @logger = Log4r::Logger.new("kameleon::[kameleon]")
@@ -51,7 +58,7 @@ module Kameleon
51
58
  # Load Global variables
52
59
  @global.merge!(yaml_recipe.fetch("global", {}))
53
60
  # Resolve dynamically-defined variables !!
54
- resolved_global = Utils.resolve_vars(@global.to_yaml, @path, @global)
61
+ resolved_global = Utils.resolve_vars(@global.to_yaml, @path, @global, :strict => false)
55
62
  @global.merge! YAML.load(resolved_global)
56
63
 
57
64
  # Loads aliases
@@ -91,7 +98,7 @@ module Kameleon
91
98
  if not args.nil?
92
99
  args.each do |arg|
93
100
  if arg.kind_of? Hash
94
- if arg.flatten[1].kind_of? Array
101
+ if arg[arg.keys[0]].kind_of? Array
95
102
  embedded_step = true
96
103
  end
97
104
  end
@@ -298,6 +305,10 @@ module Kameleon
298
305
  end
299
306
 
300
307
  def resolve!
308
+ # Resolve dynamically-defined variables !!
309
+ resolved_global = Utils.resolve_vars(@global.to_yaml, @path, @global)
310
+ @global.merge! YAML.load(resolved_global)
311
+
301
312
  consistency_check
302
313
  resolve_checkpoint unless @checkpoint.nil?
303
314
 
@@ -8,7 +8,9 @@ module Kameleon
8
8
  READ_CHUNK_SIZE = 1048576
9
9
  EXIT_TIMEOUT = 60
10
10
 
11
- attr :exit_status, :process, :shell_cmd
11
+ attr :exit_status
12
+ attr :process
13
+ attr :shell_cmd
12
14
 
13
15
  def initialize(context_name, cmd, shell_workdir, local_workdir, kwargs = {})
14
16
  @logger = Log4r::Logger.new("kameleon::[kameleon]")
@@ -30,16 +32,6 @@ module Kameleon
30
32
 
31
33
  ## Changing the default bashrc if the cache is activated
32
34
  @cache = Kameleon::Persistent_cache.instance
33
- if @cache.activated? then
34
- new_kameleon_bashrc = Tempfile.new('kameleon_bashrc').path
35
- FileUtils.cp @default_bashrc_file, new_kameleon_bashrc
36
- tpl = ERB.new(File.read(@cache.polipo_env))
37
- polipo_env_content = tpl.result(binding)
38
- File.open(new_kameleon_bashrc,'a') do |f|
39
- f.puts(polipo_env_content)
40
- end
41
- @default_bashrc_file = new_kameleon_bashrc
42
- end
43
35
 
44
36
  @shell_cmd = "source #{@default_bashrc_file} 2> /dev/null; "\
45
37
  "#{@cmd} --rcfile #{@bashrc_file}"
@@ -56,7 +48,10 @@ module Kameleon
56
48
  end
57
49
 
58
50
  def stop
59
- @process.stop(0) unless @process.nil?
51
+ unless @process.nil?
52
+ @process.stop(0)
53
+ @process = nil
54
+ end
60
55
  end
61
56
 
62
57
  def started?
@@ -64,7 +59,7 @@ module Kameleon
64
59
  end
65
60
 
66
61
  def exited?
67
- @process.exited?
62
+ return !@process.nil? && @process.exited?
68
63
  end
69
64
 
70
65
  def restart
@@ -98,6 +93,10 @@ module Kameleon
98
93
  if File.file?(@default_bashrc_file)
99
94
  tpl = ERB.new(File.read(@default_bashrc_file))
100
95
  bashrc_content = tpl.result(binding)
96
+ if @cache.activated? then
97
+ tpl = ERB.new(File.read(@cache.polipo_env))
98
+ bashrc_content << "\n" + ERB.new(File.read(@cache.polipo_env)).result(binding)
99
+ end
101
100
  end
102
101
  bashrc = Shellwords.escape(bashrc_content)
103
102
  if @shell_workdir
data/lib/kameleon/step.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  module Kameleon
2
2
 
3
3
  class Command
4
- attr_accessor :string_cmd, :microstep_name
4
+ attr_accessor :string_cmd
5
+ attr_accessor :microstep_name
5
6
 
6
7
  def initialize(yaml_cmd, microstep_name)
7
8
  @string_cmd = YAML.dump(yaml_cmd).gsub("---", "").strip
@@ -72,8 +73,13 @@ module Kameleon
72
73
  end
73
74
 
74
75
  class Microstep
75
- attr_accessor :commands, :name, :identifier, :slug, :in_cache,
76
- :on_checkpoint, :order
76
+ attr_accessor :commands
77
+ attr_accessor :name
78
+ attr_accessor :identifier
79
+ attr_accessor :slug
80
+ attr_accessor :in_cache
81
+ attr_accessor :on_checkpoint
82
+ attr_accessor :order
77
83
 
78
84
  def initialize(string_or_hash)
79
85
  @identifier = nil
@@ -128,8 +134,12 @@ module Kameleon
128
134
  end
129
135
 
130
136
  class Macrostep
131
- attr_accessor :name, :clean_microsteps, :init_microsteps, :microsteps,
132
- :path, :variables
137
+ attr_accessor :name
138
+ attr_accessor :clean_microsteps
139
+ attr_accessor :init_microsteps
140
+ attr_accessor :microsteps
141
+ attr_accessor :path
142
+ attr_accessor :variables
133
143
 
134
144
  def initialize(name, microsteps, variables, path)
135
145
  @name = name
@@ -180,7 +190,10 @@ module Kameleon
180
190
  end
181
191
 
182
192
  class Section
183
- attr_accessor :name, :clean_macrostep, :init_macrostep, :macrosteps
193
+ attr_accessor :name
194
+ attr_accessor :clean_macrostep
195
+ attr_accessor :init_macrostep
196
+ attr_accessor :macrosteps
184
197
 
185
198
  def initialize(name)
186
199
  @name = name