Class: Litbuild::SourceCodeManager
- Inherits:
-
Object
- Object
- Litbuild::SourceCodeManager
- Defined in:
- lib/litbuild/source_code_manager.rb
Overview
Find all of the tar files and patch files, possibly compressed, present in any of the directories passed to the constructor or any direct subdirectories of those directories. Given a package blueprint, provide suitable commands to unpack tar files and in-tree source tarfiles, apply patch files, or copy those files to a package user home directory.
Note, SourceCodeManager does not recurse into additional levels of subdirectories – it turns out that makes the test suite really slow, and recursive search is not useful to me, so I’m just skipping it.
Instance Method Summary collapse
-
#copy_files_commands(package) ⇒ Object
Typically, Package Users expect to have tarfiles for the top-level package and any in-tree packages in their ‘src` directory, and patches in their `patches` directory.
-
#initialize(*dirs) ⇒ SourceCodeManager
constructor
A new instance of SourceCodeManager.
- #intree_untar_commands_for(package) ⇒ Object
- #patch_commands_for(package) ⇒ Object
- #untar_command_for(package) ⇒ Object
Constructor Details
#initialize(*dirs) ⇒ SourceCodeManager
Returns a new instance of SourceCodeManager.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/litbuild/source_code_manager.rb', line 19 def initialize(*dirs) all_pkgfiles = dirs.map do |d| Dir.glob("#{d}/*.tar*") + Dir.glob("#{d}/*/*.tar*") + Dir.glob("#{d}/*.patch*") + Dir.glob("#{d}/*/*.patch*") end.flatten abs_paths = all_pkgfiles.map { |f| File.(f) } @available_files = abs_paths.sort.uniq end |
Instance Method Details
#copy_files_commands(package) ⇒ Object
Typically, Package Users expect to have tarfiles for the top-level package and any in-tree packages in their ‘src` directory, and patches in their `patches` directory. This method arranges things that way: it produces commands that copy all the necessary files from TARFILE_DIR and/or PATCH_DIR to the destination directory, skipping any that are already present where the Package Users build script expects to find them.
Binary package files are an exception to the typical case. A binary package file has name ‘binary-#packagename.tar.lz` (no version number, and always lzip-compressed), and contains the files produced by the compilation and installation process. If such a file is present in the Package User home directory, the build script simply unpacks it and does nothing else.
So: if a binary package file is present in the tarfile directory, this method simply emits a command to copy it to the Package User home directory; and if there is already a binary package file present in the Package User home directory, this method does nothing.
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 |
# File 'lib/litbuild/source_code_manager.rb', line 79 def copy_files_commands(package) pkgusr = pkgusr_name(package) # copy binary file if available, then return binfile = "binary-#{package.name}.tar.lz" return ["cp #{find_file(binfile)} ~#{pkgusr}"] \ if @available_files.detect { |f| /#{binfile}/ =~ f } # do nothing if binary file is present in home dir already return [] if homedir(package) && File.exist?( File.join(homedir(package), binfile) ) mkdir_commands = %w[src patches].map do |dir| "mkdir -p ~#{pkgusr}/#{dir}" end copy_commands = [] package.tar_files_needed.each do |filename| pkgusr_file_available?(package, filename) || (copy_commands << "cp #{find_tarfile(filename)} ~#{pkgusr}/src") end package.patch_files.each do |filename| pkgusr_file_available?(package, filename) || (copy_commands << "cp #{find_file(filename)} ~#{pkgusr}/patches") end mkdir_commands + copy_commands.sort end |
#intree_untar_commands_for(package) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/litbuild/source_code_manager.rb', line 34 def intree_untar_commands_for(package) commands = [] package.in_tree.each do |basename, version, path| intree = "#{basename}-#{version}" commands << unpack_tar(intree) if path commands << "mkdir -p #{File.dirname(path)}" commands << "mv #{intree} #{path}" else commands << "mv #{intree} #{basename}" end end commands end |
#patch_commands_for(package) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/litbuild/source_code_manager.rb', line 49 def patch_commands_for(package) return [] unless package.patch_files package.patch_files.map do |patch_file| full_fn = find_file(patch_file) "#{decompress_command(full_fn)} < #{full_fn} | patch -p1" end end |
#untar_command_for(package) ⇒ Object
30 31 32 |
# File 'lib/litbuild/source_code_manager.rb', line 30 def untar_command_for(package) unpack_tar(package.name_and_version) end |