Class: BuildTool::Commands::Recipes::Install
- Defined in:
- lib/build-tool/commands/recipes/install.rb
Overview
BuildCommand
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #do_execute(args) ⇒ Object
- #find_in_path(path, name) ⇒ Object
- #find_writable_dirs(path) ⇒ Object
- #initialize_options ⇒ Object
Methods inherited from Standard
#complete_module, #complete_modules, #initialize, #log_directory, #while_logging_to
Methods inherited from Base
#<=>, #applicable?, #cleanup_after_vcs_access, #complete, #complete_arguments, #complete_readline_1_8, #complete_readline_1_9, #configuration, #do_complete_1_8, #do_complete_1_9, #each_option, #execute, #fullname, #initialize, #log?, #say, #setup_command, #show_help, #skip_command, #summarize, #teardown_command, #usage
Methods included from HelpText
#cmdalias, #description, included, #long_description, #name
Constructor Details
This class inherits a constructor from BuildTool::Commands::Standard
Instance Method Details
#do_execute(args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/build-tool/commands/recipes/install.rb', line 22 def do_execute(args) require 'build-tool/GUI' # Check parameters if args.length < 1 or args.length > 2 return usage("Wrong number of arguments") end # First param is recipename recipename = args[0] # Second optional parameter is command name if args.length == 2 commandname = args[1] else commandname = args[0] end exename = "#{commandname}-build" conffile = Application::instance.local_configuration_dir.join("#{commandname}.yaml") # Our executable buildtool = Application::instance.application_root.join( 'bin', $0 ).to_s # Load the recipe recipe = Recipe.find_recipe(recipename) if !recipe logger.error "Unknown recipe #{recipename}!" return -1 end say <<-EOS Step 1) We need to add a symbolic link name '#{exename}' into $PATH. EOS # Check if there are already commands with exename existing = find_in_path( ENV['PATH'], exename ) found = false # Was the link found? existing.each do |exe| if exe.exist? if exe.symlink? and File.identical? exe, buildtool found = true else logger.warn "Found another command named #{exename} at #{exe.to_s}" end end end if found == true say "The symlink already exists. We will skip this step." else dirs = find_writable_dirs( ENV['PATH'] ) dir = nil if dirs.empty? logger.error "No writable directory found in $PATH. Please add one (usually $HOME/bin)" logger.error "or create a symbolic link in a directory that is part of $PATH yourself." logger.error "> ln -s #{buildtool} #{exename}" elsif dirs.length == 1 dir = dirs[0] say "Exactly one writeable directory found in $PATH. I will create the symbolic link in" say "#{dir}" else if dirs.length > 1 ( dir, index ) = Gem::DefaultUserInteraction.ui.choose_from_list( "More than one writeable directory found in $PATH. Which one should i use?", dirs) end end link = Pathname.new(dir).join(exename) if link.exist? logger.error "I can not create the link because the 'to' already exists. Please create" logger.error "a symbolic link in a directory that is part of $PATH yourself." logger.error "> ln -s #{buildtool} #{exename}" else File.symlink(buildtool, Pathname.new(dir).join(exename)) end end # Now write the settings file say <<EOS Step 2) I will create an example configuration file. Please open the file in a editor and change it to your preferences. It is important to at least set LIB_SUFFIX and MAKEFLAGS to values your system needs. LIB_SUFFIX is either '64', '32' or ''. Issue 'gcc -v' and search for --libdir=lib(64|32|). Set LIB_SUFFIX accordingly. If you can not see --libdir set LIB_SUFFIX to an empty string. MAKEFLAGS can be used provide flags to the make command. The '-jN' options is used to parallelize the compiling. Set N to your the number of cpu cores+1 for a start. You will find the file at #{conffile.to_s}. EOS if conffile.exist? say "The config file already exists. I will not copy the file." else from = File.new(recipe.join("settings.yaml"), "r") to = File.new(conffile, "w") to.write("RECIPE: #{recipename}\n\n") from.each_line do |line| to.write line end to.close from.close end say <<EOS Step 3) I will create a local configuration file that is used to override the used recipe without losing the ability to update. You will find it at > #{Application::instance.local_configuration_dir.join( commandname, 'recipe' )} EOS if File.exist?( Application::instance.local_configuration_dir.join(commandname)) logger.error( "Local configuration for #{commandname} already exists." ) else FileUtils.mkdir_p( Application::instance.local_configuration_dir.join( commandname ) ) FileUtils.cp(recipe.join("recipe-local"), Application::instance.local_configuration_dir.join( commandname, 'recipe' )) end say <<EOS Step 4) You now can start to use your recipe. The first commands you should look for are: # Show the configuration > #{exename} info # Show all modules > #{exename} module list # Show detailed info for a module > #{exename} module info <module> # Build a module (-u = enable updating) > #{exename} build -u <module> EOS # We were successful return 0 end |
#find_in_path(path, name) ⇒ Object
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/build-tool/commands/recipes/install.rb', line 174 def find_in_path( path, name ) dirs = [] path.split(':').each do |dir| hd = Pathname.new(dir).join(name) if hd.exist? dirs << hd end end dirs end |
#find_writable_dirs(path) ⇒ Object
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/build-tool/commands/recipes/install.rb', line 163 def find_writable_dirs(path) dirs = [] path.split(':').each do |dir| dirhd = Pathname.new(dir) if dirhd.directory? and dirhd.writable? dirs << dir end end dirs end |
#initialize_options ⇒ Object
17 18 19 20 |
# File 'lib/build-tool/commands/recipes/install.rb', line 17 def @options. = "Usage: #{Pathname.new($0).basename} #{self.fullname} RECIPE [SCRIPTNAME]" super end |