texlive[69614] Master: TLUtils.pm (run_cmd_with_log),

commits+karl at tug.org commits+karl at tug.org
Sat Jan 27 23:48:16 CET 2024


Revision: 69614
          https://tug.org/svn/texlive?view=revision&revision=69614
Author:   karl
Date:     2024-01-27 23:48:16 +0100 (Sat, 27 Jan 2024)
Log Message:
-----------
TLUtils.pm (run_cmd_with_log),
(update_context_cache): new fns, mostly taken from install-tl.
Hopefully to be used by tlmgr.

install-tl (run_postinst_cmd): call run_cmd_with_log.
(create_welcome): play with newlines, en passant.

Modified Paths:
--------------
    trunk/Master/install-tl
    trunk/Master/tlpkg/TeXLive/TLUtils.pm

Modified: trunk/Master/install-tl
===================================================================
--- trunk/Master/install-tl	2024-01-27 21:02:33 UTC (rev 69613)
+++ trunk/Master/install-tl	2024-01-27 22:48:16 UTC (rev 69614)
@@ -1161,22 +1161,9 @@
 
 sub run_postinst_cmd {
   my ($cmd) = @_;
-  
-  info ("running $cmd ...");
-  my ($out,$ret) = TeXLive::TLUtils::run_cmd ("$cmd 2>&1");
-  if ($ret == 0) {
-    info ("done\n");
-  } else {
-    info ("failed\n");
-    tlwarn ("$0: $cmd failed (status $ret): $!\n");
-    $ret = 1; # be sure we don't overflow the sum on anything crazy
-  }
-  log ($out);
-  
-  return $ret;
-} # run_postinst_cmd
+  &TeXLive::TLUtils::run_cmd_with_log ($cmd, \&log);
+}
 
-
 # 

 # Make texmf.cnf, backup directory, cleanups, path setting, and
 # (most importantly) post-install subprograms: mktexlsr, fmtutil,
@@ -1351,22 +1338,15 @@
     }
   }
 
-  # lmtx/context setup. The story here is that in 2023, the lmtx binary
-  # for x86_64-linux was too new to run on the system where we build TL.
-  # (luametatex: /lib64/libm.so.6: version `GLIBC_2.23' not found)
-  # So we have to try running it to see it succeeds, not just test for 
-  # the program's existence. And since it exits nonzero given no args,
-  # we have to specify --version. Hope it keeps working like that ...
-  my $lmtx = "$plat_bindir/luametatex$progext";
+  # lmtx/context cache setup, relegated to a common subroutine
+  # that tlmgr can also call.
   if (exists($install{"context"}) && $install{"context"} == 1
-      && !exists $ENV{"TEXLIVE_INSTALL_NO_CONTEXT_CACHE"}
-      && TeXLive::TLUtils::system_ok("$lmtx --version")
-     ) {
-    info("setting up ConTeXt cache: ");
-    $errcount += run_postinst_cmd("mtxrun --generate");
-    $errcount += run_postinst_cmd("context --luatex --generate");
+      && !exists $ENV{"TEXLIVE_INSTALL_NO_CONTEXT_CACHE"}) {
+    $errcount +=
+      TeXLive::TLUtils::update_context_cache($plat_bindir, $progext,
+                                             \&run_postinst_cmd);
   } else {
-    debug("skipped ConTeXt cache setup\n");
+    debug("skipped ConTeXt cache setup, not installed or told not to\n");
   }
 
   # all formats option
@@ -2832,12 +2812,10 @@
 # Create a welcome message.
 sub create_welcome {
   @::welcome_arr = ();
-  push @::welcome_arr, "\n";
   push @::welcome_arr, __("Welcome to TeX Live!");
-  push @::welcome_arr, "\n";
-  push @::welcome_arr, __(
-    "See %s/index.html for links to documentation.\nThe TeX Live web site (https://tug.org/texlive/) contains any updates and corrections. TeX Live is a joint project of the TeX user groups around the world; please consider supporting it by joining the group best for you. The list of groups is available on the web at https://tug.org/usergroups.html.",
-    $::vars{'TEXDIR'});
+  push @::welcome_arr, __("See %s/index.html for links to documentation.\n",
+                          $::vars{'TEXDIR'});
+  push @::welcome_arr, __("The TeX Live web site (https://tug.org/texlive/) provides all updates\nand corrections. TeX Live is a joint project of the TeX user groups\naround the world; please consider supporting it by joining the group\nbest for you. The list of groups is available on the web\nat https://tug.org/usergroups.html.\n");
   if (wndws()
       || ($vars{'instopt_adjustpath'}
          && $vars{'tlpdbopt_desktop_integration'} != 2)) {
@@ -2844,9 +2822,8 @@
      ; # don't tell them to make path adjustments on Windows,
        # or if they chose to "create symlinks".
    } else {
-    push @::welcome_arr, "\n";
     push @::welcome_arr, __(
-      "Add %s/texmf-dist/doc/man to MANPATH.\nAdd %s/texmf-dist/doc/info to INFOPATH.\nMost importantly, add %s/bin/%s\nto your PATH for current and future sessions.",
+      "Add %s/texmf-dist/doc/man to MANPATH.\nAdd %s/texmf-dist/doc/info to INFOPATH.\nMost importantly, add %s/bin/%s\nto your PATH for current and future sessions.\n",
       $::vars{'TEXDIR'}, $::vars{'TEXDIR'}, $::vars{'TEXDIR'},
       $::vars{'this_platform'});
   }

Modified: trunk/Master/tlpkg/TeXLive/TLUtils.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLUtils.pm	2024-01-27 21:02:33 UTC (rev 69613)
+++ trunk/Master/tlpkg/TeXLive/TLUtils.pm	2024-01-27 22:48:16 UTC (rev 69614)
@@ -41,6 +41,7 @@
   TeXLive::TLUtils::wsystem($msg, at args);
   TeXLive::TLUtils::xsystem(@args);
   TeXLive::TLUtils::run_cmd($cmd [, @envvars ]);
+  TeXLive::TLUtils::run_cmd_with_log($cmd, $logfn);
   TeXLive::TLUtils::system_pipe($prog, $infile, $outfile, $removeIn, @args);
   TeXLive::TLUtils::diskfree($path);
   TeXLive::TLUtils::get_user_home();
@@ -80,6 +81,7 @@
   TeXLive::TLUtils::time_estimate($totalsize, $donesize, $starttime)
   TeXLive::TLUtils::install_packages($from_tlpdb,$media,$to_tlpdb,$what,$opt_src, $opt_doc, $retry, $continue);
   TeXLive::TLUtils::do_postaction($how, $tlpobj, $do_fileassocs, $do_menu, $do_desktop, $do_script);
+  TeXLive::TLUtils::update_context_cache($plat_bindir);
   TeXLive::TLUtils::announce_execute_actions($how, @executes, $what);
   TeXLive::TLUtils::add_symlinks($root, $arch, $sys_bin, $sys_man, $sys_info);
   TeXLive::TLUtils::remove_symlinks($root, $arch, $sys_bin, $sys_man, $sys_info);
@@ -246,6 +248,7 @@
     &wsystem
     &xsystem
     &run_cmd
+    &run_cmd_with_log
     &system_pipe
     &diskfree
     &get_user_home
@@ -769,8 +772,9 @@
 
 =item C<run_cmd($cmd, @envvars)>
 
-Run shell command C<$cmd> and captures its output. Returns a list with CMD's
-output as the first element and the return value (exit code) as second.
+Run shell command C<$cmd> and captures its standard output (not standard
+error). Returns a list with CMD's output as the first element and its
+return value (exit code) as second.
 
 If given, C<@envvars> is a list of environment variable name / value
 pairs set in C<%ENV> for the call and reset to their original value (or
@@ -806,6 +810,34 @@
   return ($output,$retval);
 }
 
+=item C<run_cmd_with_log($cmd, $logfn)>
+
+Run shell command C<$cmd> and captures both standard output and standard
+error (as one string), passing them to C<$logfn>. The return value is
+the exit status of C<$cmd>. Environment variable overrides cannot be
+passed. (This is used for running special post-installation commands in
+install-tl and tlmgr.)
+
+=cut
+
+sub run_cmd_with_log {
+  my ($cmd,$logfn) = @_;
+  
+  info ("running $cmd ...");
+  my ($out,$ret) = TeXLive::TLUtils::run_cmd ("$cmd 2>&1");
+  if ($ret == 0) {
+    info ("done\n");
+  } else {
+    info ("failed\n");
+    tlwarn ("$0: $cmd failed (status $ret): $!\n");
+    $ret = 1; # be sure we don't overflow the sum on anything crazy
+  }
+  &$logfn ($out);
+  
+  return $ret;
+} # run_cmd_with_log
+
+
 =item C<system_pipe($prog, $infile, $outfile, $removeIn, @extraargs)>
 
 Runs C<$prog> with C<@extraargs> redirecting stdin from C<$infile>,
@@ -2198,6 +2230,10 @@
   return 1;
 }
 
+=item C<parse_into_keywords>
+
+=cut
+
 sub parse_into_keywords {
   my ($str, @keys) = @_;
   my @words = quotewords('\s+', 0, $str);
@@ -2222,6 +2258,55 @@
   return($error, %ret);
 }
 
+=item C<update_context_cache($bindir,$progext,$run_postinst_cmd)>
+
+Run the ConTeXt cache generation commands, using C<$bindir> and
+C<$progext> to check if commands can be run. Use the function reference
+C<$run_postinst_cmd> to actually run the commands. The return status is
+zero if all succeeded, nonzero otherwise. If the main ConTeXt program
+(C<luametatex>) cannot be run at all, the return status is status.
+
+Functions C<info> and C<debug> are called with status reports.
+
+=cut
+
+sub update_context_cache {
+  my ($bindir,$progext,$run_postinst_cmd) = @_;
+  
+  my $errcount = 0;
+
+  # The story here is that in 2023, the lmtx binary for x86_64-linux was
+  # too new to run on the system where we build TL. (luametatex:
+  # /lib64/libm.so.6: version `GLIBC_2.23' not found) So we have to try
+  # running it to see if it is available, not just test for the
+  # program's existence. And since it exits nonzero given no args, we
+  # have to specify --version. Hope it keeps working like that ...
+  # 
+  # If lmtx is not runnable, don't consider that an error, since nothing
+  # can be done about it.
+  my $lmtx = "$bindir/luametatex$progext";
+  if (TeXLive::TLUtils::system_ok("$lmtx --version")) {
+    info("setting up ConTeXt cache: ");
+    $errcount += &$run_postinst_cmd("mtxrun --generate");
+    #
+    # If mtxrun failed, don't bother trying more.
+    if ($errcount == 0) {
+      $errcount += &$run_postinst_cmd("context --luatex --generate");
+      #
+      # If context succeeded too, try luajittex. Missing on some platforms.
+      if ($errcount == 0) {
+        my $luajittex = "$bindir/luajittex$progext";
+        if (TeXLive::TLUtils::system_ok("$luajittex --version")) {
+          $errcount += &$run_postinst_cmd("context --luajittex --generate");
+        } else {
+          debug("skipped luajittex cache setup, can't run $luajittex\n");
+        }
+      }
+    }
+  }
+  return $errcount;
+}
+
 =item C<announce_execute_actions($how, $tlpobj, $what)>
 
 Announces that the actions given in C<$tlpobj> should be executed



More information about the tex-live-commits mailing list.