lib/pdk/module/build.rb in pdk-1.13.0 vs lib/pdk/module/build.rb in pdk-1.14.0
- old
+ new
@@ -1,13 +1,5 @@
-require 'fileutils'
-require 'minitar'
-require 'zlib'
-require 'pathspec'
-require 'find'
-require 'pdk/module'
-require 'pdk/tests/unit'
-
module PDK
module Module
class Build
def self.invoke(options = {})
new(options).build
@@ -24,10 +16,12 @@
# Read and parse the values from metadata.json for the module that is
# being built.
#
# @return [Hash{String => Object}] The hash of metadata values.
def metadata
+ require 'pdk/module/metadata'
+
@metadata ||= PDK::Module::Metadata.from_file(File.join(module_dir, 'metadata.json')).data
end
# Return the path where the built package file will be written to.
def package_file
@@ -69,19 +63,23 @@
# Create a temporary build directory where the files to be included in
# the package will be staged before building the tarball.
#
# If the directory already exists, remove it first.
def create_build_dir
+ require 'fileutils'
+
cleanup_build_dir
FileUtils.mkdir_p(build_dir)
end
# Remove the temporary build directory and all its contents from disk.
#
# @return nil.
def cleanup_build_dir
+ require 'fileutils'
+
FileUtils.rm_rf(build_dir, secure: true)
end
# Combine the module name and version into a Forge-compatible dash
# separated string.
@@ -97,10 +95,12 @@
# Iterate through all the files and directories in the module and stage
# them into the temporary build directory (unless ignored).
#
# @return nil
def stage_module_in_build_dir
+ require 'find'
+
Find.find(module_dir) do |path|
next if path == module_dir
ignored_path?(path) ? Find.prune : stage_path(path)
end
@@ -110,10 +110,13 @@
#
# @param path [String] The path to the file or directory.
#
# @return nil.
def stage_path(path)
+ require 'pathname'
+ require 'fileutils'
+
relative_path = Pathname.new(path).relative_path_from(Pathname.new(module_dir))
dest_path = File.join(build_dir, relative_path)
if File.directory?(path)
FileUtils.mkdir_p(dest_path, mode: File.stat(path).mode)
@@ -147,10 +150,12 @@
#
# @param path [String] The relative or absolute path to the symlink.
#
# @return nil.
def warn_symlink(path)
+ require 'pathname'
+
symlink_path = Pathname.new(path)
module_path = Pathname.new(module_dir)
PDK.logger.warn _('Symlinks in modules are not supported and will not be included in the package. Please investigate symlink %{from} -> %{to}.') % {
from: symlink_path.relative_path_from(module_path),
@@ -215,10 +220,15 @@
# If the destination package already exists, it will be removed before
# creating the new tarball.
#
# @return nil.
def build_package
+ require 'fileutils'
+ require 'zlib'
+ require 'minitar'
+ require 'find'
+
FileUtils.rm_f(package_file)
Dir.chdir(target_dir) do
begin
gz = Zlib::GzipWriter.new(File.open(package_file, 'wb'))
@@ -266,9 +276,12 @@
# Instantiate a new PathSpec class and populate it with the pattern(s) of
# files to be ignored.
#
# @return [PathSpec] The populated ignore path matcher.
def ignored_files
+ require 'pdk/module'
+ require 'pathspec'
+
@ignored_files ||=
begin
ignored = if ignore_file.nil?
PathSpec.new
else