From 13da5d7b2fda0da58137534e8fcdb0da9c88e55f Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Wed, 13 Sep 2023 03:30:04 +0100 Subject: [PATCH] Inline makecmd in make mode --- sphinx/cmd/make_mode.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/sphinx/cmd/make_mode.py b/sphinx/cmd/make_mode.py index 959d814f5bb..8b26d9d2e90 100644 --- a/sphinx/cmd/make_mode.py +++ b/sphinx/cmd/make_mode.py @@ -67,7 +67,6 @@ def __init__(self, srcdir: str, builddir: str, opts: Sequence[str]) -> None: self.srcdir = srcdir self.builddir = builddir self.opts = [*opts] - self.makecmd = os.environ.get('MAKE', 'make') # refer $MAKE to determine make command def builddir_join(self, *comps: str) -> str: return path.join(self.builddir, *comps) @@ -105,10 +104,11 @@ def build_latexpdf(self) -> int: if self.run_generic_build('latex') > 0: return 1 - if sys.platform == 'win32': - makecmd = os.environ.get('MAKE', 'make.bat') - else: - makecmd = self.makecmd + # Use $MAKE to determine the make command + make_fallback = 'make.bat' if sys.platform == 'win32' else 'make' + makecmd = os.environ.get('MAKE', make_fallback) + if not makecmd.lower().startswith('make'): + raise RuntimeError('Invalid $MAKE command: %r' % makecmd) try: with chdir(self.builddir_join('latex')): return subprocess.call([makecmd, 'all-pdf']) @@ -120,10 +120,11 @@ def build_latexpdfja(self) -> int: if self.run_generic_build('latex') > 0: return 1 - if sys.platform == 'win32': - makecmd = os.environ.get('MAKE', 'make.bat') - else: - makecmd = self.makecmd + # Use $MAKE to determine the make command + make_fallback = 'make.bat' if sys.platform == 'win32' else 'make' + makecmd = os.environ.get('MAKE', make_fallback) + if not makecmd.lower().startswith('make'): + raise RuntimeError('Invalid $MAKE command: %r' % makecmd) try: with chdir(self.builddir_join('latex')): return subprocess.call([makecmd, 'all-pdf']) @@ -134,11 +135,16 @@ def build_latexpdfja(self) -> int: def build_info(self) -> int: if self.run_generic_build('texinfo') > 0: return 1 + + # Use $MAKE to determine the make command + makecmd = os.environ.get('MAKE', 'make') + if not makecmd.lower().startswith('make'): + raise RuntimeError('Invalid $MAKE command: %r' % makecmd) try: with chdir(self.builddir_join('texinfo')): - return subprocess.call([self.makecmd, 'info']) + return subprocess.call([makecmd, 'info']) except OSError: - print('Error: Failed to run: %s' % self.makecmd) + print('Error: Failed to run: %s' % makecmd) return 1 def build_gettext(self) -> int: