--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.master
parent
f4a9814b4e
commit
ba8400934a
|
@ -234,6 +234,13 @@ class Package::Context
|
||||||
run nil, "sh", ["-x", "-e", "-c", command]
|
run nil, "sh", ["-x", "-e", "-c", command]
|
||||||
end
|
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
|
def package(package : Package) : Bool
|
||||||
@selected_packaging_backend.package self, package
|
@selected_packaging_backend.package self, package
|
||||||
end
|
end
|
||||||
|
|
21
src/main.cr
21
src/main.cr
|
@ -17,6 +17,7 @@ configuration_file_requested = false
|
||||||
requested_recipes = [] of String
|
requested_recipes = [] of String
|
||||||
download_only = false
|
download_only = false
|
||||||
do_not_clean = false
|
do_not_clean = false
|
||||||
|
watch_only = false
|
||||||
|
|
||||||
used_X = false
|
used_X = false
|
||||||
OptionParser.parse! do |parser|
|
OptionParser.parse! do |parser|
|
||||||
|
@ -55,6 +56,10 @@ OptionParser.parse! do |parser|
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parser.on("-w", "--watch", "Checks if the recipe is up to date and exits.") {
|
||||||
|
watch_only = true
|
||||||
|
}
|
||||||
|
|
||||||
parser.invalid_option do |flag|
|
parser.invalid_option do |flag|
|
||||||
STDERR.puts "ERROR: #{flag} is not a valid option."
|
STDERR.puts "ERROR: #{flag} is not a valid option."
|
||||||
STDERR.puts parser
|
STDERR.puts parser
|
||||||
|
@ -94,6 +99,22 @@ end
|
||||||
# FIXME: Now we need to build their respective deptrees and to deduplicate
|
# FIXME: Now we need to build their respective deptrees and to deduplicate
|
||||||
# the list of recipes.
|
# 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
|
begin
|
||||||
latest_build_dir = ""
|
latest_build_dir = ""
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,8 @@ class Package::Recipe
|
||||||
getter sources = Sources.new
|
getter sources = Sources.new
|
||||||
getter packages = Array(Package).new
|
getter packages = Array(Package).new
|
||||||
|
|
||||||
|
getter watch_script : String?
|
||||||
|
|
||||||
@prefix : String?
|
@prefix : String?
|
||||||
|
|
||||||
property recipe_directory = "."
|
property recipe_directory = "."
|
||||||
|
@ -152,6 +154,8 @@ class Package::Recipe
|
||||||
|
|
||||||
@options[key] = value
|
@options[key] = value
|
||||||
end
|
end
|
||||||
|
when "watch"
|
||||||
|
@watch_script = value.as_s_or_ls
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -165,7 +169,8 @@ class Package::Recipe
|
||||||
@packages << Package.new self, false, fake_root_directory
|
@packages << Package.new self, false, fake_root_directory
|
||||||
|
|
||||||
specs.sections.each do |section|
|
specs.sections.each do |section|
|
||||||
if section.name == "split"
|
case section.name
|
||||||
|
when "split"
|
||||||
@packages << Package.new self, section
|
@packages << Package.new self, section
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -340,6 +345,25 @@ class Package::Recipe
|
||||||
FileUtils.rm_rf fake_root_directory
|
FileUtils.rm_rf fake_root_directory
|
||||||
end
|
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
|
def to_s
|
||||||
"#{name}-#{version}"
|
"#{name}-#{version}"
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue