texlive[66798] Master: Adjust paper size configuration for ConTeXt

commits+preining at tug.org commits+preining at tug.org
Sat Apr 8 02:15:21 CEST 2023


Revision: 66798
          http://tug.org/svn/texlive?view=revision&revision=66798
Author:   preining
Date:     2023-04-08 02:15:21 +0200 (Sat, 08 Apr 2023)
Log Message:
-----------
Adjust paper size configuration for ConTeXt

- ship a file texmf-dist/tex/context/texlive/cont-sys.mkxl
  that invalidates the cache based on changes to the ls-R files
- remove mtxrun/context calls from tlmgr.pl
- adjust TLPaper.pm to use context-papersize.tex

Code provided by Max Chernoff

Modified Paths:
--------------
    trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
    trunk/Master/tlpkg/TeXLive/TLPaper.pm

Added Paths:
-----------
    trunk/Master/texmf-dist/tex/context/texlive/
    trunk/Master/texmf-dist/tex/context/texlive/cont-sys.mkxl

Modified: trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
===================================================================
--- trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2023-04-07 23:50:10 UTC (rev 66797)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2023-04-08 00:15:21 UTC (rev 66798)
@@ -892,17 +892,6 @@
 
   if ($::files_changed) {
     $errors += do_cmd_and_check("mktexlsr");
-    # see comments in install-tl about lmtx.
-    my $lmtx = "$bindir/luametatex";
-    if (defined($localtlpdb->get_package('context'))
-        && (-x "$lmtx" || -x "$lmtx.exe")
-        && TeXLive::TLUtils::system_ok("$lmtx --version")
-       ) {
-      $errors += do_cmd_and_check("mtxrun --generate");
-      $errors += do_cmd_and_check("context --luatex --generate");
-    } else {
-      debug("skipped ConTeXt cache regeneration\n");
-    }
     $::files_changed = 0;
   }
 

Added: trunk/Master/texmf-dist/tex/context/texlive/cont-sys.mkxl
===================================================================
--- trunk/Master/texmf-dist/tex/context/texlive/cont-sys.mkxl	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/context/texlive/cont-sys.mkxl	2023-04-08 00:15:21 UTC (rev 66798)
@@ -0,0 +1,46 @@
+% Update the ConTeXt filename cache if the system ls-R files are modified
+\startluacode
+    local addsuffix = file.addsuffix
+    local attributes = lfs.attributes
+    local difftime = os.difftime
+    local file_join = file.join
+    local getfirstreadablefile = caches.getfirstreadablefile
+    local gethashes = resolvers.gethashes
+    local hashed = caches.hashed
+    local ipairs = ipairs
+    local pcall = pcall
+    local resolve = resolvers.resolve
+    local time = os.time
+    local totime = utilities.parsers.totime
+
+    local stale = false
+    for _, tree in ipairs(gethashes()) do
+        local lsR_path = file_join(resolve(tree.name), "ls-R")
+        local lsR_time = attributes(lsR_path, "modification")
+
+        local hash = hashed(tree.name)
+        local path = getfirstreadablefile(addsuffix(hash, "lua"), "trees")
+
+        local state, blob = pcall(loadfile, path)
+        local hash_time
+
+        if blob then
+            local data = blob()
+            if data then
+                hash_time = time(totime(data.date .. " " .. data.time))
+            end
+        end
+
+        if lsR_time and hash_time and difftime(lsR_time, hash_time) > 0 then
+            stale = true
+        end
+    end
+
+    if stale then
+        resolvers.renewcache()
+        resolvers.load()
+    end
+\stopluacode
+
+% Set the default paper size
+\readsysfile{context-papersize.tex}{}{}

Modified: trunk/Master/tlpkg/TeXLive/TLPaper.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLPaper.pm	2023-04-07 23:50:10 UTC (rev 66797)
+++ trunk/Master/tlpkg/TeXLive/TLPaper.pm	2023-04-08 00:15:21 UTC (rev 66798)
@@ -83,14 +83,8 @@
   "context"  => {
     sub => \&paper_context,
     default_component => "tex/context/user",
-    default_file      => "cont-sys.mkxl",
+    default_file      => "context-papersize.tex",
     pkg => "context",
-    variant => {
-      sub => \&paper_context,
-      default_component => "tex/context/user",
-      default_file      => "cont-sys.mkiv",
-      pkg => "context",
-    }
   },
   "psutils"  => {
     sub => \&paper_psutils,
@@ -292,11 +286,10 @@
 
 sub setup_names {
   my $prog = shift;
-  my $variant = shift || "";
   my $outcomp = $paper_config_path_component{$prog}
-                || ($variant eq "variant" ? $paper{$prog}{'variant'}{'default_component'} : $paper{$prog}{'default_component'});
+                || $paper{$prog}{'default_component'};
   my $filecomp = $paper_config_name{$prog}
-                 || ($variant eq "variant" ? $paper{$prog}{'variant'}{'default_file'} : $paper{$prog}{'default_file'});
+                 || $paper{$prog}{'default_file'};
   return ($outcomp, $filecomp);
 }
 
@@ -681,7 +674,7 @@
 
 

 # context format:
-# /--- cont-sys.mkxl  and cont-sys.mkiv // formerly {tex,rme}
+# /--- context-papersize.tex // formerly cont-sys.{tex,rme}
 # |...
 # |\setuppapersize[letter][letter]
 # |...
@@ -696,21 +689,8 @@
   if ($newpaper && $newpaper eq "a4") {
     $newpaper = "A4";
   }
-  return (__paper_context($outtree, $newpaper, "context") | __paper_context($outtree, $newpaper, "variant"));
-}
-
-sub __paper_context {
-  my $outtree = shift;
-  my $newpaper = shift;
-  my $what = shift;
-  my $prog = $what;
-  my $prog_long = $what;
-  if ($what eq "variant") {
-    $prog = "context";
-    $prog_long = "context (MkIV)";
-  }
-  my ($outcomp, $filecomp) = setup_names($prog, $what);
-  my $dftfile = ($what eq 'variant' ? $paper{$prog}{'variant'}{'default_file'} : $paper{$prog}{'default_file'});
+  my ($outcomp, $filecomp) = setup_names('context');
+  my $dftfile = $paper{'context'}{'default_file'};
   my $outfile = "$outtree/$outcomp/$filecomp";
   my $inp = &find_paper_file("context", "tex", $filecomp, $dftfile);
 
@@ -749,7 +729,6 @@
     }
   } else {
     @lines = []
-    # TODO ???
   }
   # if we haven't found a paper line, assume a4
   $currentpaper || ($currentpaper = "A4");
@@ -768,7 +747,7 @@
         push @ret, $p unless ($p eq $currentpaper);
       }
       my %foo;
-      $foo{'program'} = $prog;
+      $foo{'program'} = 'context';
       $foo{'file'} = $inp;
       $foo{'options'} = \@ret;
       return \%foo;
@@ -803,7 +782,7 @@
             $lines[$#lines] = $addlines;
           }
         }
-        info("$prg: setting paper size for $prog_long to $newpaper: $outfile\n");
+        info("$prg: setting paper size for context to $newpaper: $outfile\n");
         mkdirhier(dirname($outfile));
         # if we create the outfile we have to call mktexlsr
         TeXLive::TLUtils::announce_execute_actions("files-changed")
@@ -810,7 +789,7 @@
           unless (-r $outfile);
         if (!open(TMP, ">$outfile")) {
           tlwarn("$prg: Cannot write to $outfile: $!\n");
-          tlwarn("Not setting paper size for $prog_long.\n");
+          tlwarn("Not setting paper size for context.\n");
           return($F_ERROR);
         }
         for (@lines) { print TMP; }
@@ -819,12 +798,12 @@
         # TODO should we return the value of announce_execute action?
         return($F_OK);
       } else {
-        tlwarn("$prg: Not a valid paper size for $prog_long: $newpaper\n");
+        tlwarn("$prg: Not a valid paper size for context: $newpaper\n");
         return($F_WARNING);
       }
     }
   } else {
-    info("Current $prog_long paper size (from $inp): $currentpaper\n");
+    info("Current context paper size (from $inp): $currentpaper\n");
   }
   return($F_OK);
 }



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