xref: /linux/scripts/jobserver-exec (revision bb29b957eaaa15be33243550d9ee576c2d601669)
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0+
3
4"""
5Determines how many parallel tasks "make" is expecting, as it is
6not exposed via any special variables, reserves them all, runs a subprocess
7with PARALLELISM environment variable set and any %PARALLELISM% in its
8arguments replaced by the count, and releases the jobs back again.
9
10See:
11    https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html#POSIX-Jobserver
12"""
13
14import os
15import sys
16
17LIB_DIR = "../tools/lib/python"
18SRC_DIR = os.path.dirname(os.path.realpath(__file__))
19
20sys.path.insert(0, os.path.join(SRC_DIR, LIB_DIR))
21
22from jobserver import JobserverExec                  # pylint: disable=C0415
23
24
25def main():
26    """Main program"""
27    if len(sys.argv) < 2:
28        name = os.path.basename(__file__)
29        sys.exit("usage: " + name +" command [args ...]\n" + __doc__)
30
31    with JobserverExec() as jobserver:
32        return jobserver.run(sys.argv[1:])
33
34
35if __name__ == "__main__":
36    sys.exit(main())
37