From 564de8ea0e9fe026077c206193bee6f467b7950d Mon Sep 17 00:00:00 2001
From: Mike Hommey <mh+mozilla@glandium.org>
Date: Tue, 8 Mar 2016 13:49:35 +0900
Subject: [PATCH] Bug 1254410 - Include app-specific configure files according
 to --enable-application/--enable-project. r=chmanchester

Because --enable-application is the current way to do things, transpose
it to configure.py, but since --enable-application=js doesn't make
sense, make it an alias of a new --enable-project option.

This only partially moves --enable-application out of old-configure.in
because there are a lot of other things intertwined with it.
---
 b2g/dev/moz.configure                 |  7 ++++++
 b2g/graphene/moz.configure            |  7 ++++++
 b2g/moz.configure                     |  7 ++++++
 browser/moz.configure                 |  7 ++++++
 build/moz.configure/init.configure    | 35 +++++++++++++++++++++++++++
 build/moz.configure/old.configure     |  6 ++---
 embedding/ios/moz.configure           |  5 ++++
 extensions/moz.configure              |  5 ++++
 js/moz.configure                      |  5 ++++
 js/src/configure.in                   |  2 ++
 mobile/android/b2gdroid/moz.configure |  7 ++++++
 mobile/android/moz.configure          |  7 ++++++
 moz.configure                         |  7 ++++++
 old-configure.in                      |  8 ------
 toolkit/moz.configure                 |  5 ++++
 15 files changed, 109 insertions(+), 11 deletions(-)
 create mode 100644 b2g/dev/moz.configure
 create mode 100644 b2g/graphene/moz.configure
 create mode 100644 b2g/moz.configure
 create mode 100644 browser/moz.configure
 create mode 100644 embedding/ios/moz.configure
 create mode 100644 extensions/moz.configure
 create mode 100644 js/moz.configure
 create mode 100644 mobile/android/b2gdroid/moz.configure
 create mode 100644 mobile/android/moz.configure
 create mode 100644 toolkit/moz.configure

diff --git a/b2g/dev/moz.configure b/b2g/dev/moz.configure
new file mode 100644
index 0000000000000..9c578cd67fa46
--- /dev/null
+++ b/b2g/dev/moz.configure
@@ -0,0 +1,7 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+include('../../toolkit/moz.configure')
diff --git a/b2g/graphene/moz.configure b/b2g/graphene/moz.configure
new file mode 100644
index 0000000000000..9c578cd67fa46
--- /dev/null
+++ b/b2g/graphene/moz.configure
@@ -0,0 +1,7 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+include('../../toolkit/moz.configure')
diff --git a/b2g/moz.configure b/b2g/moz.configure
new file mode 100644
index 0000000000000..0efa0f710787f
--- /dev/null
+++ b/b2g/moz.configure
@@ -0,0 +1,7 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+include('../toolkit/moz.configure')
diff --git a/browser/moz.configure b/browser/moz.configure
new file mode 100644
index 0000000000000..0efa0f710787f
--- /dev/null
+++ b/browser/moz.configure
@@ -0,0 +1,7 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+include('../toolkit/moz.configure')
diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.configure
index 7d18ef30bdf4e..8764f4288e4fc 100644
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -198,3 +198,38 @@ del command_line_helper
 
 option(env='MOZILLABUILD', nargs=1,
        help='Path to Mozilla Build (Windows-only)')
+
+
+option('--enable-application', nargs=1, env='MOZ_BUILD_APP',
+       help='Application to build. Same as --enable-project.')
+
+@depends('--enable-application', '--help')
+def application(app, help):
+    if app:
+        imply_option(app.format('--enable-project'))
+
+
+@depends(check_build_environment, '--help')
+def default_project(build_env, help):
+    if build_env['TOPOBJDIR'].endswith('/js/src'):
+        return 'js'
+    return 'browser'
+
+option('--enable-project', nargs=1, default=default_project,
+       help='Project to build')
+
+@depends('--enable-project', check_build_environment, '--help')
+def include_project_configure(project, build_env, help):
+    if not project:
+        error('--enable-project is required.')
+
+    path = os.path.join(build_env['TOPSRCDIR'], project[0], 'moz.configure')
+    if not os.path.exists(path):
+        error('Cannot find project %s' % project[0])
+    return path
+
+include(include_project_configure)
+
+@depends('--enable-project')
+def build_app(project):
+    return project[0]
diff --git a/build/moz.configure/old.configure b/build/moz.configure/old.configure
index 9210b9c96b1e0..2972e7ba018c7 100644
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -60,10 +60,10 @@ def autoconf(mozconfig, autoconf):
 option(env='OLD_CONFIGURE', nargs=1, help='Path to the old configure script')
 
 @depends('OLD_CONFIGURE', mozconfig, autoconf, check_build_environment, shell,
-         virtualenv_python, compile_environment)
+         virtualenv_python, compile_environment, build_app)
 @advanced
 def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell,
-                      python, compile_env):
+                      python, compile_env, build_app):
     import glob
     import itertools
     import subprocess
@@ -126,6 +126,7 @@ def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell,
         print('PYTHON=%s' % quote(python), file=out)
         if compile_env:
             print('COMPILE_ENVIRONMENT=1', file=out)
+        print('MOZ_BUILD_APP=%s' % build_app, file=out)
 
     return cmd
 
@@ -150,7 +151,6 @@ def old_configure_options(*options):
     '--enable-android-apz',
     '--enable-android-omx',
     '--enable-android-resource-constrained',
-    '--enable-application',
     '--enable-approximate-location',
     '--enable-b2g-bt',
     '--enable-b2g-camera',
diff --git a/embedding/ios/moz.configure b/embedding/ios/moz.configure
new file mode 100644
index 0000000000000..c271ec3908ce6
--- /dev/null
+++ b/embedding/ios/moz.configure
@@ -0,0 +1,5 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
diff --git a/extensions/moz.configure b/extensions/moz.configure
new file mode 100644
index 0000000000000..c271ec3908ce6
--- /dev/null
+++ b/extensions/moz.configure
@@ -0,0 +1,5 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
diff --git a/js/moz.configure b/js/moz.configure
new file mode 100644
index 0000000000000..c271ec3908ce6
--- /dev/null
+++ b/js/moz.configure
@@ -0,0 +1,5 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
diff --git a/js/src/configure.in b/js/src/configure.in
index 550a51528f31f..b97fa11d2d905 100644
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -21,4 +21,6 @@ SRCDIR=$(dirname $0)
 TOPSRCDIR="$SRCDIR"/../..
 export OLD_CONFIGURE="$SRCDIR"/old-configure
 
+set -- "$@" --enable-project=js
+
 which python2.7 > /dev/null && exec python2.7 "$TOPSRCDIR/configure.py" "$@" || exec python "$TOPSRCDIR/configure.py" "$@"
diff --git a/mobile/android/b2gdroid/moz.configure b/mobile/android/b2gdroid/moz.configure
new file mode 100644
index 0000000000000..416e1eb976aff
--- /dev/null
+++ b/mobile/android/b2gdroid/moz.configure
@@ -0,0 +1,7 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+include('../../../toolkit/moz.configure')
diff --git a/mobile/android/moz.configure b/mobile/android/moz.configure
new file mode 100644
index 0000000000000..9c578cd67fa46
--- /dev/null
+++ b/mobile/android/moz.configure
@@ -0,0 +1,7 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+include('../../toolkit/moz.configure')
diff --git a/moz.configure b/moz.configure
index 5f5cee3b3de45..cfbbc2991cf1c 100644
--- a/moz.configure
+++ b/moz.configure
@@ -6,6 +6,13 @@
 
 include('build/moz.configure/init.configure')
 
+# Note:
+# - Gecko-specific options and rules should go in toolkit/moz.configure.
+# - Firefox-specific options and rules should go in browser/moz.configure.
+# - Fennec-specific options and rules should go in
+#   mobile/android/moz.configure.
+# - Spidermonkey-specific options and rules should go in js/moz.configure.
+# - etc.
 
 option('--enable-artifact-builds', env='MOZ_ARTIFACT_BUILDS',
        help='Download and use prebuilt binary artifacts.')
diff --git a/old-configure.in b/old-configure.in
index dbd24ec22a5cd..e5cfee9f44ff0 100644
--- a/old-configure.in
+++ b/old-configure.in
@@ -3689,14 +3689,6 @@ MOZ_ARG_WITH_STRING(external-source-dir,
 [ EXTERNAL_SOURCE_DIR=$withval])
 AC_SUBST(EXTERNAL_SOURCE_DIR)
 
-MOZ_ARG_ENABLE_STRING(application,
-[  --enable-application=APP
-                          Options include:
-                            browser (Firefox)
-                            xulrunner
-                            tools/update-packaging (AUS-related packaging tools)],
-[ MOZ_BUILD_APP=$enableval ] )
-
 MOZ_ARG_WITH_STRING(xulrunner-stub-name,
 [  --with-xulrunner-stub-name=appname   Create the xulrunner stub with the given name],
   XULRUNNER_STUB_NAME=$withval)
diff --git a/toolkit/moz.configure b/toolkit/moz.configure
new file mode 100644
index 0000000000000..c271ec3908ce6
--- /dev/null
+++ b/toolkit/moz.configure
@@ -0,0 +1,5 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-- 
GitLab