Commit 49350d87292619c039ccd6f1de7332abb06e01af

Thomas de Grivel 2023-02-25T16:56:20

rbpkg_ci

diff --git a/bin/rbpkg b/bin/rbpkg
index 5731ded..a0936a4 100755
--- a/bin/rbpkg
+++ b/bin/rbpkg
@@ -23,7 +23,7 @@ when "-qq"
   shift
 end
 
-Rbpkg.init("rbpkg", verbose_level)
+Rbpkg.init("rbpkg", verbose_level, Rbpkg.log_dir)
 
 def usage()
   STDERR.puts """Usage: #{File.basename($0)} COMMAND REPO ...
diff --git a/bin/rbpkg_ci b/bin/rbpkg_ci
index c4aa13d..e036052 100755
--- a/bin/rbpkg_ci
+++ b/bin/rbpkg_ci
@@ -23,7 +23,7 @@ when "-qq"
   shift
 end
 
-Rbpkg.init("rbpkg_ci", verbose_level)
+Rbpkg.init("rbpkg_ci", verbose_level, Rbpkg.ci_log_dir)
 
 def usage()
   STDERR.puts "Usage: #{File.basename($0)} REPO BRANCH COMMIT"
@@ -44,6 +44,7 @@ def rbpkg_ci
   branch = $ARGS[0] ? shift : nil
   commit = $ARGS[0] ? shift : nil
   usage unless $ARGS == []
+  Rbpkg.ci_init
   Rbpkg::Repos.repo(repo).ci(branch, commit)
 end
 
diff --git a/lib/rbpkg.rb b/lib/rbpkg.rb
index 1e6a94c..f285e2d 100644
--- a/lib/rbpkg.rb
+++ b/lib/rbpkg.rb
@@ -35,6 +35,28 @@ module Rbpkg
     "#{dir}/ci"
   end
 
+  def self.ci_build_dir
+    "#{ci_dir}/build"
+  end
+
+  def self.ci_init
+    [ci_dir,
+     ci_build_dir,
+     ci_log_dir,
+     ci_status_dir
+    ].each do |d|
+      cmd! "mkdir -p #{sh_quote(d)}"
+    end
+  end
+
+  def self.ci_log_dir
+    "#{ci_dir}/log/#{os}/#{target}"
+  end
+
+  def self.ci_status_dir
+    "#{ci_dir}/status/#{os}/#{target}"
+  end
+
   def self.clean_all(repos)
     repos.each do |name|
       Repos.repo(name).clean_all()
@@ -126,7 +148,7 @@ module Rbpkg
     end
   end
 
-  def self.init(name, verbose_level)
+  def self.init(name, verbose_level, log_dir)
     @@verbose_level = verbose_level
     [dir,
      lock_dir,
@@ -135,7 +157,7 @@ module Rbpkg
       FileUtils.mkdir_p(d)
     end
     $log = Rbpkg::Log
-    Rbpkg::Log.init(name)
+    Rbpkg::Log.init(log_dir, name)
     Rbpkg.lock(name)
   end
 
@@ -211,7 +233,7 @@ module Rbpkg
   end
 
   def self.os_fetch
-    uname = `uname`
+    uname = `uname`.strip
     raise "uname failed" unless $?.success?
     if uname == "Linux"
       distrib = `uname -a | grep -io -e Debian -e gentoo -e Ubuntu | sed -e 's|gentoo|Gentoo|'`
@@ -255,17 +277,15 @@ module Rbpkg
   end
 
   def self.sha256_file(path)
-    if File.basename(sha256).match?(/sum/)
-      c = "#{sh_quote(sha256)} #{sh_quote(path)} | cut -d ' ' -f 1"
-      r = `#{c}`
-      raise "#{sha256} #{path.inspect} failed" unless $?.success?
-      return "SHA256 (#{path}) = #{r}"
-    end
     c = "#{sh_quote(sha256)} #{sh_quote(path)}"
-    verbose(1, c)
     r = `#{c}`
     raise "#{sha256} #{path.inspect} failed" unless $?.success?
-    r
+    if r.match?(/^SHA256 \(/)
+      r
+    else
+      part = r.split(' ')
+      "SHA256 (#{part[1]}) = #{part[0]}"
+    end
   end
 
   def self.src_dir
@@ -334,12 +354,10 @@ def cmd!(string)
 end
 
 def sh_quote(str)
-  if str.scan("\n") == []
-    if str.match?(/^[-+\/=.,:^_0-9A-Za-z]*$/)
-      str
-    else
-      "\"" + str.gsub(/([$`\\\"])/, "\\\1") + "\""
-    end
+  if str.scan("\n") == [] && str.match?(/^[-+\/=.,:^_0-9A-Za-z]*$/)
+    str
+  else
+    "\"" + str.gsub(/([$`\\\"])/, "\\\1") + "\""
   end
 end
       
diff --git a/lib/rbpkg/log.rb b/lib/rbpkg/log.rb
index 7a5f556..1dd3047 100644
--- a/lib/rbpkg/log.rb
+++ b/lib/rbpkg/log.rb
@@ -7,7 +7,7 @@ module Rbpkg
 
     def initialize(name)
       @name = name
-      @path = "#{Rbpkg.log_dir}/#{name}_#{Rbpkg.date}_#{$$}.log"
+      @path = "#{Rbpkg::Log.log_dir}/#{name}_#{Rbpkg.date}_#{$$}.log"
       @path_html = "#{path}.html"
       @status = :running
       raise "log file exists: #{@path.inspect}" if File.exist?(@path)
@@ -66,7 +66,8 @@ EOF
       verbose(3, "Logging to #{log.path}")
     end
 
-    def self.init(name)
+    def self.init(log_dir, name)
+      @@log_dir = log_dir
       @@name = name
       @@log = {}
       add(name)
@@ -92,6 +93,10 @@ EOF
       end
     end
 
+    def self.log_dir
+      @@log_dir
+    end
+
     def self.ok(name)
       log = remove(name)
       log.status = :ok
diff --git a/lib/rbpkg/repo.rb b/lib/rbpkg/repo.rb
index 35d890f..b44a619 100644
--- a/lib/rbpkg/repo.rb
+++ b/lib/rbpkg/repo.rb
@@ -69,7 +69,7 @@ class Rbpkg::Repo
   end
 
   def ci_dir
-    @ci_dir || @ci_dir = "#{Rbpkg.ci_dir}/#{name}"
+    @ci_dir || @ci_dir = "#{Rbpkg.ci_build_dir}/#{name}"
   end
 
   def ci_log_name_commit(commit)