From nobody Sat Oct 4 16:15:02 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F50A2D7389; Fri, 15 Aug 2025 11:51:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755258666; cv=none; b=ROlVZNsmqE/4vpS2kbUhgLJNQsXpSBP4H8hwGvV8og/epzwdaNxKimefu4VPRy9FNMKTfiKBuQ0hKAgtaiVdgqj41tGkccwkZOKHjQbIwpwp7arY0Wfd9aDD+WrBhA76ciwwcY4GWosme2XwN6Wc+xoT+Khl5LBhzcfFOOgVyw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755258666; c=relaxed/simple; bh=gQ6kk5WPc72Dq2AQd/n6nSscjReWsPfB0/s1IlVKE+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NeL2IGo6R9Xgrvzo1RMsY3+Ps4jpqbA11WZ95uwakfhwgVD+mf6tGfPvAXw/l8mB67dS3ns7ccYXhNlv/lSqFhbWLNnhW7QpFsjgzPtVXhGi0cJLIDC2iQzOBE3xnzLo4VaC712uqSiddgEwiyF+Ao2maVGWpntr174l/uhwvsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h+M+Tq/d; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h+M+Tq/d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F193AC113CF; Fri, 15 Aug 2025 11:51:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755258666; bh=gQ6kk5WPc72Dq2AQd/n6nSscjReWsPfB0/s1IlVKE+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h+M+Tq/d+hBeMlPVTjHZo2vkzeO1qLH30Cde8nS9nSbkTp19fczQNfeHW2yUt503f 2aI7K0JnvENo9IK8lO9CY990Erpn8d0X4FcIzKy7Wl5oO0iB3JgFLl/lsoE03bUAi2 EBPYYo+YR6jifsd6/lqxUx4LjYjA+vTWkWF/SRtGOtPtByWUNPWsI586XoLmAkTCEg PJOXbsHFgvSuwx4gBO/cB524XswwN5Pv5Qr9JI6vpJZVwXfawEyBOIuYlRRN19cOPL LL7vkfgSeB42lDhXLBysGkJWdM+wpCRfjwC26z8kn9EKvYHmYJS/8xFB27Qnc+Fk0O z8F5YOQadHx1w== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1umsxc-000000042oq-0zxq; Fri, 15 Aug 2025 13:51:04 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH 10/11] scripts: sphinx-*: prevent sphinx-build crashes Date: Fri, 15 Aug 2025 13:50:38 +0200 Message-ID: <461e00fe7ce75eaac90d98572bb93910b39361e2.1755258303.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab Content-Type: text/plain; charset="utf-8" On a properly set system, LANG and LC_ALL is always defined. However, some distros like Debian, Gentoo and their variants start with those undefioned. When Sphinx tries to set a locale with: locale.setlocale(locale.LC_ALL, '') It raises an exception, making Sphinx fail. This is more likely to happen with test containers. Add a logic to detect and workaround such issue by setting locale to C. Signed-off-by: Mauro Carvalho Chehab --- scripts/sphinx-build-wrapper | 10 ++++++++++ scripts/sphinx-pre-install | 14 +++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/scripts/sphinx-build-wrapper b/scripts/sphinx-build-wrapper index f6fec766c3e6..f21701d34552 100755 --- a/scripts/sphinx-build-wrapper +++ b/scripts/sphinx-build-wrapper @@ -45,6 +45,7 @@ the newer version. """ =20 import argparse +import locale import os import re import shlex @@ -495,6 +496,15 @@ class SphinxBuilder: if not sphinxdirs: sphinxdirs =3D os.environ.get("SPHINXDIRS", ".") =20 + # The sphinx-build tool has a bug: internally, it tries to set + # locale with locale.setlocale(locale.LC_ALL, ''). This causes a + # crash if language is not set. Detect and fix it. + try: + locale.setlocale(locale.LC_ALL, '') + except Exception: + self.env["LC_ALL"] =3D "C" + self.env["LANG"] =3D "C" + # sphinxdirs can be a list or a whitespace-separated string sphinxdirs_list =3D [] for sphinxdir in sphinxdirs: diff --git a/scripts/sphinx-pre-install b/scripts/sphinx-pre-install index c46d7b76f93c..50ae9cfcb3d7 100755 --- a/scripts/sphinx-pre-install +++ b/scripts/sphinx-pre-install @@ -26,6 +26,7 @@ system pacage install is recommended. """ =20 import argparse +import locale import os import re import subprocess @@ -516,8 +517,19 @@ class MissingCheckers(AncillaryMethods): """ Gets sphinx-build version. """ + env =3D os.environ.copy() + + # The sphinx-build tool has a bug: internally, it tries to set + # locale with locale.setlocale(locale.LC_ALL, ''). This causes a + # crash if language is not set. Detect and fix it. try: - result =3D self.run([cmd, "--version"], + locale.setlocale(locale.LC_ALL, '') + except Exception: + env["LC_ALL"] =3D "C" + env["LANG"] =3D "C" + + try: + result =3D self.run([cmd, "--version"], env=3Denv, stdout=3Dsubprocess.PIPE, stderr=3Dsubprocess.STDOUT, text=3DTrue, check=3DTrue) --=20 2.50.1