From f44c15b7d501f0f4ce6717e82b3bbf45051c3589 Mon Sep 17 00:00:00 2001 From: Alex Hochheiden Date: Tue, 24 Mar 2026 01:49:21 +0000 Subject: [PATCH] Bug 2023319 - Error on Windows when `topsrcdir` or `topobjdir` paths are too long r=firefox-build-system-reviewers,nalexander We can't share code with `bin\bootstrap.py`, so there's a minor amount of duplication, but it's better to notify the user before they clone than during the first `./mach configure` run. Differential Revision: https://phabricator.services.mozilla.com/D289380 --- configure.py | 39 +++++++++++++++++++++++++++++++++ python/mozboot/bin/bootstrap.py | 20 +++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/configure.py b/configure.py index c291e7123049..b8b217f4891b 100644 --- a/configure.py +++ b/configure.py @@ -100,6 +100,45 @@ def main(argv): ) return 1 + if sys.platform == "win32": + # Long paths cause two kinds of build failures on Windows: + # 1. Tools like midl.exe do not support paths exceeding MAX_PATH + # (260 characters), even with the LongPathsEnabled registry setting. + # 2. Long source paths repeated across many -I flags can exceed + # the CreateProcessW command line limit of 32,767 characters. + WIN32_MAX_PATH = 260 + LONGEST_KNOWN_OBJDIR_RELATIVE_PATH = 170 + DEFAULT_OBJDIR_NAME_LEN = 28 # /obj-x86_64-pc-windows-msvc/ + max_objdir_len = WIN32_MAX_PATH - LONGEST_KNOWN_OBJDIR_RELATIVE_PATH + # Account for the default objdir name in the srcdir limit so that + # a user doesn't fix a srcdir error only to immediately hit the + # objdir error with the default configuration. + max_srcdir_len = max_objdir_len - DEFAULT_OBJDIR_NAME_LEN + if len(topsrcdir) > max_srcdir_len: + print( + f"Source directory path ({topsrcdir}) is " + f"{len(topsrcdir)} characters, which exceeds the " + f"Windows limit of {max_srcdir_len}.\n" + f"Move your source directory to a shorter path " + f"(e.g. D:\\mozilla-source\\firefox).", + file=sys.stderr, + ) + return 1 + if len(topobjdir) > max_objdir_len: + print( + f"Object directory path ({topobjdir}) is " + f"{len(topobjdir)} characters, which exceeds the " + f"Windows limit of {max_objdir_len}.\n" + + ( + "Move your source directory to a shorter path or set " + "MOZ_OBJDIR to a shorter absolute path in your mozconfig." + if topobjdir.startswith(topsrcdir) + else "Set MOZ_OBJDIR to a shorter absolute path in your mozconfig." + ), + file=sys.stderr, + ) + return 1 + # Do not allow topobjdir == topsrcdir if os.path.samefile(topsrcdir, topobjdir): print( diff --git a/python/mozboot/bin/bootstrap.py b/python/mozboot/bin/bootstrap.py index 6be38685493e..12ceabc38dd9 100755 --- a/python/mozboot/bin/bootstrap.py +++ b/python/mozboot/bin/bootstrap.py @@ -71,6 +71,26 @@ def which(name): def validate_clone_dest(dest: Path): dest = dest.resolve() + if WINDOWS: + # Keep in sync with the path length checks in configure.py. + WIN32_MAX_PATH = 260 + LONGEST_KNOWN_OBJDIR_RELATIVE_PATH = 170 + DEFAULT_OBJDIR_NAME_LEN = 28 # /obj-x86_64-pc-windows-msvc/ + max_srcdir_len = ( + WIN32_MAX_PATH + - LONGEST_KNOWN_OBJDIR_RELATIVE_PATH + - DEFAULT_OBJDIR_NAME_LEN + ) + dest_len = len(str(dest)) + if dest_len > max_srcdir_len: + print( + f"ERROR! Destination path ({dest}) is {dest_len} characters, " + f"which exceeds the Windows limit of {max_srcdir_len}. " + f"This will cause build failures due to path length restrictions.\n" + f"Please choose a shorter path (e.g. D:\\mozilla-source\\firefox)." + ) + return None + if not dest.exists(): return dest