diff --git a/src/context.cr b/src/context.cr index 6a41b6f..b7249ec 100644 --- a/src/context.cr +++ b/src/context.cr @@ -18,5 +18,12 @@ class Package::Context def run(command) run nil, command, nil end + + def package(package : Package) : Bool + puts "#{package.fake_root_directory} -> #{packages_directory}/#{package.name}##{package.version}.pkg.tar.xz" + pp! r = run package.fake_root_directory, "tar", ["cJf", "#{packages_directory}/#{package.name}##{package.version}.pkg.tar.xz", "."] + + r.exit_status == 0 + end end diff --git a/src/main.cr b/src/main.cr index 2fc8b25..5adad77 100644 --- a/src/main.cr +++ b/src/main.cr @@ -10,13 +10,13 @@ Context.new().tap do |context| Recipe.new(context, "hello", "2.10").tap do |recipe| recipe.sources << "https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz" - recipe.download - recipe.extract - #recipe.instructions.configure << "cd hello-#{recipe.version} && ./configure" #recipe.instructions.build << "cd hello-#{recipe.version} && make" recipe.instructions.install << "cd hello-#{recipe.version} && make DESTDIR='${PKG}' install" + recipe.download + recipe.extract + raise "oh no, build failed" unless recipe.build recipe.package diff --git a/src/package.cr b/src/package.cr index 5d97b58..26fc3ef 100644 --- a/src/package.cr +++ b/src/package.cr @@ -1,9 +1,26 @@ class Package::Package - getter name : String - getter version : String + @recipe : Recipe - def initialize(@name, @version) + def initialize(@recipe) + end + + macro inherit(attribute) + @{{attribute.var.id}} : {{attribute.type.id}}? + + def {{attribute.var.id}} : {{attribute.type.id}} + @{{attribute.var.id}} || @recipe.{{attribute.var.id}} + end + end + + inherit name : String + inherit version : String + + # Internals + inherit fake_root_directory : String + + def to_s + "" end end diff --git a/src/recipe.cr b/src/recipe.cr index 1233b0e..e8d69f6 100644 --- a/src/recipe.cr +++ b/src/recipe.cr @@ -26,16 +26,21 @@ class Package::Recipe getter packages : Array(Package) getter instructions = Instructions.new - def initialize(@context, @name, @version) @sources = Sources.new - @packages = [ - Package.new @name, @version - ] + @packages = [] of Package @working_uuid = UUID.random end + def self.new(context, name, version) + instance = Recipe.allocate.tap &.initialize(context, name, version) + + instance.packages << Package.new instance + + instance + end + def working_directory @context.working_directory end @@ -100,9 +105,13 @@ class Package::Recipe success end + # TODO: + # - Errors management. Stop at first failure? + # - Splits. This should be done between #build and #package. def package - puts "#{fake_root_directory} -> #{@context.packages_directory}/#{name}##{version}.pkg.tar.xz" - pp! @context.run fake_root_directory, "tar", ["cJf", "#{@context.packages_directory}/#{name}##{version}.pkg.tar.xz", "."] + @packages.find do |package| + ! @context.package package + end end def clean