~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/jobserver-exec

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/jobserver-exec (Version linux-6.12-rc7) and /scripts/jobserver-exec (Version linux-5.19.17)


  1 #!/usr/bin/env python3                              1 #!/usr/bin/env python3
  2 # SPDX-License-Identifier: GPL-2.0+                 2 # SPDX-License-Identifier: GPL-2.0+
  3 #                                                   3 #
  4 # This determines how many parallel tasks "mak      4 # This determines how many parallel tasks "make" is expecting, as it is
  5 # not exposed via an special variables, reserv      5 # not exposed via an special variables, reserves them all, runs a subprocess
  6 # with PARALLELISM environment variable set, a      6 # with PARALLELISM environment variable set, and releases the jobs back again.
  7 #                                                   7 #
  8 # https://www.gnu.org/software/make/manual/htm      8 # https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html#POSIX-Jobserver
  9 from __future__ import print_function               9 from __future__ import print_function
 10 import os, sys, errno                              10 import os, sys, errno
 11 import subprocess                                  11 import subprocess
 12                                                    12 
 13 # Extract and prepare jobserver file descripto     13 # Extract and prepare jobserver file descriptors from environment.
 14 claim = 0                                          14 claim = 0
 15 jobs = b""                                         15 jobs = b""
 16 try:                                               16 try:
 17         # Fetch the make environment options.      17         # Fetch the make environment options.
 18         flags = os.environ['MAKEFLAGS']            18         flags = os.environ['MAKEFLAGS']
 19                                                    19 
 20         # Look for "--jobserver=R,W"               20         # Look for "--jobserver=R,W"
 21         # Note that GNU Make has used --jobser     21         # Note that GNU Make has used --jobserver-fds and --jobserver-auth
 22         # so this handles all of them.             22         # so this handles all of them.
 23         opts = [x for x in flags.split(" ") if     23         opts = [x for x in flags.split(" ") if x.startswith("--jobserver")]
 24                                                    24 
 25         # Parse out R,W file descriptor number     25         # Parse out R,W file descriptor numbers and set them nonblocking.
 26         # If the MAKEFLAGS variable contains m !!  26         fds = opts[0].split("=", 1)[1]
 27         # --jobserver-auth= option, the last o !!  27         reader, writer = [int(x) for x in fds.split(",", 1)]
 28         fds = opts[-1].split("=", 1)[1]        !!  28         # Open a private copy of reader to avoid setting nonblocking
 29                                                !!  29         # on an unexpecting process with the same reader fd.
 30         # Starting with GNU Make 4.4, named pi !!  30         reader = os.open("/proc/self/fd/%d" % (reader),
 31         # Example argument: --jobserver-auth=f !!  31                          os.O_RDONLY | os.O_NONBLOCK)
 32         _, _, path = fds.partition('fifo:')    << 
 33                                                << 
 34         if path:                               << 
 35                 reader = os.open(path, os.O_RD << 
 36                 writer = os.open(path, os.O_WR << 
 37         else:                                  << 
 38                 reader, writer = [int(x) for x << 
 39                 # Open a private copy of reade << 
 40                 # on an unexpecting process wi << 
 41                 reader = os.open("/proc/self/f << 
 42                                  os.O_RDONLY | << 
 43                                                    32 
 44         # Read out as many jobserver slots as      33         # Read out as many jobserver slots as possible.
 45         while True:                                34         while True:
 46                 try:                               35                 try:
 47                         slot = os.read(reader,     36                         slot = os.read(reader, 8)
 48                         jobs += slot               37                         jobs += slot
 49                 except (OSError, IOError) as e     38                 except (OSError, IOError) as e:
 50                         if e.errno == errno.EW     39                         if e.errno == errno.EWOULDBLOCK:
 51                                 # Stop at the      40                                 # Stop at the end of the jobserver queue.
 52                                 break              41                                 break
 53                         # If something went wr     42                         # If something went wrong, give back the jobs.
 54                         if len(jobs):              43                         if len(jobs):
 55                                 os.write(write     44                                 os.write(writer, jobs)
 56                         raise e                    45                         raise e
 57         # Add a bump for our caller's reserver     46         # Add a bump for our caller's reserveration, since we're just going
 58         # to sit here blocked on our child.        47         # to sit here blocked on our child.
 59         claim = len(jobs) + 1                      48         claim = len(jobs) + 1
 60 except (KeyError, IndexError, ValueError, OSEr     49 except (KeyError, IndexError, ValueError, OSError, IOError) as e:
 61         # Any missing environment strings or b     50         # Any missing environment strings or bad fds should result in just
 62         # not being parallel.                      51         # not being parallel.
 63         pass                                       52         pass
 64                                                    53 
 65 # We can only claim parallelism if there was a     54 # We can only claim parallelism if there was a jobserver (i.e. a top-level
 66 # "-jN" argument) and there were no other fail     55 # "-jN" argument) and there were no other failures. Otherwise leave out the
 67 # environment variable and let the child figur     56 # environment variable and let the child figure out what is best.
 68 if claim > 0:                                      57 if claim > 0:
 69         os.environ['PARALLELISM'] = '%d' % (cl     58         os.environ['PARALLELISM'] = '%d' % (claim)
 70                                                    59 
 71 rc = subprocess.call(sys.argv[1:])                 60 rc = subprocess.call(sys.argv[1:])
 72                                                    61 
 73 # Return all the reserved slots.                   62 # Return all the reserved slots.
 74 if len(jobs):                                      63 if len(jobs):
 75         os.write(writer, jobs)                     64         os.write(writer, jobs)
 76                                                    65 
 77 sys.exit(rc)                                       66 sys.exit(rc)
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php