Skip to content

Commit

Permalink
Bug 1253203 - Move parts of configure.py into sandboxed moz.configure…
Browse files Browse the repository at this point in the history
…. r=nalexander,r=chmanchester

This moves all the reading mozconfig, finding autoconf, refreshing the
old configure, and running the old configure into sandboxed
moz.configure. This effectively bootstraps the sandboxed python configure.
  • Loading branch information
glandium committed Mar 8, 2016
1 parent 70fc008 commit 74b4506
Show file tree
Hide file tree
Showing 10 changed files with 645 additions and 286 deletions.
62 changes: 17 additions & 45 deletions build/autoconf/altoptions.m4
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ dnl MOZ_ARG_WITH_STRING( NAME, HELP, IF-SET [, ELSE])
dnl MOZ_ARG_HEADER(Comment)
dnl MOZ_READ_MYCONFIG() - Read in 'myconfig.sh' file

define([MOZ_DIVERSION_ARGS], 12)

AC_DEFUN([MOZ_ARG],[dnl
AC_DIVERT_PUSH(MOZ_DIVERSION_ARGS)dnl
'$1',
AC_DIVERT_POP()dnl
])
AC_DEFUN([MOZ_AC_ARG_ENABLE],[MOZ_ARG([--enable-]translit([$1],[_],[-]))AC_ARG_ENABLE([$1], [$2], [$3], [$4])])
AC_DEFUN([MOZ_AC_ARG_WITH],[MOZ_ARG([--with-]translit([$1],[_],[-]))AC_ARG_WITH([$1], [$2], [$3], [$4])])

dnl MOZ_TWO_STRING_TEST(NAME, VAL, STR1, IF-STR1, STR2, IF-STR2 [, ELSE])
AC_DEFUN([MOZ_TWO_STRING_TEST],
Expand All @@ -35,45 +44,45 @@ AC_DEFUN([MOZ_TWO_STRING_TEST],

dnl MOZ_ARG_ENABLE_BOOL(NAME, HELP, IF-YES [, IF-NO [, ELSE]])
AC_DEFUN([MOZ_ARG_ENABLE_BOOL],
[AC_ARG_ENABLE([$1], [$2],
[MOZ_AC_ARG_ENABLE([$1], [$2],
[MOZ_TWO_STRING_TEST([$1], [$enableval], yes, [$3], no, [$4])],
[$5])])

dnl MOZ_ARG_DISABLE_BOOL(NAME, HELP, IF-NO [, IF-YES [, ELSE]])
AC_DEFUN([MOZ_ARG_DISABLE_BOOL],
[AC_ARG_ENABLE([$1], [$2],
[MOZ_AC_ARG_ENABLE([$1], [$2],
[MOZ_TWO_STRING_TEST([$1], [$enableval], no, [$3], yes, [$4])],
[$5])])

dnl MOZ_ARG_ENABLE_STRING(NAME, HELP, IF-SET [, ELSE])
AC_DEFUN([MOZ_ARG_ENABLE_STRING],
[AC_ARG_ENABLE([$1], [$2], [$3], [$4])])
[MOZ_AC_ARG_ENABLE([$1], [$2], [$3], [$4])])

dnl MOZ_ARG_ENABLE_BOOL_OR_STRING(NAME, HELP, IF-YES, IF-NO, IF-SET[, ELSE]]])
AC_DEFUN([MOZ_ARG_ENABLE_BOOL_OR_STRING],
[ifelse([$5], ,
[errprint([Option, $1, needs an "IF-SET" argument.
])
m4exit(1)],
[AC_ARG_ENABLE([$1], [$2],
[MOZ_AC_ARG_ENABLE([$1], [$2],
[MOZ_TWO_STRING_TEST([$1], [$enableval], yes, [$3], no, [$4], [$5])],
[$6])])])

dnl MOZ_ARG_WITH_BOOL(NAME, HELP, IF-YES [, IF-NO [, ELSE])
AC_DEFUN([MOZ_ARG_WITH_BOOL],
[AC_ARG_WITH([$1], [$2],
[MOZ_AC_ARG_WITH([$1], [$2],
[MOZ_TWO_STRING_TEST([$1], [$withval], yes, [$3], no, [$4])],
[$5])])

dnl MOZ_ARG_WITHOUT_BOOL(NAME, HELP, IF-NO [, IF-YES [, ELSE])
AC_DEFUN([MOZ_ARG_WITHOUT_BOOL],
[AC_ARG_WITH([$1], [$2],
[MOZ_AC_ARG_WITH([$1], [$2],
[MOZ_TWO_STRING_TEST([$1], [$withval], no, [$3], yes, [$4])],
[$5])])

dnl MOZ_ARG_WITH_STRING(NAME, HELP, IF-SET [, ELSE])
AC_DEFUN([MOZ_ARG_WITH_STRING],
[AC_ARG_WITH([$1], [$2], [$3], [$4])])
[MOZ_AC_ARG_WITH([$1], [$2], [$3], [$4])])

dnl MOZ_ARG_HEADER(Comment)
dnl This is used by webconfig to group options
Expand All @@ -82,42 +91,5 @@ define(MOZ_ARG_HEADER, [# $1])
dnl MOZ_READ_MYCONFIG() - Read in 'myconfig.sh' file
AC_DEFUN([MOZ_READ_MOZCONFIG],
[AC_REQUIRE([AC_INIT_BINSH])dnl
inserted=
dnl Shell is hard, so here is what the following does:
dnl - Reset $@ (command line arguments)
dnl - Add the configure options from mozconfig to $@ one by one
dnl - Add the original command line arguments after that, one by one
dnl
dnl There are several tricks involved:
dnl - It is not possible to preserve the whitespaces in $@ by assigning to
dnl another variable, so the two first steps above need to happen in the first
dnl iteration of the third step.
dnl - We always want the configure options to be added, so the loop must be
dnl iterated at least once, so we add a dummy argument first, and discard it.
dnl - something | while read line ... makes the while run in a subshell, meaning
dnl that anything it does is not propagated to the main shell, so we can't do
dnl set -- foo there. As a consequence, what the while loop reading mach
dnl environment output does is output a set of shell commands for the main shell
dnl to eval.
dnl - Extra care is due when lines from mach environment output contain special
dnl shell characters, so we use ' for quoting and ensure no ' end up in between
dnl the quoting mark unescaped.
dnl Some of the above is directly done in mach environment --format=configure.
failed_eval() {
echo "Failed eval'ing the following:"
$(dirname [$]0)/[$1]/mach environment --format=configure
exit 1
}
set -- dummy "[$]@"
for ac_option
do
if test -z "$inserted"; then
set --
eval "$($(dirname [$]0)/[$1]/mach environment --format=configure)" || failed_eval
inserted=1
else
set -- "[$]@" "$ac_option"
fi
done
. ./old-configure.vars
])
4 changes: 4 additions & 0 deletions build/autoconf/config.status.m4
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ fi
cat >> $CONFIG_STATUS <<EOF
]
flags = [
undivert(MOZ_DIVERSION_ARGS)dnl
]
EOF
changequote([, ])
Expand Down
122 changes: 122 additions & 0 deletions build/moz.configure/init.configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# -*- 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('util.configure')

option(env='DIST', nargs=1, help='DIST directory')

# Do not allow objdir == srcdir builds.
# ==============================================================
@depends('--help', 'DIST')
def check_build_environment(help, dist):
topobjdir = os.path.realpath(os.path.abspath('.'))
topsrcdir = os.path.realpath(os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..')))

set_config('TOPSRCDIR', topsrcdir)
set_config('TOPOBJDIR', topobjdir)
set_config('MOZ_BUILD_ROOT', topobjdir)
if dist:
set_config('DIST', normsep(dist[0]))
else:
set_config('DIST', os.path.join(topobjdir, 'dist'))

if help:
return

if topsrcdir == topobjdir:
error(
' ***\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 a couple representative files in the source tree
conflict_files = [
'* %s' % f for f in ('Makefile', 'config/autoconf.mk')
if os.path.exists(os.path.join(topsrcdir, f))
]
if conflict_files:
error(
' ***\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)
)


option(env='MOZ_CURRENT_PROJECT', nargs=1, help='Current build project')
option(env='MOZCONFIG', nargs=1, help='Mozconfig location')

# Read user mozconfig
# ==============================================================
# Note: the dependency on --help is only there to always read the mozconfig,
# even when --help is passed. Without this dependency, the function wouldn't
# be called when --help is passed, and the mozconfig wouldn't be read.
@depends('MOZ_CURRENT_PROJECT', 'MOZCONFIG', check_build_environment, '--help')
@advanced
def mozconfig(current_project, mozconfig, build_env, help):
from mozbuild.mozconfig import MozconfigLoader

# Don't read the mozconfig for the js configure (yay backwards
# compatibility)
if build_env['TOPOBJDIR'].endswith('/js/src'):
return {'path': None}

loader = MozconfigLoader(build_env['TOPSRCDIR'])
current_project = current_project[0] if current_project else None
mozconfig = mozconfig[0] if mozconfig else None
mozconfig = loader.find_mozconfig(env={'MOZCONFIG': mozconfig})
mozconfig = loader.read_mozconfig(mozconfig, moz_build_app=current_project)

return mozconfig


@template
@advanced
def command_line_helper():
# This escapes the sandbox. Don't copy this. This is only here because
# it is a one off and because the required functionality doesn't need
# to be exposed for other usecases.
return depends.__self__._helper


@depends(mozconfig)
def mozconfig_options(mozconfig):
if mozconfig['path']:
helper = command_line_helper()
warn('Adding configure options from %s' % mozconfig['path'])
for arg in mozconfig['configure_args']:
warn(' %s' % arg)
# We could be using imply_option() here, but it has other
# contraints that don't really apply to the command-line
# emulation that mozconfig provides.
helper.add(arg, origin='mozconfig', args=helper._args)

# Ideally we'd handle mozconfig['env'] and mozconfig['vars'] here,
# but at the moment, moz.configure has no knowledge of the options
# that may appear there. We'll opt-in when we move things from
# old-configure.in, which will be tedious but necessary until we
# can discriminate what old-configure.in supports.

del command_line_helper


option(env='MOZILLABUILD', nargs=1,
help='Path to Mozilla Build (Windows-only)')
Loading

0 comments on commit 74b4506

Please sign in to comment.