diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.configure --- a/build/moz.configure/init.configure +++ b/build/moz.configure/init.configure @@ -14,107 +14,26 @@ 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__), "..", "..")) if dist: dist = normsep(dist[0]) 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) set_config("DIST", check_build_environment.dist) diff --git a/configure.py b/configure.py --- a/configure.py +++ b/configure.py @@ -40,18 +40,85 @@ import mozpack.path as mozpath 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: os.environ["OLD_CONFIGURE"] = os.path.join(base_dir, "old-configure") 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" if not os.path.exists(clobber_file): # Simply touch the file.