Archived
3
0

--watch, @watch added.

No auto-watch at the moment, and the --watch feature is still
experimental and it might be altered or be made to work slightly
differently in the future.
This commit is contained in:
Luka Vandervelden 2019-08-29 16:05:39 +02:00
parent f4a9814b4e
commit ba8400934a
3 changed files with 53 additions and 1 deletions

View File

@ -234,6 +234,13 @@ class Package::Context
run nil, "sh", ["-x", "-e", "-c", command]
end
def captured_sh(command)
output = IO::Memory.new
child = Process.run "sh", ["-x", "-e", "-c", command], output: output
{child, output}
end
def package(package : Package) : Bool
@selected_packaging_backend.package self, package
end

View File

@ -17,6 +17,7 @@ configuration_file_requested = false
requested_recipes = [] of String
download_only = false
do_not_clean = false
watch_only = false
used_X = false
OptionParser.parse! do |parser|
@ -55,6 +56,10 @@ OptionParser.parse! do |parser|
exit 0
}
parser.on("-w", "--watch", "Checks if the recipe is up to date and exits.") {
watch_only = true
}
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
@ -94,6 +99,22 @@ end
# FIXME: Now we need to build their respective deptrees and to deduplicate
# the list of recipes.
if watch_only
if recipes.size == 0
context.repositories.each do |repo|
Dir.children(repo).each do |i|
recipe_file_name = "#{repo}/#{i}/recipe.spec"
if File.exists? recipe_file_name
recipes << context.read_recipe recipe_file_name
end
end
end
end
recipes.each &.watch
exit 0
end
begin
latest_build_dir = ""

View File

@ -57,6 +57,8 @@ class Package::Recipe
getter sources = Sources.new
getter packages = Array(Package).new
getter watch_script : String?
@prefix : String?
property recipe_directory = "."
@ -152,6 +154,8 @@ class Package::Recipe
@options[key] = value
end
when "watch"
@watch_script = value.as_s_or_ls
end
end
@ -165,7 +169,8 @@ class Package::Recipe
@packages << Package.new self, false, fake_root_directory
specs.sections.each do |section|
if section.name == "split"
case section.name
when "split"
@packages << Package.new self, section
end
end
@ -340,6 +345,25 @@ class Package::Recipe
FileUtils.rm_rf fake_root_directory
end
def watch
if script = @watch_script
status, output = @context.captured_sh script
output = output.to_s
.gsub(/^[ \t\n]*/, "").gsub(/[ \t\n]*$/, "")
if output != @version
STDERR.puts "WARNING: '#{@name}' is old! (#{output} / #{@version})"
else
puts "'#{@name}' is up to date"
end
return
end
STDERR.puts "WARNING: '#{@name}' has no watch."
end
def to_s
"#{name}-#{version}"
end