Bug 1747332 - Move build environment checks to configure.py. r=firefox-build-system-reviewers,andi

We also avoid creating the virtualenv before those checks, and remove
the long useless check for build residue in the source directory (these
files will not have been created because builds that would create them
have been forbidden for years)

Differential Revision: https://phabricator.services.mozilla.com/D134584
This commit is contained in:
Mike Hommey 2021-12-23 20:47:47 +00:00
Родитель 81194e954e
Коммит 0040b4ada7
2 изменённых файлов: 69 добавлений и 83 удалений

Просмотреть файл

@ -16,13 +16,8 @@ bindgen_config_paths = dependable(None)
option(env="DIST", nargs=1, help="DIST directory")
# Do not allow objdir == srcdir builds.
# ==============================================================
@depends("--help", "DIST")
@imports(_from="__builtin__", _import="open")
@imports(_from="os.path", _import="exists")
@imports(_from="six", _import="ensure_text")
def check_build_environment(help, dist):
def check_build_environment(_, dist):
topobjdir = os.path.realpath(".")
topsrcdir = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", ".."))
@ -31,88 +26,12 @@ def check_build_environment(help, dist):
else:
dist = os.path.join(topobjdir, "dist")
result = namespace(
return namespace(
topsrcdir=topsrcdir,
topobjdir=topobjdir,
dist=dist,
)
if help:
return result
# This limitation has mostly to do with GNU make. Since make can't represent
# variables with spaces without correct quoting and many paths are used
# without proper quoting, using paths with spaces commonly results in
# targets or dependencies being treated as multiple paths. This, of course,
# undermines the ability for make to perform up-to-date checks and makes
# the build system not work very efficiently. In theory, a non-make build
# backend will make this limitation go away. But there is likely a long tail
# of things that will need fixing due to e.g. lack of proper path quoting.
if len(topsrcdir.split()) > 1:
die("Source directory cannot be located in a path with spaces: %s" % topsrcdir)
if len(topobjdir.split()) > 1:
die("Object directory cannot be located in a path with spaces: %s" % topobjdir)
if topsrcdir == topobjdir:
die(
" ***\n"
" * Building directly in the main source directory is not allowed.\n"
" *\n"
" * To build, you must run configure from a separate directory\n"
" * (referred to as an object directory).\n"
" *\n"
" * If you are building with a mozconfig, you will need to change your\n"
" * mozconfig to point to a different object directory.\n"
" ***"
)
# Check for CRLF line endings.
with open(os.path.join(topsrcdir, "configure.py"), "r") as fh:
data = ensure_text(fh.read())
if "\r" in data:
die(
"\n ***\n"
" * The source tree appears to have Windows-style line endings.\n"
" *\n"
" * If using Git, Git is likely configured to use Windows-style\n"
" * line endings.\n"
" *\n"
" * To convert the working copy to UNIX-style line endings, run\n"
" * the following:\n"
" *\n"
" * $ git config core.autocrlf false\n"
" * $ git config core.eof lf\n"
" * $ git rm --cached -r .\n"
" * $ git reset --hard\n"
" *\n"
" * If not using Git, the tool you used to obtain the source\n"
" * code likely converted files to Windows line endings. See\n"
" * usage information for that tool for more.\n"
" ***"
)
# Check for a couple representative files in the source tree
conflict_files = [
"* %s" % f
for f in ("Makefile", "config/autoconf.mk")
if exists(os.path.join(topsrcdir, f))
]
if conflict_files:
die(
" ***\n"
" * Your source tree contains these files:\n"
" %s\n"
" * This indicates that you previously built in the source tree.\n"
" * A source tree build can confuse the separate objdir build.\n"
" *\n"
" * To clean up the source tree:\n"
" * 1. cd %s\n"
" * 2. gmake distclean\n"
" ***" % ("\n ".join(conflict_files), topsrcdir)
)
return result
set_config("TOPSRCDIR", check_build_environment.topsrcdir)
set_config("TOPOBJDIR", check_build_environment.topobjdir)

Просмотреть файл

@ -42,6 +42,33 @@ import six
def main(argv):
# Check for CRLF line endings.
with open(__file__, "r") as fh:
data = fh.read()
if "\r" in data:
print(
"\n ***\n"
" * The source tree appears to have Windows-style line endings.\n"
" *\n"
" * If using Git, Git is likely configured to use Windows-style\n"
" * line endings.\n"
" *\n"
" * To convert the working copy to UNIX-style line endings, run\n"
" * the following:\n"
" *\n"
" * $ git config core.autocrlf false\n"
" * $ git config core.eof lf\n"
" * $ git rm --cached -r .\n"
" * $ git reset --hard\n"
" *\n"
" * If not using Git, the tool you used to obtain the source\n"
" * code likely converted files to Windows line endings. See\n"
" * usage information for that tool for more.\n"
" ***",
file=sys.stderr,
)
return 1
config = {}
if "OLD_CONFIGURE" not in os.environ:
@ -50,6 +77,46 @@ def main(argv):
sandbox = ConfigureSandbox(config, os.environ, argv)
if not sandbox._help:
# This limitation has mostly to do with GNU make. Since make can't represent
# variables with spaces without correct quoting and many paths are used
# without proper quoting, using paths with spaces commonly results in
# targets or dependencies being treated as multiple paths. This, of course,
# undermines the ability for make to perform up-to-date checks and makes
# the build system not work very efficiently. In theory, a non-make build
# backend will make this limitation go away. But there is likely a long tail
# of things that will need fixing due to e.g. lack of proper path quoting.
topsrcdir = os.path.realpath(os.path.dirname(__file__))
if len(topsrcdir.split()) > 1:
print(
"Source directory cannot be located in a path with spaces: %s"
% topsrcdir,
file=sys.stderr,
)
return 1
topobjdir = os.path.realpath(os.curdir)
if len(topobjdir.split()) > 1:
print(
"Object directory cannot be located in a path with spaces: %s"
% topobjdir,
file=sys.stderr,
)
return 1
# Do not allow topobjdir == topsrcdir
if os.path.samefile(topsrcdir, topobjdir):
print(
" ***\n"
" * Building directly in the main source directory is not allowed.\n"
" *\n"
" * To build, you must run configure from a separate directory\n"
" * (referred to as an object directory).\n"
" *\n"
" * If you are building with a mozconfig, you will need to change your\n"
" * mozconfig to point to a different object directory.\n"
" ***",
file=sys.stderr,
)
return 1
_activate_build_virtualenv()
clobber_file = "CLOBBER"