add possibility to create package
This commit is contained in:
parent
a7807f089c
commit
ed7fc9aa7f
6 changed files with 104 additions and 10 deletions
52
lib/make.rb
52
lib/make.rb
|
@ -29,7 +29,7 @@ module Make
|
|||
|
||||
class Context
|
||||
attr_accessor :name, :use_cache, :environment, :steps, :packages, :repository
|
||||
attr_accessor :target, :archive, :source_type
|
||||
attr_accessor :target, :archive, :source_type, :version
|
||||
|
||||
def initialize(options: OpenStruct.new)
|
||||
@target = options.target || :user
|
||||
|
@ -55,15 +55,21 @@ module Make
|
|||
@packages = makefile["packages"] || []
|
||||
|
||||
project_sources = {
|
||||
repository: makefile["repository"] != nil,
|
||||
archive: makefile["archive"] != nil
|
||||
repository: makefile["repository"],
|
||||
archive: makefile["archive"]
|
||||
}.select { |_, v| v }
|
||||
|
||||
if project_sources.size == 1
|
||||
source_data = project_sources.values.first
|
||||
@source_type = project_sources.keys.first
|
||||
@version = source_data["version"] || source_data["branch"]
|
||||
|
||||
raise "No version provided" if @version == nil
|
||||
@version = @version.to_s
|
||||
else
|
||||
raise "Exactly one type of source: 'repository' or 'archive'"
|
||||
end
|
||||
|
||||
puts @source_type
|
||||
|
||||
@repository = Make.rostruct(makefile["repository"] || OpenStruct.new)
|
||||
|
@ -97,7 +103,7 @@ module Make
|
|||
when :user
|
||||
"#{ENV["HOME"]}/.local"
|
||||
when :package
|
||||
"#{sys_prefix}/pkg/#{@name}/#{@repository.branch}"
|
||||
"#{sys_prefix}/pkg/#{@name}/#{@version}"
|
||||
when :system
|
||||
"#{sys_prefix}/"
|
||||
else
|
||||
|
@ -227,13 +233,45 @@ module Make
|
|||
def install
|
||||
System.install(context.packages)
|
||||
end
|
||||
|
||||
def create_package(options)
|
||||
puts "Creating packahge for options: #{options}"
|
||||
puts @context
|
||||
puts "Prefix #{@context.get_prefix}"
|
||||
system("tar --zstd -Pcf #{@context.name}-#{@context.version}.pkg #{@context.get_prefix}")
|
||||
end
|
||||
end
|
||||
|
||||
# dat make -t pkg --cache --name dry-run
|
||||
# dat make --name dry-run
|
||||
def self.command(options)
|
||||
context = Context.new(options: options)
|
||||
builder = Builder.new(context)
|
||||
builder.build
|
||||
context = Context.new(options: options)
|
||||
builder = Builder.new(context)
|
||||
builder.build
|
||||
end
|
||||
|
||||
# dat pkginstall {file-path}
|
||||
# an example `dat pkginstall postgresql-17.5.pkg`
|
||||
def self.install_package(path)
|
||||
puts "Installing package: #{path}"
|
||||
system("sudo tar --zstd -xf #{path} -C /")
|
||||
end
|
||||
|
||||
# dat pkgmake {name}
|
||||
def self.create_package(options)
|
||||
options["target"] = :package if options["target"] == nil
|
||||
context = Context.new(options: options)
|
||||
builder = Builder.new(context)
|
||||
builder.create_package(options)
|
||||
end
|
||||
|
||||
# TODO: better name, it is just to obtain information
|
||||
# about the package
|
||||
def self.context(package_name, target = :package)
|
||||
options = OpenStruct.new
|
||||
options["target"] = target
|
||||
options["name"] = package_name
|
||||
Context.new(options: options)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue