Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- FacebookAI/xlm-roberta-large/onnx/sentencepiece.bpe.modelAdded+3
- mosesdecoder/contrib/memscore/Makefile.amAdded+24
- mosesdecoder/contrib/memscore/aclocal.m4Added+851
- mosesdecoder/contrib/memscore/config.h.inAdded+79
- mosesdecoder/contrib/memscore/datastorage.hAdded+52
- mosesdecoder/contrib/memscore/depcompAdded+530
- mosesdecoder/contrib/memscore/install-shAdded+323
- mosesdecoder/contrib/memscore/lexdecom.cppAdded+183
- mosesdecoder/contrib/memscore/phraselm.cppAdded+63
- mosesdecoder/contrib/memscore/phrasetable.hAdded+710
- mosesdecoder/contrib/memscore/scorer-impl.hAdded+124
- mosesdecoder/contrib/promix/README.mdAdded+66
- mosesdecoder/contrib/promix/bleu.pyAdded+27
- mosesdecoder/contrib/promix/coll.pyAdded+260
- mosesdecoder/contrib/promix/main.pyAdded+112
- mosesdecoder/contrib/promix/nbest.pyAdded+230
- mosesdecoder/contrib/promix/test.pyAdded+25
- mosesdecoder/contrib/promix/test_sampler.pyAdded+53
- mosesdecoder/contrib/promix/test_train.pyAdded+306
- mosesdecoder/contrib/promix/util.pyAdded+12
- mosesdecoder/jam-files/boost-build/build/ac.jamAdded+198
- mosesdecoder/jam-files/boost-build/build/project.jamAdded+1121
- mosesdecoder/jam-files/boost-build/build/property-set.jamAdded+489
- mosesdecoder/jam-files/boost-build/build/targets.jamAdded+1659
- mosesdecoder/jam-files/boost-build/build/version.jamAdded+161
- mosesdecoder/jam-files/boost-build/build/virtual-target.jamAdded+1317
- mosesdecoder/jam-files/boost-build/util/assert.jamAdded+336
- mosesdecoder/jam-files/boost-build/util/doc.jamAdded+997
- mosesdecoder/jam-files/boost-build/util/numbers.jamAdded+218
- mosesdecoder/jam-files/boost-build/util/regex.jamAdded+193
- mosesdecoder/jam-files/engine/build.batAdded+565
- mosesdecoder/jam-files/engine/builtins.cAdded+2354
- mosesdecoder/jam-files/engine/builtins.hAdded+70
- mosesdecoder/jam-files/engine/bump_version.pyAdded+98
- mosesdecoder/jam-files/engine/class.cAdded+191
- mosesdecoder/jam-files/engine/command.hAdded+73
- mosesdecoder/jam-files/engine/compile.hAdded+59
- mosesdecoder/jam-files/engine/cwd.cAdded+83
- mosesdecoder/jam-files/engine/filent.cAdded+311
- mosesdecoder/jam-files/engine/fileunix.cAdded+180
- mosesdecoder/jam-files/engine/frames.cAdded+29
- mosesdecoder/jam-files/engine/function.cAdded
- mosesdecoder/jam-files/engine/function.hAdded+46
- mosesdecoder/jam-files/engine/hash.hAdded+79
- mosesdecoder/jam-files/engine/hcache.cAdded+519
- mosesdecoder/jam-files/engine/hdrmacro.hAdded+21
- mosesdecoder/jam-files/engine/headers.cAdded+197
- mosesdecoder/jam-files/engine/jam.cAdded+656
- mosesdecoder/jam-files/engine/jam.hAdded+475
- mosesdecoder/jam-files/engine/jamgram.yAdded+373
123version https://git-lfs.github.com/spec/v1oid sha256:cfc8146abe2a0488e9e2a0c56de7952f7c11ab059eca145a0a727afce0db2865size 5069051123456789101112131415161718192021222324# memscore - in-memory phrase scoring for Statistical Machine Translation# Christian Hardmeier, FBK-irst, Trento, 2010# $Id$
## Process this file with automake to produce Makefile.in
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = foreignAM_CXXFLAGS = $(BOOST_CPPFLAGS) -Wall -ffast-math -ftrapping-math -fomit-frame-pointer
bin_PROGRAMS = memscorememscore_SOURCES = datastorage.h memscore.h phrasetable.h scorer.h scorer-impl.h statistic.h timestamp.h \ phrasetable.cpp memscore.cpp scorer.cpp lexdecom.cpp lexdecom.h
if IRSTLMmemscore_SOURCES += phraselm.cpp phraselm.hendifif CHANNEL_SCORERmemscore_SOURCES += channel-scorer.cpp channel-scorer.hendif
memscore_LDADD = $(IRSTLM_LIBS) $(GSL_LIBS)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851# generated automatically by aclocal 1.9.6 -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,# 2005 Free Software Foundation, Inc.# This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY, to the extent permitted by law; without# even the implied warranty of MERCHANTABILITY or FITNESS FOR A# PARTICULAR PURPOSE.
# Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# AM_AUTOMAKE_VERSION(VERSION)# ----------------------------# Automake X.Y traces this macro to ensure aclocal.m4 has been# generated from the m4 files accompanying Automake X.Y.AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version="1.9"])
# AM_SET_CURRENT_AUTOMAKE_VERSION# -------------------------------# Call AM_AUTOMAKE_VERSION so it can be traced.# This function is AC_REQUIREd by AC_INIT_AUTOMAKE.AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], [AM_AUTOMAKE_VERSION([1.9.6])])
# AM_AUX_DIR_EXPAND -*- Autoconf -*-
# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to# `$srcdir', `$srcdir/..', or `$srcdir/../..'.## Of course, Automake must honor this variable whenever it calls a# tool from the auxiliary directory. The problem is that $srcdir (and# therefore $ac_aux_dir as well) can be either absolute or relative,# depending on how configure is run. This is pretty annoying, since# it makes $ac_aux_dir quite unusable in subdirectories: in the top# source directory, any form will work fine, but in subdirectories a# relative path needs to be adjusted first.## $ac_aux_dir/missing# fails when called from a subdirectory if $ac_aux_dir is relative# $top_srcdir/$ac_aux_dir/missing# fails if $ac_aux_dir is absolute,# fails when called from a subdirectory in a VPATH build with# a relative $ac_aux_dir## The reason of the latter failure is that $top_srcdir and $ac_aux_dir# are both prefixed by $srcdir. In an in-source build this is usually# harmless because $srcdir is `.', but things will broke when you# start a VPATH build or use an absolute $srcdir.## So we could use something similar to $top_srcdir/$ac_aux_dir/missing,# iff we strip the leading $srcdir from $ac_aux_dir. That would be:# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`# and then we would define $MISSING as# MISSING="\${SHELL} $am_aux_dir/missing"# This will work as long as MISSING is not called from configure, because# unfortunately $(top_srcdir) has no meaning in configure.# However there are other variables, like CC, which are often used in# configure, and could therefore not use this "fixed" $ac_aux_dir.## Another solution, used here, is to always expand $ac_aux_dir to an# absolute PATH. The drawback is that using absolute paths prevent a# configured tree to be moved without reconfiguration.
AC_DEFUN([AM_AUX_DIR_EXPAND],[dnl Rely on autoconf to set up CDPATH properly.AC_PREREQ([2.50])dnl# expand $ac_aux_dir to an absolute patham_aux_dir=`cd $ac_aux_dir && pwd`])
# AM_CONDITIONAL -*- Autoconf -*-
# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005# Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# serial 7
# AM_CONDITIONAL(NAME, SHELL-CONDITION)# -------------------------------------# Define a conditional.AC_DEFUN([AM_CONDITIONAL],[AC_PREREQ(2.52)dnl ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnlAC_SUBST([$1_TRUE])AC_SUBST([$1_FALSE])if $2; then $1_TRUE= $1_FALSE='#'else $1_TRUE='#' $1_FALSE=fiAC_CONFIG_COMMANDS_PRE([if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then AC_MSG_ERROR([[conditional "$1" was never defined.Usually this means the macro was only invoked conditionally.]])fi])])
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005# Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# serial 8
# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be# written in clear, in which case automake, when reading aclocal.m4,# will think it sees a *use*, and therefore will trigger all it's# C support machinery. Also note that it means that autoscan, seeing# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
# _AM_DEPENDENCIES(NAME)# ----------------------# See how the compiler implements dependency checking.# NAME is "CC", "CXX", "GCJ", or "OBJC".# We try a few techniques and use that to set a single cache variable.## We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular# dependency, and given that the user is not expected to run this macro,# just rely on AC_PROG_CC.AC_DEFUN([_AM_DEPENDENCIES],[AC_REQUIRE([AM_SET_DEPDIR])dnlAC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnlAC_REQUIRE([AM_MAKE_INCLUDE])dnlAC_REQUIRE([AM_DEP_TRACK])dnl
ifelse([$1], CC, [depcc="$CC" am_compiler_list=], [$1], CXX, [depcc="$CXX" am_compiler_list=], [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], [depcc="$$1" am_compiler_list=])
AC_CACHE_CHECK([dependency style of $depcc], [am_cv_$1_dependencies_compiler_type],[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named `D' -- because `-MD' means `put the output # in D'. mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub
am_cv_$1_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` fi for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with # Solaris 8's {/usr,}/bin/sh. touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
case $depmode in nosideeffect) # after this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; none) break ;; esac # We check with `-c' and `-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle `-M -o', and we need to detect this. if depmode=$depmode \ source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thusly: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_$1_dependencies_compiler_type=$depmode break fi fi done
cd .. rm -rf conftest.direlse am_cv_$1_dependencies_compiler_type=nonefi])AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])AM_CONDITIONAL([am__fastdep$1], [ test "x$enable_dependency_tracking" != xno \ && test "$am_cv_$1_dependencies_compiler_type" = gcc3])])
# AM_SET_DEPDIR# -------------# Choose a directory name for dependency files.# This macro is AC_REQUIREd in _AM_DEPENDENCIESAC_DEFUN([AM_SET_DEPDIR],[AC_REQUIRE([AM_SET_LEADING_DOT])dnlAC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl])
# AM_DEP_TRACK# ------------AC_DEFUN([AM_DEP_TRACK],[AC_ARG_ENABLE(dependency-tracking,[ --disable-dependency-tracking speeds up one-time build --enable-dependency-tracking do not reject slow dependency extractors])if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\'fiAM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])AC_SUBST([AMDEPBACKSLASH])])
# Generate code to set up dependency tracking. -*- Autoconf -*-
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005# Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
#serial 3
# _AM_OUTPUT_DEPENDENCY_COMMANDS# ------------------------------AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],[for mf in $CONFIG_FILES; do # Strip MF so we end up with the name of the file. mf=`echo "$mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile or not. # We used to match only the files named `Makefile.in', but # some people rename them; so instead we look at the file content. # Grep'ing the first line is not enough: some people post-process # each Makefile.in and add a new line on top of each file to say so. # So let's grep whole file. if grep '^#.*generated by automake' $mf > /dev/null 2>&1; then dirpart=`AS_DIRNAME("$mf")` else continue fi # Extract the definition of DEPDIR, am__include, and am__quote # from the Makefile without running `make'. DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` test -z "$DEPDIR" && continue am__include=`sed -n 's/^am__include = //p' < "$mf"` test -z "am__include" && continue am__quote=`sed -n 's/^am__quote = //p' < "$mf"` # When using ansi2knr, U may be empty or an underscore; expand it U=`sed -n 's/^U = //p' < "$mf"` # Find all dependency output files, they are included files with # $(DEPDIR) in their names. We invoke sed twice because it is the # simplest approach to changing $(DEPDIR) to its actual value in the # expansion. for file in `sed -n " s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do # Make sure the directory exists. test -f "$dirpart/$file" && continue fdir=`AS_DIRNAME(["$file"])` AS_MKDIR_P([$dirpart/$fdir]) # echo "creating $dirpart/$file" echo '# dummy' > "$dirpart/$file" donedone])# _AM_OUTPUT_DEPENDENCY_COMMANDS
# AM_OUTPUT_DEPENDENCY_COMMANDS# -----------------------------# This macro should only be invoked once -- use via AC_REQUIRE.## This code is only required when automatic dependency tracking# is enabled. FIXME. This creates each `.P' file that we will# need in order to bootstrap the dependency handling code.AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],[AC_CONFIG_COMMANDS([depfiles], [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])])
# Do all the work for Automake. -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005# Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# serial 12
# This macro actually does too much. Some checks are only needed if# your package does certain things. But this isn't really a big deal.
# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])# AM_INIT_AUTOMAKE([OPTIONS])# -----------------------------------------------# The call with PACKAGE and VERSION arguments is the old style# call (pre autoconf-2.50), which is being phased out. PACKAGE# and VERSION should now be passed to AC_INIT and removed from# the call to AM_INIT_AUTOMAKE.# We support both call styles for the transition. After# the next Automake release, Autoconf can make the AC_INIT# arguments mandatory, and then we can depend on a new Autoconf# release and drop the old call support.AC_DEFUN([AM_INIT_AUTOMAKE],[AC_PREREQ([2.58])dnldnl Autoconf wants to disallow AM_ names. We explicitly allowdnl the ones we care about.m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnlAC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnlAC_REQUIRE([AC_PROG_INSTALL])dnl# test to see if srcdir already configuredif test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then AC_MSG_ERROR([source directory already configured; run "make distclean" there first])fi
# test whether we have cygpathif test -z "$CYGPATH_W"; then if (cygpath --version) >/dev/null 2>/dev/null; then CYGPATH_W='cygpath -w' else CYGPATH_W=echo fifiAC_SUBST([CYGPATH_W])
# Define the identity of the package.dnl Distinguish between old-style and new-style calls.m4_ifval([$2],[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl AC_SUBST([PACKAGE], [$1])dnl AC_SUBST([VERSION], [$2])],[_AM_SET_OPTIONS([$1])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
_AM_IF_OPTION([no-define],,[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
# Some tools Automake needs.AC_REQUIRE([AM_SANITY_CHECK])dnlAC_REQUIRE([AC_ARG_PROGRAM])dnlAM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})AM_MISSING_PROG(AUTOCONF, autoconf)AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})AM_MISSING_PROG(AUTOHEADER, autoheader)AM_MISSING_PROG(MAKEINFO, makeinfo)AM_PROG_INSTALL_SHAM_PROG_INSTALL_STRIPAC_REQUIRE([AM_PROG_MKDIR_P])dnl# We need awk for the "check" target. The system "awk" is bad on# some platforms.AC_REQUIRE([AC_PROG_AWK])dnlAC_REQUIRE([AC_PROG_MAKE_SET])dnlAC_REQUIRE([AM_SET_LEADING_DOT])dnl_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], [_AM_PROG_TAR([v7])])])_AM_IF_OPTION([no-dependencies],,[AC_PROVIDE_IFELSE([AC_PROG_CC], [_AM_DEPENDENCIES(CC)], [define([AC_PROG_CC], defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnlAC_PROVIDE_IFELSE([AC_PROG_CXX], [_AM_DEPENDENCIES(CXX)], [define([AC_PROG_CXX], defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl])])
# When config.status generates a header, we must update the stamp-h file.# This file resides in the same directory as the config header# that is generated. The stamp files are numbered to have different names.
# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the# loop where config.status creates the headers, so we can generate# our stamp files there.AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],[# Compute $1's index in $config_headers._am_stamp_count=1for _am_header in $config_headers :; do case $_am_header in $1 | $1:* ) break ;; * ) _am_stamp_count=`expr $_am_stamp_count + 1` ;; esacdoneecho "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count])
# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# AM_PROG_INSTALL_SH# ------------------# Define $install_sh.AC_DEFUN([AM_PROG_INSTALL_SH],[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnlinstall_sh=${install_sh-"$am_aux_dir/install-sh"}AC_SUBST(install_sh)])
# Copyright (C) 2003, 2005 Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# serial 2
# Check whether the underlying file-system supports filenames# with a leading dot. For instance MS-DOS doesn't.AC_DEFUN([AM_SET_LEADING_DOT],[rm -rf .tst 2>/dev/nullmkdir .tst 2>/dev/nullif test -d .tst; then am__leading_dot=.else am__leading_dot=_firmdir .tst 2>/dev/nullAC_SUBST([am__leading_dot])])
# Check to see how 'make' treats includes. -*- Autoconf -*-
# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# serial 3
# AM_MAKE_INCLUDE()# -----------------# Check to see how make treats includes.AC_DEFUN([AM_MAKE_INCLUDE],[am_make=${MAKE-make}cat > confinc << 'END'am__doit: @echo done.PHONY: am__doitEND# If we don't find an include directive, just comment out the code.AC_MSG_CHECKING([for style of include used by $am_make])am__include="#"am__quote=_am_result=none# First try GNU make style include.echo "include confinc" > confmf# We grep out `Entering directory' and `Leaving directory'# messages which can occur if `w' ends up in MAKEFLAGS.# In particular we don't look at `^make:' because GNU make might# be invoked under some other name (usually "gmake"), in which# case it prints its new name instead of `make'.if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then am__include=include am__quote= _am_result=GNUfi# Now try BSD make style include.if test "$am__include" = "#"; then echo '.include "confinc"' > confmf if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then am__include=.include am__quote="\"" _am_result=BSD fifiAC_SUBST([am__include])AC_SUBST([am__quote])AC_MSG_RESULT([$_am_result])rm -f confinc confmf])
# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*-
# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2005# Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# serial 4
# AM_MISSING_PROG(NAME, PROGRAM)# ------------------------------AC_DEFUN([AM_MISSING_PROG],[AC_REQUIRE([AM_MISSING_HAS_RUN])$1=${$1-"${am_missing_run}$2"}AC_SUBST($1)])
# AM_MISSING_HAS_RUN# ------------------# Define MISSING if not defined so far and test if it supports --run.# If it does, set am_missing_run to use it, otherwise, to nothing.AC_DEFUN([AM_MISSING_HAS_RUN],[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnltest x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing"# Use eval to expand $SHELLif eval "$MISSING --run true"; then am_missing_run="$MISSING --run "else am_missing_run= AC_MSG_WARN([`missing' script is too old or missing])fi])
# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# AM_PROG_MKDIR_P# ---------------# Check whether `mkdir -p' is supported, fallback to mkinstalldirs otherwise.## Automake 1.8 used `mkdir -m 0755 -p --' to ensure that directories# created by `make install' are always world readable, even if the# installer happens to have an overly restrictive umask (e.g. 077).# This was a mistake. There are at least two reasons why we must not# use `-m 0755':# - it causes special bits like SGID to be ignored,# - it may be too restrictive (some setups expect 775 directories).## Do not use -m 0755 and let people choose whatever they expect by# setting umask.## We cannot accept any implementation of `mkdir' that recognizes `-p'.# Some implementations (such as Solaris 8's) are not thread-safe: if a# parallel make tries to run `mkdir -p a/b' and `mkdir -p a/c'# concurrently, both version can detect that a/ is missing, but only# one can create it and the other will error out. Consequently we# restrict ourselves to GNU make (using the --version option ensures# this.)AC_DEFUN([AM_PROG_MKDIR_P],[if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then # We used to keeping the `.' as first argument, in order to # allow $(mkdir_p) to be used without argument. As in # $(mkdir_p) $(somedir) # where $(somedir) is conditionally defined. However this is wrong # for two reasons: # 1. if the package is installed by a user who cannot write `.' # make install will fail, # 2. the above comment should most certainly read # $(mkdir_p) $(DESTDIR)$(somedir) # so it does not work when $(somedir) is undefined and # $(DESTDIR) is not. # To support the latter case, we have to write # test -z "$(somedir)" || $(mkdir_p) $(DESTDIR)$(somedir), # so the `.' trick is pointless. mkdir_p='mkdir -p --'else # On NextStep and OpenStep, the `mkdir' command does not # recognize any option. It will interpret all options as # directories to create, and then abort because `.' already # exists. for d in ./-p ./--version; do test -d $d && rmdir $d done # $(mkinstalldirs) is defined by Automake if mkinstalldirs exists. if test -f "$ac_aux_dir/mkinstalldirs"; then mkdir_p='$(mkinstalldirs)' else mkdir_p='$(install_sh) -d' fifiAC_SUBST([mkdir_p])])
# Helper functions for option handling. -*- Autoconf -*-
# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# serial 3
# _AM_MANGLE_OPTION(NAME)# -----------------------AC_DEFUN([_AM_MANGLE_OPTION],[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
# _AM_SET_OPTION(NAME)# ------------------------------# Set option NAME. Presently that only means defining a flag for this option.AC_DEFUN([_AM_SET_OPTION],[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
# _AM_SET_OPTIONS(OPTIONS)# ----------------------------------# OPTIONS is a space-separated list of Automake options.AC_DEFUN([_AM_SET_OPTIONS],[AC_FOREACH([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])# -------------------------------------------# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.AC_DEFUN([_AM_IF_OPTION],[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
# Check to make sure that the build environment is sane. -*- Autoconf -*-
# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005# Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# serial 4
# AM_SANITY_CHECK# ---------------AC_DEFUN([AM_SANITY_CHECK],[AC_MSG_CHECKING([whether build environment is sane])# Just in casesleep 1echo timestamp > conftest.file# Do `set' in a subshell so we don't clobber the current shell's# arguments. Must try -L first in case configure is actually a# symlink; some systems play weird games with the mod time of symlinks# (eg FreeBSD returns the mod time of the symlink's containing# directory).if ( set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null` if test "$[*]" = "X"; then # -L didn't work. set X `ls -t $srcdir/configure conftest.file` fi rm -f conftest.file if test "$[*]" != "X $srcdir/configure conftest.file" \ && test "$[*]" != "X conftest.file $srcdir/configure"; then
# If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a # broken ls alias from the environment. This has actually # happened. Such a system could not be considered "sane". AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a brokenalias in your environment]) fi
test "$[2]" = conftest.file )then # Ok. :else AC_MSG_ERROR([newly created file is older than distributed files!Check your system clock])fiAC_MSG_RESULT(yes)])
# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# AM_PROG_INSTALL_STRIP# ---------------------# One issue with vendor `install' (even GNU) is that you can't# specify the program used to strip binaries. This is especially# annoying in cross-compiling environments, where the build's strip# is unlikely to handle the host's binaries.# Fortunately install-sh will honor a STRIPPROG variable, so we# always use install-sh in `make install-strip', and initialize# STRIPPROG with the value of the STRIP variable (set by the user).AC_DEFUN([AM_PROG_INSTALL_STRIP],[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl# Installed binaries are usually stripped using `strip' when the user# run `make install-strip'. However `strip' might not be the right# tool to use in cross-compilation environments, therefore Automake# will honor the `STRIP' environment variable to overrule this program.dnl Don't test for $cross_compiling = yes, because it might be `maybe'.if test "$cross_compiling" != no; then AC_CHECK_TOOL([STRIP], [strip], :)fiINSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s"AC_SUBST([INSTALL_STRIP_PROGRAM])])
# Check how to create a tarball. -*- Autoconf -*-
# Copyright (C) 2004, 2005 Free Software Foundation, Inc.## This file is free software; the Free Software Foundation# gives unlimited permission to copy and/or distribute it,# with or without modifications, as long as this notice is preserved.
# serial 2
# _AM_PROG_TAR(FORMAT)# --------------------# Check how to create a tarball in format FORMAT.# FORMAT should be one of `v7', `ustar', or `pax'.## Substitute a variable $(am__tar) that is a command# writing to stdout a FORMAT-tarball containing the directory# $tardir.# tardir=directory && $(am__tar) > result.tar## Substitute a variable $(am__untar) that extract such# a tarball read from stdin.# $(am__untar) < result.tarAC_DEFUN([_AM_PROG_TAR],[# Always define AMTAR for backward compatibility.AM_MISSING_PROG([AMTAR], [tar])m4_if([$1], [v7], [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'], [m4_case([$1], [ustar],, [pax],, [m4_fatal([Unknown tar format])])AC_MSG_CHECKING([how to create a $1 tar archive])# Loop over all known methods to create a tar archive until one works._am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'_am_tools=${am_cv_prog_tar_$1-$_am_tools}# Do not fold the above two line into one, because Tru64 sh and# Solaris sh will not grok spaces in the rhs of `-'.for _am_tool in $_am_toolsdo case $_am_tool in gnutar) for _am_tar in tar gnutar gtar; do AM_RUN_LOG([$_am_tar --version]) && break done am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' am__untar="$_am_tar -xf -" ;; plaintar) # Must skip GNU tar: if it does not support --format= it doesn't create # ustar tarball either. (tar --version) >/dev/null 2>&1 && continue am__tar='tar chf - "$$tardir"' am__tar_='tar chf - "$tardir"' am__untar='tar xf -' ;; pax) am__tar='pax -L -x $1 -w "$$tardir"' am__tar_='pax -L -x $1 -w "$tardir"' am__untar='pax -r' ;; cpio) am__tar='find "$$tardir" -print | cpio -o -H $1 -L' am__tar_='find "$tardir" -print | cpio -o -H $1 -L' am__untar='cpio -i -H $1 -d' ;; none) am__tar=false am__tar_=false am__untar=false ;; esac
# If the value was cached, stop now. We just wanted to have am__tar # and am__untar set. test -n "${am_cv_prog_tar_$1}" && break
# tar/untar a dummy directory, and stop if the command works rm -rf conftest.dir mkdir conftest.dir echo GrepMe > conftest.dir/file AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) rm -rf conftest.dir if test -s conftest.tar; then AM_RUN_LOG([$am__untar <conftest.tar]) grep GrepMe conftest.dir/file >/dev/null 2>&1 && break fidonerm -rf conftest.dir
AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])AC_MSG_RESULT([$am_cv_prog_tar_$1])])AC_SUBST([am__tar])AC_SUBST([am__untar])]) # _AM_PROG_TAR
m4_include([m4/ax_boost_base.m4])12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to enable channel scorer */#undef ENABLE_CHANNEL_SCORER
/* define if the Boost library is available */#undef HAVE_BOOST
/* Define to 1 if you have the <inttypes.h> header file. */#undef HAVE_INTTYPES_H
/* flag for IRSTLM */#undef HAVE_IRSTLM
/* Define to 1 if you have the `gsl' library (-lgsl). */#undef HAVE_LIBGSL
/* Define to 1 if you have the `gslcblas' library (-lgslcblas). */#undef HAVE_LIBGSLCBLAS
/* Define to 1 if you have the `m' library (-lm). */#undef HAVE_LIBM
/* Define to 1 if you have the `z' library (-lz). */#undef HAVE_LIBZ
/* Define to 1 if you have the <memory.h> header file. */#undef HAVE_MEMORY_H
/* Define to 1 if the system has the type `ptrdiff_t'. */#undef HAVE_PTRDIFF_T
/* Define to 1 if you have the <stdint.h> header file. */#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */#undef HAVE_UNISTD_H
/* Name of package */#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */#undef PACKAGE_NAME
/* Define to the full name and version of this package. */#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */#undef PACKAGE_TARNAME
/* Define to the version of this package. */#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */#undef STDC_HEADERS
/* Version number of package */#undef VERSION
/* Define to `unsigned int' if <sys/types.h> does not define. */#undef size_t12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// memscore - in-memory phrase scoring for Statistical Machine Translation// Christian Hardmeier, FBK-irst, Trento, 2010// $Id$
#ifndef DATASTORAGE_H#define DATASTORAGE_H
#include "memscore.h"
template<class T>class DataStorage{private: T *base_; size_t pos_; size_t chunk_size_;
DataStorage() : base_(NULL), pos_(0) { int ps = getpagesize(); chunk_size_ = 10 * ps * sizeof(T); base_ = new T[chunk_size_]; }
DataStorage(const DataStorage &cc) { abort(); }
~DataStorage() {}
public: static DataStorage &get_instance() { static DataStorage<T> instance; return instance; }
T *alloc(size_t count) { if(count == 0) return NULL;
// The memory leak is intended. if(pos_ + count > chunk_size_) { base_ = new T[chunk_size_]; pos_ = 0; }
T *ret = base_ + pos_; pos_ += count; return ret; }};
#endif123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530#! /bin/sh# depcomp - compile a program generating dependencies as side-effects
scriptversion=2005-07-09.11
# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2, or (at your option)# any later version.
# This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA# 02110-1301, USA.
# As a special exception to the GNU General Public License, if you# distribute this file as part of a program that contains a# configuration script generated by Autoconf, you may include it under# the same distribution terms that you use for the rest of that program.
# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
case $1 in '') echo "$0: No command. Try \`$0 --help' for more information." 1>&2 exit 1; ;; -h | --h*) cat <<\EOFUsage: depcomp [--help] [--version] PROGRAM [ARGS]
Run PROGRAMS ARGS to compile a file, generating dependenciesas side-effects.
Environment variables: depmode Dependency tracking mode. source Source file read by `PROGRAMS ARGS'. object Object file output by `PROGRAMS ARGS'. DEPDIR directory where to store dependencies. depfile Dependency file to output. tmpdepfile Temporary file to use when outputing dependencies. libtool Whether libtool is used (yes/no).
Report bugs to <bug-automake@gnu.org>.EOF exit $? ;; -v | --v*) echo "depcomp $scriptversion" exit $? ;;esac
if test -z "$depmode" || test -z "$source" || test -z "$object"; then echo "depcomp: Variables source, object and depmode must be set" 1>&2 exit 1fi
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.depfile=${depfile-`echo "$object" | sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
rm -f "$tmpdepfile"
# Some modes work just like other modes, but use different flags. We# parameterize here, but still list the modes in the big case below,# to make depend.m4 easier to write. Note that we *cannot* use a case# here, because this file can only contain one case statement.if test "$depmode" = hp; then # HP compiler uses -M and no extra arg. gccflag=-M depmode=gccfi
if test "$depmode" = dashXmstdout; then # This is just like dashmstdout with a different argument. dashmflag=-xM depmode=dashmstdoutfi
case "$depmode" ingcc3)## gcc 3 implements dependency tracking that does exactly what## we want. Yay! Note: for some reason libtool 1.4 doesn't like## it if -MD -MP comes after the -MF stuff. Hmm. "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi mv "$tmpdepfile" "$depfile" ;;
gcc)## There are various ways to get dependency output from gcc. Here's## why we pick this rather obscure method:## - Don't want to use -MD because we'd like the dependencies to end## up in a subdir. Having to rename by hand is ugly.## (We might end up doing this anyway to support other compilers.)## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like## -MM, not -M (despite what the docs say).## - Using -M directly means running the compiler twice (even worse## than renaming). if test -z "$gccflag"; then gccflag=-MD, fi "$@" -Wp,"$gccflag$tmpdepfile" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" echo "$object : \\" > "$depfile" alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz## The second -e expression handles DOS-style file names with drive letters. sed -e 's/^[^:]*: / /' \ -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"## This next piece of magic avoids the `deleted header file' problem.## The problem is that when a header file which appears in a .P file## is deleted, the dependency causes make to die (because there is## typically no way to rebuild the header). We avoid this by adding## dummy dependencies for each header file. Too bad gcc doesn't do## this for us directly. tr ' ' '' < "$tmpdepfile" |## Some versions of gcc put a space before the `:'. On the theory## that the space means something, we add a space to the output as## well.## Some versions of the HPUX 10.20 sed can't process this invocation## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;;
hp) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;;
sgi) if test "$libtool" = yes; then "$@" "-Wp,-MDupdate,$tmpdepfile" else "$@" -MDupdate "$tmpdepfile" fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile"
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files echo "$object : \\" > "$depfile"
# Clip off the initial element (the dependent). Don't try to be # clever and replace this with sed code, as IRIX sed won't handle # lines with more than a fixed number of characters (4096 in # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; # the IRIX cc adds comments like `#:fec' to the end of the # dependency line. tr ' ' '' < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ tr '' ' ' >> $depfile echo >> $depfile
# The second pass generates a dummy entry for each header file. tr ' ' '' < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ >> $depfile else # The sourcefile does not contain any dependencies, so just # store a dummy comment line, to avoid errors with the Makefile # "include basename.Plo" scheme. echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;;
aix) # The C for AIX Compiler uses -M and outputs the dependencies # in a .u file. In older versions, this file always lives in the # current directory. Also, the AIX compiler puts `$object:' at the # start of each line; $object doesn't have directory information. # Version 6 uses the directory in both cases. stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'` tmpdepfile="$stripped.u" if test "$libtool" = yes; then "$@" -Wc,-M else "$@" -M fi stat=$?
if test -f "$tmpdepfile"; then : else stripped=`echo "$stripped" | sed 's,^.*/,,'` tmpdepfile="$stripped.u" fi
if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi
if test -f "$tmpdepfile"; then outname="$stripped.o" # Each line is of the form `foo.o: dependent.h'. # Do two passes, one to just change these to # `$object: dependent.h' and one to simply `dependent.h:'. sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile" sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" else # The sourcefile does not contain any dependencies, so just # store a dummy comment line, to avoid errors with the Makefile # "include basename.Plo" scheme. echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;;
icc) # Intel's C compiler understands `-MD -MF file'. However on # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c # ICC 7.0 will fill foo.d with something like # foo.o: sub/foo.c # foo.o: sub/foo.h # which is wrong. We want: # sub/foo.o: sub/foo.c # sub/foo.o: sub/foo.h # sub/foo.c: # sub/foo.h: # ICC 7.1 will output # foo.o: sub/foo.c sub/foo.h # and will wrap long lines using \ : # foo.o: sub/foo.c ... \ # sub/foo.h ... \ # ...
"$@" -MD -MF "$tmpdepfile" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" # Each line is of the form `foo.o: dependent.h', # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. # Do two passes, one to just change these to # `$object: dependent.h' and one to simply `dependent.h:'. sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" # Some versions of the HPUX 10.20 sed can't process this invocation # correctly. Breaking it into two sed invocations is a workaround. sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;;
tru64) # The Tru64 compiler uses -MD to generate dependencies as a side # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put # dependencies in `foo.d' instead, so we check for that too. # Subdirectories are respected. dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` test "x$dir" = "x$object" && dir= base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
if test "$libtool" = yes; then # With Tru64 cc, shared objects can also be used to make a # static library. This mecanism is used in libtool 1.4 series to # handle both shared and static libraries in a single compilation. # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. # # With libtool 1.5 this exception was removed, and libtool now # generates 2 separate objects for the 2 libraries. These two # compilations output dependencies in in $dir.libs/$base.o.d and # in $dir$base.o.d. We have to check for both files, because # one of the two compilations can be disabled. We should prefer # $dir$base.o.d over $dir.libs/$base.o.d because the latter is # automatically cleaned when .libs/ is deleted, while ignoring # the former would cause a distcleancheck panic. tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4 tmpdepfile2=$dir$base.o.d # libtool 1.5 tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5 tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504 "$@" -Wc,-MD else tmpdepfile1=$dir$base.o.d tmpdepfile2=$dir$base.d tmpdepfile3=$dir$base.d tmpdepfile4=$dir$base.d "$@" -MD fi
stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" exit $stat fi
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" do test -f "$tmpdepfile" && break done if test -f "$tmpdepfile"; then sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" # That's a tab and a space in the []. sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" else echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;;
#nosideeffect) # This comment above is used by automake to tell side-effect # dependency tracking mechanisms from slower ones.
dashmstdout) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout, regardless of -o. "$@" || exit $?
# Remove the call to Libtool. if test "$libtool" = yes; then while test $1 != '--mode=compile'; do shift done shift fi
# Remove `-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done
test -z "$dashmflag" && dashmflag=-M # Require at least two characters before searching for `:' # in the target name. This is to cope with DOS-style filenames: # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise. "$@" $dashmflag | sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" rm -f "$depfile" cat < "$tmpdepfile" > "$depfile" tr ' ' '' < "$tmpdepfile" | \## Some versions of the HPUX 10.20 sed can't process this invocation## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;;
dashXmstdout) # This case only exists to satisfy depend.m4. It is never actually # run, as this mode is specially recognized in the preamble. exit 1 ;;
makedepend) "$@" || exit $? # Remove any Libtool call if test "$libtool" = yes; then while test $1 != '--mode=compile'; do shift done shift fi # X makedepend shift cleared=no for arg in "$@"; do case $cleared in no) set ""; shift cleared=yes ;; esac case "$arg" in -D*|-I*) set fnord "$@" "$arg"; shift ;; # Strip any option that makedepend may not understand. Remove # the object too, otherwise makedepend will parse it as a source file. -*|$object) ;; *) set fnord "$@" "$arg"; shift ;; esac done obj_suffix="`echo $object | sed 's/^.*\././'`" touch "$tmpdepfile" ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" rm -f "$depfile" cat < "$tmpdepfile" > "$depfile" sed '1,2d' "$tmpdepfile" | tr ' ' '' | \## Some versions of the HPUX 10.20 sed can't process this invocation## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" "$tmpdepfile".bak ;;
cpp) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout. "$@" || exit $?
# Remove the call to Libtool. if test "$libtool" = yes; then while test $1 != '--mode=compile'; do shift done shift fi
# Remove `-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done
"$@" -E | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | sed '$ s: \\$::' > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" cat < "$tmpdepfile" >> "$depfile" sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;;
msvisualcpp) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout, regardless of -o, # because we must use -o when running libtool. "$@" || exit $? IFS=" " for arg do case "$arg" in "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") set fnord "$@" shift shift ;; *) set fnord "$@" "$arg" shift shift ;; esac done "$@" -E | sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" echo " " >> "$depfile" . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" rm -f "$tmpdepfile" ;;
none) exec "$@" ;;
*) echo "Unknown depmode $depmode" 1>&2 exit 1 ;;esac
exit 0
# Local Variables:# mode: shell-script# sh-indentation: 2# eval: (add-hook 'write-file-hooks 'time-stamp)# time-stamp-start: "scriptversion="# time-stamp-format: "%:y-%02m-%02d.%02H"# time-stamp-end: "$"# End:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323#!/bin/sh# install - install a program, script, or datafile
scriptversion=2005-05-14.22
# This originates from X11R5 (mit/util/scripts/install.sh), which was# later released in X11R6 (xc/config/util/install.sh) with the# following copyright and license.## Copyright (C) 1994 X Consortium## Permission is hereby granted, free of charge, to any person obtaining a copy# of this software and associated documentation files (the "Software"), to# deal in the Software without restriction, including without limitation the# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or# sell copies of the Software, and to permit persons to whom the Software is# furnished to do so, subject to the following conditions:## The above copyright notice and this permission notice shall be included in# all copies or substantial portions of the Software.## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.## Except as contained in this notice, the name of the X Consortium shall not# be used in advertising or otherwise to promote the sale, use or other deal-# ings in this Software without prior written authorization from the X Consor-# tium.### FSF changes to this file are in the public domain.## Calling this script install-sh is preferred over install.sh, to prevent# `make' implicit rules from creating a file called install from it# when there is no Makefile.## This script is compatible with the BSD install script, but was written# from scratch. It can only install one file at a time, a restriction# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"cpprog="${CPPROG-cp}"chmodprog="${CHMODPROG-chmod}"chownprog="${CHOWNPROG-chown}"chgrpprog="${CHGRPPROG-chgrp}"stripprog="${STRIPPROG-strip}"rmprog="${RMPROG-rm}"mkdirprog="${MKDIRPROG-mkdir}"
chmodcmd="$chmodprog 0755"chowncmd=chgrpcmd=stripcmd=rmcmd="$rmprog -f"mvcmd="$mvprog"src=dst=dir_arg=dstarg=no_target_directory=
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES...
In the 1st form, copy SRCFILE to DSTFILE.In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.In the 4th, create DIRECTORIES.
Options:-c (ignored)-d create directories instead of installing files.-g GROUP $chgrpprog installed files to GROUP.-m MODE $chmodprog installed files to MODE.-o USER $chownprog installed files to USER.-s $stripprog installed files.-t DIRECTORY install into DIRECTORY.-T report an error if DSTFILE is a directory.--help display this help and exit.--version display version info and exit.
Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG"
while test -n "$1"; do case $1 in -c) shift continue;;
-d) dir_arg=true shift continue;;
-g) chgrpcmd="$chgrpprog $2" shift shift continue;;
--help) echo "$usage"; exit $?;;
-m) chmodcmd="$chmodprog $2" shift shift continue;;
-o) chowncmd="$chownprog $2" shift shift continue;;
-s) stripcmd=$stripprog shift continue;;
-t) dstarg=$2 shift shift continue;;
-T) no_target_directory=true shift continue;;
--version) echo "$0 $scriptversion"; exit $?;;
*) # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. test -n "$dir_arg$dstarg" && break # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dstarg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dstarg" shift # fnord fi shift # arg dstarg=$arg done break;; esacdone
if test -z "$1"; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call `install-sh -d' without argument. # This can happen when creating conditional directories. exit 0fi
for srcdo # Protect names starting with `-'. case $src in -*) src=./$src ;; esac
if test -n "$dir_arg"; then dst=$src src=
if test -d "$dst"; then mkdircmd=: chmodcmd= else mkdircmd=$mkdirprog fi else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi
if test -z "$dstarg"; then echo "$0: no destination specified." >&2 exit 1 fi
dst=$dstarg # Protect names starting with `-'. case $dst in -*) dst=./$dst ;; esac
# If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then if test -n "$no_target_directory"; then echo "$0: $dstarg: Is a directory" >&2 exit 1 fi dst=$dst/`basename "$src"` fi fi
# This sed command emulates the dirname command. dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# Skip lots of stat calls in the usual case. if test ! -d "$dstdir"; then defaultIFS=' ' IFS="${IFS-$defaultIFS}"
oIFS=$IFS # Some sh's can't handle IFS=/ for some reason. IFS='%' set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` shift IFS=$oIFS
pathcomp=
while test $# -ne 0 ; do pathcomp=$pathcomp$1 shift if test ! -d "$pathcomp"; then $mkdirprog "$pathcomp" # mkdir can fail with a `File exist' error in case several # install-sh are creating the directory concurrently. This # is OK. test -d "$pathcomp" || exit fi pathcomp=$pathcomp/ done fi
if test -n "$dir_arg"; then $doit $mkdircmd "$dst" \ && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
else dstfile=`basename "$dst"`
# Make a couple of temp file names in the proper directory. dsttmp=$dstdir/_inst.$$_ rmtmp=$dstdir/_rm.$$_
# Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 trap '(exit $?); exit' 1 2 13 15
# Copy the file name to the temp name. $doit $cpprog "$src" "$dsttmp" &&
# and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
# Now rename the file to the real destination. { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \ || { # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f.
# Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { if test -f "$dstdir/$dstfile"; then $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \ || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ || { echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 (exit 1); exit 1 } else : fi } &&
# Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" } } fi || { (exit 1); exit 1; }done
# The final little trick to "correctly" pass the exit status to the exit trap.{ (exit 0); exit 0}
# Local variables:# eval: (add-hook 'write-file-hooks 'time-stamp)# time-stamp-start: "scriptversion="# time-stamp-format: "%:y-%02m-%02d.%02H"# time-stamp-end: "$"# End:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183/* * File: lexdecom.cpp * Author: Felipe Sánchez-Martínez, Universitat d'Alacant <fsanchez@dlsi.ua.es> * * Created on 2010/01/27 */
#include "lexdecom.h"#include "scorer-impl.h"
#include <iostream>#include <fstream>
PhraseScorer*LexicalDecompositionPhraseScorer::create_scorer(const char *argv[], int &argp, bool reverse, const PhraseScorerFactory &ptf){
if(argv[argp] == NULL) usage();
String lwfile(argv[argp++]);
return new LexicalDecompositionPhraseScorer(ptf.get_phrase_table(), reverse, lwfile, argv, argp, ptf);}
LexicalDecompositionPhraseScorer::LexicalDecompositionPhraseScorer(PhraseTable &pd, bool reverse, const String &weightfile, const char *argv[], int &argp, const PhraseScorerFactory &ptf) : PhraseScorer(pd, reverse){
black_box_scorer = AbsoluteDiscountPhraseScorer::create_scorer(argv, argp, reverse, ptf);
std::ifstream wfile(weightfile.c_str());
//Code copied from LexicalWeightPhraseScorer; it should be factored !! -- 2010/01/27
std::cerr<<"Reading lexical weights from '"<<weightfile<<"' ... ";
while(!wfile.eof()) { if(wfile.fail()) { std::cerr << "Problem reading file: " << weightfile << std::endl; exit(1); } String src, tgt; Score weight;
wfile >> src >> tgt >> weight; Count src_id = PhraseText::index_word(src); Count tgt_id = PhraseText::index_word(tgt); weight_map_.insert(std::make_pair(std::make_pair(src_id, tgt_id), weight)); }
wfile.close(); std::cerr<<"done."<<std::endl;}
ScoreLexicalDecompositionPhraseScorer::get_weight(const String &s_src, const String &s_tgt) const{ //Code copied from LexicalWeightPhraseScorer; it should be factored !! -- 2010/01/27
Count src = PhraseText::index_word(s_src); Count tgt = PhraseText::index_word(s_tgt); return get_weight(src, tgt);}
inline ScoreLexicalDecompositionPhraseScorer::get_weight(Count src, Count tgt) const{ //Code copied from LexicalWeightPhraseScorer; it should be factored !! -- 2010/01/27
WeightMapType_::const_iterator it = weight_map_.find(std::make_pair(src, tgt)); if(it == weight_map_.end()) return 0.00001; // default value copied from Philipp Koehn's scorer return it->second;}
voidLexicalDecompositionPhraseScorer::do_score_phrases(){
//Estimate p(J|I) = p(src_len|tgt_len)
black_box_scorer->score_phrases();
std::cerr<<"LexicalDecompositionPhraseScorer::do_score_phrases"<<std::endl;
std::map<unsigned, std::map<unsigned, Count> > count_srclen_tgtlen; std::map<unsigned, Count> total_tgtlen;
for(PhraseTable::iterator it = phrase_table_.begin(); it != phrase_table_.end(); it++) { const PhrasePairInfo &ppair = *it; PhraseInfo &src = phrase_table_.get_src_phrase(ppair.get_src()); PhraseInfo &tgt = phrase_table_.get_tgt_phrase(ppair.get_tgt()); unsigned src_len = src.get_phrase().size(); unsigned tgt_len = tgt.get_phrase().size();
/*//Debug code for (unsigned i=0; i<src_len; i++) std::cerr<<src.get_phrase().word(i)<<" "; std::cerr<<"-> "<<src_len<<" ||| "; for (unsigned i=0; i<tgt_len; i++) std::cerr<<tgt.get_phrase().word(i)<<" "; std::cerr<<"-> "<<tgt_len<<std::endl; */
count_srclen_tgtlen[src_len][tgt_len]+=ppair.get_count(); total_tgtlen[tgt_len]+=ppair.get_count(); }
std::map<unsigned, std::map<unsigned, Count> >::iterator its; std::map<unsigned, Count>::iterator itt;
for (its=count_srclen_tgtlen.begin(); its!=count_srclen_tgtlen.end(); its++) { unsigned src_len=its->first;
for(itt=its->second.begin(); itt!=its->second.end(); itt++) { unsigned tgt_len=itt->first; Count cnt=itt->second; prob_srclen_tgtlen_[src_len][tgt_len] = static_cast<Score>(cnt)/static_cast<Score>(total_tgtlen[tgt_len]); } }}
ScoreLexicalDecompositionPhraseScorer::get_noisy_or_combination(Count src_word, PhraseInfo &tgt_phrase){
Score sc=1.0;
unsigned tgt_len=tgt_phrase.get_phrase().size();
for(unsigned i=0; i<tgt_len; i++) { Count tgt_word=tgt_phrase.get_phrase()[i]; sc *= (1.0 - get_weight(src_word, tgt_word)); }
return (1.0 - sc);}
ScoreLexicalDecompositionPhraseScorer::do_get_score(const PhraseTable::const_iterator &it){
/* The implementation of this method relies on the asumption that the smoothed probabilities produced by AbsoluteDiscountPhraseScorer are deficient. */
PhraseInfo &src_phrase = phrase_table_.get_src_phrase(it->get_src()); PhraseInfo &tgt_phrase = phrase_table_.get_tgt_phrase(it->get_tgt());
unsigned src_len=src_phrase.get_phrase().size(); unsigned tgt_len=tgt_phrase.get_phrase().size();
Score prod=1.0;
for(unsigned j=0; j<src_len; j++) prod *= get_noisy_or_combination(src_phrase.get_phrase()[j], tgt_phrase);
Score lambda= static_cast<Score>(black_box_scorer->get_discount()) * tgt_phrase.get_distinct() / tgt_phrase.get_count();
Score ret_value = black_box_scorer->get_score(it) + (lambda * prod * prob_srclen_tgtlen_[src_len][tgt_len]);
/* //Debug code for (unsigned i=0; i<src_len; i++) std::cerr<<src_phrase.get_phrase().word(i)<<" "; std::cerr<<" ||| "; for (unsigned i=0; i<tgt_len; i++) std::cerr<<tgt_phrase.get_phrase().word(i)<<" "; std::cerr<<"==> discount: "<<black_box_scorer->get_discount()<<"; black box score: "<<black_box_scorer->get_score(it) <<"; lambda: "<<lambda<<"; prod: " <<prod<<"; prob_srclen_tgtlen_["<<src_len<<"]["<<tgt_len<<"]: "<<prob_srclen_tgtlen_[src_len][tgt_len] <<"; count: "<<it->get_count()<<"; score: "<<ret_value; std::cerr<<std::endl; */
return ret_value;}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263// memscore - in-memory phrase scoring for Statistical Machine Translation// Christian Hardmeier, FBK-irst, Trento, 2010// $Id$
#include <cmath>#include <iostream>#include <fstream>#include <sstream>#include <string>
#include <n_gram.h>#include <lmtable.h>
#include "phrasetable.h"#include "phraselm.h"
void PhraseLanguageModel::attach(PhraseInfoList &pilist){ phrase_info_list_ = &pilist; score_idx_ = pilist.register_data(1);}
void PhraseLanguageModel::compute_statistic(){ compute_lmscores(*phrase_info_list_, false);}
void PhraseLanguageModel::compute_lmscores(PhraseInfoList &phrase_info_list, bool closed_world){ lmtable lm; std::ifstream lmstream(lmfile_.c_str()); lm.load(lmstream, lmfile_.c_str(), NULL, 0); lm.setlogOOVpenalty(10000000);
assert(!computation_done_);
Score marginal_score = .0; for(PhraseInfoList::iterator it = phrase_info_list.begin(); it != phrase_info_list.end(); ++it) { PhraseInfo &pi = *it; ngram ng(lm.getDict()); Score lmscore = 0; for(PhraseText::const_string_iterator it = pi.get_phrase().string_begin(); it != pi.get_phrase().string_end(); it++) { ng.pushw(it->c_str()); lmscore += lm.clprob(ng); }
pi.data(score_idx_) = exp10(lmscore); marginal_score += pi.data(score_idx_); }
if(closed_world) for(PhraseInfoList::iterator it = phrase_info_list.begin(); it != phrase_info_list.end(); ++it) { PhraseInfo &pi = *it; pi.data(score_idx_) /= marginal_score; }
computation_done_ = true;}
void ClosedPhraseLanguageModel::compute_statistic(){ compute_lmscores(*phrase_info_list_, true);}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710// memscore - in-memory phrase scoring for Statistical Machine Translation// Christian Hardmeier, FBK-irst, Trento, 2010// $Id$
#ifndef PHRASETABLE_H#define PHRASETABLE_H
#include <cassert>#include <iostream>#include <iterator>#include <list>#include <map>#include <set>#include <string>#include <vector>
#include <boost/bimap.hpp>#include <boost/dynamic_bitset.hpp>#include <boost/iterator/transform_iterator.hpp>#include <boost/pool/object_pool.hpp>#include <boost/pool/pool_alloc.hpp>#include <boost/ptr_container/ptr_vector.hpp>#include <boost/tuple/tuple.hpp>#include <boost/tuple/tuple_comparison.hpp>
#include "datastorage.h"#include "memscore.h"
class PhraseText{ friend std::ostream &operator<<(std::ostream &os, const PhraseText &pt);
private: typedef boost::ptr_vector<Count,boost::view_clone_allocator> WordListType_; typedef boost::bimap<String,Count> DictionaryType_;
WordListType_ word_list_;
static DictionaryType_ dictionary_; static Count last_id_;
typedef const String &(*LookupFunction_)(Count id);
public: typedef WordListType_::const_iterator const_iterator; typedef boost::transform_iterator<LookupFunction_,WordListType_::const_iterator> const_string_iterator; typedef WordListType_::size_type size_type;
PhraseText(const String &s);
const_iterator begin() const { return word_list_.begin(); }
const_iterator end() const { return word_list_.end(); }
const_string_iterator string_begin() const { return boost::make_transform_iterator(word_list_.begin(), dictionary_lookup); }
const_string_iterator string_end() const { return boost::make_transform_iterator(word_list_.end(), dictionary_lookup); }
Count operator[](size_type i) const { return word_list_[i]; }
const String &word(size_type i) const { return dictionary_lookup(operator[](i)); }
size_type size() const { return word_list_.size(); }
static const String &dictionary_lookup(Count id) { DictionaryType_::right_const_iterator it = dictionary_.right.find(id); assert(it != dictionary_.right.end()); return it->second; }
static Count index_word(const String &word) { Count id; DictionaryType_::left_const_iterator it = dictionary_.left.find(word); if(it != dictionary_.left.end()) id = it->second; else { id = last_id_++; dictionary_.insert(DictionaryType_::value_type(word, id)); } return id; }};
class PhraseInfo{ friend class boost::object_pool<PhraseInfo>; friend std::ostream &operator<<(std::ostream &os, const PhraseInfo &pt);
protected: Count data_size_;
Count count_; Count distinct_; PhraseText phrase_; Score *data_;
Count n1_; Count n2_; Count n3plus_;
PhraseInfo(Count data_size, const String &phrase) : data_size_(data_size), count_(0), distinct_(0), phrase_(phrase), n1_(0), n2_(0), n3plus_(0) { data_ = DataStorage<Score>::get_instance().alloc(data_size_); }
public: Score &data(Count base, Count i = 0) { assert(base + i < data_size_); return *(data_ + base + i); }
const Score &data(Count base, Count i = 0) const { assert(base + i < data_size_); return *(data_ + base + i); }
Count get_count() const { return count_; }
void inc_count() { count_++; }
Count get_distinct() const { return distinct_; }
void inc_distinct() { distinct_++; }
const PhraseText &get_phrase() const { return phrase_; }
void inc_n1() { n1_++; }
Count get_n1() { return n1_; }
void inc_n2() { n2_++; }
Count get_n2() { return n2_; }
void inc_n3plus() { n3plus_++; }
Count get_n3plus() { return n3plus_; }
};
inline std::ostream &operator<<(std::ostream &os, const PhraseInfo &pt){ return os << pt.get_phrase();}
class PhraseInfoList{protected: typedef std::map<String,Phrase> IDMapType_; typedef boost::ptr_vector<PhraseInfo,boost::view_clone_allocator> ListType_; //typedef std::vector<PhraseInfo *,boost::pool_allocator<PhraseInfo *> > ListType_; //typedef std::vector<PhraseInfo> ListType_; typedef std::list<PhraseStatistic *> StatListType_;
IDMapType_ idmap_; ListType_ list_; StatListType_ statistics_; boost::object_pool<PhraseInfo> phrase_info_pool_;
Count data_size_;public: typedef ListType_::iterator iterator; typedef ListType_::const_iterator const_iterator; typedef ListType_::size_type size_type;
PhraseInfoList() : data_size_(0) {}
Phrase index_phrase(const String &s_phr); DataIndex register_data(Count size); void attach_statistic(PhraseStatistic &s); void compute_statistics();
PhraseInfo &operator[](Phrase phr) { return list_[phr]; }
iterator begin() { return list_.begin(); }
iterator end() { return list_.end(); }
const_iterator begin() const { return list_.begin(); }
const_iterator end() const { return list_.end(); }
size_type size() const { return list_.size(); }
};
class PhraseAlignment{ friend std::ostream &operator<<(std::ostream &os, const PhraseAlignment &pa);
private: class Alignment { friend std::ostream &operator<<(std::ostream &os, const Alignment &pa);
private: typedef boost::tuple<Count,Count,String> AlignmentTuple_; typedef std::map<AlignmentTuple_,Count> AlignmentMapType_; typedef std::vector<const Alignment *> AlignmentVectorType_;
static AlignmentMapType_ alignment_map_; static AlignmentVectorType_ alignment_vector_;
Count slen_, tlen_; boost::dynamic_bitset<unsigned int> matrix_;
Alignment(Count slen, Count tlen, const String &alignment);
public: bool is_aligned(Count s, Count t) const { assert(t < tlen_); assert(s < slen_); return matrix_[t * slen_ + s]; }
Count get_source_length() const { return slen_; }
Count get_target_length() const { return tlen_; }
bool operator<(const Alignment &pa) const { if(slen_ < pa.slen_) return true; if(tlen_ < pa.tlen_) return true; return (matrix_ < pa.matrix_); }
static Count index_alignment(Count slen, Count tlen, const String &alignment);
static const Alignment *find(Count index) { return alignment_vector_[index]; } }; friend std::ostream &operator<<(std::ostream &os, const Alignment &pa);
const Alignment *alignment_; bool reverse_;
public: PhraseAlignment(Count index, bool reverse = false) : alignment_(Alignment::find(index)), reverse_(reverse) {}
bool is_aligned(Count s, Count t) const { if(!reverse_) return alignment_->is_aligned(s, t); else return alignment_->is_aligned(t, s); }
Count get_source_length() const { if(!reverse_) return alignment_->get_source_length(); else return alignment_->get_target_length(); }
Count get_target_length() const { if(!reverse_) return alignment_->get_target_length(); else return alignment_->get_source_length(); }
static Count index_alignment(Count slen, Count tlen, const String &alignment) { return Alignment::index_alignment(slen, tlen, alignment); }};
typedef std::map<PhrasePair,PhrasePairData> PhrasePairCounts;
class PhrasePairInfo{protected: static const Count CONTINUATION_BIT;
static bool init_phase_; static Count data_nscores_; static Count data_ncounts_;
enum { COUNT_COUNT_IDX = 0, COUNT_FREE_IDX }; // COUNT_FREE_IDX must remain last! enum { SCORE_FREE_IDX = 0 }; // SCORE_FREE_IDX must remain last!
Phrase src_, tgt_; PhrasePairData data_; bool reverse_;
void realloc_data(Count nalignments);
public: typedef std::vector<std::pair<PhraseAlignment,Count> > AlignmentVector;
static DataIndex register_score_data(Count size); static DataIndex register_count_data(Count size);
PhrasePairInfo(Count src, Count tgt, Count alignment, Count count);
PhrasePairInfo(Count src, Count tgt, PhrasePairData data, bool reverse = false) : src_(src), tgt_(tgt), data_(data), reverse_(reverse) { init_phase_ = false; }
PhrasePairInfo(const PhrasePairCounts::const_iterator &in) : src_(in->first.first), tgt_(in->first.second), data_(in->second), reverse_(false) {}
PhrasePairData get_phrase_pair_data() { return data_; }
Phrase get_src() const { return !reverse_ ? src_ : tgt_; }
Phrase get_tgt() const { return !reverse_ ? tgt_ : src_; }
Count get_count() const { return count_data(COUNT_COUNT_IDX); }
Score &score_data(DataIndex base, DataIndex index = 0) { return score_data(data_, base, index); }
const Score &score_data(DataIndex base, DataIndex index = 0) const { return score_data(data_, base, index); }
Count &count_data(DataIndex base, DataIndex index = 0) { return count_data(data_, base, index); }
const Count &count_data(DataIndex base, DataIndex index = 0) const { return count_data(data_, base, index); }
void inc_count() { count_data(data_, COUNT_COUNT_IDX)++; }
AlignmentVector get_alignments() const; void add_alignment(Count alignment);
private: static Score &score_data(PhrasePairData data, DataIndex base, DataIndex index = 0) { return *reinterpret_cast<Score *>(data + (base + index) * sizeof(Score)); }
static Count &count_data(PhrasePairData data, DataIndex base, DataIndex index = 0) { return *reinterpret_cast<Count *>(data + data_nscores_ * sizeof(Score) + (base + index) * sizeof(Count)); }
static const Count COUNTS_PER_ALIGNMENT = 2;
static Count *alignment_data(PhrasePairData data, Count index) { return reinterpret_cast<Count *>(data + data_nscores_ * sizeof(Score) + data_ncounts_ * sizeof(Count) + COUNTS_PER_ALIGNMENT * index * sizeof(Count)); }
Count *alignment_data(Count index) { return alignment_data(data_, index); }
const Count *alignment_data(Count index) const { return alignment_data(data_, index); }};
class PhraseTable{public: typedef PhrasePairInfo value_type;
protected: typedef std::iterator_traits<PhrasePairCounts::iterator>::value_type InputEntry_; typedef value_type (*EntryTransformer_)(InputEntry_);
static value_type pass_entry(InputEntry_ in) { return PhrasePairInfo(in.first.first, in.first.second, in.second, false); }
static value_type swap_src_tgt(InputEntry_ in) { return PhrasePairInfo(in.first.first, in.first.second, in.second, true); }
public: typedef boost::transform_iterator<EntryTransformer_,PhrasePairCounts::iterator> iterator; typedef boost::transform_iterator<EntryTransformer_,PhrasePairCounts::const_iterator> const_iterator;
virtual ~PhraseTable() {}
virtual PhraseInfo &get_src_phrase(Phrase src) = 0; virtual Count n_src_phrases() const = 0; virtual PhraseInfo &get_tgt_phrase(Phrase tgt) = 0; virtual Count n_tgt_phrases() const = 0; virtual PhrasePairCounts &get_joint_counts() = 0; virtual void attach_src_statistic(PhraseStatistic &s) = 0; virtual void attach_tgt_statistic(PhraseStatistic &s) = 0; virtual void compute_phrase_statistics() = 0; virtual DataIndex register_src_data(Count n) = 0; virtual DataIndex register_tgt_data(Count n) = 0; virtual PhraseTable &reverse() = 0;
virtual iterator begin() = 0; virtual iterator end() = 0; virtual iterator find(PhrasePair p) = 0; virtual iterator find(const PhrasePairCounts::iterator &it) = 0;
virtual const_iterator begin() const = 0; virtual const_iterator end() const = 0; virtual const_iterator find(PhrasePair p) const = 0; virtual const_iterator find(const PhrasePairCounts::const_iterator &it) const = 0;
virtual PhrasePairCounts::iterator raw_begin() = 0; virtual PhrasePairCounts::iterator raw_end() = 0; virtual PhrasePairCounts::iterator raw_find(PhrasePair p) = 0;
virtual PhrasePairCounts::const_iterator raw_begin() const = 0; virtual PhrasePairCounts::const_iterator raw_end() const = 0; virtual PhrasePairCounts::const_iterator raw_find(PhrasePair p) const = 0;
/* static iterator swap_iterator(const iterator &it) { if(it.functor() == swap_src_tgt) return boost::make_transform_iterator(it.base(), pass_entry); else if(it.functor() == pass_entry) return boost::make_transform_iterator(it.base(), swap_src_tgt); else abort(); }
static const_iterator swap_iterator(const const_iterator &it) { if(it.functor() == swap_src_tgt) return boost::make_transform_iterator(it.base(), pass_entry); else if(it.functor() == pass_entry) return boost::make_transform_iterator(it.base(), swap_src_tgt); else abort(); } */};
class ReversePhraseTable : public PhraseTable{protected: PhraseTable &phrase_table_;
public: ReversePhraseTable(PhraseTable &phrase_table) : phrase_table_(phrase_table) {}
virtual PhraseInfo &get_src_phrase(Phrase src) { return phrase_table_.get_tgt_phrase(src); }
virtual Count n_src_phrases() const { return phrase_table_.n_tgt_phrases(); }
virtual PhraseInfo &get_tgt_phrase(Phrase tgt) { return phrase_table_.get_src_phrase(tgt); }
virtual Count n_tgt_phrases() const { return phrase_table_.n_src_phrases(); }
virtual PhrasePairCounts &get_joint_counts() { return phrase_table_.get_joint_counts(); }
virtual void attach_src_statistic(PhraseStatistic &s) { return phrase_table_.attach_tgt_statistic(s); }
virtual void attach_tgt_statistic(PhraseStatistic &s) { return phrase_table_.attach_src_statistic(s); }
virtual void compute_phrase_statistics() { phrase_table_.compute_phrase_statistics(); }
virtual DataIndex register_src_data(Count n) { return phrase_table_.register_tgt_data(n); }
virtual DataIndex register_tgt_data(Count n) { return phrase_table_.register_src_data(n); }
virtual PhraseTable &reverse() { return phrase_table_; }
virtual iterator begin() { return boost::make_transform_iterator(phrase_table_.raw_begin(), swap_src_tgt); }
virtual iterator end() { return boost::make_transform_iterator(raw_end(), swap_src_tgt); }
virtual iterator find(PhrasePair p) { return boost::make_transform_iterator(raw_find(p), swap_src_tgt); }
virtual iterator find(const PhrasePairCounts::iterator &it) { return boost::make_transform_iterator(it, swap_src_tgt); }
virtual const_iterator begin() const { return boost::make_transform_iterator(phrase_table_.raw_begin(), swap_src_tgt); }
virtual const_iterator end() const { return boost::make_transform_iterator(raw_end(), swap_src_tgt); }
virtual const_iterator find(PhrasePair p) const { return boost::make_transform_iterator(raw_find(p), swap_src_tgt); }
virtual const_iterator find(const PhrasePairCounts::const_iterator &it) const { return boost::make_transform_iterator(it, swap_src_tgt); }
virtual PhrasePairCounts::iterator raw_begin() { return phrase_table_.raw_begin(); }
virtual PhrasePairCounts::iterator raw_end() { return phrase_table_.raw_end(); }
virtual PhrasePairCounts::iterator raw_find(PhrasePair p) { return phrase_table_.raw_find(std::make_pair(p.second, p.first)); }
virtual PhrasePairCounts::const_iterator raw_begin() const { return phrase_table_.raw_begin(); }
virtual PhrasePairCounts::const_iterator raw_end() const { return phrase_table_.raw_end(); }
virtual PhrasePairCounts::const_iterator raw_find(PhrasePair p) const { return phrase_table_.raw_find(std::make_pair(p.second, p.first)); }};
class MemoryPhraseTable : public PhraseTable{protected: PhraseInfoList src_info_; PhraseInfoList tgt_info_; PhrasePairCounts joint_counts_;
ReversePhraseTable reverse_;
public: MemoryPhraseTable() : reverse_(*this) {}
void load_data(std::istream &instream);
virtual PhraseInfo &get_src_phrase(Phrase src) { assert(src < src_info_.size()); return src_info_[src]; }
virtual Count n_src_phrases() const { return src_info_.size(); }
virtual PhraseInfo &get_tgt_phrase(Phrase tgt) { assert(tgt < tgt_info_.size()); return tgt_info_[tgt]; }
virtual Count n_tgt_phrases() const { return tgt_info_.size(); }
virtual PhrasePairCounts &get_joint_counts() { return joint_counts_; }
virtual void attach_src_statistic(PhraseStatistic &s); virtual void attach_tgt_statistic(PhraseStatistic &s); virtual void compute_phrase_statistics();
virtual DataIndex register_src_data(Count n) { return src_info_.register_data(n); }
virtual DataIndex register_tgt_data(Count n) { return tgt_info_.register_data(n); }
virtual PhraseTable &reverse() { return reverse_; }
virtual iterator begin() { return boost::make_transform_iterator(raw_begin(), pass_entry); }
virtual iterator end() { return boost::make_transform_iterator(raw_end(), pass_entry); }
virtual iterator find(PhrasePair p) { return boost::make_transform_iterator(raw_find(p), pass_entry); }
virtual iterator find(const PhrasePairCounts::iterator &it) { return boost::make_transform_iterator(it, pass_entry); }
virtual const_iterator begin() const { return boost::make_transform_iterator(raw_begin(), pass_entry); }
virtual const_iterator end() const { return boost::make_transform_iterator(raw_end(), pass_entry); }
virtual const_iterator find(PhrasePair p) const { return boost::make_transform_iterator(raw_find(p), pass_entry); }
virtual const_iterator find(const PhrasePairCounts::const_iterator &it) const { return boost::make_transform_iterator(it, pass_entry); }
virtual PhrasePairCounts::iterator raw_begin() { return joint_counts_.begin(); }
virtual PhrasePairCounts::iterator raw_end() { return joint_counts_.end(); }
virtual PhrasePairCounts::iterator raw_find(PhrasePair p) { return joint_counts_.find(p); }
virtual PhrasePairCounts::const_iterator raw_begin() const { return joint_counts_.begin(); }
virtual PhrasePairCounts::const_iterator raw_end() const { return joint_counts_.end(); }
virtual PhrasePairCounts::const_iterator raw_find(PhrasePair p) const { return joint_counts_.find(p); }};
#endif123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124// memscore - in-memory phrase scoring for Statistical Machine Translation// Christian Hardmeier, FBK-irst, Trento, 2010// $Id$
#ifndef SCORER_IMPL_H#define SCORER_IMPL_H
#include "phrasetable.h"#include "scorer.h"
class MLPhraseScorer : public PhraseScorer{private: explicit MLPhraseScorer(PhraseTable &pd, bool reverse) : PhraseScorer(pd, reverse) {}
virtual void do_score_phrases(); virtual Score do_get_score(const PhraseTable::const_iterator &it);
public: static PhraseScorer *create_scorer(const char *argv[], int &argp, bool reverse, const PhraseScorerFactory &ptf);};
class WittenBellPhraseScorer : public PhraseScorer{private: explicit WittenBellPhraseScorer(PhraseTable &pd, bool reverse) : PhraseScorer(pd, reverse) {}
virtual Score do_get_score(const PhraseTable::const_iterator &it);
public: static PhraseScorer *create_scorer(const char *argv[], int &argp, bool reverse, const PhraseScorerFactory &ptf);};
class AbsoluteDiscountPhraseScorer : public PhraseScorer{private: Score discount_;
explicit AbsoluteDiscountPhraseScorer(PhraseTable &pd, bool reverse) : PhraseScorer(pd, reverse) {}
virtual void do_score_phrases(); virtual Score do_get_score(const PhraseTable::const_iterator &it);
public: Score get_discount(); static PhraseScorer *create_scorer(const char *argv[], int &argp, bool reverse, const PhraseScorerFactory &ptf);};
class KNDiscount1PhraseScorer : public PhraseScorer{private: Count total_distinct_; Score discount_; Count total_count_;
explicit KNDiscount1PhraseScorer(PhraseTable &pd, bool reverse) : PhraseScorer(pd, reverse) {}
virtual void do_score_phrases(); virtual Score do_get_score(const PhraseTable::const_iterator &it);
public: static PhraseScorer *create_scorer(const char *argv[], int &argp, bool reverse, const PhraseScorerFactory &ptf);};
class KNDiscount3PhraseScorer : public PhraseScorer{private: Score discount1_; Score discount2_; Score discount3plus_;
Count total_distinct_n1_; Count total_distinct_n2_; Count total_distinct_n3plus_;
explicit KNDiscount3PhraseScorer(PhraseTable &pd, bool reverse) : PhraseScorer(pd, reverse) {}
virtual void do_score_phrases(); virtual Score do_get_score(const PhraseTable::const_iterator &it);
public: static PhraseScorer *create_scorer(const char *argv[], int &argp, bool reverse, const PhraseScorerFactory &ptf);};
class LexicalWeightPhraseScorer : public PhraseScorer{private: typedef std::map<std::pair<Count,Count>,Score> WeightMapType_;
WeightMapType_ weight_map_; bool overall_max_score_; const Count null_word_;
LexicalWeightPhraseScorer(PhraseTable &pd, bool reverse, const String &weights, bool overall_max = true);
Score get_weight(const String &s_src, const String &s_tgt) const; Score get_weight(Count src, Count tgt) const;
virtual void do_score_phrases(); virtual Score do_get_score(const PhraseTable::const_iterator &it);
public: static PhraseScorer *create_scorer(const char *argv[], int &argp, bool reverse, const PhraseScorerFactory &ptf);};
class ConstantPhraseScorer : public PhraseScorer{private: Score constant_;
ConstantPhraseScorer(PhraseTable &pt, bool reverse, Score constant) : PhraseScorer(pt, reverse), constant_(constant) {}
virtual Score do_get_score(const PhraseTable::const_iterator &it);
public: static PhraseScorer *create_scorer(const char *argv[], int &argp, bool reverse, const PhraseScorerFactory &ptf);};
#endif123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566promix - for training translation model interpolation weights using PRO
Author: Barry Haddow <bhaddow [AT] inf.ed.ac.uk>
ABOUT-----
The code here provides the "inner loop" for a batch tuning algorithm (like MERT) which optimises phrase table interpolation weights at the same time as the standard linearmodel weights. Interpolation of the phrase tables uses the "naive" method of tmcombine.
Currently the interpolation only works for two phrase tables, but will soonbe extended to work for more than two.
REQUIREMENTS------------The scripts require the Moses Python interface (in contrib/python). It should be builtfirst, following the instructions in that directory.
The scripts also require scipy and numpy. They have been tested with the following versions:
* Python 2.7* Scipy 0.11.0* Numpy 1.6.2
Run the test.py script to check that everything is functioning correctly.
USAGE-----Since the code in this directory provides the inner loop for a batch tuning algorithm,it is run from the increasingly inaccurately named mert-moses.pl. If you want to runthe optimiser directly, run `main.py -h` for usage.
A sample command for mert-moses.pl is as follows:
MOSES/scripts/training/mert-moses.pl \ input-file ref-file \ decoder \ ini-file \ --promix-training MOSES/contrib/promix/main.py \ --maximum-iterations 15 \ --promix-table phrase-table-1 \ --promix-table phrase-table-2 \ --filtercmd "MOSES/scripts/training/filter-model-given-input.pl --Binarizer MOSES/bin/processPhraseTable" \ --nbest 100 --working-dir ./tmp --decoder-flags "-threads 4 -v 0 " \ --rootdir MOSES/scripts -mertdir MOSES/bin \ --return-best-dev
Note that promix training requires a filter and binarise script, and that the phrase tablereferenced in the ini file is not used. The argument `--return-best-dev` is not essential,but recommended.
REFERENCES----------
The code here was created for:
Haddow, Barry (2013) Applying Pairwise Ranked Optimisation toImprove the Interpolation of Translation Models. In: Proceedings of NAACL 2013
See also:
Sennrich, Rico (2012). Perplexity Minimization for Translation Model Domain Adaptation in Statistical Machine Translation. In: Proceedings of EACL 2012.123456789101112131415161718192021222324252627#!/usr/bin/env python
from math import exp,log
class BleuScoreException(Exception): pass
class BleuScorer: def __init__(self): """References should be a list. If each element is a string, assume they are filenames, if a list, assume tokenised strings""" self.smooth = 1.0 self.order = 4
def score(self,scores): if len(scores) != self.order*2+1: raise BleuScoreException("Wrong number of scores. Expected %d, but found %d" % (self.order*2+1, len(scores))) logbleu = 0.0 for j in range(self.order): logbleu += log(scores[2*j] + self.smooth) - log(scores[2*j+1] + self.smooth) logbleu /= self.order brevity = 1.0 - float(scores[-1]) / scores[1] if brevity < 0: logbleu += brevity return exp(logbleu) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy.# Passes Python2.7's test suite and incorporates all the latest updates.
# From http://code.activestate.com/recipes/576693/
try: from thread import get_ident as _get_identexcept ImportError: from dummy_thread import get_ident as _get_ident
try: from _abcoll import KeysView, ValuesView, ItemsViewexcept ImportError: pass
class OrderedDict(dict): 'Dictionary that remembers insertion order' # An inherited dict maps keys to values. # The inherited dict provides __getitem__, __len__, __contains__, and get. # The remaining methods are order-aware. # Big-O running times for all methods are the same as for regular dictionaries.
# The internal self.__map dictionary maps keys to links in a doubly linked list. # The circular doubly linked list starts and ends with a sentinel element. # The sentinel element never gets deleted (this simplifies the algorithm). # Each link is stored as a list of length three: [PREV, NEXT, KEY].
def __init__(self, *args, **kwds): '''Initialize an ordered dictionary. Signature is the same as for regular dictionaries, but keyword arguments are not recommended because their insertion order is arbitrary.
''' if len(args) > 1: raise TypeError('expected at most 1 arguments, got %d' % len(args)) try: self.__root except AttributeError: self.__root = root = [] # sentinel node root[:] = [root, root, None] self.__map = {} self.__update(*args, **kwds)
def __setitem__(self, key, value, dict_setitem=dict.__setitem__): 'od.__setitem__(i, y) <==> od[i]=y' # Setting a new item creates a new link which goes at the end of the linked # list, and the inherited dictionary is updated with the new key/value pair. if key not in self: root = self.__root last = root[0] last[1] = root[0] = self.__map[key] = [last, root, key] dict_setitem(self, key, value)
def __delitem__(self, key, dict_delitem=dict.__delitem__): 'od.__delitem__(y) <==> del od[y]' # Deleting an existing item uses self.__map to find the link which is # then removed by updating the links in the predecessor and successor nodes. dict_delitem(self, key) link_prev, link_next, key = self.__map.pop(key) link_prev[1] = link_next link_next[0] = link_prev
def __iter__(self): 'od.__iter__() <==> iter(od)' root = self.__root curr = root[1] while curr is not root: yield curr[2] curr = curr[1]
def __reversed__(self): 'od.__reversed__() <==> reversed(od)' root = self.__root curr = root[0] while curr is not root: yield curr[2] curr = curr[0]
def clear(self): 'od.clear() -> None. Remove all items from od.' try: for node in self.__map.itervalues(): del node[:] root = self.__root root[:] = [root, root, None] self.__map.clear() except AttributeError: pass dict.clear(self)
def popitem(self, last=True): '''od.popitem() -> (k, v), return and remove a (key, value) pair. Pairs are returned in LIFO order if last is true or FIFO order if false.
''' if not self: raise KeyError('dictionary is empty') root = self.__root if last: link = root[0] link_prev = link[0] link_prev[1] = root root[0] = link_prev else: link = root[1] link_next = link[1] root[1] = link_next link_next[0] = root key = link[2] del self.__map[key] value = dict.pop(self, key) return key, value
# -- the following methods do not depend on the internal structure --
def keys(self): 'od.keys() -> list of keys in od' return list(self)
def values(self): 'od.values() -> list of values in od' return [self[key] for key in self]
def items(self): 'od.items() -> list of (key, value) pairs in od' return [(key, self[key]) for key in self]
def iterkeys(self): 'od.iterkeys() -> an iterator over the keys in od' return iter(self)
def itervalues(self): 'od.itervalues -> an iterator over the values in od' for k in self: yield self[k]
def iteritems(self): 'od.iteritems -> an iterator over the (key, value) items in od' for k in self: yield (k, self[k])
def update(*args, **kwds): '''od.update(E, **F) -> None. Update od from dict/iterable E and F.
If E is a dict instance, does: for k in E: od[k] = E[k] If E has a .keys() method, does: for k in E.keys(): od[k] = E[k] Or if E is an iterable of items, does: for k, v in E: od[k] = v In either case, this is followed by: for k, v in F.items(): od[k] = v
''' if len(args) > 2: raise TypeError('update() takes at most 2 positional ' 'arguments (%d given)' % (len(args),)) elif not args: raise TypeError('update() takes at least 1 argument (0 given)') self = args[0] # Make progressively weaker assumptions about "other" other = () if len(args) == 2: other = args[1] if isinstance(other, dict): for key in other: self[key] = other[key] elif hasattr(other, 'keys'): for key in other.keys(): self[key] = other[key] else: for key, value in other: self[key] = value for key, value in kwds.items(): self[key] = value
__update = update # let subclasses override update without breaking __init__
__marker = object()
def pop(self, key, default=__marker): '''od.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised.
''' if key in self: result = self[key] del self[key] return result if default is self.__marker: raise KeyError(key) return default
def setdefault(self, key, default=None): 'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od' if key in self: return self[key] self[key] = default return default
def __repr__(self, _repr_running={}): 'od.__repr__() <==> repr(od)' call_key = id(self), _get_ident() if call_key in _repr_running: return '...' _repr_running[call_key] = 1 try: if not self: return '%s()' % (self.__class__.__name__,) return '%s(%r)' % (self.__class__.__name__, self.items()) finally: del _repr_running[call_key]
def __reduce__(self): 'Return state information for pickling' items = [[k, self[k]] for k in self] inst_dict = vars(self).copy() for k in vars(OrderedDict()): inst_dict.pop(k, None) if inst_dict: return (self.__class__, (items,), inst_dict) return self.__class__, (items,)
def copy(self): 'od.copy() -> a shallow copy of od' return self.__class__(self)
@classmethod def fromkeys(cls, iterable, value=None): '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S and values equal to v (which defaults to None).
''' d = cls() for key in iterable: d[key] = value return d
def __eq__(self, other): '''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive while comparison to a regular mapping is order-insensitive.
''' if isinstance(other, OrderedDict): return len(self)==len(other) and self.items() == other.items() return dict.__eq__(self, other)
def __ne__(self, other): return not self == other
# -- the following methods are only used in Python 2.7 --
def viewkeys(self): "od.viewkeys() -> a set-like object providing a view on od's keys" return KeysView(self)
def viewvalues(self): "od.viewvalues() -> an object providing a view on od's values" return ValuesView(self)
def viewitems(self): "od.viewitems() -> a set-like object providing a view on od's items" return ItemsView(self)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112#!/usr/bin/env python
## Implementation of PRO training and extensions to train phrase weights#
import gzipimport loggingfrom numpy import arrayimport optparseimport os.pathimport sys
from nbest import *from sampler import *from train import *
logging.basicConfig(format = "%(asctime)-15s %(message)s")log = logging.getLogger('main')log.setLevel(logging.DEBUG) class Config: def __init__(self): self.parser = optparse.OptionParser(usage="%prog [options] ") self.parser.add_option("-t", "--trainer", action="store",\ dest="trainer", metavar="TYPE", type="choice", choices=("pro","mix"),\ default="pro",\ help="type of trainer to run (pro,mix)") self.parser.add_option("-n", "--nbest", action="append", \ dest="nbest", metavar="NBEST-FILE",\ help="nbest output file(s) from decoder") self.parser.add_option("-S", "--scfile", action="append",\ dest="score", metavar="SCORE-FILE",\ help="score file(s) from extractor (in same order as nbests)") self.parser.add_option("-p", "--phrase-table" , action="append",\ dest="ttable", metavar="TTABLE",\ help="ttable to be used in mixture model training") self.parser.add_option("-i", "--input-file", action="store",\ dest="input_file", metavar="INPUT-FILE", help="source text file") self.parser.add_option("-m", "--moses-bin-dir", action="store",\ dest="moses_bin_dir", metavar="DIR", help="directory containing Moses binaries", default=os.path.expanduser("~/moses/bin")) self.nbest_files = [] self.score_files = [] self.ttables = []
def parse(self,args=sys.argv[1:]): (options,args) = self.parser.parse_args(args) self.nbest_files = options.nbest self.score_files = options.score self.ttables = options.ttable self.input_file = options.input_file self.trainer = options.trainer self.moses_bin_dir = options.moses_bin_dir if not self.nbest_files: self.nbest_files = ["data/esen.nc.nbest.segment"] if not self.score_files: self.score_files = ["data/esen.nc.scores"] if len(self.nbest_files) != len(self.score_files): self.parser.error("Must have equal numbers of score files and nbest files") if self.trainer == "mix": if not self.input_file or not self.ttables: self.parser.error("Need to specify input file and ttables for mix training") #if len(self.ttables) != 2: # self.parser.error("Can only train mix model with 2 ttables at the moment")
def main(): config = Config() config.parse()
samples = [] sampler = HopkinsMaySampler() nbests = 0 for nbest_file,score_data_file in zip(config.nbest_files,config.score_files): log.debug("nbest: " + nbest_file + "; score:" + score_data_file) segments = False if config.trainer == "mix": segments = True for nbest in get_scored_nbests(nbest_file, score_data_file, config.input_file, segments=segments): samples += sampler.sample(nbest) nbests += 1 log.debug("Samples loaded") trainer = None if config.trainer == "mix": # Add the phrase table scores scorer = MosesPhraseScorer(config.ttables) log.debug("Scoring samples...") for sample in samples: scorer.add_scores(sample.hyp1) scorer.add_scores(sample.hyp2) log.debug("...samples scored") trainer = MixtureModelTrainer(samples) elif config.trainer == "pro": trainer = ProTrainer(samples) else: assert(0) log.debug("Starting training...") weights,mix_weights = trainer.train(debug=False) log.debug("...training complete") for i,w in enumerate(weights): print "F%d %10.8f" % (i,w) for i,f in enumerate(mix_weights): for j,w in enumerate(f): print "M%d_%d %10.8f" % (i,j,w)
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230#!/usr/bin/env python
import gzipimport osimport reimport numpy as npimport sys
from bleu import BleuScorerfrom coll import OrderedDict# Edit to set moses python pathsys.path.append(os.path.dirname(__file__) + "/../python")import moses.dictree as binpt
class DataFormatException(Exception): pass
class Hypothesis: def __init__(self,text,fv,segments=False): self.alignment = [] #only stored for segmented hypos self.tokens = [] #only stored for segmented hypos if not segments: self.text = text # Triples of (source-start, source-end, target-end) where segments end positions # are 1 beyond the last token else: # recover segmentation self.tokens = [] align_re = re.compile("\|(\d+)-(\d+)\|") for token in text.split(): match = align_re.match(token) if match: self.alignment.append\ ((int(match.group(1)), 1+int(match.group(2)), len(self.tokens))) else: self.tokens.append(token) self.text = " ".join(self.tokens) if not self.alignment: raise DataFormatException("Expected segmentation information not found in nbest")
self.fv = np.array(fv) self.score = 0
def __str__(self): return "{text=%s fv=%s score=%5.4f}" % (self.text, str(self.fv), self.score)
class NBestList: def __init__(self,id): self.id = id self.hyps = []
# Maps feature ids (short feature names) to their values_feature_index = {}def set_feature_start(name,index): indexes = _feature_index.get(name, [index,0]) indexes[0] = index _feature_index[name] = indexes
def set_feature_end(name,index): indexes = _feature_index.get(name, [0,index]) indexes[1] = index _feature_index[name] = indexes
def get_feature_index(name): return _feature_index.get(name, [0,0])
def get_nbests(nbest_file, segments=False): """Iterate through nbest lists""" if nbest_file.endswith("gz"): fh = gzip.GzipFile(nbest_file) else: fh = open(nbest_file) lineno = 0 nbest = None for line in fh: fields = line.split(" ||| ") if len(fields) != 4: raise DataFormatException("nbest(%d): %s" % (lineno,line)) (id, text, scores, total) = fields if nbest and nbest.id != id: yield nbest nbest = None if not nbest: nbest = NBestList(id) fv = [] score_name = None for score in scores.split(): if score.endswith(":"): score = score[:-1] if score_name: set_feature_end(score_name,len(fv)) score_name = score set_feature_start(score_name,len(fv)) else: fv.append(float(score)) if score_name: set_feature_end(score_name,len(fv)) hyp = Hypothesis(text[:-1],fv,segments) nbest.hyps.append(hyp) if nbest: yield nbest
def get_scores(score_data_file): """Iterate through the score data, returning a set of scores for each sentence""" scorer = BleuScorer() fh = open(score_data_file) lineno = 0 score_vectors = None for line in fh: if line.startswith("SCORES_TXT_BEGIN"): score_vectors = [] elif line.startswith("SCORES_TXT_END"): scores = [scorer.score(score_vector) for score_vector in score_vectors] yield scores else: score_vectors.append([float(i) for i in line[:-1].split()])
def get_scored_nbests(nbest_file, score_data_file, input_file, segments=False): score_gen = get_scores(score_data_file) input_gen = None if input_file: input_gen = open(input_file) try: for nbest in get_nbests(nbest_file, segments=segments): scores = score_gen.next() if len(scores) != len(nbest.hyps): raise DataFormatException("Length of nbest %s does not match score list (%d != %d)" % (nbest.id,len(nbest.hyps), len(scores))) input_line = None if input_gen: input_line = input_gen.next()[:-1] for hyp,score in zip(nbest.hyps, scores): hyp.score = score hyp.input_line = input_line yield nbest except StopIteration: raise DataFormatException("Score file shorter than nbest list file")
class PhraseCache: """An LRU cache for ttable lookups""" def __init__(self, max_size): self.max_size = max_size self.pairs_to_scores = OrderedDict()
def get(self, source, target): key = (source,target) scores = self.pairs_to_scores.get(key,None) if scores: # cache hit - update access time del self.pairs_to_scores[key] self.pairs_to_scores[key] = scores return scores
def add(self,source,target,scores): key = (source,target) self.pairs_to_scores[key] = scores while len(self.pairs_to_scores) > self.max_size: self.pairs_to_scores.popitem(last=False)
# # Should I store full lists of options, or just phrase pairs?# Should probably store phrase-pairs, but may want to add# high scoring pairs (say, 20?) when I load the translations# of a given phrase#
class CachedPhraseTable: def __init__(self,ttable_file,nscores=5,cache_size=20000): wa = False if binpt.PhraseDictionaryTree.canLoad(ttable_file,True): # assume word alignment is included wa = True self.ttable = binpt.PhraseDictionaryTree(ttable_file,nscores = nscores,wa = wa, tableLimit=0) self.cache = PhraseCache(cache_size) self.nscores = nscores
def get_scores(self,phrase): source = " ".join(phrase[0]) target_tuple = tuple(phrase[1]) target = " ".join(target_tuple) scores = self.cache.get(source,target) if not scores: # cache miss scores = [0] * (self.nscores-1) # ignore penalty entries = self.ttable.query(source, converter=None) # find correct target for entry in entries: if entry.rhs == target_tuple: scores = entry.scores[:-1] break #print "QUERY",source,"|||",target,"|||",scores self.cache.add(source,target,scores) #else: # print "CACHE",source,"|||",target,"|||",scores return scores
class MosesPhraseScorer: def __init__(self,ttable_files, cache_size=20000): self.ttables = [] for ttable_file in ttable_files: self.ttables.append(CachedPhraseTable(ttable_file, cache_size=cache_size)) def add_scores(self, hyp): """Add the phrase scores to a hypothesis""" # Collect up the phrase pairs phrases = [] source_tokens = hyp.input_line.split() tgt_st = 0 if not hyp.alignment: raise DataFormatException("Alignments missing from: " + str(hyp)) for src_st,src_end,tgt_end in hyp.alignment: phrases.append((source_tokens[src_st:src_end], hyp.tokens[tgt_st:tgt_end])) tgt_st = tgt_end # Look up the scores phrase_scores = [] for ttable in self.ttables: phrase_scores.append([]) for phrase in phrases: phrase_scores[-1].append(ttable.get_scores(phrase))# phrase_scores = np.array(phrase_scores)# eps = np.exp(-100)# phrase_scores[phrase_scores<eps]=eps floor = np.exp(-100) phrase_scores = np.clip(np.array(phrase_scores), floor, np.inf) hyp.phrase_scores = phrase_scores
12345678910111213141516171819202122232425#!/usr/bin/env python
import unittest
import test_bleuimport test_mainimport test_mosesimport test_nbestimport test_samplerimport test_train
def main(): test_list = [] test_list.append(test_bleu.suite) test_list.append(test_main.suite)# test_list.append(test_moses.suite) test_list.append(test_nbest.suite) test_list.append(test_sampler.suite) test_list.append(test_train.suite)
suite = unittest.TestSuite(test_list) unittest.TextTestRunner().run(suite)
if __name__ == "__main__": main()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#!/usr/bin/env python
import randomimport unittest
from nbest import *from sampler import *
class TestNBestSampler(unittest.TestCase):
def setUp(self): self.h1 = Hypothesis("a",[]) self.h2 = Hypothesis("b",[]) self.h3 = Hypothesis("c",[]) self.nbest = NBestList(1) self.nbest.hyps.append(self.h1) self.nbest.hyps.append(self.h2) self.nbest.hyps.append(self.h3) self.sampler = HopkinsMaySampler() def test_nsamples(self): self.h1.score = 0.1 self.h2.score = 0.2 self.h3.score = 0.3 samples = self.sampler.sample(self.nbest) self.assertEqual(len(samples), self.sampler.nsamples) def test_biggest(self): random.seed(0) self.h1.score = 0.1 self.h2.score = 0.2 self.h3.score = 0.3 samples = self.sampler.sample(self.nbest) for sample in samples: self.assertAlmostEqual(sample.diff,0.2) def test_score_diff(self): self.h1.score = 0.1 self.h2.score = 0.1 + (0.9*self.sampler.min_diff) self.h3.score = 0.1 + (1.8*self.sampler.min_diff)
# Should only see pairs with h1,h3 samples = self.sampler.sample(self.nbest) for sample in samples: self.assertTrue((sample.hyp1 == self.h1 and sample.hyp2 == self.h3) or \ (sample.hyp2 == self.h1 and sample.hyp1 == self.h3))
if __name__ == "__main__": unittest.main()
suite = unittest.TestLoader().loadTestsFromTestCase(TestNBestSampler)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306#!/usr/bin/env python
import unittest
from math import log,exp
import nbestimport numpy.testing as nptestimport samplerfrom train import *import util
class TestParabaloidOptimiser(unittest.TestCase): def setUp(self): self.o = ParabaloidOptimiser(np.array([1,2,3,4]))
def test_parabaloid_bfgs(self): start = np.array([2,2,2,2]) minimum = self.o.optimise_bfgs(start) for m in minimum: self.assertAlmostEqual(m,0)
def test_parabaloid_lbfgs(self): start = np.array([2,2,2,2]) minimum = self.o.optimise_lbfgs(start) for m in minimum: self.assertAlmostEqual(m,0)
class TestLogisticRegressionOptimiser(unittest.TestCase):
def test_objective(self): x = np.array([[1], [0]]) y = np.array([1,-1]) lro = LogisticRegressionOptimiser(x,y) w = np.array([2]) expected = -log(1 / (1 + exp(-2))) - log(0.5) self.assertAlmostEqual(lro.objective(w), expected) def test_reg_objective(self): x = np.array([[1], [0]]) y = np.array([1,-1]) alpha = 0.1 lro = LogisticRegressionOptimiser(x,y,alpha) w = np.array([2]) expected = -log(1 / (1 + exp(-2))) - log(0.5) + 0.5*2*2 * alpha self.assertAlmostEqual(lro.objective(w), expected) def test_gradient_j(self): x = np.array([[1], [0]]) y = np.array([1,-1]) lro = LogisticRegressionOptimiser(x,y) w = np.array([2]) expected = -1 / (1 + exp(2)) self.assertAlmostEqual(lro.grad_j(w,0), expected)
def test_gradient(self): x = np.array([[1,1], [0,1]]) y = np.array([1,-1]) w = np.array([2,1]) lro = LogisticRegressionOptimiser(x,y) e0 = -1 / (1 + exp(3)) e1 = -1 / (1 + exp(3)) + 1/ (1 + exp(-1)) actual = lro.grad(w) #print "expected: ",e0,e1 self.assertAlmostEqual(actual[0], e0) self.assertAlmostEqual(actual[1], e1)
def test_reg_gradient(self): x = np.array([[1,1], [0,1]]) y = np.array([1,-1]) alpha = 0.2 w = np.array([2,1]) lro = LogisticRegressionOptimiser(x,y, alpha) e0 = -1 / (1 + exp(3)) + w[0]*alpha e1 = -1 / (1 + exp(3)) + 1/ (1 + exp(-1)) +w[1]*alpha actual = lro.grad(w) self.assertAlmostEqual(actual[0], e0) self.assertAlmostEqual(actual[1], e1)
def test_train(self): x = np.array([[1,1],[-1,-2]]) y = np.array([1,-1]) w0 = np.array([1,-1]) lro = LogisticRegressionOptimiser(x,y) actual = lro.train(w0, debug=False) self.assertAlmostEqual(actual[0], 12.03882542) self.assertAlmostEqual(actual[1], 8.02317419)
def test_train_reg(self): x = np.array([[1,1],[-1,1]]) y = np.array([1,-1]) alpha = 0.1 w0 = np.array([1,-1]) lro = LogisticRegressionOptimiser(x,y,alpha) actual = lro.train(w0, debug=False) self.assertAlmostEqual(actual[1],0) # 2nd input should be ignored # classify first example as negative, second as positive self.assertTrue(1 / (1+exp(-np.dot(actual,np.array([1,1])))) > 0.5) self.assertTrue(1 / (1+exp(-np.dot(actual,np.array([-1,-2])))) < 0.5)
def test_xy(self): """Test pre-calculation of the y_i*x_ij vectors""" x = np.array([[1,3], [2,8], [1,3]]) y = np.array([1,1,-1]) lro = LogisticRegressionOptimiser(x,y) expected = np.array([[1,3], [2,8], [-1,-3]]) for i in 0,1,2: for j in 0,1: self.assertEqual(lro.xy[i][j], expected[i][j])#class TestMixtureModelTrainer(unittest.TestCase): def setUp(self): # 3 phrase table features, but last one is ignored for interpolation nbest._feature_index = {"tm" : [0,3], "lm" : [3,4]} log05 = np.log(0.5) log03 = np.log(0.3) log02 = np.log(0.2) log01 = np.log(0.1) hyp0 = nbest.Hypothesis("a |0-0| b c |1-2|", [log05, log05, log02, log03], True) hyp0.input_line = "A B C" hyp0.score = 3 # Two ttables, columns correspond to features, rows to phrase pairs hyp0.phrase_scores = np.array([\ [[0.2, 0.3],\ [0.4, 0.3]],\ [[0, 0.2],\ [0.4,0.2]]])
hyp1 = nbest.Hypothesis("x |0-2|", [log02, log03, log03, log01], True) hyp1.input_line = "X Y Z" hyp1.score = 2 hyp1.phrase_scores = np.array([\ [[0.1, 0.1]],\ [[0.8,0.1]]])
hyp2 = nbest.Hypothesis("z |0-1| w |2-2| p |3-3|", [log02, log02, log05, log05], True) hyp2.score = 1 hyp2.input_line = "M N O" # phrase_table x phrase_pair x feature hyp2.phrase_scores = np.array([\ [[0.1, 0.2],\ [0.3,0.5],\ [0.4,0.6]],\ [[0.1,0.5],\ [0.6,0.1],\ [0.2,0.2]]]) self.samples = [sampler.Sample(hyp0,hyp1), sampler.Sample(hyp1,hyp2)] self.trainer = MixtureModelTrainer(self.samples)
def get_phrase_scores(self, hypothesis, iw): nptest.assert_almost_equal(np.sum(iw, axis=0), np.array([1.0,1.0])) phrase_probs = hypothesis.phrase_scores interpolated_probs = np.sum(np.expand_dims(iw,1)*phrase_probs, axis = 0)
total_probs = np.prod(interpolated_probs, axis = 0) return util.safelog(total_probs) def model_score(self, hypothesis, weights): # interpolation weights # ttable x feature iw = np.array([[weights[-2], weights[-1]], [1-weights[-2],1-weights[-1]]]) #print "iw:",iw phrase_scores = self.get_phrase_scores(hypothesis,iw) weighted_phrase_scores = weights[:2] * phrase_scores score = np.sum(weighted_phrase_scores)
other_score = np.sum(weights[2:4]*hypothesis.fv[2:4]) return score + other_score
def test_objective(self): # 2 phrase weights, 2 other feature weights, # 2 interpolation weights (1 per model x 2 phrase features) weights = np.array([0.2,0.1,0.4,0.5,0.3,0.6]) actual = self.trainer.objective(weights) # Expected objective is the sum of the logs of sigmoids of the score differences # Weighted by 1 if hyp1 > hyp2, -1 otherwise expected = 0 for sample in self.samples: hyp1_model_score = self.model_score(sample.hyp1, weights) hyp2_model_score = self.model_score(sample.hyp2, weights) y = 1 if sample.hyp2.score > sample.hyp1.score: y = -1 expected -= log(sigmoid(y * (hyp1_model_score - hyp2_model_score))) # regularisation expected += 0.5 * self.trainer.alpha * np.dot(weights[:-2], weights[:-2]) self.assertAlmostEquals(actual,expected)
def test_gradient_other(self): # Gradients are just differences in feature vectors # fv(hypo0)-fv(hyp1), fv(hyp1)-fv(hyp2) delta_s = np.vstack((self.samples[0].hyp1.fv-self.samples[0].hyp2.fv,\ self.samples[1].hyp1.fv-self.samples[1].hyp2.fv)) # feature functions across rows, samples down columns # choose other features other_delta_s = delta_s[:,2:] actual = self.trainer.gradient_other() nptest.assert_almost_equal(actual,other_delta_s)
def test_gradient_phrase(self): iw = np.array([[0.3, 0.4],[0.7,0.6]]) sample_deltaf_list = [] for sample in self.samples: f_A = self.get_phrase_scores(sample.hyp1, iw) f_B = self.get_phrase_scores(sample.hyp2, iw) sample_deltaf_list.append(f_A - f_B) expected = np.vstack(sample_deltaf_list) # samples down, features along actual = self.trainer.gradient_phrase(iw) nptest.assert_almost_equal(actual,expected)
def test_gradient_interp(self): # The interpolation weights - ttable x feature iw = np.array([[0.3, 0.4],[0.7,0.6]]) phrasew = np.array([1,2]) # The phrase weights num_ttables = iw.shape[0] num_phrase_features = iw.shape[1] bysample_list = [] # Stack up gradients for each sample for sample in self.samples: # Get the gradient of the interpolation weights for each # hypothesis (A and B) in the sample byhyp = [] for hyp in [sample.hyp1,sample.hyp2]: # the weights are flattened. rows of iw joined together, last row omitted grad_k = np.array([0.0] * ((num_ttables - 1) * num_phrase_features)) # Iterate through the phrase features for j,probs in enumerate(np.transpose(hyp.phrase_scores)): # j is phrase feature index # probs is phrase-pair, ttable grad_jk = np.array([0.0] * (len(iw)-1)) for l,phi in enumerate(probs): # For each phrase-pair the gradient term for the lambda # is the probability for this ttable - probability for last ttable # divided by overall phrase probability num = phi[:-1] - phi[-1] denom = np.sum(iw[:,j]*phi) # use interpolation weights for this feature grad_jk = grad_jk + (num/denom) self.assertEquals(len(grad_jk), num_ttables-1) #print "num",num,"denom",denom,"grad_jk",grad_jk # add gradient in correct place #print "\n",j,grad_k,phrasew[j]*grad_jk grad_k[j*(num_ttables-1):(j+1)*(num_ttables-1)] =\ grad_k[j*(num_ttables-1):(j+1)*(num_ttables-1)] + phrasew[j]*grad_jk #print "\ngrad_k",grad_k byhyp.append(grad_k) bysample_list.append(byhyp[0]-byhyp[1]) #print "diff: ", bysample_list[-1] expected = np.vstack(bysample_list) actual = self.trainer.gradient_interp(iw,phrasew) nptest.assert_almost_equal(actual,expected, decimal=5)
def test_gradient(self): # 2 phrase weights, 2 other feature weights, # 2 interpolation weights (2 models and 2 tables) weights = np.array([0.2,0.1,0.4,0.5,0.6,0.3]) expected = np.array([0.0] * len(weights)) # Get the gradients iw = np.array([[weights[-2], weights[-1]], [1-weights[-2],1-weights[-1]]]) phrase_g = self.trainer.gradient_phrase(iw) other_g = self.trainer.gradient_other() interp_g = self.trainer.gradient_interp(iw,weights[:2]) for k,sample in enumerate(self.samples): hyp1_model_score = self.model_score(sample.hyp1, weights) hyp2_model_score = self.model_score(sample.hyp2, weights) y = 1 if sample.hyp2.score > sample.hyp1.score: y = -1 delta_score = hyp1_model_score - hyp2_model_score sig_delta_score = sigmoid(-y * delta_score) # phrase derivative term expected[:2] -= (phrase_g[k]*sig_delta_score*y) # other derivative term expected[2:4] -= (other_g[k]*sig_delta_score*y) # inter derivative term expected[-2:] -= (interp_g[k]*sig_delta_score*y) expected += self.trainer.alpha*np.append(weights[:-2], np.array([0.0,0.0])) actual = self.trainer.gradient(weights) nptest.assert_almost_equal(actual,expected)
def test_split_weights(self): w = np.array([1,2,3,4,0.2,0.3]) sw = self.trainer.get_split_weights(w) self.assertEquals(len(sw),3) nptest.assert_almost_equal(sw['phrase'], np.array([1,2])) nptest.assert_almost_equal(sw['other'], np.array([3,4])) nptest.assert_almost_equal(sw['interp'], \ np.array([[0.2,0.3], [0.8,0.7]]))
def test_train(self): """Simple test that it runs without errors""" print "x=",self.trainer.train()
if __name__ == "__main__": unittest.main()
suite = unittest.TestSuite([ unittest.TestLoader().loadTestsFromTestCase(TestParabaloidOptimiser), unittest.TestLoader().loadTestsFromTestCase(TestLogisticRegressionOptimiser), unittest.TestLoader().loadTestsFromTestCase(TestMixtureModelTrainer)])
123456789101112#!/usr/bin/python
import numpy as np
floor = np.exp(-100)def safelog(x): """Wraps np.log to give it a floor""" #return np.log(x) return np.log(np.clip(x,floor,np.inf))
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198# Copyright (c) 2010 Vladimir Prus.## Use, modification and distribution is subject to the Boost Software# License Version 1.0. (See accompanying file LICENSE_1_0.txt or# http://www.boost.org/LICENSE_1_0.txt)
import property-set ;import path ;import modules ;import "class" ; import errors ;import configure ;
rule find-include-path ( variable : properties : header : provided-path ? ){ # FIXME: document which properties affect this function by # default. local target-os = [ $(properties).get <target-os> ] ; properties = [ property-set.create <target-os>$(toolset) ] ; if $($(variable)-$(properties)) { return $($(variable)-$(properties)) ; } else { provided-path ?= [ modules.peek : $(variable) ] ; includes = $(provided-path) ; includes += [ $(properties).get <include> ] ; if [ $(properties).get <target-os> ] != windows { # FIXME: use sysroot includes += /usr/include ; } local result ; while ! $(result) && $(includes) { local f = [ path.root $(header) $(includes[1]) ] ; ECHO "Checking " $(f) ; if [ path.exists $(f) ] { result = $(includes[1]) ; } else if $(provided-path) { errors.user-error "Could not find header" $(header) : "in the user-specified directory" $(provided-path) ; } includes = $(includes[2-]) ; } $(variable)-$(properties) = $(result) ; return $(result) ; } }
rule find-library ( variable : properties : names + : provided-path ? ){ local target-os = [ $(properties).get <target-os> ] ; properties = [ property-set.create <target-os>$(toolset) ] ; if $($(variable)-$(properties)) { return $($(variable)-$(properties)) ; } else { provided-path ?= [ modules.peek : $(variable) ] ; paths = $(provided-path) ; paths += [ $(properties).get <library-path> ] ; if [ $(properties).get <target-os> ] != windows { paths += /usr/lib /usr/lib32 /usr/lib64 ; } local result ; while ! $(result) && $(paths) { while ! $(result) && $(names) { local f ; if $(target-os) = windows { f = $(paths[1])/$(names[1]).lib ; if [ path.exists $(f) ] { result = $(f) ; } } else { # FIXME: check for .a as well, depending on # the 'link' feature. f = $(paths[1])/lib$(names[1]).so ; ECHO "CHECKING $(f) " ; if [ path.exists $(f) ] { result = $(f) ; } } if ! $(result) && $(provided-path) { errors.user-error "Could not find either of: " $(names) : "in the user-specified directory" $(provided-path) ; } names = $(names[2-]) ; } paths = $(paths[2-]) ; } $(variable)-$(properties) = $(result) ; return $(result) ; }}
class ac-library : basic-target{ import errors ; import indirect ; import virtual-target ; import ac ; import configure ;
rule __init__ ( name : project : * : * ) { basic-target.__init__ $(name) : $(project) : $(sources) : $(requirements) ; reconfigure $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ; } rule set-header ( header ) { self.header = $(header) ; } rule set-default-names ( names + ) { self.default-names = $(names) ; } rule reconfigure ( * : * ) { ECHO "XXX" $(1) ; if ! $(1) { # This is 'using xxx ;'. Nothing to configure, really. } else { for i in 1 2 3 4 5 6 7 8 9 { # FIXME: this naming is inconsistent with XXX_INCLUDE/XXX_LIBRARY if ! ( $($(i)[1]) in root include-path library-path library-name condition ) { errors.user-error "Invalid named parameter" $($(i)[1]) ; } local name = $($(i)[1]) ; local value = $($(i)[2-]) ; if $($(name)) && $($(name)) != $(value) { errors.user-error "Attempt to change value of '$(name)'" ; } $(name) = $(value) ; } include-path ?= $(root)/include ; library-path ?= $(root)/lib ; } } rule construct ( name : sources * : property-set ) { # FIXME: log results. local libnames = $(library-name) ; if ! $(libnames) && ! $(include-path) && ! $(library-path) { libnames = [ modules.peek : $(name:U)_NAME ] ; # Backward compatibility only. libnames ?= [ modules.peek : $(name:U)_BINARY ] ; } libnames ?= $(self.default-names) ; local includes = [ ac.find-include-path $(name:U)_INCLUDE : $(property-set) : $(self.header) : $(include-path) ] ; local library = [ ac.find-library $(name:U)_LIBRARY : $(property-set) : $(libnames) : $(library-path) ] ; if $(includes) && $(library) { library = [ virtual-target.from-file $(library) : . : $(self.project) ] ; configure.log-library-search-result $(name) : "found" ; return [ property-set.create <include>$(includes) <source>$(library) ] ; } else { configure.log-library-search-result $(name) : "no found" ; } }}
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121# Copyright 2002, 2003 Dave Abrahams# Copyright 2002, 2005, 2006 Rene Rivera# Copyright 2002, 2003, 2004, 2005, 2006 Vladimir Prus# Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
# Implements project representation and loading. Each project is represented by:# - a module where all the Jamfile content live.# - an instance of 'project-attributes' class.# (given a module name, can be obtained using the 'attributes' rule)# - an instance of 'project-target' class (from targets.jam)# (given a module name, can be obtained using the 'target' rule)## Typically, projects are created as result of loading a Jamfile, which is done# by rules 'load' and 'initialize', below. First, module for Jamfile is loaded# and new project-attributes instance is created. Some rules necessary for# project are added to the module (see 'project-rules' module) at the bottom of# this file. Default project attributes are set (inheriting attributes of parent# project, if it exists). After that the Jamfile is read. It can declare its own# attributes using the 'project' rule which will be combined with any already# set attributes.## The 'project' rule can also declare a project id which will be associated with# the project module.## There can also be 'standalone' projects. They are created by calling# 'initialize' on an arbitrary module and not specifying their location. After# the call, the module can call the 'project' rule, declare main targets and# behave as a regular project except that, since it is not associated with any# location, it should not declare targets that are not prebuilt.## The list of all loaded Jamfile is stored in the .project-locations variable.# It is possible to obtain a module name for a location using the 'module-name'# rule. Standalone projects are not recorded and can only be referenced using# their project id.
import "class" : new ;import errors ;import modules ;import path ;import print ;import property-set ;import sequence ;
# Loads the Jamfile at the given location. After loading, project global file# and Jamfiles needed by the requested one will be loaded recursively. If the# Jamfile at that location is loaded already, does nothing. Returns the project# module for the Jamfile.#rule load ( jamfile-location ){ if --debug-loading in [ modules.peek : ARGV ] { ECHO "Loading Jamfile at" '$(jamfile-location)' ; }
local module-name = [ module-name $(jamfile-location) ] ; # If Jamfile is already loaded, don't try again. if ! $(module-name) in $(.jamfile-modules) { load-jamfile $(jamfile-location) : $(module-name) ;
# We want to make sure that child project are loaded only after parent # projects. In particular, because parent projects define attributes # which are inherited by children, and we don't want children to be # loaded before parent has defined everything. # # While "build-project" and "use-project" can potentially refer to child # projects from parent projects, we don't immediately load child # projects when seeing those attributes. Instead, we record the minimal # information to be used only later. load-used-projects $(module-name) ; } return $(module-name) ;}
rule load-used-projects ( module-name ){ local used = [ modules.peek $(module-name) : .used-projects ] ; local location = [ attribute $(module-name) location ] ; import project ; while $(used) { local id = $(used[1]) ; local where = $(used[2]) ;
project.use $(id) : [ path.root [ path.make $(where) ] $(location) ] ; used = $(used[3-]) ; }}
# Note the use of character groups, as opposed to listing 'Jamroot' and# 'jamroot'. With the latter, we would get duplicate matches on Windows and# would have to eliminate duplicates.JAMROOT ?= [ modules.peek : JAMROOT ] ;JAMROOT ?= project-root.jam [Jj]amroot [Jj]amroot.jam ;
# Loads parent of Jamfile at 'location'. Issues an error if nothing is found.#rule load-parent ( location ){ local found = [ path.glob-in-parents $(location) : $(JAMROOT) $(JAMFILE) ] ;
if ! $(found) { ECHO error: Could not find parent for project at '$(location)' ; EXIT error: Did not find Jamfile.jam or Jamroot.jam in any parent directory. ; }
return [ load $(found[1]:D) ] ;}
# Makes the specified 'module' act as if it were a regularly loaded Jamfile at# 'location'. Reports an error if a Jamfile has already been loaded for that# location.#rule act-as-jamfile ( module : location ){ if [ module-name $(location) ] in $(.jamfile-modules) { errors.error "Jamfile was already loaded for '$(location)'" ; } # Set up non-default mapping from location to module. .module.$(location) = $(module) ;
# Add the location to the list of project locations so that we don't try to # reload the same Jamfile in the future. .jamfile-modules += [ module-name $(location) ] ;
initialize $(module) : $(location) ;}
# Returns the project module corresponding to the given project-id or plain# directory name. Returns nothing if such a project can not be found.#rule find ( name : current-location ){ local project-module ;
# Try interpreting name as project id. if [ path.is-rooted $(name) ] { project-module = $($(name).jamfile-module) ; }
if ! $(project-module) { local location = [ path.root [ path.make $(name) ] $(current-location) ] ;
# If no project is registered for the given location, try to load it. # First see if we have a Jamfile. If not, then see if we might have a # project root willing to act as a Jamfile. In that case, project root # must be placed in the directory referred by id.
project-module = [ module-name $(location) ] ; if ! $(project-module) in $(.jamfile-modules) { if [ path.glob $(location) : $(JAMROOT) $(JAMFILE) ] { project-module = [ load $(location) ] ; } else { project-module = ; } } }
return $(project-module) ;}
# Returns the name of the module corresponding to 'jamfile-location'. If no# module corresponds to that location yet, associates the default module name# with that location.#rule module-name ( jamfile-location ){ if ! $(.module.$(jamfile-location)) { # Root the path, so that locations are always unambiguous. Without this, # we can't decide if '../../exe/program1' and '.' are the same paths. jamfile-location = [ path.root $(jamfile-location) [ path.pwd ] ] ; .module.$(jamfile-location) = Jamfile<$(jamfile-location)> ; } return $(.module.$(jamfile-location)) ;}
# Default patterns to search for the Jamfiles to use for build declarations.#JAMFILE = [ modules.peek : JAMFILE ] ;JAMFILE ?= [Bb]uild.jam [Jj]amfile.v2 [Jj]amfile [Jj]amfile.jam ;
# Find the Jamfile at the given location. This returns the exact names of all# the Jamfiles in the given directory. The optional parent-root argument causes# this to search not the given directory but the ones above it up to the# directory given in it.#rule find-jamfile ( dir # The directory(s) to look for a Jamfile. parent-root ? # Optional flag indicating to search for the parent Jamfile. : no-errors ? ){ # Glob for all the possible Jamfiles according to the match pattern. # local jamfile-glob = ; if $(parent-root) { if ! $(.parent-jamfile.$(dir)) { .parent-jamfile.$(dir) = [ path.glob-in-parents $(dir) : $(JAMFILE) ] ; } jamfile-glob = $(.parent-jamfile.$(dir)) ; } else { if ! $(.jamfile.$(dir)) { .jamfile.$(dir) = [ path.glob $(dir) : $(JAMFILE) ] ; } jamfile-glob = $(.jamfile.$(dir)) ;
}
local jamfile-to-load = $(jamfile-glob) ; # Multiple Jamfiles found in the same place. Warn about this and ensure we # use only one of them. As a temporary convenience measure, if there is # Jamfile.v2 among found files, suppress the warning and use it. # if $(jamfile-to-load[2-]) { local v2-jamfiles = [ MATCH (.*[Jj]amfile\\.v2)|(.*[Bb]uild\\.jam) : $(jamfile-to-load) ] ;
if $(v2-jamfiles) && ! $(v2-jamfiles[2]) { jamfile-to-load = $(v2-jamfiles) ; } else { local jamfile = [ path.basename $(jamfile-to-load[1]) ] ; ECHO "warning: Found multiple Jamfiles at '"$(dir)"'!" "Loading the first one: '$(jamfile)'." ; }
jamfile-to-load = $(jamfile-to-load[1]) ; }
# Could not find it, error. # if ! $(no-errors) && ! $(jamfile-to-load) { errors.error Unable to load Jamfile. : Could not find a Jamfile in directory '$(dir)'. : Attempted to find it with pattern '"$(JAMFILE:J= )"'. : Please consult the documentation at 'http://www.boost.org'. ; }
return $(jamfile-to-load) ;}
# Load a Jamfile at the given directory. Returns nothing. Will attempt to load# the file as indicated by the JAMFILE patterns. Effect of calling this rule# twice with the same 'dir' is undefined.#local rule load-jamfile ( dir # The directory of the project Jamfile. : jamfile-module ){ # See if the Jamfile is where it should be. # local jamfile-to-load = [ path.glob $(dir) : $(JAMROOT) ] ; if ! $(jamfile-to-load) { jamfile-to-load = [ find-jamfile $(dir) ] ; } if $(jamfile-to-load[2]) { errors.error "Multiple Jamfiles found at '$(dir)'" : "Filenames are: " $(jamfile-to-load:D=) ; } # Now load the Jamfile in it's own context. # The call to 'initialize' may load parent Jamfile, which might have # 'use-project' statement that causes a second attempt to load the # same project we're loading now. Checking inside .jamfile-modules # prevents that second attempt from messing up. if ! $(jamfile-module) in $(.jamfile-modules) {
# Initialize the Jamfile module before loading. # initialize $(jamfile-module) : [ path.parent $(jamfile-to-load) ] : $(jamfile-to-load:BS) ;
if ! $(jamfile-module) in $(.jamfile-modules) { .jamfile-modules += $(jamfile-module) ;
local saved-project = $(.current-project) ;
mark-as-user $(jamfile-module) ; modules.load $(jamfile-module) : [ path.native $(jamfile-to-load) ] : . ; if [ MATCH ($(JAMROOT)) : $(jamfile-to-load:BS) ] { jamfile = [ find-jamfile $(dir) : no-errors ] ; if $(jamfile) { load-aux $(jamfile-module) : [ path.native $(jamfile) ] ; } }
# Now do some checks. if $(.current-project) != $(saved-project) { errors.error "The value of the .current-project variable has magically" : "changed after loading a Jamfile. This means some of the targets" : "might be defined in the wrong project." : "after loading" $(jamfile-module) : "expected value" $(saved-project) : "actual value" $(.current-project) ; }
if $(.global-build-dir) { local id = [ attribute $(jamfile-module) id ] ; local project-root = [ attribute $(jamfile-module) project-root ] ; local location = [ attribute $(jamfile-module) location ] ;
if $(location) && $(project-root) = $(dir) { # This is Jamroot. if ! $(id) { ECHO "warning: the --build-dir option was specified" ; ECHO "warning: but Jamroot at '$(dir)'" ; ECHO "warning: specified no project id" ; ECHO "warning: the --build-dir option will be ignored" ; } } } } }}
rule mark-as-user ( module-name ){ if USER_MODULE in [ RULENAMES ] { USER_MODULE $(module-name) ; }}
rule load-aux ( module-name : file ){ mark-as-user $(module-name) ;
module $(module-name) { include $(2) ; local rules = [ RULENAMES $(1) ] ; IMPORT $(1) : $(rules) : $(1) : $(1).$(rules) ; }}
.global-build-dir = [ MATCH --build-dir=(.*) : [ modules.peek : ARGV ] ] ;if $(.global-build-dir){ # If the option is specified several times, take the last value. .global-build-dir = [ path.make $(.global-build-dir[-1]) ] ;}
# Initialize the module for a project.#rule initialize ( module-name # The name of the project module. : location ? # The location (directory) of the project to initialize. If # not specified, a standalone project will be initialized. : basename ? ){ if --debug-loading in [ modules.peek : ARGV ] { ECHO "Initializing project '$(module-name)'" ; }
local jamroot ;
local parent-module ; if $(module-name) = test-config { # No parent. } else if $(module-name) = site-config { parent-module = test-config ; } else if $(module-name) = user-config { parent-module = site-config ; } else if $(module-name) = project-config { parent-module = user-config ; } else { # We search for parent/project-root only if Jamfile was specified, i.e. # if the project is not standalone. if $(location) && ! [ MATCH ($(JAMROOT)) : $(basename) ] { parent-module = [ load-parent $(location) ] ; } else { # It's either jamroot or standalone project. If it's jamroot, # inherit from user-config. if $(location) { # If project-config module exist, inherit from it. if $(project-config.attributes) { parent-module = project-config ; } else { parent-module = user-config ; } jamroot = true ; } } }
# TODO: need to consider if standalone projects can do anything but define # prebuilt targets. If so, we need to give it a more sensible "location", so # that source paths are correct. location ?= "" ; # Create the module for the Jamfile first. module $(module-name) { }
# load-parent can end up loading this module again. # Make sure this isn't duplicated. if ! $($(module-name).attributes) {
$(module-name).attributes = [ new project-attributes $(location) $(module-name) ] ; local attributes = $($(module-name).attributes) ;
if $(location) { $(attributes).set source-location : [ path.make $(location) ] : exact ; } else if ! $(module-name) in test-config site-config user-config project-config { # This is a standalone project with known location. Set source location # so that it can declare targets. This is intended so that you can put # a .jam file in your sources and use it via 'using'. Standard modules # (in 'tools' subdir) may not assume source dir is set. local s = [ modules.binding $(module-name) ] ; if ! $(s) { errors.error "Could not determine project location $(module-name)" ; } $(attributes).set source-location : $(s:D) : exact ; }
$(attributes).set requirements : [ property-set.empty ] : exact ; $(attributes).set usage-requirements : [ property-set.empty ] : exact ;
# Import rules common to all project modules from project-rules module, # defined at the end of this file. local rules = [ RULENAMES project-rules ] ; IMPORT project-rules : $(rules) : $(module-name) : $(rules) ;
if $(parent-module) { inherit-attributes $(module-name) : $(parent-module) ; $(attributes).set parent-module : $(parent-module) : exact ; }
if $(jamroot) { $(attributes).set project-root : $(location) : exact ; }
local parent ; if $(parent-module) { parent = [ target $(parent-module) ] ; }
if ! $(.target.$(module-name)) { .target.$(module-name) = [ new project-target $(module-name) : $(module-name) $(parent) : [ attribute $(module-name) requirements ] ] ;
if --debug-loading in [ modules.peek : ARGV ] { ECHO "Assigned project target" $(.target.$(module-name)) "to '$(module-name)'" ; } } }
.current-project = [ target $(module-name) ] ;}
# Make 'project-module' inherit attributes of project root and parent module.#rule inherit-attributes ( project-module : parent-module ){ local attributes = $($(project-module).attributes) ; local pattributes = [ attributes $(parent-module) ] ; # Parent module might be locationless configuration module. if [ modules.binding $(parent-module) ] { $(attributes).set parent : [ path.parent [ path.make [ modules.binding $(parent-module) ] ] ] ; } local v = [ $(pattributes).get project-root ] ; $(attributes).set project-root : $(v) : exact ; $(attributes).set default-build : [ $(pattributes).get default-build ] ; $(attributes).set requirements : [ $(pattributes).get requirements ] : exact ; $(attributes).set usage-requirements : [ $(pattributes).get usage-requirements ] : exact ;
local parent-build-dir = [ $(pattributes).get build-dir ] ; if $(parent-build-dir) { # Have to compute relative path from parent dir to our dir. Convert both # paths to absolute, since we cannot find relative path from ".." to # ".".
local location = [ attribute $(project-module) location ] ; local parent-location = [ attribute $(parent-module) location ] ;
local pwd = [ path.pwd ] ; local parent-dir = [ path.root $(parent-location) $(pwd) ] ; local our-dir = [ path.root $(location) $(pwd) ] ; $(attributes).set build-dir : [ path.join $(parent-build-dir) [ path.relative $(our-dir) $(parent-dir) ] ] : exact ; }}
# Associate the given id with the given project module.#rule register-id ( id : module ){ $(id).jamfile-module = $(module) ;}
# Class keeping all the attributes of a project.## The standard attributes are "id", "location", "project-root", "parent"# "requirements", "default-build", "source-location" and "projects-to-build".#class project-attributes{ import property ; import property-set ; import errors ; import path ; import print ; import sequence ; import project ;
rule __init__ ( location project-module ) { self.location = $(location) ; self.project-module = $(project-module) ; }
# Set the named attribute from the specification given by the user. The # value actually set may be different. # rule set ( attribute : specification * : exact ? # Sets value from 'specification' without any processing. ) { if $(exact) { self.$(attribute) = $(specification) ; } else if $(attribute) = "requirements" { local result = [ property-set.refine-from-user-input $(self.requirements) : $(specification) : $(self.project-module) : $(self.location) ] ;
if $(result[1]) = "@error" { errors.error Requirements for project at '$(self.location)' conflict with parent's. : Explanation: $(result[2-]) ; } else { self.requirements = $(result) ; } } else if $(attribute) = "usage-requirements" { local unconditional ; for local p in $(specification) { local split = [ property.split-conditional $(p) ] ; split ?= nothing $(p) ; unconditional += $(split[2]) ; }
local non-free = [ property.remove free : $(unconditional) ] ; if $(non-free) { errors.error usage-requirements $(specification) have non-free properties $(non-free) ; } local t = [ property.translate-paths $(specification) : $(self.location) ] ; if $(self.usage-requirements) { self.usage-requirements = [ property-set.create [ $(self.usage-requirements).raw ] $(t) ] ; } else { self.usage-requirements = [ property-set.create $(t) ] ; } } else if $(attribute) = "default-build" { self.default-build = [ property.make $(specification) ] ; } else if $(attribute) = "source-location" { self.source-location = ; for local src-path in $(specification) { self.source-location += [ path.root [ path.make $(src-path) ] $(self.location) ] ; } } else if $(attribute) = "build-dir" { self.build-dir = [ path.root [ path.make $(specification) ] $(self.location) ] ; } else if $(attribute) = "id" { id = [ path.root $(specification) / ] ; project.register-id $(id) : $(self.project-module) ; self.id = $(id) ; } else if ! $(attribute) in "default-build" "location" "parent" "projects-to-build" "project-root" "source-location" { errors.error Invalid project attribute '$(attribute)' specified for project at '$(self.location)' ; } else { self.$(attribute) = $(specification) ; } }
# Returns the value of the given attribute. # rule get ( attribute ) { return $(self.$(attribute)) ; }
# Prints the project attributes. # rule print ( ) { local id = $(self.id) ; id ?= (none) ; local parent = $(self.parent) ; parent ?= (none) ; print.section "'"$(id)"'" ; print.list-start ; print.list-item "Parent project:" $(parent) ; print.list-item "Requirements:" [ $(self.requirements).raw ] ; print.list-item "Default build:" $(self.default-build) ; print.list-item "Source location:" $(self.source-location) ; print.list-item "Projects to build:" [ sequence.insertion-sort $(self.projects-to-build) ] ; print.list-end ; }}
# Returns the project which is currently being loaded.#rule current ( ){ return $(.current-project) ;}
# Temporarily changes the current project to 'project'. Should be followed by# 'pop-current'.#rule push-current ( project ){ .saved-current-project += $(.current-project) ; .current-project = $(project) ;}
rule pop-current ( ){ .current-project = $(.saved-current-project[-1]) ; .saved-current-project = $(.saved-current-project[1--2]) ;}
# Returns the project-attribute instance for the specified Jamfile module.#rule attributes ( project ){ return $($(project).attributes) ;}
# Returns the value of the specified attribute in the specified Jamfile module.#rule attribute ( project attribute ){ return [ $($(project).attributes).get $(attribute) ] ;}
# Returns the project target corresponding to the 'project-module'.#rule target ( project-module ){ if ! $(.target.$(project-module)) { .target.$(project-module) = [ new project-target $(project-module) : $(project-module) : [ attribute $(project-module) requirements ] ] ; } return $(.target.$(project-module)) ;}
# Use/load a project.#rule use ( id : location ){ local saved-project = $(.current-project) ; local project-module = [ project.load $(location) ] ; local declared-id = [ project.attribute $(project-module) id ] ;
if ! $(declared-id) || $(declared-id) != $(id) { # The project at 'location' either has no id or that id is not equal to # the 'id' parameter. if $($(id).jamfile-module) && ( $($(id).jamfile-module) != $(project-module) ) { errors.user-error Attempt to redeclare already existing project id '$(id)' location '$(location)' ; } $(id).jamfile-module = $(project-module) ; } .current-project = $(saved-project) ;}
# Defines a Boost.Build extension project. Such extensions usually contain# library targets and features that can be used by many people. Even though# extensions are really projects, they can be initialized as a module would be# with the "using" (project.project-rules.using) mechanism.#rule extension ( id : options * : * ){ # The caller is a standalone module for the extension. local mod = [ CALLER_MODULE ] ;
# We need to do the rest within the extension module. module $(mod) { import path ;
# Find the root project. local root-project = [ project.current ] ; root-project = [ $(root-project).project-module ] ; while [ project.attribute $(root-project) parent-module ] && [ project.attribute $(root-project) parent-module ] != user-config { root-project = [ project.attribute $(root-project) parent-module ] ; }
# Create the project data, and bring in the project rules into the # module. project.initialize $(__name__) : [ path.join [ project.attribute $(root-project) location ] ext $(1:L) ] ;
# Create the project itself, i.e. the attributes. All extensions are # created in the "/ext" project space. project /ext/$(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ; local attributes = [ project.attributes $(__name__) ] ;
# Inherit from the root project of whomever is defining us. project.inherit-attributes $(__name__) : $(root-project) ; $(attributes).set parent-module : $(root-project) : exact ; }}
rule glob-internal ( project : wildcards + : excludes * : rule-name ){ local location = [ $(project).get source-location ] ;
local result ; local paths = [ path.$(rule-name) $(location) : [ sequence.transform path.make : $(wildcards) ] : [ sequence.transform path.make : $(excludes) ] ] ; if $(wildcards:D) || $(rule-name) != glob { # The paths we have found are relative to the current directory, but the # names specified in the sources list are assumed to be relative to the # source directory of the corresponding project. So, just make the names # absolute. for local p in $(paths) { # If the path is below source location, use relative path. # Otherwise, use full path just to avoid any ambiguities. local rel = [ path.relative $(p) $(location) : no-error ] ; if $(rel) = not-a-child { result += [ path.root $(p) [ path.pwd ] ] ; } else { result += $(rel) ; } } } else { # There were no wildcards in the directory path, so the files are all in # the source directory of the project. Just drop the directory, instead # of making paths absolute. result = $(paths:D="") ; }
return $(result) ;}
# This module defines rules common to all projects.#module project-rules{ rule using ( toolset-module : * ) { import toolset ; import modules ; import project ;
# Temporarily change the search path so the module referred to by # 'using' can be placed in the same directory as Jamfile. User will # expect the module to be found even though the directory is not in # BOOST_BUILD_PATH. local x = [ modules.peek : BOOST_BUILD_PATH ] ; local caller = [ CALLER_MODULE ] ; local caller-location = [ modules.binding $(caller) ] ; modules.poke : BOOST_BUILD_PATH : $(caller-location:D) $(x) ; toolset.using $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ; modules.poke : BOOST_BUILD_PATH : $(x) ;
# The above might have clobbered .current-project. Restore the correct # value. modules.poke project : .current-project : [ project.target $(caller) ] ; }
import modules ;
rule import ( * : * : * ) { modules.import project ;
local caller = [ CALLER_MODULE ] ; local saved = [ modules.peek project : .current-project ] ; module $(caller) { modules.import $(1) : $(2) : $(3) ; } modules.poke project : .current-project : $(saved) ; }
rule project ( id ? : options * : * ) { import errors ; import path ; import project ;
local caller = [ CALLER_MODULE ] ; local attributes = [ project.attributes $(caller) ] ; if $(id) { $(attributes).set id : $(id) ; }
local explicit-build-dir ;
for n in 2 3 4 5 6 7 8 9 { local option = $($(n)) ; if $(option) { $(attributes).set $(option[1]) : $(option[2-]) ; } if $(option[1]) = "build-dir" { explicit-build-dir = [ path.make $(option[2-]) ] ; } }
# If '--build-dir' is specified, change the build dir for the project. local global-build-dir = [ modules.peek project : .global-build-dir ] ;
if $(global-build-dir) { local location = [ $(attributes).get location ] ; # Project with an empty location is a 'standalone' project such as # user-config or qt. It has no build dir. If we try to set build dir # for user-config, we shall then try to inherit it, with either # weird or wrong consequences. if $(location) && $(location) = [ $(attributes).get project-root ] { # Re-read the project id, since it might have been changed in # the project's attributes. id = [ $(attributes).get id ] ; # This is Jamroot. if $(id) { if $(explicit-build-dir) && [ path.is-rooted $(explicit-build-dir) ] { errors.user-error Absolute directory specified via 'build-dir' project attribute : Do not know how to combine that with the --build-dir option. ; } # Strip the leading slash from id. local rid = [ MATCH /(.*) : $(id) ] ; local p = [ path.join $(global-build-dir) $(rid) $(explicit-build-dir) ] ;
$(attributes).set build-dir : $(p) : exact ; } } else { # Not Jamroot. if $(explicit-build-dir) { errors.user-error When --build-dir is specified, the 'build-dir' project : attribute is allowed only for top-level 'project' invocations ; } } } }
# Declare and set a project global constant. Project global constants are # normal variables but should not be changed. They are applied to every # child Jamfile. # rule constant ( name # Variable name of the constant. : value + # Value of the constant. ) { import project ; local caller = [ CALLER_MODULE ] ; local p = [ project.target $(caller) ] ; $(p).add-constant $(name) : $(value) ; }
# Declare and set a project global constant, whose value is a path. The path # is adjusted to be relative to the invocation directory. The given value # path is taken to be either absolute, or relative to this project root. # rule path-constant ( name # Variable name of the constant. : value + # Value of the constant. ) { import project ; local caller = [ CALLER_MODULE ] ; local p = [ project.target $(caller) ] ; $(p).add-constant $(name) : $(value) : path ; }
rule use-project ( id : where ) { import modules ; # See comment in 'load' for explanation. local caller = [ CALLER_MODULE ] ; modules.poke $(caller) : .used-projects : [ modules.peek $(caller) : .used-projects ] $(id) $(where) ; }
rule build-project ( dir ) { import project ; local caller = [ CALLER_MODULE ] ; local attributes = [ project.attributes $(caller) ] ;
local now = [ $(attributes).get projects-to-build ] ; $(attributes).set projects-to-build : $(now) $(dir) ; }
rule explicit ( target-names * ) { import project ; # If 'explicit' is used in a helper rule defined in Jamroot and # inherited by children, then most of the time we want 'explicit' to # operate on the Jamfile where the helper rule is invoked. local t = [ project.current ] ; for local n in $(target-names) { $(t).mark-target-as-explicit $(n) ; } }
rule always ( target-names * ) { import project ; local t = [ project.current ] ; for local n in $(target-names) { $(t).mark-target-as-always $(n) ; } } rule glob ( wildcards + : excludes * ) { import project ; return [ project.glob-internal [ project.current ] : $(wildcards) : $(excludes) : glob ] ; }
rule glob-tree ( wildcards + : excludes * ) { import project ;
if $(wildcards:D) || $(excludes:D) { errors.user-error The patterns to 'glob-tree' may not include directory ; } return [ project.glob-internal [ project.current ] : $(wildcards) : $(excludes) : glob-tree ] ; }
# Calculates conditional requirements for multiple requirements at once. # This is a shorthand to reduce duplication and to keep an inline # declarative syntax. For example: # # lib x : x.cpp : [ conditional <toolset>gcc <variant>debug : # <define>DEBUG_EXCEPTION <define>DEBUG_TRACE ] ; # rule conditional ( condition + : requirements * ) { local condition = $(condition:J=,) ; if [ MATCH (:) : $(condition) ] { return $(condition)$(requirements) ; } else { return $(condition):$(requirements) ; } } rule option ( name : value ) { local m = [ CALLER_MODULE ] ; if $(m) != site-config && $(m) != user-config && $(m) != project-config { import errors ; errors.error "The 'option' rule may be used only in site-config or user-config" ; } import option ; option.set $(name) : $(value) ; } }123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489# Copyright 2003 Dave Abrahams# Copyright 2003, 2004, 2005, 2006 Vladimir Prus# Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
import "class" : new ;import feature ;import path ;import project ;import property ;import sequence ;import set ;import option ;
# Class for storing a set of properties.## There is 1<->1 correspondence between identity and value. No two instances# of the class are equal. To maintain this property, the 'property-set.create'# rule should be used to create new instances. Instances are immutable.## Each property is classified with regard to its effect on build results.# Incidental properties have no effect on build results, from Boost.Build's# point of view. Others are either free, or non-free and we refer to non-free# ones as 'base'. Each property belongs to exactly one of those categories.## It is possible to get a list of properties belonging to each category as# well as a list of properties with a specific attribute.## Several operations, like and refine and as-path are provided. They all use# caching whenever possible.#class property-set{ import errors ; import feature ; import path ; import property ; import property-set ; import set ; rule __init__ ( raw-properties * ) { self.raw = $(raw-properties) ;
for local p in $(raw-properties) { if ! $(p:G) { errors.error "Invalid property: '$(p)'" ; } } }
# Returns Jam list of stored properties. # rule raw ( ) { return $(self.raw) ; }
rule str ( ) { return "[" $(self.raw) "]" ; }
# Returns properties that are neither incidental nor free. # rule base ( ) { if ! $(self.base-initialized) { init-base ; } return $(self.base) ; }
# Returns free properties which are not incidental. # rule free ( ) { if ! $(self.base-initialized) { init-base ; } return $(self.free) ; }
# Returns dependency properties. # rule dependency ( ) { if ! $(self.dependency-initialized) { init-dependency ; } return $(self.dependency) ; }
rule non-dependency ( ) { if ! $(self.dependency-initialized) { init-dependency ; } return $(self.non-dependency) ; }
rule conditional ( ) { if ! $(self.conditional-initialized) { init-conditional ; } return $(self.conditional) ; }
rule non-conditional ( ) { if ! $(self.conditional-initialized) { init-conditional ; } return $(self.non-conditional) ; }
# Returns incidental properties. # rule incidental ( ) { if ! $(self.base-initialized) { init-base ; } return $(self.incidental) ; }
rule refine ( ps ) { if ! $(self.refined.$(ps)) { local r = [ property.refine $(self.raw) : [ $(ps).raw ] ] ; if $(r[1]) != "@error" { self.refined.$(ps) = [ property-set.create $(r) ] ; } else { self.refined.$(ps) = $(r) ; } } return $(self.refined.$(ps)) ; }
rule expand ( ) { if ! $(self.expanded) { self.expanded = [ property-set.create [ feature.expand $(self.raw) ] ] ; } return $(self.expanded) ; }
rule expand-composites ( ) { if ! $(self.composites) { self.composites = [ property-set.create [ feature.expand-composites $(self.raw) ] ] ; } return $(self.composites) ; }
rule evaluate-conditionals ( context ? ) { context ?= $(__name__) ; if ! $(self.evaluated.$(context)) { self.evaluated.$(context) = [ property-set.create [ property.evaluate-conditionals-in-context $(self.raw) : [ $(context).raw ] ] ] ; } return $(self.evaluated.$(context)) ; }
rule propagated ( ) { if ! $(self.propagated-ps) { local result ; for local p in $(self.raw) { if propagated in [ feature.attributes $(p:G) ] { result += $(p) ; } } self.propagated-ps = [ property-set.create $(result) ] ; } return $(self.propagated-ps) ; }
rule add-defaults ( ) { if ! $(self.defaults) { self.defaults = [ property-set.create [ feature.add-defaults $(self.raw) ] ] ; } return $(self.defaults) ; }
rule as-path ( ) { if ! $(self.as-path) { self.as-path = [ property.as-path [ base ] ] ; } return $(self.as-path) ; }
# Computes the path to be used for a target with the given properties. # Returns a list of # - the computed path # - if the path is relative to the build directory, a value of 'true'. # rule target-path ( ) { if ! $(self.target-path) { # The <location> feature can be used to explicitly change the # location of generated targets. local l = [ get <location> ] ; if $(l) { self.target-path = $(l) ; } else { local p = [ as-path ] ; p = [ property-set.hash-maybe $(p) ] ; # A real ugly hack. Boost regression test system requires # specific target paths, and it seems that changing it to handle # other directory layout is really hard. For that reason, we # teach V2 to do the things regression system requires. The # value of '<location-prefix>' is prepended to the path. local prefix = [ get <location-prefix> ] ; if $(prefix) { self.target-path = [ path.join $(prefix) $(p) ] ; } else { self.target-path = $(p) ; } if ! $(self.target-path) { self.target-path = . ; } # The path is relative to build dir. self.target-path += true ; } } return $(self.target-path) ; }
rule add ( ps ) { if ! $(self.added.$(ps)) { self.added.$(ps) = [ property-set.create $(self.raw) [ $(ps).raw ] ] ; } return $(self.added.$(ps)) ; }
rule add-raw ( properties * ) { return [ add [ property-set.create $(properties) ] ] ; }
# Returns all values of 'feature'. # rule get ( feature ) { if ! $(self.map-built) { # For each feature, create a member var and assign all values to it. # Since all regular member vars start with 'self', there will be no # conflicts between names. self.map-built = true ; for local v in $(self.raw) { $(v:G) += $(v:G=) ; } } return $($(feature)) ; } # private
rule init-base ( ) { for local p in $(self.raw) { local att = [ feature.attributes $(p:G) ] ; # A feature can be both incidental and free, in which case we add it # to incidental. if incidental in $(att) { self.incidental += $(p) ; } else if free in $(att) { self.free += $(p) ; } else { self.base += $(p) ; } } self.base-initialized = true ; }
rule init-dependency ( ) { for local p in $(self.raw) { local att = [ feature.attributes $(p:G) ] ;
if dependency in $(att) { self.dependency += $(p) ; } else { self.non-dependency += $(p) ; } } self.dependency-initialized = true ; }
rule init-conditional ( ) { for local p in $(self.raw) { if [ MATCH (:) : $(p:G=) ] { self.conditional += $(p) ; } else { self.non-conditional += $(p) ; } } self.conditional-initialized = true ; }}
# Creates a new 'property-set' instance for the given raw properties or returns# an already existing ones.#rule create ( raw-properties * ){ raw-properties = [ sequence.unique [ sequence.insertion-sort $(raw-properties) ] ] ;
local key = $(raw-properties:J=-:E=) ;
if ! $(.ps.$(key)) { .ps.$(key) = [ new property-set $(raw-properties) ] ; } return $(.ps.$(key)) ;}NATIVE_RULE property-set : create ;
# Creates a new 'property-set' instance after checking that all properties are# valid and converting incidental properties into gristed form.#rule create-with-validation ( raw-properties * ){ property.validate $(raw-properties) ; return [ create [ property.make $(raw-properties) ] ] ;}
# Creates a property-set from the input given by the user, in the context of# 'jamfile-module' at 'location'.#rule create-from-user-input ( raw-properties * : jamfile-module location ){ local specification = [ property.translate-paths $(raw-properties) : $(location) ] ; specification = [ property.translate-indirect $(specification) : $(jamfile-module) ] ; local project-id = [ project.attribute $(jamfile-module) id ] ; project-id ?= [ path.root $(location) [ path.pwd ] ] ; specification = [ property.translate-dependencies $(specification) : $(project-id) : $(location) ] ; specification = [ property.expand-subfeatures-in-conditions $(specification) ] ; specification = [ property.make $(specification) ] ; return [ property-set.create $(specification) ] ;}
# Refines requirements with requirements provided by the user. Specially handles# "-<property>value" syntax in specification to remove given requirements.# - parent-requirements -- property-set object with requirements to refine.# - specification -- string list of requirements provided by the user.# - project-module -- module to which context indirect features will be# bound.# - location -- path to which path features are relative.#rule refine-from-user-input ( parent-requirements : specification * : project-module : location ){ if ! $(specification) { return $(parent-requirements) ; } else { local add-requirements ; local remove-requirements ;
for local r in $(specification) { local m = [ MATCH "^-(.*)" : $(r) ] ; if $(m) { remove-requirements += $(m) ; } else { add-requirements += $(r) ; } }
if $(remove-requirements) { # Need to create a property set, so that path features and indirect # features are translated just like they are in project # requirements. local ps = [ property-set.create-from-user-input $(remove-requirements) : $(project-module) $(location) ] ;
parent-requirements = [ property-set.create [ set.difference [ $(parent-requirements).raw ] : [ $(ps).raw ] ] ] ; specification = $(add-requirements) ; }
local requirements = [ property-set.create-from-user-input $(specification) : $(project-module) $(location) ] ;
return [ $(parent-requirements).refine $(requirements) ] ; }}
# Returns a property-set with an empty set of properties.#rule empty ( ){ if ! $(.empty) { .empty = [ create ] ; } return $(.empty) ;}
if [ option.get hash : : yes ] = yes{ rule hash-maybe ( path ? ) { path ?= "" ; return [ MD5 $(path) ] ; }}else{ rule hash-maybe ( path ? ) { return $(path) ; } }
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659# Copyright Vladimir Prus 2002.# Copyright Rene Rivera 2006.## Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or copy at# http://www.boost.org/LICENSE_1_0.txt)
# Supports 'abstract' targets, which are targets explicitly defined in a# Jamfile.## Abstract targets are represented by classes derived from 'abstract-target'# class. The first abstract target is 'project-target', which is created for# each Jamfile, and can be obtained by the 'target' rule in the Jamfile's module# (see project.jam).## Project targets keep a list of 'main-target' instances. A main target is what# the user explicitly defines in a Jamfile. It is possible to have several# definitions for a main target, for example to have different lists of sources# for different platforms. So, main targets keep a list of alternatives.## Each alternative is an instance of 'abstract-target'. When a main target# subvariant is defined by some rule, that rule will decide what class to use,# create an instance of that class and add it to the list of alternatives for# the main target.## Rules supplied by the build system will use only targets derived from# 'basic-target' class, which will provide some default behaviour. There will be# different classes derived from it such as 'make-target', created by the 'make'# rule, and 'typed-target', created by rules such as 'exe' and 'lib'.
## +------------------------+# |abstract-target |# +========================+# |name |# |project |# | |# |generate(properties) = 0|# +-----------+------------+# |# ^# / \# +-+-+# |# |# +------------------------+------+------------------------------+# | | |# | | |# +----------+-----------+ +------+------+ +------+-------+# | project-target | | main-target | | basic-target |# +======================+ 1 * +=============+ alternatives +==============+# | generate(properties) |o-----------+ generate |<>------------->| generate |# | main-target | +-------------+ | construct = 0|# +----------------------+ +--------------+# |# ^# / \# +-+-+# |# |# ...--+----------------+------------------+----------------+---+# | | | |# | | | |# ... ---+-----+ +------+-------+ +------+------+ +--------+-----+# | | typed-target | | make-target | | stage-target |# . +==============+ +=============+ +==============+# . | construct | | construct | | construct |# +--------------+ +-------------+ +--------------+
import assert ;import "class" : new ;import errors ;import feature ;import indirect ;import path ;import property ;import property-set ;import sequence ;import set ;import toolset ;import build-request ;
# Base class for all abstract targets.#class abstract-target{ import project ; import assert ; import "class" ; import errors ;
rule __init__ ( name # Name of the target in Jamfile. : project-target # The project target to which this one belongs. ) { # Note: it might seem that we don't need either name or project at all. # However, there are places where we really need it. One example is # error messages which should name problematic targets. Another is # setting correct paths for sources and generated files.
self.name = $(name) ; self.project = $(project-target) ; self.location = [ errors.nearest-user-location ] ; }
# Returns the name of this target. rule name ( ) { return $(self.name) ; }
# Returns the project for this target. rule project ( ) { return $(self.project) ; }
# Return the location where the target was declared. rule location ( ) { return $(self.location) ; }
# Returns a user-readable name for this target. rule full-name ( ) { local location = [ $(self.project).get location ] ; return $(location)/$(self.name) ; }
# Generates virtual targets for this abstract target using the specified # properties, unless a different value of some feature is required by the # target. # On success, returns: # - a property-set with the usage requirements to be applied to dependants # - a list of produced virtual targets, which may be empty. # If 'property-set' is empty, performs the default build of this target, in # a way specific to the derived class. # rule generate ( property-set ) { errors.error "method should be defined in derived classes" ; }
rule rename ( new-name ) { self.name = $(new-name) ; }}
if --debug-building in [ modules.peek : ARGV ]{ modules.poke : .debug-building : true ;}
rule indent ( ){ return $(.indent:J="") ;}
rule increase-indent ( ){ .indent += " " ;}
rule decrease-indent ( ){ .indent = $(.indent[2-]) ;}
# Project target class (derived from 'abstract-target').## This class has the following responsibilities:# - Maintaining a list of main targets in this project and building them.## Main targets are constructed in two stages:# - When Jamfile is read, a number of calls to 'add-alternative' is made. At# that time, alternatives can also be renamed to account for inline targets.# - The first time 'main-target' or 'has-main-target' rule is called, all# alternatives are enumerated and main targets are created.#class project-target : abstract-target{ import project ; import targets ; import path ; import print ; import property-set ; import set ; import sequence ; import "class" : new ; import errors ;
rule __init__ ( name : project-module parent-project ? : requirements * : default-build * ) { abstract-target.__init__ $(name) : $(__name__) ;
self.project-module = $(project-module) ; self.location = [ project.attribute $(project-module) location ] ; self.requirements = $(requirements) ; self.default-build = $(default-build) ;
if $(parent-project) { inherit $(parent-project) ; } }
# This is needed only by the 'make' rule. Need to find the way to make # 'make' work without this method. # rule project-module ( ) { return $(self.project-module) ; }
rule get ( attribute ) { return [ project.attribute $(self.project-module) $(attribute) ] ; }
rule build-dir ( ) { if ! $(self.build-dir) { self.build-dir = [ get build-dir ] ; if ! $(self.build-dir) { self.build-dir = [ path.join [ $(self.project).get location ] bin ] ; } } return $(self.build-dir) ; }
# Generates all possible targets contained in this project. # rule generate ( property-set * ) { if [ modules.peek : .debug-building ] { ECHO [ targets.indent ] "building project" [ name ] " ('$(__name__)') with" [ $(property-set).raw ] ; targets.increase-indent ; }
local usage-requirements = [ property-set.empty ] ; local targets ;
for local t in [ targets-to-build ] { local g = [ $(t).generate $(property-set) ] ; usage-requirements = [ $(usage-requirements).add $(g[1]) ] ; targets += $(g[2-]) ; } targets.decrease-indent ; return $(usage-requirements) [ sequence.unique $(targets) ] ; }
# Computes and returns a list of abstract-target instances which must be # built when this project is built. # rule targets-to-build ( ) { local result ;
if ! $(self.built-main-targets) { build-main-targets ; }
# Collect all main targets here, except for "explicit" ones. for local t in $(self.main-targets) { if ! [ $(t).name ] in $(self.explicit-targets) { result += $(t) ; } }
# Collect all projects referenced via "projects-to-build" attribute. local self-location = [ get location ] ; for local pn in [ get projects-to-build ] { result += [ find $(pn)/ ] ; }
return $(result) ; }
# Add 'target' to the list of targets in this project that should be build # only by explicit request # rule mark-target-as-explicit ( target-name * ) { # Record the name of the target, not instance, since this rule is called # before main target instances are created. self.explicit-targets += $(target-name) ; } rule mark-target-as-always ( target-name * ) { # Record the name of the target, not instance, since this rule is called # before main target instances are created. self.always-targets += $(target-name) ; }
# Add new target alternative # rule add-alternative ( target-instance ) { if $(self.built-main-targets) { errors.error add-alternative called when main targets are already created. : in project [ full-name ] ; } self.alternatives += $(target-instance) ; }
# Returns a 'main-target' class instance corresponding to 'name'. # rule main-target ( name ) { if ! $(self.built-main-targets) { build-main-targets ; } return $(self.main-target.$(name)) ; }
# Returns whether a main target with the specified name exists. # rule has-main-target ( name ) { if ! $(self.built-main-targets) { build-main-targets ; }
if $(self.main-target.$(name)) { return true ; } }
# Worker function for the find rule not implementing any caching and simply # returning nothing in case the target can not be found. # rule find-really ( id ) { local result ; local current-location = [ get location ] ;
local split = [ MATCH (.*)//(.*) : $(id) ] ; local project-part = $(split[1]) ; local target-part = $(split[2]) ;
local extra-error-message ; if $(project-part) { # There is an explicitly specified project part in id. Looks up the # project and passes the request to it. local pm = [ project.find $(project-part) : $(current-location) ] ; if $(pm) { project-target = [ project.target $(pm) ] ; result = [ $(project-target).find $(target-part) : no-error ] ; } else { # TODO: This extra error message will not get displayed most # likely due to some buggy refactoring. Refactor the code so the # message gets diplayed again. extra-error-message = error: could not find project '$(project-part)' ; } } else { # Interpret target-name as name of main target. Need to do this # before checking for file. Consider the following scenario with a # toolset not modifying its executable's names, e.g. gcc on # Unix-like platforms: # # exe test : test.cpp ; # install s : test : <location>. ; # # After the first build we would have a target named 'test' in the # Jamfile and a file named 'test' on the disk. We need the target to # override the file. result = [ main-target $(id) ] ; # Interpret id as an existing file reference. if ! $(result) { result = [ new file-reference [ path.make $(id) ] : $(self.project) ] ; if ! [ $(result).exists ] { result = ; } }
# Interpret id as project-id. if ! $(result) { local project-module = [ project.find $(id) : $(current-location) ] ; if $(project-module) { result = [ project.target $(project-module) ] ; } } }
return $(result) ; }
# Find and return the target with the specified id, treated relative to # self. Id may specify either a target or a file name with the target taking # priority. May report an error or return nothing if the target is not found # depending on the 'no-error' parameter. # rule find ( id : no-error ? ) { local v = $(.id.$(id)) ; if ! $(v) { v = [ find-really $(id) ] ; if ! $(v) { v = none ; } .id.$(id) = $(v) ; }
if $(v) != none { return $(v) ; } else { if ! $(no-error) { local current-location = [ get location ] ; ECHO "error: Unable to find file or target named" ; ECHO "error: '$(id)'" ; ECHO "error: referred from project at" ; ECHO "error: '$(current-location)'" ; ECHO $(extra-error-message) ; EXIT ; } } }
rule build-main-targets ( ) { self.built-main-targets = true ; for local a in $(self.alternatives) { local name = [ $(a).name ] ; local target = $(self.main-target.$(name)) ; if ! $(target) { local t = [ new main-target $(name) : $(self.project) ] ; self.main-target.$(name) = $(t) ; self.main-targets += $(t) ; target = $(self.main-target.$(name)) ; } if $(name) in $(self.always-targets) { $(a).always ; }
$(target).add-alternative $(a) ; } }
# Accessor, add a constant. # rule add-constant ( name # Variable name of the constant. : value + # Value of the constant. : type ? # Optional type of value. ) { switch $(type) { case path : local r ; for local v in $(value) { local l = $(self.location) ; if ! $(l) { # Project corresponding to config files do not have # 'location' attribute, but do have source location. # It might be more reasonable to make every project have # a location and use some other approach to prevent buildable # targets in config files, but that's for later. l = [ get source-location ] ; } v = [ path.root [ path.make $(v) ] $(l) ] ; # Now make the value absolute path. v = [ path.root $(v) [ path.pwd ] ] ; # Constants should be in platform-native form. v = [ path.native $(v) ] ; r += $(v) ; } value = $(r) ; } if ! $(name) in $(self.constants) { self.constants += $(name) ; } self.constant.$(name) = $(value) ; # Inject the constant in the scope of the Jamroot module. modules.poke $(self.project-module) : $(name) : $(value) ; }
rule inherit ( parent ) { for local c in [ modules.peek $(parent) : self.constants ] { # No need to pass the type. Path constants were converted to # absolute paths already by parent. add-constant $(c) : [ modules.peek $(parent) : self.constant.$(c) ] ; }
# Import rules from parent. local this-module = [ project-module ] ; local parent-module = [ $(parent).project-module ] ; # Do not import rules coming from 'project-rules' as they must be # imported localized. local user-rules = [ set.difference [ RULENAMES $(parent-module) ] : [ RULENAMES project-rules ] ] ; IMPORT $(parent-module) : $(user-rules) : $(this-module) : $(user-rules) ; EXPORT $(this-module) : $(user-rules) ; }}
# Helper rules to detect cycles in main target references.#local rule start-building ( main-target-instance ){ if $(main-target-instance) in $(.targets-being-built) { local names ; for local t in $(.targets-being-built) $(main-target-instance) { names += [ $(t).full-name ] ; }
errors.error "Recursion in main target references" : "the following target are being built currently:" : $(names) ; } .targets-being-built += $(main-target-instance) ;}
local rule end-building ( main-target-instance ){ .targets-being-built = $(.targets-being-built[1--2]) ;}
# A named top-level target in Jamfile.#class main-target : abstract-target{ import assert ; import errors ; import feature ; import print ; import property-set ; import sequence ; import targets : start-building end-building ;
rule __init__ ( name : project ) { abstract-target.__init__ $(name) : $(project) ; }
# Add a new alternative for this target rule add-alternative ( target ) { local d = [ $(target).default-build ] ; if $(self.alternatives) && ( $(self.default-build) != $(d) ) { errors.error "default build must be identical in all alternatives" : "main target is" [ full-name ] : "with" [ $(d).raw ] : "differing from previous default build" [ $(self.default-build).raw ] ; } else { self.default-build = $(d) ; } self.alternatives += $(target) ; }
# Returns the best viable alternative for this property-set. See the # documentation for selection rules. # local rule select-alternatives ( property-set debug ? ) { # When selecting alternatives we have to consider defaults, for example: # lib l : l.cpp : <variant>debug ; # lib l : l_opt.cpp : <variant>release ; # won't work unless we add default value <variant>debug. property-set = [ $(p).add-defaults ] ;
# The algorithm: we keep the current best viable alternative. When we've # got a new best viable alternative, we compare it with the current one.
local best ; local best-properties ;
if $(self.alternatives[2-]) { local bad ; local worklist = $(self.alternatives) ; while $(worklist) && ! $(bad) { local v = $(worklist[1]) ; local properties = [ $(v).match $(property-set) $(debug) ] ;
if $(properties) != no-match { if ! $(best) { best = $(v) ; best-properties = $(properties) ; } else { if $(properties) = $(best-properties) { bad = true ; } else if $(properties) in $(best-properties) { # Do nothing, this alternative is worse } else if $(best-properties) in $(properties) { best = $(v) ; best-properties = $(properties) ; } else { bad = true ; } } } worklist = $(worklist[2-]) ; } if ! $(bad) { return $(best) ; } } else { return $(self.alternatives) ; } }
rule apply-default-build ( property-set ) { return [ targets.apply-default-build $(property-set) : $(self.default-build) ] ; }
# Select an alternative for this main target, by finding all alternatives # which requirements are satisfied by 'properties' and picking the one with # the longest requirements set. Returns the result of calling 'generate' on # that alternative. # rule generate ( property-set ) { start-building $(__name__) ;
# We want composite properties in build request act as if all the # properties it expands too are explicitly specified. property-set = [ $(property-set).expand ] ;
local all-property-sets = [ apply-default-build $(property-set) ] ; local usage-requirements = [ property-set.empty ] ; local result ; for local p in $(all-property-sets) { local r = [ generate-really $(p) ] ; if $(r) { usage-requirements = [ $(usage-requirements).add $(r[1]) ] ; result += $(r[2-]) ; } } end-building $(__name__) ; return $(usage-requirements) [ sequence.unique $(result) ] ; }
# Generates the main target with the given property set and returns a list # which first element is property-set object containing usage-requirements # of generated target and with generated virtual target in other elements. # It is possible that no targets are generated. # local rule generate-really ( property-set ) { local best-alternatives = [ select-alternatives $(property-set) ] ; if ! $(best-alternatives) { ECHO "error: No best alternative for" [ full-name ] ; select-alternatives $(property-set) debug ; return [ property-set.empty ] ; } else { # Now return virtual targets for the only alternative. return [ $(best-alternatives).generate $(property-set) ] ; } }
rule rename ( new-name ) { abstract-target.rename $(new-name) ; for local a in $(self.alternatives) { $(a).rename $(new-name) ; } }}
# Abstract target refering to a source file. This is an artificial entity# allowing sources to a target to be represented using a list of abstract target# instances.#class file-reference : abstract-target{ import virtual-target ; import property-set ; import path ;
rule __init__ ( file : project ) { abstract-target.__init__ $(file) : $(project) ; }
rule generate ( properties ) { return [ property-set.empty ] [ virtual-target.from-file $(self.name) : [ location ] : $(self.project) ] ; }
# Returns true if the referred file really exists. rule exists ( ) { location ; return $(self.file-path) ; }
# Returns the location of target. Needed by 'testing.jam'. rule location ( ) { if ! $(self.file-location) { local source-location = [ $(self.project).get source-location ] ; for local src-dir in $(source-location) { if ! $(self.file-location) { local location = [ path.root $(self.name) $(src-dir) ] ; if [ CHECK_IF_FILE [ path.native $(location) ] ] { self.file-location = $(src-dir) ; self.file-path = $(location) ; } } } } return $(self.file-location) ; }}
# Given a target-reference, made in context of 'project', returns the# abstract-target instance that is referred to, as well as properties explicitly# specified for this reference.#rule resolve-reference ( target-reference : project ){ # Separate target name from properties override. local split = [ MATCH "^([^<]*)(/(<.*))?$" : $(target-reference) ] ; local id = $(split[1]) ; local sproperties = ; if $(split[3]) { sproperties = [ property.make [ feature.split $(split[3]) ] ] ; sproperties = [ feature.expand-composites $(sproperties) ] ; }
# Find the target. local target = [ $(project).find $(id) ] ;
return $(target) [ property-set.create $(sproperties) ] ;}
# Attempts to generate the target given by target reference, which can refer# both to a main target or to a file. Returns a list consisting of# - usage requirements# - generated virtual targets, if any#rule generate-from-reference ( target-reference # Target reference. : project # Project where the reference is made. : property-set # Properties of the main target that makes the reference.){ local r = [ resolve-reference $(target-reference) : $(project) ] ; local target = $(r[1]) ; local sproperties = $(r[2]) ;
# Take properties which should be propagated and refine them with # source-specific requirements. local propagated = [ $(property-set).propagated ] ; local rproperties = [ $(propagated).refine $(sproperties) ] ; if $(rproperties[1]) = "@error" { errors.error "When building" [ full-name ] " with properties " $(properties) : "Invalid properties specified for " $(source) ":" $(rproperties[2-]) ; } return [ $(target).generate $(rproperties) ] ;}
rule apply-default-build ( property-set : default-build ){ # 1. First, see what properties from default-build are already present # in property-set.
local raw = [ $(property-set).raw ] ; local specified-features = $(raw:G) ;
local defaults-to-apply ; for local d in [ $(default-build).raw ] { if ! $(d:G) in $(specified-features) { defaults-to-apply += $(d) ; } }
# 2. If there are any defaults to be applied, form a new build request. # Pass it through to 'expand-no-defaults' since default-build might # contain "release debug" resulting in two property-sets. local result ; if $(defaults-to-apply) { properties = [ build-request.expand-no-defaults
# We have to compress subproperties here to prevent property # lists like: # # <toolset>msvc <toolset-msvc:version>7.1 <threading>multi # # from being expanded into: # # <toolset-msvc:version>7.1/<threading>multi # <toolset>msvc/<toolset-msvc:version>7.1/<threading>multi # # due to a cross-product property combination. That may be an # indication that build-request.expand-no-defaults is the wrong # rule to use here. [ feature.compress-subproperties $(raw) ] $(defaults-to-apply) ] ;
if $(properties) { for local p in $(properties) { result += [ property-set.create [ feature.expand [ feature.split $(p) ] ] ] ; } } else { result = [ property-set.empty ] ; } } else { result = $(property-set) ; } return $(result) ;}
# Given a build request and requirements, return properties common to dependency# build request and target requirements.## TODO: Document exactly what 'common properties' are, whether they should# include default property values, whether they should contain any conditional# properties or should those be already processed, etc. See whether there are# any differences between use cases with empty and non-empty build-request as# well as with requirements containing and those not containing any non-free# features.#rule common-properties ( build-request requirements ){ # For optimization, we add free requirements directly, without using a # complex algorithm. This gives the complex algorithm a better chance of # caching results. local free = [ $(requirements).free ] ; local non-free = [ property-set.create [ $(requirements).base ] [ $(requirements).incidental ] ] ;
local key = .rp.$(build-request)-$(non-free) ; if ! $($(key)) { $(key) = [ common-properties2 $(build-request) $(non-free) ] ; } return [ $($(key)).add-raw $(free) ] ;}
# Given a 'context' -- a set of already present properties, and 'requirements',# decide which extra properties should be applied to 'context'. For conditional# requirements, this means evaluating the condition. For indirect conditional# requirements, this means calling a rule. Ordinary requirements are always# applied.## Handles the situation where evaluating one conditional requirement affects# conditions of another conditional requirements, such as:# <toolset>gcc:<variant>release <variant>release:<define>RELEASE## If 'what' is 'refined' returns context refined with new requirements. If# 'what' is 'added' returns just the requirements to be applied.#rule evaluate-requirements ( requirements : context : what ){ # Apply non-conditional requirements. It is possible that further # conditional requirement change a value set by non-conditional # requirements. For example: # # exe a : a.cpp : <threading>single <toolset>foo:<threading>multi ; # # I am not sure if this should be an error, or not, especially given that # # <threading>single # # might come from project's requirements.
local unconditional = [ feature.expand [ $(requirements).non-conditional ] ] ; local raw = [ $(context).raw ] ; raw = [ property.refine $(raw) : $(unconditional) ] ;
# We have collected properties that surely must be present in common # properties. We now try to figure out what other properties should be added # in order to satisfy rules (4)-(6) from the docs.
local conditionals = [ $(requirements).conditional ] ; # The 'count' variable has one element for each conditional feature and for # each occurrence of '<indirect-conditional>' feature. It is used as a loop # counter: for each iteration of the loop before we remove one element and # the property set should stabilize before we are done. It is assumed that # #conditionals iterations should be enough for properties to propagate # along conditions in any direction. local count = $(conditionals) [ $(requirements).get <conditional> ] and-once-more ;
local added-requirements ;
local current = $(raw) ;
# It is assumed that ordinary conditional requirements can not add # <conditional> properties (a.k.a. indirect conditional properties), and # that rules referred to by <conditional> properties can not add new # <conditional> properties. So the list of indirect conditionals does not # change. local indirect = [ $(requirements).get <conditional> ] ; indirect = [ MATCH ^@(.*) : $(indirect) ] ;
local ok ; while $(count) { # Evaluate conditionals in context of current properties. local e = [ property.evaluate-conditionals-in-context $(conditionals) : $(current) ] ;
# Evaluate indirect conditionals. for local i in $(indirect) { e += [ indirect.call $(i) $(current) ] ; }
if $(e) = $(added-requirements) { # If we got the same result, we have found the final properties. count = ; ok = true ; } else { # Oops, conditional evaluation results have changed. Also 'current' # contains leftovers from a previous evaluation. Recompute 'current' # using initial properties and conditional requirements. added-requirements = $(e) ; current = [ property.refine $(raw) : [ feature.expand $(e) ] ] ; } count = $(count[2-]) ; } if ! $(ok) { errors.error "Can not evaluate conditional properties " $(conditionals) ; }
if $(what) = added { return [ property-set.create $(unconditional) $(added-requirements) ] ; } else if $(what) = refined { return [ property-set.create $(current) ] ; } else { errors.error "Invalid value of the 'what' parameter." ; }}
rule common-properties2 ( build-request requirements ){ # This guarantees that default properties are present in the result, unless # they are overriden by some requirement. FIXME: There is possibility that # we have added <foo>bar, which is composite and expands to <foo2>bar2, but # default value of <foo2> is not bar2, in which case it is not clear what to # do. # build-request = [ $(build-request).add-defaults ] ; # Features added by 'add-default' can be composite and expand to features # without default values -- so they are not added yet. It could be clearer/ # /faster to expand only newly added properties but that is not critical. build-request = [ $(build-request).expand ] ;
return [ evaluate-requirements $(requirements) : $(build-request) : refined ] ;}
rule push-target ( target ){ .targets = $(target) $(.targets) ;}
rule pop-target ( ){ .targets = $(.targets[2-]) ;}
# Return the metatarget that is currently being generated.rule current ( ){ return $(.targets[1]) ;}
# Implements the most standard way of constructing main target alternative from# sources. Allows sources to be either file or other main target and handles# generation of those dependency targets.#class basic-target : abstract-target{ import build-request ; import build-system ; import "class" : new ; import errors ; import feature ; import property ; import property-set ; import sequence ; import set ; import targets ; import virtual-target ;
rule __init__ ( name : project : sources * : requirements * : default-build * : usage-requirements * ) { abstract-target.__init__ $(name) : $(project) ;
self.sources = $(sources) ; if ! $(requirements) { requirements = [ property-set.empty ] ; } self.requirements = $(requirements) ; if ! $(default-build) { default-build = [ property-set.empty ] ; } self.default-build = $(default-build) ; if ! $(usage-requirements) { usage-requirements = [ property-set.empty ] ; } self.usage-requirements = $(usage-requirements) ;
if $(sources:G) { errors.user-error properties found in the 'sources' parameter for [ full-name ] ; } } rule always ( ) { self.always = 1 ; } # Returns the list of abstract-targets which are used as sources. The extra # properties specified for sources are not represented. The only user for # this rule at the moment is the "--dump-tests" feature of the test system. # rule sources ( ) { if ! $(self.source-targets) { for local s in $(self.sources) { self.source-targets += [ targets.resolve-reference $(s) : $(self.project) ] ; } } return $(self.source-targets) ; }
rule requirements ( ) { return $(self.requirements) ; }
rule default-build ( ) { return $(self.default-build) ; }
# Returns the alternative condition for this alternative, if the condition # is satisfied by 'property-set'. # rule match ( property-set debug ? ) { # The condition is composed of all base non-conditional properties. It # is not clear if we should expand 'self.requirements' or not. For one # thing, it would be nice to be able to put # <toolset>msvc-6.0 # in requirements. On the other hand, if we have <variant>release as a # condition it does not make sense to require <optimization>full to be # in the build request just to select this variant. local bcondition = [ $(self.requirements).base ] ; local ccondition = [ $(self.requirements).conditional ] ; local condition = [ set.difference $(bcondition) : $(ccondition) ] ; if $(debug) { ECHO " next alternative: required properties:" $(condition:E=(empty)) ; }
if $(condition) in [ $(property-set).raw ] { if $(debug) { ECHO " matched" ; } return $(condition) ; } else { if $(debug) { ECHO " not matched" ; } return no-match ; } }
# Takes a target reference, which might be either target id or a dependency # property, and generates that target using 'property-set' as build request. # # The results are added to the variable called 'result-var'. Usage # requirements are added to the variable called 'usage-requirements-var'. # rule generate-dependencies ( dependencies * : property-set : result-var usage-requirements-var ) { for local dependency in $(dependencies) { local grist = $(dependency:G) ; local id = $(dependency:G=) ;
local result = [ targets.generate-from-reference $(id) : $(self.project) : $(property-set) ] ;
$(result-var) += $(result[2-]:G=$(grist)) ; $(usage-requirements-var) += [ $(result[1]).raw ] ; } }
# Determines final build properties, generates sources, and calls # 'construct'. This method should not be overridden. # rule generate ( property-set ) { if [ modules.peek : .debug-building ] { ECHO ; local fn = [ full-name ] ; ECHO [ targets.indent ] "Building target '$(fn)'" ; targets.increase-indent ; ECHO [ targets.indent ] "Build request: " $(property-set) [ $(property-set).raw ] ; local cf = [ build-system.command-line-free-features ] ; ECHO [ targets.indent ] "Command line free features: " [ $(cf).raw ] ; ECHO [ targets.indent ] "Target requirements: " [ $(self.requirements).raw ] ; } targets.push-target $(__name__) ;
if ! $(self.generated.$(property-set)) { # Apply free features from the command line. If user said # define=FOO # he most likely wants this define to be set for all compiles. property-set = [ $(property-set).refine [ build-system.command-line-free-features ] ] ; local rproperties = [ targets.common-properties $(property-set) $(self.requirements) ] ;
if [ modules.peek : .debug-building ] { ECHO ; ECHO [ targets.indent ] "Common properties: " [ $(rproperties).raw ] ; }
if ( $(rproperties[1]) != "@error" ) && ( [ $(rproperties).get <build> ] != no ) { local source-targets ; local properties = [ $(rproperties).non-dependency ] ; local usage-requirements ;
generate-dependencies [ $(rproperties).dependency ] : $(rproperties) : properties usage-requirements ;
generate-dependencies $(self.sources) : $(rproperties) : source-targets usage-requirements ;
if [ modules.peek : .debug-building ] { ECHO ; ECHO [ targets.indent ] "Usage requirements for" $(self.name)": " $(usage-requirements) ; }
rproperties = [ property-set.create $(properties) $(usage-requirements) ] ; usage-requirements = [ property-set.create $(usage-requirements) ] ;
if [ modules.peek : .debug-building ] { ECHO [ targets.indent ] "Build properties: " [ $(rproperties).raw ] ; }
local extra = [ $(rproperties).get <source> ] ; source-targets += $(extra:G=) ; # We might get duplicate sources, for example if we link to two # libraries having the same <library> usage requirement. # Use stable sort, since for some targets the order is # important. E.g. RUN_PY target need python source to come # first. source-targets = [ sequence.unique $(source-targets) : stable ] ;
local result = [ construct $(self.name) : $(source-targets) : $(rproperties) ] ;
if $(result) { local gur = $(result[1]) ; result = $(result[2-]) ; if $(self.always) { for local t in $(result) { $(t).always ; } } local s = [ create-subvariant $(result) : [ virtual-target.recent-targets ] : $(property-set) : $(source-targets) : $(rproperties) : $(usage-requirements) ] ; virtual-target.clear-recent-targets ;
local ur = [ compute-usage-requirements $(s) ] ; ur = [ $(ur).add $(gur) ] ; $(s).set-usage-requirements $(ur) ; if [ modules.peek : .debug-building ] { ECHO [ targets.indent ] "Usage requirements from" $(self.name)": " [ $(ur).raw ] ; }
self.generated.$(property-set) = $(ur) $(result) ; } } else { if $(rproperties[1]) = "@error" { ECHO [ targets.indent ] "Skipping build of:" [ full-name ] "cannot compute common properties" ; } else if [ $(rproperties).get <build> ] = no { # If we just see <build>no, we cannot produce any reasonable # diagnostics. The code that adds this property is expected # to explain why a target is not built, for example using # the configure.log-component-configuration function. } else { ECHO [ targets.indent ] "Skipping build of: " [ full-name ] " unknown reason" ; }
# We are here either because there has been an error computing # properties or there is <build>no in properties. In the latter # case we do not want any diagnostic. In the former case, we # need diagnostics. FIXME
# If this target fails to build, add <build>no to properties to # cause any parent target to fail to build. Except that it # - does not work now, since we check for <build>no only in # common properties, but not in properties that came from # dependencies # - it is not clear if that is a good idea anyway. The alias # target, for example, should not fail to build if a # dependency fails. self.generated.$(property-set) = [ property-set.create <build>no ] ; } } else { if [ modules.peek : .debug-building ] { ECHO [ targets.indent ] "Already built" ; local ur = $(self.generated.$(property-set)) ; ur = $(ur[0]) ; targets.increase-indent ; ECHO [ targets.indent ] "Usage requirements from" $(self.name)": " [ $(ur).raw ] ; targets.decrease-indent ; } }
targets.pop-target ; targets.decrease-indent ; return $(self.generated.$(property-set)) ; }
# Given the set of generated targets, and refined build properties, # determines and sets appropriate usage requirements on those targets. # rule compute-usage-requirements ( subvariant ) { local rproperties = [ $(subvariant).build-properties ] ; xusage-requirements = [ targets.evaluate-requirements $(self.usage-requirements) : $(rproperties) : added ] ;
# We generate all dependency properties and add them, as well as their # usage requirements, to the result. local extra ; generate-dependencies [ $(xusage-requirements).dependency ] : $(rproperties) : extra extra ;
local result = [ property-set.create [ $(xusage-requirements).non-dependency ] $(extra) ] ;
# Propagate usage requirements we got from sources, except for the # <pch-header> and <pch-file> features. # # That feature specifies which pch file to use, and should apply only to # direct dependents. Consider: # # pch pch1 : ... # lib lib1 : ..... pch1 ; # pch pch2 : # lib lib2 : pch2 lib1 ; # # Here, lib2 should not get <pch-header> property from pch1. # # Essentially, when those two features are in usage requirements, they # are propagated only to direct dependents. We might need a more general # mechanism, but for now, only those two features are special. # # TODO - Actually there are more possible candidates like for instance # when listing static library X as a source for another static library. # Then static library X will be added as a <source> property to the # second library's usage requirements but those requirements should last # only up to the first executable or shared library that actually links # to it. local raw = [ $(subvariant).sources-usage-requirements ] ; raw = [ $(raw).raw ] ; raw = [ property.change $(raw) : <pch-header> ] ; raw = [ property.change $(raw) : <pch-file> ] ; return [ $(result).add [ property-set.create $(raw) ] ] ; }
# Creates new subvariant instances for 'targets'. # 'root-targets' - virtual targets to be returned to dependants # 'all-targets' - virtual targets created while building this main target # 'build-request' - property-set instance with requested build properties # local rule create-subvariant ( root-targets * : all-targets * : build-request : sources * : rproperties : usage-requirements ) { for local e in $(root-targets) { $(e).root true ; }
# Process all virtual targets that will be created if this main target # is created. local s = [ new subvariant $(__name__) : $(build-request) : $(sources) : $(rproperties) : $(usage-requirements) : $(all-targets) ] ; for local v in $(all-targets) { if ! [ $(v).creating-subvariant ] { $(v).creating-subvariant $(s) ; } } return $(s) ; }
# Constructs virtual targets for this abstract target and the dependency # graph. Returns a usage-requirements property-set and a list of virtual # targets. Should be overriden in derived classes. # rule construct ( name : source-targets * : properties * ) { errors.error "method should be defined in derived classes" ; }}
class typed-target : basic-target{ import generators ;
rule __init__ ( name : project : type : sources * : requirements * : default-build * : usage-requirements * ) { basic-target.__init__ $(name) : $(project) : $(sources) : $(requirements) : $(default-build) : $(usage-requirements) ;
self.type = $(type) ; }
rule type ( ) { return $(self.type) ; }
rule construct ( name : source-targets * : property-set ) { local r = [ generators.construct $(self.project) $(name:S=) : $(self.type) : [ property-set.create [ $(property-set).raw ] <main-target-type>$(self.type) ] : $(source-targets) : true ] ; if ! $(r) { ECHO "warn: Unable to construct" [ full-name ] ;
# Are there any top-level generators for this type/property set. if ! [ generators.find-viable-generators $(self.type) : $(property-set) ] { ECHO "error: no generators were found for type '$(self.type)'" ; ECHO "error: and the requested properties" ; ECHO "error: make sure you've configured the needed tools" ; ECHO "See http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html" ; ECHO "To debug this problem, try the --debug-generators option." ; EXIT ; } } return $(r) ; }}
# Return the list of sources to use, if main target rule is invoked with# 'sources'. If there are any objects in 'sources', they are treated as main# target instances, and the name of such targets are adjusted to be# '<name_of_this_target>__<name_of_source_target>'. Such renaming is disabled if# a non-empty value is passed as the 'no-renaming' parameter.#rule main-target-sources ( sources * : main-target-name : no-renaming ? ){ local result ; for local t in $(sources) { if [ class.is-instance $(t) ] { local name = [ $(t).name ] ; if ! $(no-renaming) { name = $(main-target-name)__$(name) ; $(t).rename $(name) ; } # Inline targets are not built by default. local p = [ $(t).project ] ; $(p).mark-target-as-explicit $(name) ; result += $(name) ; } else { result += $(t) ; } } return $(result) ;}
# Returns the requirements to use when declaring a main target, obtained by# translating all specified property paths and refining project requirements# with the ones specified for the target.#rule main-target-requirements ( specification * # Properties explicitly specified for the main target. : project # Project where the main target is to be declared.){ specification += [ toolset.requirements ] ;
local requirements = [ property-set.refine-from-user-input [ $(project).get requirements ] : $(specification) : [ $(project).project-module ] : [ $(project).get location ] ] ; if $(requirements[1]) = "@error" { errors.error "Conflicting requirements for target:" $(requirements) ; } return $(requirements) ;}
# Returns the usage requirements to use when declaring a main target, which are# obtained by translating all specified property paths and adding project's# usage requirements.#rule main-target-usage-requirements ( specification * # Use-properties explicitly specified for a main target. : project # Project where the main target is to be declared.){ local project-usage-requirements = [ $(project).get usage-requirements ] ;
# We do not use 'refine-from-user-input' because: # - I am not sure if removing parent's usage requirements makes sense # - refining usage requirements is not needed, since usage requirements are # always free. local usage-requirements = [ property-set.create-from-user-input $(specification) : [ $(project).project-module ] [ $(project).get location ] ] ;
return [ $(project-usage-requirements).add $(usage-requirements) ] ;}
# Return the default build value to use when declaring a main target, which is# obtained by using the specified value if not empty and parent's default build# attribute otherwise.#rule main-target-default-build ( specification * # Default build explicitly specified for a main target. : project # Project where the main target is to be declared.){ local result ; if $(specification) { result = $(specification) ; } else { result = [ $(project).get default-build ] ; } return [ property-set.create-with-validation $(result) ] ;}
# Registers the specified target as a main target alternative and returns it.#rule main-target-alternative ( target ){ local ptarget = [ $(target).project ] ; $(ptarget).add-alternative $(target) ; return $(target) ;}
# Creates a new metargets with the specified properties, using 'klass' as# the class. The 'name', 'sources',# 'requirements', 'default-build' and 'usage-requirements' are assumed to be in# the form specified by the user in Jamfile corresponding to 'project'.#rule create-metatarget ( klass : project : name : sources * : requirements * : default-build * : usage-requirements * ){ return [ targets.main-target-alternative [ new $(klass) $(name) : $(project) : [ targets.main-target-sources $(sources) : $(name) ] : [ targets.main-target-requirements $(requirements) : $(project) ] : [ targets.main-target-default-build $(default-build) : $(project) ] : [ targets.main-target-usage-requirements $(usage-requirements) : $(project) ] ] ] ;}
# Creates a typed-target with the specified properties. The 'name', 'sources',# 'requirements', 'default-build' and 'usage-requirements' are assumed to be in# the form specified by the user in Jamfile corresponding to 'project'.#rule create-typed-target ( type : project : name : sources * : requirements * : default-build * : usage-requirements * ){ return [ targets.main-target-alternative [ new typed-target $(name) : $(project) : $(type) : [ targets.main-target-sources $(sources) : $(name) ] : [ targets.main-target-requirements $(requirements) : $(project) ] : [ targets.main-target-default-build $(default-build) : $(project) ] : [ targets.main-target-usage-requirements $(usage-requirements) : $(project) ] ] ] ;}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161# Copyright 2002, 2003, 2004, 2006 Vladimir Prus# Copyright 2008 Jurko Gospodnetic# Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
import errors ;import numbers ;
major = "2011" ;minor = "12" ;
rule boost-build ( ){ return "$(major).$(minor)-svn" ;}
rule print ( ){ if [ verify-engine-version ] { ECHO "Boost.Build" [ boost-build ] ; } }
rule verify-engine-version ( ){ local v = [ modules.peek : JAM_VERSION ] ; if $(v[1]) != $(major) || $(v[2]) != $(minor) { local argv = [ modules.peek : ARGV ] ; local e = $(argv[1]) ; local l = [ modules.binding version ] ; l = $(l:D) ; l = $(l:D) ; ECHO "warning: mismatched versions of Boost.Build engine and core" ; ECHO "warning: Boost.Build engine ($(e)) is $(v:J=.)" ; ECHO "warning: Boost.Build core (at $(l)) is" [ boost-build ] ; } else { return true ; } }
# Utility rule for testing whether all elements in a sequence are equal to 0.#local rule is-all-zeroes ( sequence * ){ local result = "true" ; for local e in $(sequence) { if $(e) != "0" { result = "" ; } } return $(result) ;}
# Returns "true" if the first version is less than the second one.#rule version-less ( lhs + : rhs + ){ numbers.check $(lhs) ; numbers.check $(rhs) ;
local done ; local result ;
while ! $(done) && $(lhs) && $(rhs) { if [ numbers.less $(lhs[1]) $(rhs[1]) ] { done = "true" ; result = "true" ; } else if [ numbers.less $(rhs[1]) $(lhs[1]) ] { done = "true" ; } else { lhs = $(lhs[2-]) ; rhs = $(rhs[2-]) ; } } if ( ! $(done) && ! $(lhs) && ! [ is-all-zeroes $(rhs) ] ) { result = "true" ; } return $(result) ;}
# Returns "true" if the current JAM version version is at least the given# version.#rule check-jam-version ( version + ){ local version-tag = $(version:J=.) ; if ! $(version-tag) { errors.error Invalid version specifier: : $(version:E="(undefined)") ; }
if ! $(.jam-version-check.$(version-tag))-is-not-empty { local jam-version = [ modules.peek : JAM_VERSION ] ; if ! $(jam-version) { errors.error "Unable to deduce Boost Jam version. Your Boost Jam" "installation is most likely terribly outdated." ; } .jam-version-check.$(version-tag) = "true" ; if [ version-less [ modules.peek : JAM_VERSION ] : $(version) ] { .jam-version-check.$(version-tag) = "" ; } } return $(.jam-version-check.$(version-tag)) ;}
rule __test__ ( ){ import assert ; local jam-version = [ modules.peek : JAM_VERSION ] ; local future-version = $(jam-version) ; future-version += "1" ;
assert.true check-jam-version $(jam-version) ; assert.false check-jam-version $(future-version) ;
assert.true version-less 0 : 1 ; assert.false version-less 0 : 0 ; assert.true version-less 1 : 2 ; assert.false version-less 1 : 1 ; assert.false version-less 2 : 1 ; assert.true version-less 3 1 20 : 3 4 10 ; assert.false version-less 3 1 10 : 3 1 10 ; assert.false version-less 3 4 10 : 3 1 20 ; assert.true version-less 3 1 20 5 1 : 3 4 10 ; assert.false version-less 3 1 10 5 1 : 3 1 10 ; assert.false version-less 3 4 10 5 1 : 3 1 20 ; assert.true version-less 3 1 20 : 3 4 10 5 1 ; assert.true version-less 3 1 10 : 3 1 10 5 1 ; assert.false version-less 3 4 10 : 3 1 20 5 1 ; assert.false version-less 3 1 10 : 3 1 10 0 0 ; assert.false version-less 3 1 10 0 0 : 3 1 10 ; assert.false version-less 3 1 10 0 : 3 1 10 0 0 ; assert.false version-less 3 1 10 0 : 03 1 10 0 0 ; assert.false version-less 03 1 10 0 : 3 1 10 0 0 ;
# TODO: Add tests for invalid input data being sent to version-less.}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317# Copyright 2003 Dave Abrahams# Copyright 2005, 2006 Rene Rivera# Copyright 2002, 2003, 2004, 2005, 2006 Vladimir Prus# Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
# Implements virtual targets, which correspond to actual files created during a# build, but are not yet targets in Jam sense. They are needed, for example,# when searching for possible transformation sequences, when it is not yet known# whether a particular target should be created at all.
import "class" : new ;import errors ;import path ;import sequence ;import set ;import type ;import utility ;
# +--------------------------+# | virtual-target |# +==========================+# | actualize |# +--------------------------+# | actualize-action() = 0 |# | actualize-location() = 0 |# +----------------+---------+# |# ^# / \# +-+-+# |# +---------------------+ +-------+--------------+# | action | | abstract-file-target |# +=====================| * +======================+# | action-name | +--+ action |# | properties | | +----------------------+# +---------------------+--+ | actualize-action() |# | actualize() |0..1 +-----------+----------+# | path() | |# | adjust-properties() | sources |# | actualize-sources() | targets |# +------+--------------+ ^# | / \# ^ +-+-+# / \ |# +-+-+ +-------------+-------------+# | | |# | +------+---------------+ +--------+-------------+# | | file-target | | searched-lib-target |# | +======================+ +======================+# | | actualize-location() | | actualize-location() |# | +----------------------+ +----------------------+# |# +-+------------------------------+# | |# +----+----------------+ +---------+-----------+# | compile-action | | link-action |# +=====================+ +=====================+# | adjust-properties() | | adjust-properties() |# +---------------------+ | actualize-sources() |# +---------------------+## The 'compile-action' and 'link-action' classes are not defined here but in# builtin.jam modules. They are shown in the diagram to give the big picture.
# Models a potential target. It can be converted into a Jam target and used in# building, if needed. However, it can be also dropped, which allows us to# search for different transformations and select only one.#class virtual-target{ import scanner ; import sequence ; import utility ; import virtual-target ;
rule __init__ ( name # Target/project name. : project # Project to which this target belongs. ) { self.name = $(name) ; self.project = $(project) ; self.dependencies = ; }
# Name of this target. # rule name ( ) { return $(self.name) ; }
# Project of this target. # rule project ( ) { return $(self.project) ; }
# Adds additional 'virtual-target' instances this one depends on. # rule depends ( d + ) { self.dependencies = [ sequence.merge $(self.dependencies) : [ sequence.insertion-sort $(d) ] ] ; }
rule dependencies ( ) { return $(self.dependencies) ; } rule always ( ) { .always = 1 ; } # Generates all the actual targets and sets up build actions for this # target. # # If 'scanner' is specified, creates an additional target with the same # location as the actual target, which will depend on the actual target and # be associated with a 'scanner'. That additional target is returned. See # the docs (#dependency_scanning) for rationale. Target must correspond to a # file if 'scanner' is specified. # # If scanner is not specified then the actual target is returned. # rule actualize ( scanner ? ) { local actual-name = [ actualize-no-scanner ] ; if $(.always) { ALWAYS $(actual-name) ; } if ! $(scanner) { return $(actual-name) ; } else { # Add the scanner instance to the grist for name. local g = [ sequence.join [ utility.ungrist $(actual-name:G) ] $(scanner) : - ] ; local name = $(actual-name:G=$(g)) ;
if ! $(self.made.$(name)) { self.made.$(name) = true ;
DEPENDS $(name) : $(actual-name) ;
actualize-location $(name) ;
scanner.install $(scanner) : $(name) $(__name__) ; } return $(name) ; } }
# private: (overridables)
# Sets up build actions for 'target'. Should call appropriate rules and set # target variables. # rule actualize-action ( target ) { errors.error "method should be defined in derived classes" ; }
# Sets up variables on 'target' which specify its location. # rule actualize-location ( target ) { errors.error "method should be defined in derived classes" ; }
# If the target is a generated one, returns the path where it will be # generated. Otherwise, returns an empty list. # rule path ( ) { errors.error "method should be defined in derived classes" ; }
# Returns the actual target name to be used in case when no scanner is # involved. # rule actual-name ( ) { errors.error "method should be defined in derived classes" ; }
# implementation rule actualize-no-scanner ( ) { # In fact, we just need to merge virtual-target with # abstract-file-target as the latter is the only class derived from the # former. But that has been left for later. errors.error "method should be defined in derived classes" ; }}
# Target corresponding to a file. The exact mapping for file is not yet# specified in this class. (TODO: Actually, the class name could be better...)## May be a source file (when no action is specified) or a derived file# (otherwise).## The target's grist is a concatenation of its project's location, action# properties (for derived targets) and, optionally, value identifying the main# target.#class abstract-file-target : virtual-target{ import project ; import regex ; import sequence ; import path ; import type ; import property-set ; import indirect ;
rule __init__ ( name # Target's name. exact ? # If non-empty, the name is exactly the name created file # should have. Otherwise, the '__init__' method will add a # suffix obtained from 'type' by calling # 'type.generated-target-suffix'. : type ? # Target's type. : project : action ? ) { virtual-target.__init__ $(name) : $(project) ;
self.type = $(type) ; self.action = $(action) ; if $(action) { $(action).add-targets $(__name__) ;
if $(self.type) && ! $(exact) { _adjust-name $(name) ; } } }
rule type ( ) { return $(self.type) ; }
# Sets the path. When generating target name, it will override any path # computation from properties. # rule set-path ( path ) { self.path = [ path.native $(path) ] ; }
# Returns the currently set action. # rule action ( ) { return $(self.action) ; }
# Sets/gets the 'root' flag. Target is root if it directly corresponds to # some variant of a main target. # rule root ( set ? ) { if $(set) { self.root = true ; } return $(self.root) ; }
# Gets or sets the subvariant which created this target. Subvariant is set # when target is brought into existance and is never changed after that. In # particular, if a target is shared by a subvariant, only the first is # stored. # rule creating-subvariant ( s ? # If specified, specifies the value to set, # which should be a 'subvariant' class # instance. ) { if $(s) && ! $(self.creating-subvariant) { self.creating-subvariant = $(s) ; } return $(self.creating-subvariant) ; }
rule actualize-action ( target ) { if $(self.action) { $(self.action).actualize ; } }
# Return a human-readable representation of this target. If this target has # an action, that is: # # { <action-name>-<self.name>.<self.type> <action-sources>... } # # otherwise, it is: # # { <self.name>.<self.type> } # rule str ( ) { local action = [ action ] ; local name-dot-type = [ sequence.join $(self.name) "." $(self.type) ] ;
if $(action) { local sources = [ $(action).sources ] ; local action-name = [ $(action).action-name ] ;
local ss ; for local s in $(sources) { ss += [ $(s).str ] ; }
return "{" $(action-name)-$(name-dot-type) $(ss) "}" ; } else { return "{" $(name-dot-type) "}" ; } }
rule less ( a ) { if [ str ] < [ $(a).str ] { return true ; } }
rule equal ( a ) { if [ str ] = [ $(a).str ] { return true ; } }
# private: rule actual-name ( ) { if ! $(self.actual-name) { local grist = [ grist ] ; local basename = [ path.native $(self.name) ] ; self.actual-name = <$(grist)>$(basename) ; } return $(self.actual-name) ; }
# Helper to 'actual-name', above. Computes a unique prefix used to # distinguish this target from other targets with the same name creating # different files. # rule grist ( ) { # Depending on target, there may be different approaches to generating # unique prefixes. We generate prefixes in the form: # <one letter approach code> <the actual prefix> local path = [ path ] ; if $(path) { # The target will be generated to a known path. Just use the path # for identification, since path is as unique as it can get. return p$(path) ; } else { # File is either source, which will be searched for, or is not a # file at all. Use the location of project for distinguishing. local project-location = [ $(self.project).get location ] ; local location-grist = [ sequence.join [ regex.split $(project-location) "/" ] : "!" ] ;
if $(self.action) { local ps = [ $(self.action).properties ] ; local property-grist = [ $(ps).as-path ] ; # 'property-grist' can be empty when 'ps' is an empty property # set. if $(property-grist) { location-grist = $(location-grist)/$(property-grist) ; } }
return l$(location-grist) ; } }
# Given the target name specified in constructor, returns the name which # should be really used, by looking at the <tag> properties. Tag properties # need to be specified as <tag>@rule-name. This makes Boost Build call the # specified rule with the target name, type and properties to get the new # name. If no <tag> property is specified or the rule specified by <tag> # returns nothing, returns the result of calling # virtual-target.add-prefix-and-suffix. # rule _adjust-name ( specified-name ) { local ps ; if $(self.action) { ps = [ $(self.action).properties ] ; } else { ps = [ property-set.empty ] ; }
# We add ourselves to the properties so that any tag rule can get more # direct information about the target than just that available through # the properties. This is useful in implementing name changes based on # the sources of the target. For example to make unique names of object # files based on the source file. --grafik ps = [ property-set.create [ $(ps).raw ] <target>$(__name__) ] ;
local tag = [ $(ps).get <tag> ] ;
if $(tag) { local rule-name = [ MATCH ^@(.*) : $(tag) ] ; if $(rule-name) { if $(tag[2]) { errors.error "<tag>@rulename is present but is not the only" "<tag> feature" ; }
self.name = [ indirect.call $(rule-name) $(specified-name) : $(self.type) : $(ps) ] ; } else { errors.error "The value of the <tag> feature must be '@rule-name'" ; } }
# If there is no tag or the tag rule returned nothing. if ! $(tag) || ! $(self.name) { self.name = [ virtual-target.add-prefix-and-suffix $(specified-name) : $(self.type) : $(ps) ] ; } }
rule actualize-no-scanner ( ) { local name = [ actual-name ] ;
# Do anything only on the first invocation. if ! $(self.made.$(name)) { self.made.$(name) = true ;
if $(self.action) { # For non-derived target, we do not care if there are several # virtual targets that refer to the same name. One case when # this is unavoidable is when the file name is main.cpp and two # targets have types CPP (for compiling) and MOCCABLE_CPP (for # conversion to H via Qt tools). virtual-target.register-actual-name $(name) : $(__name__) ; }
for local i in $(self.dependencies) { DEPENDS $(name) : [ $(i).actualize ] ; }
actualize-location $(name) ; actualize-action $(name) ; } return $(name) ; }}
# Appends the suffix appropriate to 'type/property-set' combination to the# specified name and returns the result.#rule add-prefix-and-suffix ( specified-name : type ? : property-set ){ local suffix = [ type.generated-target-suffix $(type) : $(property-set) ] ;
# Handle suffixes for which no leading dot is desired. Those are specified # by enclosing them in <...>. Needed by python so it can create "_d.so" # extensions, for example. if $(suffix:G) { suffix = [ utility.ungrist $(suffix) ] ; } else { suffix = .$(suffix) ; }
local prefix = [ type.generated-target-prefix $(type) : $(property-set) ] ;
if [ MATCH ^($(prefix)) : $(specified-name) ] { prefix = ; } return $(prefix:E="")$(specified-name)$(suffix:E="") ;}
# File targets with explicitly known location.## The file path is determined as# * Value passed to the 'set-path' method, if any.# * For derived files, project's build dir, joined with components that# describe action properties. If free properties are not equal to the# project's reference properties an element with the name of the main# target is added.# * For source files, project's source dir.## The file suffix is determined as:# * The value passed to the 'suffix' method, if any.# * The suffix corresponding to the target's type.#class file-target : abstract-file-target{ import "class" : new ; import common ; import errors ;
rule __init__ ( name exact ? : type ? # Optional type for this target. : project : action ? : path ? ) { abstract-file-target.__init__ $(name) $(exact) : $(type) : $(project) : $(action) ;
self.path = $(path) ; }
rule clone-with-different-type ( new-type ) { return [ new file-target $(self.name) exact : $(new-type) : $(self.project) : $(self.action) : $(self.path) ] ; }
rule actualize-location ( target ) { if $(self.action) { # This is a derived file. local path = [ path ] ; LOCATE on $(target) = $(path) ;
# Make sure the path exists. DEPENDS $(target) : $(path) ; common.MkDir $(path) ;
# It is possible that the target name includes a directory too, for # example when installing headers. Create that directory. if $(target:D) { local d = $(target:D) ; d = $(d:R=$(path)) ; DEPENDS $(target) : $(d) ; common.MkDir $(d) ; }
# For a real file target, we create a fake target depending on the # real target. This allows us to run # # bjam hello.o # # without trying to guess the name of the real target. Note that the # target has no directory name and uses a special <e> grist. # # First, that means that "bjam hello.o" will build all known hello.o # targets. Second, the <e> grist makes sure this target will not be # confused with other targets, for example, if we have subdir 'test' # with target 'test' in it that includes a 'test.o' file, then the # target for directory will be just 'test' the target for test.o # will be <ptest/bin/gcc/debug>test.o and the target we create below # will be <e>test.o DEPENDS $(target:G=e) : $(target) ; # Allow bjam <path-to-file>/<file> to work. This will not catch all # possible ways to refer to the path (relative/absolute, extra ".", # various "..", but should help in obvious cases. DEPENDS $(target:G=e:R=$(path)) : $(target) ; } else { SEARCH on $(target) = [ path.native $(self.path) ] ; } }
# Returns the directory for this target. # rule path ( ) { if ! $(self.path) { if $(self.action) { local p = [ $(self.action).properties ] ; local path,relative-to-build-dir = [ $(p).target-path ] ; local path = $(path,relative-to-build-dir[1]) ; local relative-to-build-dir = $(path,relative-to-build-dir[2]) ;
if $(relative-to-build-dir) { path = [ path.join [ $(self.project).build-dir ] $(path) ] ; }
self.path = [ path.native $(path) ] ; } } return $(self.path) ; }}
class notfile-target : abstract-file-target{ rule __init__ ( name : project : action ? ) { abstract-file-target.__init__ $(name) : : $(project) : $(action) ; }
# Returns nothing to indicate that the target's path is not known. # rule path ( ) { return ; }
rule actualize-location ( target ) { NOTFILE $(target) ; ALWAYS $(target) ; # TEMPORARY $(target) ; NOUPDATE $(target) ; }}
# Class representing an action. Both 'targets' and 'sources' should list# instances of 'virtual-target'. Action name should name a rule with this# prototype:# rule action-name ( targets + : sources * : properties * )# Targets and sources are passed as actual Jam targets. The rule may not# establish additional dependency relationships.#class action{ import "class" ; import errors ; import type ; import toolset ; import property-set ; import indirect ; import path ; import set : difference ;
rule __init__ ( sources * : action-name + : property-set ? ) { self.sources = $(sources) ;
self.action-name = [ indirect.make-qualified $(action-name) ] ;
if ! $(property-set) { property-set = [ property-set.empty ] ; }
if ! [ class.is-instance $(property-set) ] { errors.error "Property set instance required" ; }
self.properties = $(property-set) ; }
rule add-targets ( targets * ) { self.targets += $(targets) ; }
rule replace-targets ( old-targets * : new-targets * ) { self.targets = [ set.difference $(self.targets) : $(old-targets) ] ; self.targets += $(new-targets) ; }
rule targets ( ) { return $(self.targets) ; }
rule sources ( ) { return $(self.sources) ; }
rule action-name ( ) { return $(self.action-name) ; }
rule properties ( ) { return $(self.properties) ; }
# Generates actual build instructions. # rule actualize ( ) { if ! $(self.actualized) { self.actualized = true ;
local ps = [ properties ] ; local properties = [ adjust-properties $(ps) ] ;
local actual-targets ; for local i in [ targets ] { actual-targets += [ $(i).actualize ] ; }
actualize-sources [ sources ] : $(properties) ;
DEPENDS $(actual-targets) : $(self.actual-sources) $(self.dependency-only-sources) ; # This works around a bug with -j and actions that # produce multiple target, where: # - dependency on the first output is found, and # the action is started # - dependency on the second output is found, and # bjam noticed that command is already running # - instead of waiting for the command, dependents # of the second targets are immediately updated. if $(actual-targets[2]) { INCLUDES $(actual-targets) : $(actual-targets) ; } # Action name can include additional argument to rule, which should # not be passed to 'set-target-variables' toolset.set-target-variables [ indirect.get-rule $(self.action-name[1]) ] $(actual-targets) : $(properties) ;
# Reflect ourselves in a variable for the target. This allows # looking up additional info for the action given the raw target. # For example to debug or output action information from action # rules. .action on $(actual-targets) = $(__name__) ;
indirect.call $(self.action-name) $(actual-targets) : $(self.actual-sources) : [ $(properties).raw ] ;
# Since we set up the creating action here, we set up the action for # cleaning up as well. common.Clean clean-all : $(actual-targets) ; } }
# Helper for 'actualize-sources'. For each passed source, actualizes it with # the appropriate scanner. Returns the actualized virtual targets. # rule actualize-source-type ( sources * : property-set ) { local result = ; for local i in $(sources) { local scanner ; if [ $(i).type ] { scanner = [ type.get-scanner [ $(i).type ] : $(property-set) ] ; } result += [ $(i).actualize $(scanner) ] ; } return $(result) ; }
# Creates actual Jam targets for sources. Initializes the following member # variables: # 'self.actual-sources' -- sources passed to the updating action. # 'self.dependency-only-sources' -- sources marked as dependencies, but # are not used otherwise. # # New values will be *appended* to the variables. They may be non-empty if # caller wants it. # rule actualize-sources ( sources * : property-set ) { local dependencies = [ $(self.properties).get <dependency> ] ;
self.dependency-only-sources += [ actualize-source-type $(dependencies) : $(property-set) ] ; self.actual-sources += [ actualize-source-type $(sources) : $(property-set) ] ;
# This is used to help bjam find dependencies in generated headers and # other main targets, e.g. in: # # make a.h : ....... ; # exe hello : hello.cpp : <implicit-dependency>a.h ; # # For bjam to find the dependency the generated target must be # actualized (i.e. have its Jam target constructed). In the above case, # if we are building just hello ("bjam hello"), 'a.h' will not be # actualized unless we do it here. local implicit = [ $(self.properties).get <implicit-dependency> ] ; for local i in $(implicit) { $(i:G=).actualize ; } }
# Determines real properties when trying to build with 'properties'. This is # the last chance to fix properties, for example to adjust includes to get # generated headers correctly. Default implementation simply returns its # argument. # rule adjust-properties ( property-set ) { return $(property-set) ; }}
# Action class which does nothing --- it produces the targets with specific# properties out of nowhere. It is needed to distinguish virtual targets with# different properties that are known to exist and have no actions which create# them.#class null-action : action{ rule __init__ ( property-set ? ) { action.__init__ : .no-action : $(property-set) ; }
rule actualize ( ) { if ! $(self.actualized) { self.actualized = true ; for local i in [ targets ] { $(i).actualize ; } } }}
# Class which acts exactly like 'action', except that its sources are not# scanned for dependencies.#class non-scanning-action : action{ rule __init__ ( sources * : action-name + : property-set ? ) { action.__init__ $(sources) : $(action-name) : $(property-set) ; }
rule actualize-source-type ( sources * : property-set ) { local result ; for local i in $(sources) { result += [ $(i).actualize ] ; } return $(result) ; }}
# Creates a virtual target with an appropriate name and type from 'file'. If a# target with that name in that project already exists, returns that already# created target.## FIXME: a more correct way would be to compute the path to the file, based on# name and source location for the project, and use that path to determine if# the target has already been created. This logic should be shared with how we# usually find targets identified by a specific target id. It should also be# updated to work correctly when the file is specified using both relative and# absolute paths.## TODO: passing a project with all virtual targets is starting to be annoying.#rule from-file ( file : file-loc : project ){ import type ; # Had to do this here to break a circular dependency.
# Check whether we already created a target corresponding to this file. local path = [ path.root [ path.root $(file) $(file-loc) ] [ path.pwd ] ] ;
if $(.files.$(path)) { return $(.files.$(path)) ; } else { local name = [ path.make $(file) ] ; local type = [ type.type $(file) ] ; local result ;
result = [ new file-target $(file) : $(type) : $(project) : : $(file-loc) ] ;
.files.$(path) = $(result) ; return $(result) ; }}
# Registers a new virtual target. Checks if there is already a registered target# with the same name, type, project and subvariant properties as well as the# same sources and equal action. If such target is found it is returned and a# new 'target' is not registered. Otherwise, 'target' is registered and# returned.#rule register ( target ){ local signature = [ sequence.join [ $(target).path ] [ $(target).name ] : - ] ;
local result ; for local t in $(.cache.$(signature)) { local a1 = [ $(t).action ] ; local a2 = [ $(target).action ] ;
if ! $(result) { if ! $(a1) && ! $(a2) { result = $(t) ; } else { if $(a1) && $(a2) && ( [ $(a1).action-name ] = [ $(a2).action-name ] ) && ( [ $(a1).sources ] = [ $(a2).sources ] ) { local ps1 = [ $(a1).properties ] ; local ps2 = [ $(a2).properties ] ; local p1 = [ $(ps1).base ] [ $(ps1).free ] [ set.difference [ $(ps1).dependency ] : [ $(ps1).incidental ] ] ; local p2 = [ $(ps2).base ] [ $(ps2).free ] [ set.difference [ $(ps2).dependency ] : [ $(ps2).incidental ] ] ; if $(p1) = $(p2) { result = $(t) ; } } } } }
if ! $(result) { .cache.$(signature) += $(target) ; result = $(target) ; }
.recent-targets += $(result) ; .all-targets += $(result) ;
return $(result) ;}
# Each target returned by 'register' is added to the .recent-targets list,# returned by this function. This allows us to find all virtual targets created# when building a specific main target, even those constructed only as# intermediate targets.#rule recent-targets ( ){ return $(.recent-targets) ;}
rule clear-recent-targets ( ){ .recent-targets = ;}
# Returns all virtual targets ever created.#rule all-targets ( ){ return $(.all-targets) ;}
# Returns all targets from 'targets' with types equal to 'type' or derived from# it.#rule select-by-type ( type : targets * ){ local result ; for local t in $(targets) { if [ type.is-subtype [ $(t).type ] $(type) ] { result += $(t) ; } } return $(result) ;}
rule register-actual-name ( actual-name : virtual-target ){ if $(.actual.$(actual-name)) { local cs1 = [ $(.actual.$(actual-name)).creating-subvariant ] ; local cs2 = [ $(virtual-target).creating-subvariant ] ; local cmt1 = [ $(cs1).main-target ] ; local cmt2 = [ $(cs2).main-target ] ;
local action1 = [ $(.actual.$(actual-name)).action ] ; local action2 = [ $(virtual-target).action ] ; local properties-added ; local properties-removed ; if $(action1) && $(action2) { local p1 = [ $(action1).properties ] ; p1 = [ $(p1).raw ] ; local p2 = [ $(action2).properties ] ; p2 = [ $(p2).raw ] ; properties-removed = [ set.difference $(p1) : $(p2) ] ; properties-removed ?= "none" ; properties-added = [ set.difference $(p2) : $(p1) ] ; properties-added ?= "none" ; } errors.error "Duplicate name of actual target:" $(actual-name) : "previous virtual target" [ $(.actual.$(actual-name)).str ] : "created from" [ $(cmt1).full-name ] : "another virtual target" [ $(virtual-target).str ] : "created from" [ $(cmt2).full-name ] : "added properties:" $(properties-added) : "removed properties:" $(properties-removed) ; } else { .actual.$(actual-name) = $(virtual-target) ; }}
# Traverses the dependency graph of 'target' and return all targets that will be# created before this one is created. If the root of some dependency graph is# found during traversal, it is either included or not, depending on the# 'include-roots' value. In either case traversal stops at root targets, i.e.# root target sources are not traversed.#rule traverse ( target : include-roots ? : include-sources ? ){ local result ; if [ $(target).action ] { local action = [ $(target).action ] ; # This includes the 'target' as well. result += [ $(action).targets ] ;
for local t in [ $(action).sources ] { if ! [ $(t).root ] { result += [ traverse $(t) : $(include-roots) : $(include-sources) ] ; } else if $(include-roots) { result += $(t) ; } } } else if $(include-sources) { result = $(target) ; } return $(result) ;}
# Takes an 'action' instance and creates a new instance of it and all targets# produced by the action. The rule-name and properties are set to# 'new-rule-name' and 'new-properties', if those are specified. Returns the# cloned action.#rule clone-action ( action : new-project : new-action-name ? : new-properties ? ){ if ! $(new-action-name) { new-action-name = [ $(action).action-name ] ; } if ! $(new-properties) { new-properties = [ $(action).properties ] ; }
local action-class = [ modules.peek $(action) : __class__ ] ; local cloned-action = [ class.new $(action-class) [ $(action).sources ] : $(new-action-name) : $(new-properties) ] ;
local cloned-targets ; for local target in [ $(action).targets ] { local n = [ $(target).name ] ; # Do not modify produced target names. local cloned-target = [ class.new file-target $(n) exact : [ $(target).type ] : $(new-project) : $(cloned-action) ] ; local d = [ $(target).dependencies ] ; if $(d) { $(cloned-target).depends $(d) ; } $(cloned-target).root [ $(target).root ] ; $(cloned-target).creating-subvariant [ $(target).creating-subvariant ] ;
cloned-targets += $(cloned-target) ; }
return $(cloned-action) ;}
class subvariant{ import sequence ; import type ;
rule __init__ ( main-target # The instance of main-target class. : property-set # Properties requested for this target. : sources * : build-properties # Actually used properties. : sources-usage-requirements # Properties propagated from sources. : created-targets * ) # Top-level created targets. { self.main-target = $(main-target) ; self.properties = $(property-set) ; self.sources = $(sources) ; self.build-properties = $(build-properties) ; self.sources-usage-requirements = $(sources-usage-requirements) ; self.created-targets = $(created-targets) ;
# Pre-compose a list of other dependency graphs this one depends on. local deps = [ $(build-properties).get <implicit-dependency> ] ; for local d in $(deps) { self.other-dg += [ $(d:G=).creating-subvariant ] ; }
self.other-dg = [ sequence.unique $(self.other-dg) ] ; }
rule main-target ( ) { return $(self.main-target) ; }
rule created-targets ( ) { return $(self.created-targets) ; }
rule requested-properties ( ) { return $(self.properties) ; }
rule build-properties ( ) { return $(self.build-properties) ; }
rule sources-usage-requirements ( ) { return $(self.sources-usage-requirements) ; }
rule set-usage-requirements ( usage-requirements ) { self.usage-requirements = $(usage-requirements) ; }
rule usage-requirements ( ) { return $(self.usage-requirements) ; }
# Returns all targets referenced by this subvariant, either directly or # indirectly, and either as sources, or as dependency properties. Targets # referred to using the dependency property are returned as properties, not # targets. # rule all-referenced-targets ( theset ) { # Find directly referenced targets. local deps = [ $(self.build-properties).dependency ] ; local all-targets = $(self.sources) $(deps) ;
# Find other subvariants. local r ; for local t in $(all-targets) { if ! [ $(theset).contains $(t) ] { $(theset).add $(t) ; r += [ $(t:G=).creating-subvariant ] ; } } r = [ sequence.unique $(r) ] ; for local s in $(r) { if $(s) != $(__name__) { $(s).all-referenced-targets $(theset) ; } } }
# Returns the properties specifying implicit include paths to generated # headers. This traverses all targets in this subvariant and subvariants # referred by <implcit-dependecy> properties. For all targets of type # 'target-type' (or for all targets, if 'target-type' is not specified), the # result will contain <$(feature)>path-to-that-target. # rule implicit-includes ( feature : target-type ? ) { local key = ii$(feature)-$(target-type:E="") ; if ! $($(key))-is-not-empty { local target-paths = [ all-target-directories $(target-type) ] ; target-paths = [ sequence.unique $(target-paths) ] ; local result = $(target-paths:G=$(feature)) ; if ! $(result) { result = "" ; } $(key) = $(result) ; } if $($(key)) = "" { return ; } else { return $($(key)) ; } }
rule all-target-directories ( target-type ? ) { if ! $(self.target-directories) { compute-target-directories $(target-type) ; } return $(self.target-directories) ; }
rule compute-target-directories ( target-type ? ) { local result ; for local t in $(self.created-targets) { # Skip targets of the wrong type. if ! $(target-type) || [ type.is-derived [ $(t).type ] $(target-type) ] { result = [ sequence.merge $(result) : [ $(t).path ] ] ; } } for local d in $(self.other-dg) { result += [ $(d).all-target-directories $(target-type) ] ; } self.target-directories = $(result) ; }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336# Copyright 2001, 2002, 2003 Dave Abrahams# Copyright 2006 Rene Rivera# Copyright 2002, 2003 Vladimir Prus# Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
import errors ;import modules ;
################################################################################## Private implementation details.#################################################################################
# Rule added as a replacement for the regular Jam = operator but which does not# ignore trailing empty string elements.#local rule exact-equal-test ( lhs * : rhs * ){ local lhs_extended = $(lhs) xxx ; local rhs_extended = $(rhs) xxx ; if $(lhs_extended) = $(rhs_extended) { return true ; }}
# Two lists are considered set-equal if they contain the same elements, ignoring# duplicates and ordering.#local rule set-equal-test ( set1 * : set2 * ){ if ( $(set1) in $(set2) ) && ( $(set2) in $(set1) ) { return true ; }}
################################################################################## Public interface.#################################################################################
# Assert the equality of A and B, ignoring trailing empty string elements.#rule equal ( a * : b * ){ if $(a) != $(b) { errors.error-skip-frames 3 assertion failure: \"$(a)\" "==" \"$(b)\" (ignoring trailing empty strings) ; }}
# Assert that the result of calling RULE-NAME on the given arguments has a false# logical value (is either an empty list or all empty strings).#rule false ( rule-name args * : * ){ local result ; module [ CALLER_MODULE ] { modules.poke assert : result : [ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ; }
if $(result) { errors.error-skip-frames 3 assertion failure: Expected false result from "[" $(rule-name) [ errors.lol->list $(args) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] "]" : Got: "[" \"$(result)\" "]" ; }}
# Assert that ELEMENT is present in LIST.#rule "in" ( element : list * ){ if ! $(element) in $(list) { errors.error-skip-frames 3 assertion failure: Expected \"$(element)\" in "[" \"$(list)\" "]" ; }}
# Assert the inequality of A and B, ignoring trailing empty string elements.#rule not-equal ( a * : b * ){ if $(a) = $(b) { errors.error-skip-frames 3 assertion failure: \"$(a)\" "!=" \"$(b)\" (ignoring trailing empty strings) ; }}
# Assert that ELEMENT is not present in LIST.#rule not-in ( element : list * ){ if $(element) in $(list) { errors.error-skip-frames 3 assertion failure: Did not expect \"$(element)\" in "[" \"$(list)\" "]" ; }}
# Assert the inequality of A and B as sets.#rule not-set-equal ( a * : b * ){ if [ set-equal-test $(a) : $(b) ] { errors.error-skip-frames 3 assertion failure: Expected "[" \"$(a)\" "]" and "[" \"$(b)\" "]" to not be equal as sets ; }}
# Assert that A and B are not exactly equal, not ignoring trailing empty string# elements.#rule not-exact-equal ( a * : b * ){ if [ exact-equal-test $(a) : $(b) ] { errors.error-skip-frames 3 assertion failure: \"$(a)\" "!=" \"$(b)\" ; }}
# Assert that EXPECTED is the result of calling RULE-NAME with the given# arguments.#rule result ( expected * : rule-name args * : * ){ local result ; module [ CALLER_MODULE ] { modules.poke assert : result : [ $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ; }
if ! [ exact-equal-test $(result) : $(expected) ] { errors.error-skip-frames 3 assertion failure: "[" $(rule-name) [ errors.lol->list $(args) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] "]" : Expected: "[" \"$(expected)\" "]" : Got: "[" \"$(result)\" "]" ; }}
# Assert that EXPECTED is set-equal (i.e. duplicates and ordering are ignored)# to the result of calling RULE-NAME with the given arguments. Note that rules# called this way may accept at most 8 parameters.#rule result-set-equal ( expected * : rule-name args * : * ){ local result ; module [ CALLER_MODULE ] { modules.poke assert : result : [ $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ; }
if ! [ set-equal-test $(result) : $(expected) ] { errors.error-skip-frames 3 assertion failure: "[" $(rule-name) [ errors.lol->list $(args) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] "]" : Expected: "[" \"$(expected)\" "]" : Got: "[" \"$(result)\" "]" ; }}
# Assert the equality of A and B as sets.#rule set-equal ( a * : b * ){ if ! [ set-equal-test $(a) : $(b) ] { errors.error-skip-frames 3 assertion failure: Expected "[" \"$(a)\" "]" and "[" \"$(b)\" "]" to be equal as sets ; }}
# Assert that the result of calling RULE-NAME on the given arguments has a true# logical value (is neither an empty list nor all empty strings).#rule true ( rule-name args * : * ){ local result ; module [ CALLER_MODULE ] { modules.poke assert : result : [ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ; }
if ! $(result) { errors.error-skip-frames 3 assertion failure: Expected true result from "[" $(rule-name) [ errors.lol->list $(args) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] "]" ; }}
# Assert the exact equality of A and B, not ignoring trailing empty string# elements.#rule exact-equal ( a * : b * ){ if ! [ exact-equal-test $(a) : $(b) ] { errors.error-skip-frames 3 assertion failure: \"$(a)\" "==" \"$(b)\" ; }}
# Assert that the given variable is not an empty list.#rule variable-not-empty ( name ){ local value = [ modules.peek [ CALLER_MODULE ] : $(name) ] ; if ! $(value)-is-not-empty { errors.error-skip-frames 3 assertion failure: Expected variable \"$(name)\" not to be an empty list ; }}
rule __test__ ( ){ # Helper rule used to avoid test duplication related to different list # equality test rules. # local rule run-equality-test ( equality-assert : ignore-trailing-empty-strings ? ) { local not-equality-assert = not-$(equality-assert) ;
# When the given equality test is expected to ignore trailing empty # strings some of the test results should be inverted. local not-equality-assert-i = not-$(equality-assert) ; if $(ignore-trailing-empty-strings) { not-equality-assert-i = $(equality-assert) ; }
$(equality-assert) : ; $(equality-assert) "" "" : "" "" ; $(not-equality-assert-i) : "" "" ; $(equality-assert) x : x ; $(not-equality-assert) : x ; $(not-equality-assert) "" : x ; $(not-equality-assert) "" "" : x ; $(not-equality-assert-i) x : x "" ; $(equality-assert) x "" : x "" ; $(not-equality-assert) x : "" x ; $(equality-assert) "" x : "" x ;
$(equality-assert) 1 2 3 : 1 2 3 ; $(not-equality-assert) 1 2 3 : 3 2 1 ; $(not-equality-assert) 1 2 3 : 1 5 3 ; $(not-equality-assert) 1 2 3 : 1 "" 3 ; $(not-equality-assert) 1 2 3 : 1 1 2 3 ; $(not-equality-assert) 1 2 3 : 1 2 2 3 ; $(not-equality-assert) 1 2 3 : 5 6 7 ;
# Extra variables used here just to make sure Boost Jam or Boost Build # do not handle lists with empty strings differently depending on # whether they are literals or stored in variables.
local empty = ; local empty-strings = "" "" ; local x-empty-strings = x "" "" ; local empty-strings-x = "" "" x ;
$(equality-assert) : $(empty) ; $(not-equality-assert-i) "" : $(empty) ; $(not-equality-assert-i) "" "" : $(empty) ; $(not-equality-assert-i) : $(empty-strings) ; $(not-equality-assert-i) "" : $(empty-strings) ; $(equality-assert) "" "" : $(empty-strings) ; $(equality-assert) $(empty) : $(empty) ; $(equality-assert) $(empty-strings) : $(empty-strings) ; $(not-equality-assert-i) $(empty) : $(empty-strings) ; $(equality-assert) $(x-empty-strings) : $(x-empty-strings) ; $(equality-assert) $(empty-strings-x) : $(empty-strings-x) ; $(not-equality-assert) $(empty-strings-x) : $(x-empty-strings) ; $(not-equality-assert-i) x : $(x-empty-strings) ; $(not-equality-assert) x : $(empty-strings-x) ; $(not-equality-assert-i) x : $(x-empty-strings) ; $(not-equality-assert-i) x "" : $(x-empty-strings) ; $(equality-assert) x "" "" : $(x-empty-strings) ; $(not-equality-assert) x : $(empty-strings-x) ; $(not-equality-assert) "" x : $(empty-strings-x) ; $(equality-assert) "" "" x : $(empty-strings-x) ; }
# --------------- # Equality tests. # ---------------
run-equality-test equal : ignore-trailing-empty-strings ; run-equality-test exact-equal ;
# ------------------------- # assert.set-equal() tests. # -------------------------
set-equal : ; not-set-equal "" "" : ; set-equal "" "" : "" ; set-equal "" "" : "" "" ; set-equal a b c : a b c ; set-equal a b c : b c a ; set-equal a b c a : a b c ; set-equal a b c : a b c a ; not-set-equal a b c : a b c d ; not-set-equal a b c d : a b c ;}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997# Copyright 2002, 2005 Dave Abrahams# Copyright 2002, 2003, 2006 Rene Rivera# Copyright 2003 Vladimir Prus# Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
# Documentation system, handles --help requests.# It defines rules that attach documentation to modules, rules, and variables.# Collects and generates documentation for the various parts of the build# system. The documentation is collected from comments integrated into the code.
import modules ;import print ;import set ;import container ;import "class" ;import sequence ;import path ;
# The type of output to generate.# "console" is formated text echoed to the console (the default);# "text" is formated text appended to the output file;# "html" is HTML output to the file.#help-output = console ;
# The file to output documentation to when generating "text" or "html" help.# This is without extension as the extension is determined by the type of# output.#help-output-file = help ;
# Whether to include local rules in help output.#.option.show-locals ?= ;
# When showing documentation for a module, whether to also generate# automatically the detailed docs for each item in the module.#.option.detailed ?= ;
# Generate debug output as the help is generated and modules are parsed.#.option.debug ?= ;
# Enable or disable a documentation option.#local rule set-option ( option # The option name. : value ? # Enabled (non-empty), or disabled (empty)){ .option.$(option) = $(value) ;}
# Set the type of output.#local rule set-output ( type ){ help-output = $(type) ;}
# Set the output to a file.#local rule set-output-file ( file ){ help-output-file = $(file) ;}
# Extracts the brief comment from a complete comment. The brief comment is the# first sentence.#local rule brief-comment ( docs * # The comment documentation.){ local d = $(docs:J=" ") ; local p = [ MATCH ".*([.])$" : $(d) ] ; if ! $(p) { d = $(d)"." ; } d = $(d)" " ; local m = [ MATCH "^([^.]+[.])(.*)" : $(d) ] ; local brief = $(m[1]) ; while $(m[2]) && [ MATCH "^([^ ])" : $(m[2]) ] { m = [ MATCH "^([^.]+[.])(.*)" : $(m[2]) ] ; brief += $(m[1]) ; } return $(brief:J="") ;}
# Specifies the documentation for the current module.#local rule set-module-doc ( module-name ? # The name of the module to document. : docs * # The documentation for the module.){ module-name ?= * ;
$(module-name).brief = [ brief-comment $(docs) ] ; $(module-name).docs = $(docs) ;
if ! $(module-name) in $(documented-modules) { documented-modules += $(module-name) ; }}
# Specifies the documentation for the current module.#local rule set-module-copyright ( module-name ? # The name of the module to document. : copyright * # The copyright for the module.){ module-name ?= * ;
$(module-name).copy-brief = [ brief-comment $(copyright) ] ; $(module-name).copy-docs = $(docs) ;
if ! $(module-name) in $(documented-modules) { documented-modules += $(module-name) ; }}
# Specifies the documentation for a rule in the current module. If called in the# global module, this documents a global rule.#local rule set-rule-doc ( name # The name of the rule. module-name ? # The name of the module to document. is-local ? # Whether the rule is local to the module. : docs * # The documentation for the rule.){ module-name ?= * ;
$(module-name).$(name).brief = [ brief-comment $(docs) ] ; $(module-name).$(name).docs = $(docs) ; $(module-name).$(name).is-local = $(is-local) ;
if ! $(name) in $($(module-name).rules) { $(module-name).rules += $(name) ; }}
# Specify a class, will turn a rule into a class.#local rule set-class-doc ( name # The name of the class. module-name ? # The name of the module to document. : super-name ? # The super class name.){ module-name ?= * ;
$(module-name).$(name).is-class = true ; $(module-name).$(name).super-name = $(super-name) ; $(module-name).$(name).class-rules = [ MATCH "^($(name)[.].*)" : $($(module-name).rules) ] ; $(module-name).$($(module-name).$(name).class-rules).is-class-rule = true ;
$(module-name).classes += $(name) ; $(module-name).class-rules += $($(module-name).$(name).class-rules) ; $(module-name).rules = [ set.difference $($(module-name).rules) : $(name) $($(module-name).$(name).class-rules) ] ;}
# Set the argument call signature of a rule.#local rule set-rule-arguments-signature ( name # The name of the rule. module-name ? # The name of the module to document. : signature * # The arguments signature.){ module-name ?= * ;
$(module-name).$(name).signature = $(signature) ;}
# Specifies the documentation for an argument of a rule.#local rule set-argument-doc ( name # The name of the argument. qualifier # Argument syntax qualifier, "*", "+", etc. rule-name # The name of the rule. module-name ? # THe optional name of the module. : docs * # The documentation.){ module-name ?= * ;
$(module-name).$(rule-name).args.$(name).qualifier = $(qualifier) ; $(module-name).$(rule-name).args.$(name).docs = $(docs) ;
if ! $(name) in $($(module-name).$(rule-name).args) { $(module-name).$(rule-name).args += $(name) ; }}
# Specifies the documentation for a variable in the current module. If called in# the global module, the global variable is documented.#local rule set-variable-doc ( name # The name of the variable. default # The default value. initial # The initial value. module-name ? # The name of the module to document. : docs * # The documentation for the variable.){ module-name ?= * ;
$(module-name).$(name).brief = [ brief-comment $(docs) ] ; $(module-name).$(name).default = $(default) ; $(module-name).$(name).initial = $(initial) ; $(module-name).$(name).docs = $(docs) ;
if ! $(name) in $($(module-name).variables) { $(module-name).variables += $(name) ; }}
# Generates a general description of the documentation and help system.#local rule print-help-top ( ){ print.section "General command line usage" ;
print.text " bjam [options] [properties] [targets]
Options, properties and targets can be specified in any order. " ;
print.section "Important Options" ;
print.list-start ; print.list-item "--clean Remove targets instead of building" ; print.list-item "-a Rebuild everything" ; print.list-item "-n Don't execute the commands, only print them" ; print.list-item "-d+2 Show commands as they are executed" ; print.list-item "-d0 Supress all informational messages" ; print.list-item "-q Stop at first error" ; print.list-item "--debug-configuration Diagnose configuration" ; print.list-item "--debug-building Report which targets are built with what properties" ; print.list-item "--debug-generator Diagnose generator search/execution" ; print.list-end ;
print.section "Further Help" The following options can be used to obtain additional documentation. ;
print.list-start ; print.list-item "--help-options Print more obscure command line options." ; print.list-item "--help-internal Boost.Build implementation details." ; print.list-item "--help-doc-options Implementation details doc formatting." ; print.list-end ;}
# Generate Jam/Boost.Jam command usage information.#local rule print-help-usage ( ){ print.section "Boost.Jam Usage" "bjam [ options... ] targets..." ; print.list-start ; print.list-item -a; Build all targets, even if they are current. ; print.list-item -fx; Read '"x"' as the Jamfile for building instead of searching for the Boost.Build system. ; print.list-item -jx; Run up to '"x"' commands concurrently. ; print.list-item -n; Do not execute build commands. Instead print out the commands as they would be executed if building. ; print.list-item -ox; Output the used build commands to file '"x"'. ; print.list-item -q; Quit as soon as a build failure is encountered. Without this option Boost.Jam will continue building as many targets as it can. print.list-item -sx=y; Sets a Jam variable '"x"' to the value '"y"', overriding any value that variable would have from the environment. ; print.list-item -tx; Rebuild the target '"x"', even if it is up-to-date. ; print.list-item -v; Display the version of bjam. ; print.list-item --x; Any option not explicitly handled by Boost.Jam remains available to build scripts using the '"ARGV"' variable. ; print.list-item -dn; Enables output of diagnostic messages. The debug level '"n"' and all below it are enabled by this option. ; print.list-item -d+n; Enables output of diagnostic messages. Only the output for debug level '"n"' is enabled. ; print.list-end ; print.section "Debug Levels" Each debug level shows a different set of information. Usually with higher levels producing more verbose information. The following levels are supported: ; print.list-start ; print.list-item 0; Turn off all diagnostic output. Only errors are reported. ; print.list-item 1; Show the actions taken for building targets, as they are executed. ; print.list-item 2; Show "quiet" actions and display all action text, as they are executed. ; print.list-item 3; Show dependency analysis, and target/source timestamps/paths. ; print.list-item 4; Show arguments of shell invocations. ; print.list-item 5; Show rule invocations and variable expansions. ; print.list-item 6; Show directory/header file/archive scans, and attempts at binding to targets. ; print.list-item 7; Show variable settings. ; print.list-item 8; Show variable fetches, variable expansions, and evaluation of '"if"' expressions. ; print.list-item 9; Show variable manipulation, scanner tokens, and memory usage. ; print.list-item 10; Show execution times for rules. ; print.list-item 11; Show parsing progress of Jamfiles. ; print.list-item 12; Show graph for target dependencies. ; print.list-item 13; Show changes in target status (fate). ; print.list-end ;}
# Generates description of options controlling the help system. This# automatically reads the options as all variables in the doc module of the form# ".option.*".#local rule print-help-options ( module-name # The doc module.){ print.section "Help Options" These are all the options available for enabling or disabling to control the help system in various ways. Options can be enabled or disabled with '"--help-enable-<option>"', and "'--help-disable-<option>'" respectively. ; local options-to-list = [ MATCH ^[.]option[.](.*) : $($(module-name).variables) ] ; if $(options-to-list) { print.list-start ; for local option in [ sequence.insertion-sort $(options-to-list) ] { local def = disabled ; if $($(module-name)..option.$(option).default) != "(empty)" { def = enabled ; } print.list-item $(option): $($(module-name)..option.$(option).docs) Default is $(def). ; } print.list-end ; }}
# Generate brief documentation for all the known items in the section for a# module. Possible sections are: "rules", and "variables".#local rule print-help-module-section ( module # The module name. section # rules or variables. : section-head # The title of the section. section-description * # The detailed description of the section.){ if $($(module).$(section)) { print.section $(section-head) $(section-description) ; print.list-start ; for local item in [ sequence.insertion-sort $($(module).$(section)) ] { local show = ; if ! $($(module).$(item).is-local) { show = yes ; } if $(.option.show-locals) { show = yes ; } if $(show) { print.list-item $(item): $($(module).$(item).brief) ; } } print.list-end ; }}
# Generate documentation for all possible modules. We attempt to list all known# modules together with a brief description of each.#local rule print-help-all ( ignored # Usually the module name, but is ignored here.){ print.section "Modules" "These are all the known modules. Use --help <module> to get more" "detailed information." ; if $(documented-modules) { print.list-start ; for local module-name in [ sequence.insertion-sort $(documented-modules) ] { # The brief docs for each module. print.list-item $(module-name): $($(module-name).brief) ; } print.list-end ; } # The documentation for each module when details are requested. if $(documented-modules) && $(.option.detailed) { for local module-name in [ sequence.insertion-sort $(documented-modules) ] { # The brief docs for each module. print-help-module $(module-name) ; } }}
# Generate documentation for a module. Basic information about the module is# generated.#local rule print-help-module ( module-name # The module to generate docs for.){ # Print the docs. print.section "Module '$(module-name)'" $($(module-name).docs) ;
# Print out the documented classes. print-help-module-section $(module-name) classes : "Module '$(module-name)' classes" Use --help $(module-name).<class-name> to get more information. ;
# Print out the documented rules. print-help-module-section $(module-name) rules : "Module '$(module-name)' rules" Use --help $(module-name).<rule-name> to get more information. ;
# Print out the documented variables. print-help-module-section $(module-name) variables : "Module '$(module-name)' variables" Use --help $(module-name).<variable-name> to get more information. ;
# Print out all the same information but indetailed form. if $(.option.detailed) { print-help-classes $(module-name) ; print-help-rules $(module-name) ; print-help-variables $(module-name) ; }}
# Generate documentation for a set of rules in a module.#local rule print-help-rules ( module-name # Module of the rules. : name * # Optional list of rules to describe.){ name ?= $($(module-name).rules) ; if [ set.intersection $(name) : $($(module-name).rules) $($(module-name).class-rules) ] { # Print out the given rules. for local rule-name in [ sequence.insertion-sort $(name) ] { if $(.option.show-locals) || ! $($(module-name).$(rule-name).is-local) { local signature = $($(module-name).$(rule-name).signature:J=" ") ; signature ?= "" ; print.section "Rule '$(module-name).$(rule-name) ( $(signature) )'" $($(module-name).$(rule-name).docs) ; if $($(module-name).$(rule-name).args) { print.list-start ; for local arg-name in $($(module-name).$(rule-name).args) { print.list-item $(arg-name): $($(module-name).$(rule-name).args.$(arg-name).docs) ; } print.list-end ; } } } }}
# Generate documentation for a set of classes in a module.#local rule print-help-classes ( module-name # Module of the classes. : name * # Optional list of classes to describe.){ name ?= $($(module-name).classes) ; if [ set.intersection $(name) : $($(module-name).classes) ] { # Print out the given classes. for local class-name in [ sequence.insertion-sort $(name) ] { if $(.option.show-locals) || ! $($(module-name).$(class-name).is-local) { local signature = $($(module-name).$(class-name).signature:J=" ") ; signature ?= "" ; print.section "Class '$(module-name).$(class-name) ( $(signature) )'" $($(module-name).$(class-name).docs) "Inherits from '"$($(module-name).$(class-name).super-name)"'." ; if $($(module-name).$(class-name).args) { print.list-start ; for local arg-name in $($(module-name).$(class-name).args) { print.list-item $(arg-name): $($(module-name).$(class-name).args.$(arg-name).docs) ; } print.list-end ; } }
# Print out the documented rules of the class. print-help-module-section $(module-name) $(class-name).class-rules : "Class '$(module-name).$(class-name)' rules" Use --help $(module-name).<rule-name> to get more information. ;
# Print out all the rules if details are requested. if $(.option.detailed) { print-help-rules $(module-name) : $($(module-name).$(class-name).class-rules) ; } } }}
# Generate documentation for a set of variables in a module.#local rule print-help-variables ( module-name ? # Module of the variables. : name * # Optional list of variables to describe.){ name ?= $($(module-name).variables) ; if [ set.intersection $(name) : $($(module-name).variables) ] { # Print out the given variables. for local variable-name in [ sequence.insertion-sort $(name) ] { print.section "Variable '$(module-name).$(variable-name)'" $($(module-name).$(variable-name).docs) ; if $($(module-name).$(variable-name).default) || $($(module-name).$(variable-name).initial) { print.list-start ; if $($(module-name).$(variable-name).default) { print.list-item "default value:" '$($(module-name).$(variable-name).default:J=" ")' ; } if $($(module-name).$(variable-name).initial) { print.list-item "initial value:" '$($(module-name).$(variable-name).initial:J=" ")' ; } print.list-end ; } } }}
# Generate documentation for a project.#local rule print-help-project ( unused ? : jamfile * # The project Jamfile.){ if $(jamfile<$(jamfile)>.docs) { # Print the docs. print.section "Project-specific help" Project has jamfile at $(jamfile) ;
print.lines $(jamfile<$(jamfile)>.docs) "" ; }}
# Generate documentation for a config file.#local rule print-help-config ( unused ? : type # The type of configuration file user or site. config-file # The configuration Jamfile.){ if $(jamfile<$(config-file)>.docs) { # Print the docs. print.section "Configuration help" Configuration file at $(config-file) ;
print.lines $(jamfile<$(config-file)>.docs) "" ; }}
ws = " " ;
# Extract the text from a block of comments.#local rule extract-comment ( var # The name of the variable to extract from.){ local comment = ; local line = $($(var)[1]) ; local l = [ MATCH "^[$(ws)]*(#)(.*)$" : $(line) ] ; while $(l[1]) && $($(var)) { if $(l[2]) { comment += [ MATCH "^[$(ws)]?(.*)$" : $(l[2]) ] ; } else { comment += "" ; } $(var) = $($(var)[2-]) ; line = $($(var)[1]) ; l = [ MATCH "^[$(ws)]*(#)(.*)$" : $(line) ] ; } return $(comment) ;}
# Extract s single line of Jam syntax, ignoring any comments.#local rule extract-syntax ( var # The name of the variable to extract from.){ local syntax = ; local line = $($(var)[1]) ; while ! $(syntax) && ! [ MATCH "^[$(ws)]*(#)" : $(line) ] && $($(var)) { local m = [ MATCH "^[$(ws)]*(.*)$" : $(line) ] ; if $(m) { syntax = $(m) ; } $(var) = $($(var)[2-]) ; line = $($(var)[1]) ; } return $(syntax) ;}
# Extract the next token, this is either a single Jam construct or a comment as# a single token.#local rule extract-token ( var # The name of the variable to extract from.){ local parts = ; while ! $(parts) { parts = [ MATCH "^[$(ws)]*([^$(ws)]+)[$(ws)]*(.*)" : $($(var)[1]) ] ; if ! $(parts) { $(var) = $($(var)[2-]) ; } } local token = ; if [ MATCH "^(#)" : $(parts[1]) ] { token = $(parts:J=" ") ; $(var) = $($(var)[2-]) ; } else { token = $(parts[1]) ; $(var) = $(parts[2-]:J=" ") $($(var)[2-]) ; } return $(token) ;}
# Scan for a rule declaration as the next item in the variable.#local rule scan-rule ( syntax ? # The first part of the text which contains the rule declaration. : var # The name of the variable to extract from.){ local rule-parts = [ MATCH "^[$(ws)]*(rule|local[$(ws)]*rule)[$(ws)]+([^$(ws)]+)[$(ws)]*(.*)" : $(syntax:J=" ") ] ; if $(rule-parts[1]) { # Mark as doc for rule. local rule-name = $(rule-parts[2]) ; if $(scope-name) { rule-name = $(scope-name).$(rule-name) ; } local is-local = [ MATCH "^(local).*" : $(rule-parts[1]) ] ; if $(comment-block) { set-rule-doc $(rule-name) $(module-name) $(is-local) : $(comment-block) ; } # Parse args of rule. $(var) = $(rule-parts[3-]) $($(var)) ; set-rule-arguments-signature $(rule-name) $(module-name) : [ scan-rule-arguments $(var) ] ; # Scan within this rules scope. local scope-level = [ extract-token $(var) ] ; local scope-name = $(rule-name) ; while $(scope-level) { local comment-block = [ extract-comment $(var) ] ; local syntax-block = [ extract-syntax $(var) ] ; if [ scan-rule $(syntax-block) : $(var) ] { } else if [ MATCH "^(\\{)" : $(syntax-block) ] { scope-level += "{" ; } else if [ MATCH "^[^\\}]*([\\}])[$(ws)]*$" : $(syntax-block) ] { scope-level = $(scope-level[2-]) ; } }
return true ; }}
# Scan the arguments of a rule.#local rule scan-rule-arguments ( var # The name of the variable to extract from.){ local arg-syntax = ; local token = [ extract-token $(var) ] ; while $(token) != "(" && $(token) != "{" { token = [ extract-token $(var) ] ; } if $(token) != "{" { token = [ extract-token $(var) ] ; } local arg-signature = ; while $(token) != ")" && $(token) != "{" { local arg-name = ; local arg-qualifier = " " ; local arg-doc = ; if $(token) = ":" { arg-signature += $(token) ; token = [ extract-token $(var) ] ; } arg-name = $(token) ; arg-signature += $(token) ; token = [ extract-token $(var) ] ; if [ MATCH "^([\\*\\+\\?])" : $(token) ] { arg-qualifier = $(token) ; arg-signature += $(token) ; token = [ extract-token $(var) ] ; } if $(token) = ":" { arg-signature += $(token) ; token = [ extract-token $(var) ] ; } if [ MATCH "^(#)" : $(token) ] { $(var) = $(token) $($(var)) ; arg-doc = [ extract-comment $(var) ] ; token = [ extract-token $(var) ] ; } set-argument-doc $(arg-name) $(arg-qualifier) $(rule-name) $(module-name) : $(arg-doc) ; } while $(token) != "{" { token = [ extract-token $(var) ] ; } $(var) = "{" $($(var)) ; arg-signature ?= "" ; return $(arg-signature) ;}
# Scan for a variable declaration.#local rule scan-variable ( syntax ? # The first part of the text which contains the variable declaration. : var # The name of the variable to extract from.){ # [1] = name, [2] = value(s) local var-parts = [ MATCH "^[$(ws)]*([^$(ws)]+)[$(ws)]+([\\?\\=]*)[$(ws)]+([^\\;]*)\\;" : $(syntax) ] ; if $(var-parts) { local value = [ MATCH "^(.*)[ ]$" : $(var-parts[3-]:J=" ") ] ; local default-value = "" ; local initial-valie = "" ; if $(var-parts[2]) = "?=" { default-value = $(value) ; default-value ?= "(empty)" ; } else { initial-value = $(value) ; initial-value ?= "(empty)" ; } if $(comment-block) { set-variable-doc $(var-parts[1]) $(default-value) $(initial-value) $(module-name) : $(comment-block) ; } return true ; }}
# Scan a class declaration.#local rule scan-class ( syntax ? # The syntax text for the class declaration.){ # [1] = class?, [2] = name, [3] = superclass local class-parts = [ MATCH "^[$(ws)]*([^$(ws)]+)[$(ws)]+([^$(ws)]+)[$(ws)]+:*[$(ws)]*([^$(ws);]*)" : $(syntax) ] ; if $(class-parts[1]) = "class" || $(class-parts[1]) = "class.class" { set-class-doc $(class-parts[2]) $(module-name) : $(class-parts[3]) ; }}
# Scan a module file for documentation comments. This also invokes any actions# assigned to the module. The actions are the rules that do the actual output of# the documentation. This rule is invoked as the header scan rule for the module# file.#rule scan-module ( target # The module file. : text * # The text in the file, one item per line. : action * # Rule to call to output docs for the module.){ if $(.option.debug) { ECHO "HELP:" scanning module target '$(target)' ; } local module-name = $(target:B) ; local module-documented = ; local comment-block = ; local syntax-block = ; # This is a hack because we can not get the line of a file if it happens to # not have a new-line termination. text += "}" ; while $(text) { comment-block = [ extract-comment text ] ; syntax-block = [ extract-syntax text ] ; if $(.option.debug) { ECHO "HELP:" comment block; '$(comment-block)' ; ECHO "HELP:" syntax block; '$(syntax-block)' ; } if [ scan-rule $(syntax-block) : text ] { } else if [ scan-variable $(syntax-block) : text ] { } else if [ scan-class $(syntax-block) ] { } else if [ MATCH .*([cC]opyright).* : $(comment-block:J=" ") ] { # mark as the copy for the module. set-module-copyright $(module-name) : $(comment-block) ; } else if $(action[1]) in "print-help-project" "print-help-config" && ! $(jamfile<$(target)>.docs) { # special module docs for the project jamfile. jamfile<$(target)>.docs = $(comment-block) ; } else if ! $(module-documented) { # document the module. set-module-doc $(module-name) : $(comment-block) ; module-documented = true ; } } if $(action) { $(action[1]) $(module-name) : $(action[2-]) ; }}
# Import scan-module to global scope, so that it is available during header# scanning phase.#IMPORT $(__name__) : scan-module : : doc.scan-module ;
# Read in a file using the SHELL builtin and return the individual lines as# would be done for header scanning.#local rule read-file ( file # The file to read in.){ file = [ path.native [ path.root [ path.make $(file) ] [ path.pwd ] ] ] ; if ! $(.file<$(file)>.lines) { local content ; switch [ modules.peek : OS ] { case NT : content = [ SHELL "TYPE \"$(file)\"" ] ;
case * : content = [ SHELL "cat \"$(file)\"" ] ; } local lines ; local nl = "" ; local << = "([^$(nl)]*)[$(nl)](.*)" ; local line+ = [ MATCH "$(<<)" : "$(content)" ] ; while $(line+) { lines += $(line+[1]) ; line+ = [ MATCH "$(<<)" : "$(line+[2])" ] ; } .file<$(file)>.lines = $(lines) ; } return $(.file<$(file)>.lines) ;}
# Add a scan action to perform to generate the help documentation. The action# rule is passed the name of the module as the first argument. The second# argument(s) are optional and passed directly as specified here.#local rule do-scan ( modules + # The modules to scan and perform the action on. : action * # The action rule, plus the secondary arguments to pass to the action rule.){ if $(help-output) = text { print.output $(help-output-file).txt plain ; ALWAYS $(help-output-file).txt ; DEPENDS all : $(help-output-file).txt ; } if $(help-output) = html { print.output $(help-output-file).html html ; ALWAYS $(help-output-file).html ; DEPENDS all : $(help-output-file).html ; } for local module-file in $(modules[1--2]) { scan-module $(module-file) : [ read-file $(module-file) ] ; } scan-module $(modules[-1]) : [ read-file $(modules[-1]) ] : $(action) ;}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218# Copyright 2001, 2002 Dave Abrahams# Copyright 2002, 2003 Vladimir Prus# Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
import errors ;
rule trim-leading-zeroes ( value ){ return [ CALC $(value) + 0 ] ;}
rule check ( numbers * ){ for local n in $(numbers) { switch $(n) { case *[^0-9]* : errors.error $(n) "in" $(numbers) : is not a number ; } }}
rule increment ( number ){ return [ CALC $(number) + 1 ] ;}
rule decrement ( number ){ return [ CALC $(number) - 1 ] ;}
rule range ( start finish ? : step ? ){ if ! $(finish) { finish = $(start) ; start = 1 ; } step ?= 1 ;
check $(start) $(finish) $(step) ;
if $(finish) != 0 { local result ; while [ less $(start) $(finish) ] || $(start) = $(finish) { result += $(start) ; start = [ CALC $(start) + $(step) ] ; } return $(result) ; }}
rule less ( n1 n2 ){ switch [ CALC $(n2) - $(n1) ] { case [1-9]* : return true ; }}
rule log10 ( number ){ switch $(number) { case *[^0-9]* : errors.error $(number) is not a number ; case 0 : errors.error can't take log of zero ; case [1-9] : return 0 ; case [1-9]? : return 1 ; case [1-9]?? : return 2 ; case [1-9]??? : return 3 ; case [1-9]???? : return 4 ; case [1-9]????? : return 5 ; case [1-9]?????? : return 6 ; case [1-9]??????? : return 7 ; case [1-9]???????? : return 8 ; case [1-9]????????? : return 9 ; case * : { import sequence ; import string ; local chars = [ string.chars $(number) ] ; while $(chars[1]) = 0 { chars = $(chars[2-]) ; } if ! $(chars) { errors.error can't take log of zero ; } else { return [ decrement [ sequence.length $(chars) ] ] ; } } }}
rule __test__ ( ){ import assert ;
assert.result 1 : increment 0 ; assert.result 2 : increment 1 ; assert.result 1 : decrement 2 ; assert.result 0 : decrement 1 ; assert.result 50 : increment 49 ; assert.result 49 : decrement 50 ; assert.result 99 : increment 98 ; assert.result 99 : decrement 100 ; assert.result 100 : increment 99 ; assert.result 999 : decrement 1000 ; assert.result 1000 : increment 999 ;
assert.result 1 2 3 : range 3 ; assert.result 1 2 3 4 5 6 7 8 9 10 11 12 : range 12 ; assert.result 3 4 5 6 7 8 9 10 11 : range 3 11 ; assert.result : range 0 ; assert.result 1 4 7 10 : range 10 : 3 ; assert.result 2 4 6 8 10 : range 2 10 : 2 ; assert.result 25 50 75 100 : range 25 100 : 25 ;
assert.result 0 : trim-leading-zeroes 0 ; assert.result 1234 : trim-leading-zeroes 1234 ; assert.result 123456 : trim-leading-zeroes 0000123456 ; assert.result 1000123456 : trim-leading-zeroes 1000123456 ; assert.result 10000 : trim-leading-zeroes 10000 ; assert.result 10000 : trim-leading-zeroes 00010000 ;
assert.true less 1 2 ; assert.true less 1 12 ; assert.true less 1 21 ; assert.true less 005 217 ; assert.false less 0 0 ; assert.false less 03 3 ; assert.false less 3 03 ; assert.true less 005 217 ; assert.true less 0005 217 ; assert.true less 5 00217 ;
# TEMPORARY disabled, because nested "try"/"catch" do not work and I do no # have the time to fix that right now. if $(0) { try ; { decrement 0 ; } catch can't decrement zero! ;
try ; { check foo ; } catch : not a number ;
try ; { increment foo ; } catch : not a number ;
try ; { log10 0 ; } catch can't take log of zero ;
try ; { log10 000 ; } catch can't take log of zero ;
}
assert.result 0 : log10 1 ; assert.result 0 : log10 9 ; assert.result 1 : log10 10 ; assert.result 1 : log10 99 ; assert.result 2 : log10 100 ; assert.result 2 : log10 101 ; assert.result 2 : log10 125 ; assert.result 2 : log10 999 ; assert.result 3 : log10 1000 ; assert.result 10 : log10 12345678901 ;
for local x in [ range 75 110 : 5 ] { for local y in [ range $(x) 111 : 3 ] { if $(x) != $(y) { assert.true less $(x) $(y) ; } } }
for local x in [ range 90 110 : 2 ] { for local y in [ range 80 $(x) : 4 ] { assert.false less $(x) $(y) ; } }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193# Copyright 2001, 2002 Dave Abrahams# Copyright 2003 Douglas Gregor# Copyright 2003 Rene Rivera# Copyright 2002, 2003, 2004, 2005 Vladimir Prus# Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
## Returns a list of the following substrings:# 1) from beginning till the first occurrence of 'separator' or till the end,# 2) between each occurrence of 'separator' and the next occurrence,# 3) from the last occurrence of 'separator' till the end.# If no separator is present, the result will contain only one element.#
rule split ( string separator ){ local result ; local s = $(string) ;
# Break pieaces off 's' until it has no separators left. local match = 1 ; while $(match) { match = [ MATCH ^(.*)($(separator))(.*) : $(s) ] ; if $(match) { match += "" ; # in case 3rd item was empty - works around MATCH bug result = $(match[3]) $(result) ; s = $(match[1]) ; } } # Combine the remaining part at the beginning, which does not have # separators, with the pieces broken off. Note that the rule's signature # does not allow the initial s to be empty. return $(s) $(result) ;}
# Returns the concatenated results of Applying regex.split to every element of# the list using the separator pattern.#rule split-list ( list * : separator ){ local result ; for s in $(list) { result += [ split $(s) $(separator) ] ; } return $(result) ;}
# Match string against pattern, and return the elements indicated by indices.#rule match ( pattern : string : indices * ){ indices ?= 1 2 3 4 5 6 7 8 9 ; local x = [ MATCH $(pattern) : $(string) ] ; return $(x[$(indices)]) ;}
# Matches all elements of 'list' agains the 'pattern' and returns a list of# elements indicated by indices of all successful matches. If 'indices' is# omitted returns a list of first paranthethised groups of all successful# matches.#rule transform ( list * : pattern : indices * ){ indices ?= 1 ; local result ; for local e in $(list) { local m = [ MATCH $(pattern) : $(e) ] ; if $(m) { result += $(m[$(indices)]) ; } } return $(result) ;}
NATIVE_RULE regex : transform ;
# Escapes all of the characters in symbols using the escape symbol escape-symbol# for the given string, and returns the escaped string.#rule escape ( string : symbols : escape-symbol ){ local result = "" ; local m = 1 ; while $(m) { m = [ MATCH ^([^$(symbols)]*)([$(symbols)])(.*) : $(string) ] ; if $(m) { m += "" ; # Supposedly a bug fix; borrowed from regex.split result = "$(result)$(m[1])$(escape-symbol)$(m[2])" ; string = $(m[3]) ; } } string ?= "" ; result = "$(result)$(string)" ; return $(result) ;}
# Replaces occurrences of a match string in a given string and returns the new# string. The match string can be a regex expression.#rule replace ( string # The string to modify. match # The characters to replace. replacement # The string to replace with. ){ local result = "" ; local parts = 1 ; while $(parts) { parts = [ MATCH ^(.*)($(match))(.*) : $(string) ] ; if $(parts) { parts += "" ; result = "$(replacement)$(parts[3])$(result)" ; string = $(parts[1]) ; } } string ?= "" ; result = "$(string)$(result)" ; return $(result) ;}
# Replaces occurrences of a match string in a given list of strings and returns# a list of new strings. The match string can be a regex expression.## list - the list of strings to modify.# match - the search expression.# replacement - the string to replace with.#rule replace-list ( list * : match : replacement ){ local result ; for local e in $(list) { result += [ replace $(e) $(match) $(replacement) ] ; } return $(result) ;}
rule __test__ ( ){ import assert ;
assert.result a b c : split "a/b/c" / ; assert.result "" a b c : split "/a/b/c" / ; assert.result "" "" a b c : split "//a/b/c" / ; assert.result "" a "" b c : split "/a//b/c" / ; assert.result "" a "" b c "" : split "/a//b/c/" / ; assert.result "" a "" b c "" "" : split "/a//b/c//" / ;
assert.result a c b d : match (.)(.)(.)(.) : abcd : 1 3 2 4 ;
assert.result a b c d : match (.)(.)(.)(.) : abcd ;
assert.result ababab cddc : match ((ab)*)([cd]+) : abababcddc : 1 3 ;
assert.result a.h c.h : transform <a.h> \"b.h\" <c.h> : <(.*)> ;
assert.result a.h b.h c.h : transform <a.h> \"b.h\" <c.h> : <([^>]*)>|\"([^\"]*)\" : 1 2 ;
assert.result "^<?xml version=\"1.0\"^>" : escape "<?xml version=\"1.0\">" : "&|()<>^" : "^" ;
assert.result "<?xml version=\\\"1.0\\\">" : escape "<?xml version=\"1.0\">" : "\\\"" : "\\" ;
assert.result "string string " : replace "string string " " " " " ; assert.result " string string" : replace " string string" " " " " ; assert.result "string string" : replace "string string" " " " " ; assert.result "-" : replace "&" "&" "-" ;
assert.result "-" "a-b" : replace-list "&" "a&b" : "&" : "-" ;}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565@ECHO OFF
REM ~ Copyright 2002-2007 Rene Rivera.REM ~ Distributed under the Boost Software License, Version 1.0.REM ~ (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
setlocalgoto Start
:Set_Errorcolor 00goto :eof
:Clear_Errorver >nulgoto :eof
:Error_PrintREM Output an error message and set the errorlevel to indicate failure.setlocalECHO ###ECHO ### %1ECHO ###ECHO ### You can specify the toolset as the argument, i.e.:ECHO ### .\build.bat msvcECHO ###ECHO ### Toolsets supported by this script are: borland, como, gcc, gcc-nocygwin,ECHO ### intel-win32, metrowerks, mingw, msvc, vc7, vc8, vc9, vc10, vc11ECHO ###call :Set_Errorendlocalgoto :eof
:Test_PathREM Tests for the given file(executable) presence in the directories in the PATHREM environment variable. Additionaly sets FOUND_PATH to the path of theREM found file.call :Clear_Errorsetlocalset test=%~$PATH:1endlocalif not errorlevel 1 set FOUND_PATH=%~dp$PATH:1goto :eof
:Test_OptionREM Tests whether the given string is in the form of an option: "--*"call :Clear_Errorsetlocalset test=%1if not defined test ( call :Set_Error goto Test_Option_End)set test=###%test%###set test=%test:"###=%set test=%test:###"=%set test=%test:###=%if not "-" == "%test:~1,1%" call :Set_Error:Test_Option_Endendlocalgoto :eof
:Test_EmptyREM Tests whether the given string is not emptycall :Clear_Errorsetlocalset test=%1if not defined test ( call :Clear_Error goto Test_Empty_End)set test=###%test%###set test=%test:"###=%set test=%test:###"=%set test=%test:###=%if not "" == "%test%" call :Set_Error:Test_Empty_Endendlocalgoto :eof
:Call_If_Existsif EXIST %1 call %*goto :eof
:Guess_ToolsetREM Try and guess the toolset to bootstrap the build with...REM Sets BOOST_JAM_TOOLSET to the first found toolset.REM May also set BOOST_JAM_TOOLSET_ROOT to theREM location of the found toolset.
call :Clear_Errorcall :Test_Empty %ProgramFiles%if not errorlevel 1 set ProgramFiles=C:\Program Files
call :Clear_Errorif NOT "_%VS110COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET=vc11" set "BOOST_JAM_TOOLSET_ROOT=%VS110COMNTOOLS%..\..\VC\" goto :eof)call :Clear_Errorif EXIST "%ProgramFiles%\Microsoft Visual Studio 11.0\VC\VCVARSALL.BAT" ( set "BOOST_JAM_TOOLSET=vc11" set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio 11.0\VC\" goto :eof)call :Clear_Errorif NOT "_%VS100COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET=vc10" set "BOOST_JAM_TOOLSET_ROOT=%VS100COMNTOOLS%..\..\VC\" goto :eof)call :Clear_Errorif EXIST "%ProgramFiles%\Microsoft Visual Studio 10.0\VC\VCVARSALL.BAT" ( set "BOOST_JAM_TOOLSET=vc10" set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio 10.0\VC\" goto :eof)call :Clear_Errorif NOT "_%VS90COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET=vc9" set "BOOST_JAM_TOOLSET_ROOT=%VS90COMNTOOLS%..\..\VC\" goto :eof)call :Clear_Errorif EXIST "%ProgramFiles%\Microsoft Visual Studio 9.0\VC\VCVARSALL.BAT" ( set "BOOST_JAM_TOOLSET=vc9" set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio 9.0\VC\" goto :eof)call :Clear_Errorif NOT "_%VS80COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET=vc8" set "BOOST_JAM_TOOLSET_ROOT=%VS80COMNTOOLS%..\..\VC\" goto :eof)call :Clear_Errorif EXIST "%ProgramFiles%\Microsoft Visual Studio 8\VC\VCVARSALL.BAT" ( set "BOOST_JAM_TOOLSET=vc8" set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio 8\VC\" goto :eof)call :Clear_Errorif NOT "_%VS71COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET=vc7" set "BOOST_JAM_TOOLSET_ROOT=%VS71COMNTOOLS%\..\..\VC7\" goto :eof)call :Clear_Errorif NOT "_%VCINSTALLDIR%_" == "__" ( REM %VCINSTALLDIR% is also set for VC9 (and probably VC8) set "BOOST_JAM_TOOLSET=vc7" set "BOOST_JAM_TOOLSET_ROOT=%VCINSTALLDIR%\VC7\" goto :eof)call :Clear_Errorif EXIST "%ProgramFiles%\Microsoft Visual Studio .NET 2003\VC7\bin\VCVARS32.BAT" ( set "BOOST_JAM_TOOLSET=vc7" set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio .NET 2003\VC7\" goto :eof)call :Clear_Errorif EXIST "%ProgramFiles%\Microsoft Visual Studio .NET\VC7\bin\VCVARS32.BAT" ( set "BOOST_JAM_TOOLSET=vc7" set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio .NET\VC7\" goto :eof)call :Clear_Errorif NOT "_%MSVCDir%_" == "__" ( set "BOOST_JAM_TOOLSET=msvc" set "BOOST_JAM_TOOLSET_ROOT=%MSVCDir%\" goto :eof)call :Clear_Errorif EXIST "%ProgramFiles%\Microsoft Visual Studio\VC98\bin\VCVARS32.BAT" ( set "BOOST_JAM_TOOLSET=msvc" set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio\VC98\" goto :eof)call :Clear_Errorif EXIST "%ProgramFiles%\Microsoft Visual C++\VC98\bin\VCVARS32.BAT" ( set "BOOST_JAM_TOOLSET=msvc" set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual C++\VC98\" goto :eof)call :Clear_Errorcall :Test_Path cl.exeif not errorlevel 1 ( set "BOOST_JAM_TOOLSET=msvc" set "BOOST_JAM_TOOLSET_ROOT=%FOUND_PATH%..\" goto :eof)call :Clear_Errorcall :Test_Path vcvars32.batif not errorlevel 1 ( set "BOOST_JAM_TOOLSET=msvc" call "%FOUND_PATH%VCVARS32.BAT" set "BOOST_JAM_TOOLSET_ROOT=%MSVCDir%\" goto :eof)call :Clear_Errorif EXIST "C:\Borland\BCC55\Bin\bcc32.exe" ( set "BOOST_JAM_TOOLSET=borland" set "BOOST_JAM_TOOLSET_ROOT=C:\Borland\BCC55\" goto :eof)call :Clear_Errorcall :Test_Path bcc32.exeif not errorlevel 1 ( set "BOOST_JAM_TOOLSET=borland" set "BOOST_JAM_TOOLSET_ROOT=%FOUND_PATH%..\" goto :eof)call :Clear_Errorcall :Test_Path icl.exeif not errorlevel 1 ( set "BOOST_JAM_TOOLSET=intel-win32" set "BOOST_JAM_TOOLSET_ROOT=%FOUND_PATH%..\" goto :eof)call :Clear_Errorif EXIST "C:\MinGW\bin\gcc.exe" ( set "BOOST_JAM_TOOLSET=mingw" set "BOOST_JAM_TOOLSET_ROOT=C:\MinGW\" goto :eof)call :Clear_Errorif NOT "_%CWFolder%_" == "__" ( set "BOOST_JAM_TOOLSET=metrowerks" set "BOOST_JAM_TOOLSET_ROOT=%CWFolder%\" goto :eof )call :Clear_Errorcall :Test_Path mwcc.exeif not errorlevel 1 ( set "BOOST_JAM_TOOLSET=metrowerks" set "BOOST_JAM_TOOLSET_ROOT=%FOUND_PATH%..\..\" goto :eof)call :Clear_Errorcall :Error_Print "Could not find a suitable toolset."goto :eof
:Guess_YaccREM Tries to find bison or yacc in common places so we can build the grammar.call :Clear_Errorcall :Test_Path yacc.exeif not errorlevel 1 ( set "YACC=yacc -d" goto :eof)call :Clear_Errorcall :Test_Path bison.exeif not errorlevel 1 ( set "YACC=bison -d --yacc" goto :eof)call :Clear_Errorif EXIST "C:\Program Files\GnuWin32\bin\bison.exe" ( set "YACC=C:\Program Files\GnuWin32\bin\bison.exe" -d --yacc goto :eof)call :Clear_Errorcall :Error_Print "Could not find Yacc to build the Jam grammar."goto :eof
:Startset BOOST_JAM_TOOLSET=set BOOST_JAM_ARGS=
REM If no arguments guess the toolset;REM or if first argument is an option guess the toolset;REM otherwise the argument is the toolset to use.call :Clear_Errorcall :Test_Empty %1if not errorlevel 1 ( call :Guess_Toolset if not errorlevel 1 ( goto Setup_Toolset ) else ( goto Finish ))
call :Clear_Errorcall :Test_Option %1if not errorlevel 1 ( call :Guess_Toolset if not errorlevel 1 ( goto Setup_Toolset ) else ( goto Finish ))
call :Clear_Errorset BOOST_JAM_TOOLSET=%1shiftgoto Setup_Toolset
:Setup_ToolsetREM Setup the toolset command and options. This bit of codeREM needs to be flexible enough to handle both whenREM the toolset was guessed at and found, or when the toolsetREM was indicated in the command arguments.REM NOTE: The strange multiple "if ?? == _toolset_" tests are that wayREM because in BAT variables are subsituted only once during a singleREM command. A complete "if ... ( commands ) else ( commands )"REM is a single command, even though it's in multiple lines here.:Setup_Argscall :Clear_Errorcall :Test_Empty %1if not errorlevel 1 goto Config_Toolsetcall :Clear_Errorcall :Test_Option %1if errorlevel 1 ( set BOOST_JAM_ARGS=%BOOST_JAM_ARGS% %1 shift goto Setup_Args):Config_Toolsetif NOT "_%BOOST_JAM_TOOLSET%_" == "_metrowerks_" goto Skip_METROWERKSif NOT "_%CWFolder%_" == "__" ( set "BOOST_JAM_TOOLSET_ROOT=%CWFolder%\" )set "PATH=%BOOST_JAM_TOOLSET_ROOT%Other Metrowerks Tools\Command Line Tools;%PATH%"set "BOOST_JAM_CC=mwcc -runtime ss -cwd include -DNT -lkernel32.lib -ladvapi32.lib -luser32.lib"set "BOOST_JAM_OPT_JAM=-o bootstrap\jam0.exe"set "BOOST_JAM_OPT_MKJAMBASE=-o bootstrap\mkjambase0.exe"set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"set "_known_=1":Skip_METROWERKSif NOT "_%BOOST_JAM_TOOLSET%_" == "_msvc_" goto Skip_MSVCif NOT "_%MSVCDir%_" == "__" ( set "BOOST_JAM_TOOLSET_ROOT=%MSVCDir%\" )call :Call_If_Exists "%BOOST_JAM_TOOLSET_ROOT%bin\VCVARS32.BAT"if not "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( set "PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%" )set "BOOST_JAM_CC=cl /nologo /GZ /Zi /MLd /Fobootstrap/ /Fdbootstrap/ -DNT -DYYDEBUG kernel32.lib advapi32.lib user32.lib"set "BOOST_JAM_OPT_JAM=/Febootstrap\jam0"set "BOOST_JAM_OPT_MKJAMBASE=/Febootstrap\mkjambase0"set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"set "_known_=1":Skip_MSVCif NOT "_%BOOST_JAM_TOOLSET%_" == "_vc7_" goto Skip_VC7if NOT "_%VS71COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET_ROOT=%VS71COMNTOOLS%..\..\VC7\" )if "_%VCINSTALLDIR%_" == "__" call :Call_If_Exists "%BOOST_JAM_TOOLSET_ROOT%bin\VCVARS32.BAT"if NOT "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( if "_%VCINSTALLDIR%_" == "__" ( set "PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%" ) )set "BOOST_JAM_CC=cl /nologo /GZ /Zi /MLd /Fobootstrap/ /Fdbootstrap/ -DNT -DYYDEBUG kernel32.lib advapi32.lib user32.lib"set "BOOST_JAM_OPT_JAM=/Febootstrap\jam0"set "BOOST_JAM_OPT_MKJAMBASE=/Febootstrap\mkjambase0"set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"set "_known_=1":Skip_VC7if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc8_" goto Skip_VC8if NOT "_%VS80COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET_ROOT=%VS80COMNTOOLS%..\..\VC\" )if "_%VCINSTALLDIR%_" == "__" call :Call_If_Exists "%BOOST_JAM_TOOLSET_ROOT%VCVARSALL.BAT" %BOOST_JAM_ARGS%if NOT "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( if "_%VCINSTALLDIR%_" == "__" ( set "PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%" ) )set "BOOST_JAM_CC=cl /nologo /RTC1 /Zi /MTd /Fobootstrap/ /Fdbootstrap/ -DNT -DYYDEBUG -wd4996 kernel32.lib advapi32.lib user32.lib"set "BOOST_JAM_OPT_JAM=/Febootstrap\jam0"set "BOOST_JAM_OPT_MKJAMBASE=/Febootstrap\mkjambase0"set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"set "_known_=1":Skip_VC8if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc9_" goto Skip_VC9if NOT "_%VS90COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET_ROOT=%VS90COMNTOOLS%..\..\VC\" )if "_%VCINSTALLDIR%_" == "__" call :Call_If_Exists "%BOOST_JAM_TOOLSET_ROOT%VCVARSALL.BAT" %BOOST_JAM_ARGS%if NOT "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( if "_%VCINSTALLDIR%_" == "__" ( set "PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%" ) )set "BOOST_JAM_CC=cl /nologo /RTC1 /Zi /MTd /Fobootstrap/ /Fdbootstrap/ -DNT -DYYDEBUG -wd4996 kernel32.lib advapi32.lib user32.lib"set "BOOST_JAM_OPT_JAM=/Febootstrap\jam0"set "BOOST_JAM_OPT_MKJAMBASE=/Febootstrap\mkjambase0"set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"set "_known_=1":Skip_VC9if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc10_" goto Skip_VC10if NOT "_%VS100COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET_ROOT=%VS100COMNTOOLS%..\..\VC\" )if "_%VCINSTALLDIR%_" == "__" call :Call_If_Exists "%BOOST_JAM_TOOLSET_ROOT%VCVARSALL.BAT" %BOOST_JAM_ARGS%if NOT "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( if "_%VCINSTALLDIR%_" == "__" ( set "PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%" ) )set "BOOST_JAM_CC=cl /nologo /RTC1 /Zi /MTd /Fobootstrap/ /Fdbootstrap/ -DNT -DYYDEBUG -wd4996 kernel32.lib advapi32.lib user32.lib"set "BOOST_JAM_OPT_JAM=/Febootstrap\jam0"set "BOOST_JAM_OPT_MKJAMBASE=/Febootstrap\mkjambase0"set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"set "_known_=1":Skip_VC10if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc11_" goto Skip_VC11if NOT "_%VS110COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET_ROOT=%VS110COMNTOOLS%..\..\VC\" )if "_%VCINSTALLDIR%_" == "__" call :Call_If_Exists "%BOOST_JAM_TOOLSET_ROOT%VCVARSALL.BAT" %BOOST_JAM_ARGS%if NOT "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( if "_%VCINSTALLDIR%_" == "__" ( set "PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%" ) )set "BOOST_JAM_CC=cl /nologo /RTC1 /Zi /MTd /Fobootstrap/ /Fdbootstrap/ -DNT -DYYDEBUG -wd4996 kernel32.lib advapi32.lib user32.lib"set "BOOST_JAM_OPT_JAM=/Febootstrap\jam0"set "BOOST_JAM_OPT_MKJAMBASE=/Febootstrap\mkjambase0"set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"set "_known_=1":Skip_VC11if NOT "_%BOOST_JAM_TOOLSET%_" == "_borland_" goto Skip_BORLANDif "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( call :Test_Path bcc32.exe )if "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( if not errorlevel 1 ( set "BOOST_JAM_TOOLSET_ROOT=%FOUND_PATH%..\" ) )if not "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( set "PATH=%BOOST_JAM_TOOLSET_ROOT%Bin;%PATH%" )set "BOOST_JAM_CC=bcc32 -WC -w- -q -I%BOOST_JAM_TOOLSET_ROOT%Include -L%BOOST_JAM_TOOLSET_ROOT%Lib /DNT -nbootstrap"set "BOOST_JAM_OPT_JAM=-ejam0"set "BOOST_JAM_OPT_MKJAMBASE=-emkjambasejam0"set "BOOST_JAM_OPT_YYACC=-eyyacc0"set "_known_=1":Skip_BORLANDif NOT "_%BOOST_JAM_TOOLSET%_" == "_como_" goto Skip_COMOset "BOOST_JAM_CC=como -DNT"set "BOOST_JAM_OPT_JAM=-o bootstrap\jam0.exe"set "BOOST_JAM_OPT_MKJAMBASE=-o bootstrap\mkjambase0.exe"set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"set "_known_=1":Skip_COMOif NOT "_%BOOST_JAM_TOOLSET%_" == "_gcc_" goto Skip_GCCset "BOOST_JAM_CC=gcc -DNT"set "BOOST_JAM_OPT_JAM=-o bootstrap\jam0.exe"set "BOOST_JAM_OPT_MKJAMBASE=-o bootstrap\mkjambase0.exe"set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"set "_known_=1":Skip_GCCif NOT "_%BOOST_JAM_TOOLSET%_" == "_gcc-nocygwin_" goto Skip_GCC_NOCYGWINset "BOOST_JAM_CC=gcc -DNT -mno-cygwin"set "BOOST_JAM_OPT_JAM=-o bootstrap\jam0.exe"set "BOOST_JAM_OPT_MKJAMBASE=-o bootstrap\mkjambase0.exe"set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"set "_known_=1":Skip_GCC_NOCYGWINif NOT "_%BOOST_JAM_TOOLSET%_" == "_intel-win32_" goto Skip_INTEL_WIN32set "BOOST_JAM_CC=icl -DNT /nologo kernel32.lib advapi32.lib user32.lib"set "BOOST_JAM_OPT_JAM=/Febootstrap\jam0"set "BOOST_JAM_OPT_MKJAMBASE=/Febootstrap\mkjambase0"set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"set "_known_=1":Skip_INTEL_WIN32if NOT "_%BOOST_JAM_TOOLSET%_" == "_mingw_" goto Skip_MINGWif not "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( set "PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%" )set "BOOST_JAM_CC=gcc -DNT"set "BOOST_JAM_OPT_JAM=-o bootstrap\jam0.exe"set "BOOST_JAM_OPT_MKJAMBASE=-o bootstrap\mkjambase0.exe"set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"set "_known_=1":Skip_MINGWcall :Clear_Errorif "_%_known_%_" == "__" ( call :Error_Print "Unknown toolset: %BOOST_JAM_TOOLSET%")if errorlevel 1 goto Finish
echo ###echo ### Using '%BOOST_JAM_TOOLSET%' toolset.echo ###
set YYACC_SOURCES=yyacc.cset MKJAMBASE_SOURCES=mkjambase.cset BJAM_SOURCES=set BJAM_SOURCES=%BJAM_SOURCES% command.c compile.c constants.c debug.cset BJAM_SOURCES=%BJAM_SOURCES% execcmd.c execnt.c filent.c frames.c function.cset BJAM_SOURCES=%BJAM_SOURCES% glob.c hash.c hdrmacro.c headers.c jam.cset BJAM_SOURCES=%BJAM_SOURCES% jambase.c jamgram.c lists.c make.c make1.cset BJAM_SOURCES=%BJAM_SOURCES% object.c option.c output.c parse.c pathnt.cset BJAM_SOURCES=%BJAM_SOURCES% pathsys.c regexp.c rules.c scan.c search.cset BJAM_SOURCES=%BJAM_SOURCES% subst.c timestamp.c variable.c modules.cset BJAM_SOURCES=%BJAM_SOURCES% strings.c filesys.c builtins.c md5.c class.cset BJAM_SOURCES=%BJAM_SOURCES% cwd.c w32_getreg.c native.c modules/set.cset BJAM_SOURCES=%BJAM_SOURCES% modules/path.c modules/regex.cset BJAM_SOURCES=%BJAM_SOURCES% modules/property-set.c modules/sequence.cset BJAM_SOURCES=%BJAM_SOURCES% modules/order.c
set BJAM_UPDATE=:Check_Updatecall :Test_Empty %1if not errorlevel 1 goto Check_Update_Endcall :Clear_Errorsetlocalset test=%1set test=###%test%###set test=%test:"###=%set test=%test:###"=%set test=%test:###=%if "%test%" == "--update" goto Found_Updateendlocalshiftif not "_%BJAM_UPDATE%_" == "_update_" goto Check_Update:Found_Updateendlocalset BJAM_UPDATE=update:Check_Update_Endif "_%BJAM_UPDATE%_" == "_update_" ( if not exist ".\bootstrap\jam0.exe" ( set BJAM_UPDATE= ))
@echo ON@if "_%BJAM_UPDATE%_" == "_update_" goto Skip_Bootstrapif exist bootstrap rd /S /Q bootstrapmd bootstrap@if not exist jamgram.y goto Bootstrap_GrammarPrep@if not exist jamgramtab.h goto Bootstrap_GrammarPrep@goto Skip_GrammarPrep:Bootstrap_GrammarPrep%BOOST_JAM_CC% %BOOST_JAM_OPT_YYACC% %YYACC_SOURCES%@if not exist ".\bootstrap\yyacc0.exe" goto Skip_GrammarPrep.\bootstrap\yyacc0 jamgram.y jamgramtab.h jamgram.yy:Skip_GrammarPrep@if not exist jamgram.c goto Bootstrap_GrammarBuild@if not exist jamgram.h goto Bootstrap_GrammarBuild@goto Skip_GrammarBuild:Bootstrap_GrammarBuild@echo OFFif "_%YACC%_" == "__" ( call :Guess_Yacc)if errorlevel 1 goto Finish@echo ON%YACC% jamgram.y@if errorlevel 1 goto Finishdel /f jamgram.crename y.tab.c jamgram.cdel /f jamgram.hrename y.tab.h jamgram.h:Skip_GrammarBuild@echo ON@if exist jambase.c goto Skip_Jambase%BOOST_JAM_CC% %BOOST_JAM_OPT_MKJAMBASE% %MKJAMBASE_SOURCES%@if not exist ".\bootstrap\mkjambase0.exe" goto Skip_Jambase.\bootstrap\mkjambase0 jambase.c Jambase:Skip_Jambase%BOOST_JAM_CC% %BOOST_JAM_OPT_JAM% %BJAM_SOURCES%:Skip_Bootstrap@if not exist ".\bootstrap\jam0.exe" goto Skip_Jam@set args=%*@echo OFF:Set_Argssetlocalcall :Test_Empty %args%if not errorlevel 1 goto Set_Args_Endset test=###%args:~0,2%###set test=%test:"###=%set test=%test:###"=%set test=%test:###=%set test=%test:~0,1%if "-" == "%test%" goto Set_Args_Endendlocalset args=%args:~1%goto Set_Args:Set_Args_End@echo ON@if "_%BJAM_UPDATE%_" == "_update_" goto Skip_Clean.\bootstrap\jam0 -f build.jam --toolset=%BOOST_JAM_TOOLSET% "--toolset-root=%BOOST_JAM_TOOLSET_ROOT% " %args% clean:Skip_Clean.\bootstrap\jam0 -f build.jam --toolset=%BOOST_JAM_TOOLSET% "--toolset-root=%BOOST_JAM_TOOLSET_ROOT% " %args%:Skip_Jam
:Finish12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354/* * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. * * This file is part of Jam - see jam.c for Copyright information. */
#include "jam.h"#include "builtins.h"
#include "compile.h"#include "constants.h"#include "cwd.h"#include "filesys.h"#include "frames.h"#include "hash.h"#include "hdrmacro.h"#include "lists.h"#include "make.h"#include "md5.h"#include "native.h"#include "object.h"#include "parse.h"#include "pathsys.h"#include "rules.h"#include "strings.h"#include "subst.h"#include "timestamp.h"#include "variable.h"
#include <ctype.h>
#if defined(USE_EXECUNIX)# include <sys/types.h># include <sys/wait.h>#else/* * NT does not have wait() and associated macros and uses the system() return * value instead. Status code group are documented at: * http://msdn.microsoft.com/en-gb/library/ff565436.aspx */# define WIFEXITED(w) (((w) & 0XFFFFFF00) == 0)# define WEXITSTATUS(w)(w)#endif
/* * builtins.c - builtin jam rules * * External routines: * load_builtins() - define builtin rules * unknown_rule() - reports an unknown rule occurrence to the * user and exits * * Internal routines: * append_if_exists() - if file exists, append it to the list * builtin_calc() - CALC rule * builtin_delete_module() - DELETE_MODULE ( MODULE ? ) * builtin_depends() - DEPENDS/INCLUDES rule * builtin_echo() - ECHO rule * builtin_exit() - EXIT rule * builtin_export() - EXPORT ( MODULE ? : RULES * ) * builtin_flags() - NOCARE, NOTFILE, TEMPORARY rule * builtin_glob() - GLOB rule * builtin_glob_recursive() - ??? * builtin_hdrmacro() - ??? * builtin_import() - IMPORT rule * builtin_match() - MATCH rule, regexp matching * builtin_rebuilds() - REBUILDS rule * builtin_rulenames() - RULENAMES ( MODULE ? ) * builtin_split_by_characters() - splits the given string into tokens * builtin_varnames() - VARNAMES ( MODULE ? ) * get_source_line() - get a frame's file and line number * information */
/* * compile_builtin() - define builtin rules */
#define P0 (PARSE *)0#define C0 (OBJECT *)0
#if defined( OS_NT ) || defined( OS_CYGWIN ) LIST * builtin_system_registry ( FRAME *, int ); LIST * builtin_system_registry_names( FRAME *, int );#endif
int glob( char const * s, char const * c );
void backtrace ( FRAME * );void backtrace_line ( FRAME * );void print_source_line( FRAME * );
RULE * bind_builtin( char const * name_, LIST * (* f)( FRAME *, int flags ), int flags, char const * * args ){ FUNCTION * func; RULE * result; OBJECT * name = object_new( name_ );
func = function_builtin( f, flags, args );
result = new_rule_body( root_module(), name, func, 1 );
function_free( func );
object_free( name );
return result;}
RULE * duplicate_rule( char const * name_, RULE * other ){ OBJECT * name = object_new( name_ ); RULE * result = import_rule( other, root_module(), name ); object_free( name ); return result;}
/* * load_builtins() - define builtin rules */
void load_builtins(){ duplicate_rule( "Always", bind_builtin( "ALWAYS", builtin_flags, T_FLAG_TOUCHED, 0 ) );
duplicate_rule( "Depends", bind_builtin( "DEPENDS", builtin_depends, 0, 0 ) );
duplicate_rule( "echo", duplicate_rule( "Echo", bind_builtin( "ECHO", builtin_echo, 0, 0 ) ) );
{ char const * args[] = { "message", "*", ":", "result-value", "?", 0 }; duplicate_rule( "exit", duplicate_rule( "Exit", bind_builtin( "EXIT", builtin_exit, 0, args ) ) ); }
{ char const * args[] = { "directories", "*", ":", "patterns", "*", ":", "case-insensitive", "?", 0 }; duplicate_rule( "Glob", bind_builtin( "GLOB", builtin_glob, 0, args ) ); }
{ char const * args[] = { "patterns", "*", 0 }; bind_builtin( "GLOB-RECURSIVELY", builtin_glob_recursive, 0, args ); }
duplicate_rule( "Includes", bind_builtin( "INCLUDES", builtin_depends, 1, 0 ) );
{ char const * args[] = { "targets", "*", ":", "targets-to-rebuild", "*", 0 }; bind_builtin( "REBUILDS", builtin_rebuilds, 0, args ); }
duplicate_rule( "Leaves", bind_builtin( "LEAVES", builtin_flags, T_FLAG_LEAVES, 0 ) );
duplicate_rule( "Match", bind_builtin( "MATCH", builtin_match, 0, 0 ) );
{ char const * args[] = { "string", ":", "delimiters", 0 }; bind_builtin( "SPLIT_BY_CHARACTERS", builtin_split_by_characters, 0, args ); }
duplicate_rule( "NoCare", bind_builtin( "NOCARE", builtin_flags, T_FLAG_NOCARE, 0 ) );
duplicate_rule( "NOTIME", duplicate_rule( "NotFile", bind_builtin( "NOTFILE", builtin_flags, T_FLAG_NOTFILE, 0 ) ) );
duplicate_rule( "NoUpdate", bind_builtin( "NOUPDATE", builtin_flags, T_FLAG_NOUPDATE, 0 ) );
duplicate_rule( "Temporary", bind_builtin( "TEMPORARY", builtin_flags, T_FLAG_TEMP, 0 ) );
bind_builtin( "ISFILE", builtin_flags, T_FLAG_ISFILE, 0 );
duplicate_rule( "HdrMacro", bind_builtin( "HDRMACRO", builtin_hdrmacro, 0, 0 ) );
/* FAIL_EXPECTED is used to indicate that the result of a target build * action should be inverted (ok <=> fail) this can be useful when * performing test runs from Jamfiles. */ bind_builtin( "FAIL_EXPECTED", builtin_flags, T_FLAG_FAIL_EXPECTED, 0 );
bind_builtin( "RMOLD", builtin_flags, T_FLAG_RMOLD, 0 );
{ char const * args[] = { "targets", "*", 0 }; bind_builtin( "UPDATE", builtin_update, 0, args ); }
{ char const * args[] = { "targets", "*", ":", "log", "?", ":", "ignore-minus-n", "?", ":", "ignore-minus-q", "?", 0 }; bind_builtin( "UPDATE_NOW", builtin_update_now, 0, args ); }
{ char const * args[] = { "string", "pattern", "replacements", "+", 0 }; duplicate_rule( "subst", bind_builtin( "SUBST", builtin_subst, 0, args ) ); }
{ char const * args[] = { "module", "?", 0 }; bind_builtin( "RULENAMES", builtin_rulenames, 0, args ); }
{ char const * args[] = { "module", "?", 0 }; bind_builtin( "VARNAMES", builtin_varnames, 0, args ); }
{ char const * args[] = { "module", "?", 0 }; bind_builtin( "DELETE_MODULE", builtin_delete_module, 0, args ); }
{ char const * args[] = { "source_module", "?", ":", "source_rules", "*", ":", "target_module", "?", ":", "target_rules", "*", ":", "localize", "?", 0 }; bind_builtin( "IMPORT", builtin_import, 0, args ); }
{ char const * args[] = { "module", "?", ":", "rules", "*", 0 }; bind_builtin( "EXPORT", builtin_export, 0, args ); }
{ char const * args[] = { "levels", "?", 0 }; bind_builtin( "CALLER_MODULE", builtin_caller_module, 0, args ); }
{ char const * args[] = { "levels", "?", 0 }; bind_builtin( "BACKTRACE", builtin_backtrace, 0, args ); }
{ char const * args[] = { 0 }; bind_builtin( "PWD", builtin_pwd, 0, args ); }
{ char const * args[] = { "modules_to_import", "+", ":", "target_module", "?", 0 }; bind_builtin( "IMPORT_MODULE", builtin_import_module, 0, args ); }
{ char const * args[] = { "module", "?", 0 }; bind_builtin( "IMPORTED_MODULES", builtin_imported_modules, 0, args ); }
{ char const * args[] = { "instance_module", ":", "class_module", 0 }; bind_builtin( "INSTANCE", builtin_instance, 0, args ); }
{ char const * args[] = { "sequence", "*", 0 }; bind_builtin( "SORT", builtin_sort, 0, args ); }
{ char const * args[] = { "path_parts", "*", 0 }; bind_builtin( "NORMALIZE_PATH", builtin_normalize_path, 0, args ); }
{ char const * args[] = { "args", "*", 0 }; bind_builtin( "CALC", builtin_calc, 0, args ); }
{ char const * args[] = { "module", ":", "rule", 0 }; bind_builtin( "NATIVE_RULE", builtin_native_rule, 0, args ); }
{ char const * args[] = { "module", ":", "rule", ":", "version", 0 }; bind_builtin( "HAS_NATIVE_RULE", builtin_has_native_rule, 0, args ); }
{ char const * args[] = { "module", "*", 0 }; bind_builtin( "USER_MODULE", builtin_user_module, 0, args ); }
{ char const * args[] = { 0 }; bind_builtin( "NEAREST_USER_LOCATION", builtin_nearest_user_location, 0, args ); }
{ char const * args[] = { "file", 0 }; bind_builtin( "CHECK_IF_FILE", builtin_check_if_file, 0, args ); }
#ifdef HAVE_PYTHON { char const * args[] = { "python-module", ":", "function", ":", "jam-module", ":", "rule-name", 0 }; bind_builtin( "PYTHON_IMPORT_RULE", builtin_python_import_rule, 0, args ); }#endif
# if defined( OS_NT ) || defined( OS_CYGWIN ) { char const * args[] = { "key_path", ":", "data", "?", 0 }; bind_builtin( "W32_GETREG", builtin_system_registry, 0, args ); }
{ char const * args[] = { "key_path", ":", "result-type", 0 }; bind_builtin( "W32_GETREGNAMES", builtin_system_registry_names, 0, args ); }# endif
{ char const * args[] = { "command", ":", "*", 0 }; duplicate_rule( "SHELL", bind_builtin( "COMMAND", builtin_shell, 0, args ) ); }
{ char const * args[] = { "string", 0 }; bind_builtin( "MD5", builtin_md5, 0, args ); }
{ char const * args[] = { "name", ":", "mode", 0 }; bind_builtin( "FILE_OPEN", builtin_file_open, 0, args ); }
{ char const * args[] = { "string", ":", "width", 0 }; bind_builtin( "PAD", builtin_pad, 0, args ); }
{ char const * args[] = { "targets", "*", 0 }; bind_builtin( "PRECIOUS", builtin_precious, 0, args ); }
{ char const * args [] = { 0 }; bind_builtin( "SELF_PATH", builtin_self_path, 0, args ); }
{ char const * args [] = { "path", 0 }; bind_builtin( "MAKEDIR", builtin_makedir, 0, args ); }
/* Initialize builtin modules. */ init_set(); init_path(); init_regex(); init_property_set(); init_sequence(); init_order();}
/* * builtin_calc() - CALC rule * * Performs simple mathematical operations on two arguments. */
LIST * builtin_calc( FRAME * frame, int flags ){ LIST * arg = lol_get( frame->args, 0 );
LIST * result = L0; long lhs_value; long rhs_value; long result_value; char buffer[ 16 ]; char const * lhs; char const * op; char const * rhs; LISTITER iter = list_begin( arg ); LISTITER const end = list_end( arg );
if ( iter == end ) return L0; lhs = object_str( list_item( iter ) );
iter = list_next( iter ); if ( iter == end ) return L0; op = object_str( list_item( iter ) );
iter = list_next( iter ); if ( iter == end ) return L0; rhs = object_str( list_item( iter ) );
lhs_value = atoi( lhs ); rhs_value = atoi( rhs );
if ( !strcmp( "+", op ) ) result_value = lhs_value + rhs_value; else if ( !strcmp( "-", op ) ) result_value = lhs_value - rhs_value; else return L0;
sprintf( buffer, "%ld", result_value ); result = list_push_back( result, object_new( buffer ) ); return result;}
/* * builtin_depends() - DEPENDS/INCLUDES rule * * The DEPENDS/INCLUDES builtin rule appends each of the listed sources on the * dependency/includes list of each of the listed targets. It binds both the * targets and sources as TARGETs. */
LIST * builtin_depends( FRAME * frame, int flags ){ LIST * const targets = lol_get( frame->args, 0 ); LIST * const sources = lol_get( frame->args, 1 );
LISTITER iter = list_begin( targets ); LISTITER end = list_end( targets ); for ( ; iter != end; iter = list_next( iter ) ) { TARGET * const t = bindtarget( list_item( iter ) );
if ( flags ) target_include_many( t, sources ); else t->depends = targetlist( t->depends, sources ); }
/* Enter reverse links */ iter = list_begin( sources ); end = list_end( sources ); for ( ; iter != end; iter = list_next( iter ) ) { TARGET * const s = bindtarget( list_item( iter ) ); if ( flags ) { LISTITER t_iter = list_begin( targets ); LISTITER const t_end = list_end( targets ); for ( ; t_iter != t_end; t_iter = list_next( t_iter ) ) s->dependants = targetentry( s->dependants, bindtarget( list_item( t_iter ) )->includes ); } else s->dependants = targetlist( s->dependants, targets ); }
return L0;}
/* * builtin_rebuilds() - REBUILDS rule * * Appends each of the rebuild-targets listed in its second argument to the * rebuilds list for each of the targets listed in its first argument. */
LIST * builtin_rebuilds( FRAME * frame, int flags ){ LIST * targets = lol_get( frame->args, 0 ); LIST * rebuilds = lol_get( frame->args, 1 ); LISTITER iter = list_begin( targets ); LISTITER const end = list_end( targets ); for ( ; iter != end; iter = list_next( iter ) ) { TARGET * const t = bindtarget( list_item( iter ) ); t->rebuilds = targetlist( t->rebuilds, rebuilds ); } return L0;}
/* * builtin_echo() - ECHO rule * * Echoes the targets to the user. No other actions are taken. */
LIST * builtin_echo( FRAME * frame, int flags ){ list_print( lol_get( frame->args, 0 ) ); printf( "\n" ); fflush( stdout ); return L0;}
/* * builtin_exit() - EXIT rule * * Echoes the targets to the user and exits the program with a failure status. */
LIST * builtin_exit( FRAME * frame, int flags ){ LIST * const code = lol_get( frame->args, 1 ); list_print( lol_get( frame->args, 0 ) ); printf( "\n" ); if ( !list_empty( code ) ) exit( atoi( object_str( list_front( code ) ) ) ); else exit( EXITBAD ); /* yeech */ return L0;}
/* * builtin_flags() - NOCARE, NOTFILE, TEMPORARY rule * * Marks the target with the appropriate flag, for use by make0(). It binds each * target as a TARGET. */
LIST * builtin_flags( FRAME * frame, int flags ){ LIST * const targets = lol_get( frame->args, 0 ); LISTITER iter = list_begin( targets ); LISTITER const end = list_end( targets ); for ( ; iter != end; iter = list_next( iter ) ) bindtarget( list_item( iter ) )->flags |= flags; return L0;}
/* * builtin_glob() - GLOB rule */
struct globbing{ LIST * patterns; LIST * results; LIST * case_insensitive;};
static void downcase_inplace( char * p ){ for ( ; *p; ++p ) *p = tolower( *p );}
static void builtin_glob_back( void * closure, OBJECT * file, int status, timestamp const * const time ){ PROFILE_ENTER( BUILTIN_GLOB_BACK );
struct globbing * const globbing = (struct globbing *)closure; PATHNAME f; string buf[ 1 ]; LISTITER iter; LISTITER end;
/* Null out directory for matching. We wish we had file_dirscan() pass up a * PATHNAME. */ path_parse( object_str( file ), &f ); f.f_dir.len = 0;
/* For globbing, we unconditionally ignore current and parent directory * items. Since these items always exist, there is no reason why caller of * GLOB would want to see them. We could also change file_dirscan(), but * then paths with embedded "." and ".." would not work anywhere. */ if ( !strcmp( f.f_base.ptr, "." ) || !strcmp( f.f_base.ptr, ".." ) ) { PROFILE_EXIT( BUILTIN_GLOB_BACK ); return; }
string_new( buf ); path_build( &f, buf );
if ( globbing->case_insensitive ) downcase_inplace( buf->value );
iter = list_begin( globbing->patterns ); end = list_end( globbing->patterns ); for ( ; iter != end; iter = list_next( iter ) ) { if ( !glob( object_str( list_item( iter ) ), buf->value ) ) { globbing->results = list_push_back( globbing->results, object_copy( file ) ); break; } }
string_free( buf );
PROFILE_EXIT( BUILTIN_GLOB_BACK );}
static LIST * downcase_list( LIST * in ){ LIST * result = L0; LISTITER iter = list_begin( in ); LISTITER const end = list_end( in );
string s[ 1 ]; string_new( s );
for ( ; iter != end; iter = list_next( iter ) ) { string_append( s, object_str( list_item( iter ) ) ); downcase_inplace( s->value ); result = list_push_back( result, object_new( s->value ) ); string_truncate( s, 0 ); }
string_free( s ); return result;}
LIST * builtin_glob( FRAME * frame, int flags ){ LIST * const l = lol_get( frame->args, 0 ); LIST * const r = lol_get( frame->args, 1 );
LISTITER iter; LISTITER end; struct globbing globbing;
globbing.results = L0; globbing.patterns = r;
globbing.case_insensitive =# if defined( OS_NT ) || defined( OS_CYGWIN ) l; /* Always case-insensitive if any files can be found. */# else lol_get( frame->args, 2 );# endif
if ( globbing.case_insensitive ) globbing.patterns = downcase_list( r );
iter = list_begin( l ); end = list_end( l ); for ( ; iter != end; iter = list_next( iter ) ) file_dirscan( list_item( iter ), builtin_glob_back, &globbing );
if ( globbing.case_insensitive ) list_free( globbing.patterns );
return globbing.results;}
static int has_wildcards( char const * const str ){ return str[ strcspn( str, "[]*?" ) ] ? 1 : 0;}
/* * append_if_exists() - if file exists, append it to the list */
static LIST * append_if_exists( LIST * list, OBJECT * file ){ return file_query( file ) ? list_push_back( list, object_copy( file ) ) : list ;}
LIST * glob1( OBJECT * dirname, OBJECT * pattern ){ LIST * const plist = list_new( object_copy( pattern ) ); struct globbing globbing;
globbing.results = L0; globbing.patterns = plist;
globbing.case_insensitive# if defined( OS_NT ) || defined( OS_CYGWIN ) = plist; /* always case-insensitive if any files can be found */# else = L0;# endif
if ( globbing.case_insensitive ) globbing.patterns = downcase_list( plist );
file_dirscan( dirname, builtin_glob_back, &globbing );
if ( globbing.case_insensitive ) list_free( globbing.patterns );
list_free( plist );
return globbing.results;}
LIST * glob_recursive( char const * pattern ){ LIST * result = L0;
/* Check if there's metacharacters in pattern */ if ( !has_wildcards( pattern ) ) { /* No metacharacters. Check if the path exists. */ OBJECT * const p = object_new( pattern ); result = append_if_exists( result, p ); object_free( p ); } else { /* Have metacharacters in the pattern. Split into dir/name. */ PATHNAME path[ 1 ]; path_parse( pattern, path );
if ( path->f_dir.ptr ) { LIST * dirs = L0; string dirname[ 1 ]; string basename[ 1 ]; string_new( dirname ); string_new( basename );
string_append_range( dirname, path->f_dir.ptr, path->f_dir.ptr + path->f_dir.len );
path->f_grist.ptr = 0; path->f_grist.len = 0; path->f_dir.ptr = 0; path->f_dir.len = 0; path_build( path, basename );
dirs = has_wildcards( dirname->value ) ? glob_recursive( dirname->value ) : list_push_back( dirs, object_new( dirname->value ) );
if ( has_wildcards( basename->value ) ) { OBJECT * const b = object_new( basename->value ); LISTITER iter = list_begin( dirs ); LISTITER const end = list_end( dirs ); for ( ; iter != end; iter = list_next( iter ) ) result = list_append( result, glob1( list_item( iter ), b ) ); object_free( b ); } else { LISTITER iter = list_begin( dirs ); LISTITER const end = list_end( dirs ); string file_string[ 1 ]; string_new( file_string );
/* No wildcard in basename. */ for ( ; iter != end; iter = list_next( iter ) ) { OBJECT * p; path->f_dir.ptr = object_str( list_item( iter ) ); path->f_dir.len = strlen( object_str( list_item( iter ) ) ); path_build( path, file_string );
p = object_new( file_string->value );
result = append_if_exists( result, p );
object_free( p );
string_truncate( file_string, 0 ); }
string_free( file_string ); }
string_free( dirname ); string_free( basename );
list_free( dirs ); } else { /* No directory, just a pattern. */ OBJECT * const p = object_new( pattern ); result = list_append( result, glob1( constant_dot, p ) ); object_free( p ); } }
return result;}
/* * builtin_glob_recursive() - ??? */
LIST * builtin_glob_recursive( FRAME * frame, int flags ){ LIST * result = L0; LIST * const l = lol_get( frame->args, 0 ); LISTITER iter = list_begin( l ); LISTITER const end = list_end( l ); for ( ; iter != end; iter = list_next( iter ) ) result = list_append( result, glob_recursive( object_str( list_item( iter ) ) ) ); return result;}
/* * builtin_match() - MATCH rule, regexp matching */
LIST * builtin_match( FRAME * frame, int flags ){ LIST * l; LIST * r; LIST * result = L0; LISTITER l_iter; LISTITER l_end; LISTITER r_iter; LISTITER r_end;
string buf[ 1 ]; string_new( buf );
/* For each pattern */
l = lol_get( frame->args, 0 ); l_iter = list_begin( l ); l_end = list_end( l ); for ( ; l_iter != l_end; l_iter = list_next( l_iter ) ) { /* Result is cached and intentionally never freed. */ regexp * re = regex_compile( list_item( l_iter ) );
/* For each string to match against. */ r = lol_get( frame->args, 1 ); r_iter = list_begin( r ); r_end = list_end( r ); for ( ; r_iter != r_end; r_iter = list_next( r_iter ) ) { if ( regexec( re, object_str( list_item( r_iter ) ) ) ) { int i; int top;
/* Find highest parameter */
for ( top = NSUBEXP; top-- > 1; ) if ( re->startp[ top ] ) break;
/* And add all parameters up to highest onto list. */ /* Must have parameters to have results! */ for ( i = 1; i <= top; ++i ) { string_append_range( buf, re->startp[ i ], re->endp[ i ] ); result = list_push_back( result, object_new( buf->value ) ); string_truncate( buf, 0 ); } } } }
string_free( buf ); return result;}
/* * builtin_split_by_characters() - splits the given string into tokens */
LIST * builtin_split_by_characters( FRAME * frame, int flags ){ LIST * l1 = lol_get( frame->args, 0 ); LIST * l2 = lol_get( frame->args, 1 );
LIST * result = L0;
string buf[ 1 ];
char const * delimiters = object_str( list_front( l2 ) ); char * t;
string_copy( buf, object_str( list_front( l1 ) ) );
t = strtok( buf->value, delimiters ); while ( t ) { result = list_push_back( result, object_new( t ) ); t = strtok( NULL, delimiters ); }
string_free( buf );
return result;}
/* * builtin_hdrmacro() - ??? */
LIST * builtin_hdrmacro( FRAME * frame, int flags ){ LIST * const l = lol_get( frame->args, 0 ); LISTITER iter = list_begin( l ); LISTITER const end = list_end( l );
for ( ; iter != end; iter = list_next( iter ) ) { TARGET * const t = bindtarget( list_item( iter ) );
/* Scan file for header filename macro definitions. */ if ( DEBUG_HEADER ) printf( "scanning '%s' for header file macro definitions\n", object_str( list_item( iter ) ) );
macro_headers( t ); }
return L0;}
/* * builtin_rulenames() - RULENAMES ( MODULE ? ) * * Returns a list of the non-local rule names in the given MODULE. If MODULE is * not supplied, returns the list of rule names in the global module. */
static void add_rule_name( void * r_, void * result_ ){ RULE * const r = (RULE *)r_; LIST * * const result = (LIST * *)result_; if ( r->exported ) *result = list_push_back( *result, object_copy( r->name ) );}
LIST * builtin_rulenames( FRAME * frame, int flags ){ LIST * arg0 = lol_get( frame->args, 0 ); LIST * result = L0; module_t * const source_module = bindmodule( list_empty( arg0 ) ? 0 : list_front( arg0 ) );
if ( source_module->rules ) hashenumerate( source_module->rules, add_rule_name, &result ); return result;}
/* * builtin_varnames() - VARNAMES ( MODULE ? ) * * Returns a list of the variable names in the given MODULE. If MODULE is not * supplied, returns the list of variable names in the global module. */
/* helper function for builtin_varnames(), below. Used with hashenumerate, will * prepend the key of each element to the list */static void add_hash_key( void * np, void * result_ ){ LIST * * result = (LIST * *)result_; *result = list_push_back( *result, object_copy( *(OBJECT * *)np ) );}
LIST * builtin_varnames( FRAME * frame, int flags ){ LIST * arg0 = lol_get( frame->args, 0 ); LIST * result = L0; module_t * source_module = bindmodule( list_empty( arg0 ) ? 0 : list_front( arg0 ) );
struct hash * const vars = source_module->variables; if ( vars ) hashenumerate( vars, add_hash_key, &result ); return result;}
/* * builtin_delete_module() - DELETE_MODULE ( MODULE ? ) * * Clears all rules and variables from the given module. */
LIST * builtin_delete_module( FRAME * frame, int flags ){ LIST * const arg0 = lol_get( frame->args, 0 ); module_t * const source_module = bindmodule( list_empty( arg0 ) ? 0 : list_front( arg0 ) ); delete_module( source_module ); return L0;}
/* * unknown_rule() - reports an unknown rule occurrence to the user and exits */
void unknown_rule( FRAME * frame, char const * key, module_t * module, OBJECT * rule_name ){ backtrace_line( frame->prev ); if ( key ) printf("%s error", key); else printf("ERROR"); printf( ": rule \"%s\" unknown in ", object_str( rule_name ) ); if ( module->name ) printf( "module \"%s\".\n", object_str( module->name ) ); else printf( "root module.\n" ); backtrace( frame->prev ); exit( 1 );}
/* * builtin_import() - IMPORT rule * * IMPORT * ( * SOURCE_MODULE ? : * SOURCE_RULES * : * TARGET_MODULE ? : * TARGET_RULES * : * LOCALIZE ? * ) * * Imports rules from the SOURCE_MODULE into the TARGET_MODULE as local rules. * If either SOURCE_MODULE or TARGET_MODULE is not supplied, it refers to the * global module. SOURCE_RULES specifies which rules from the SOURCE_MODULE to * import; TARGET_RULES specifies the names to give those rules in * TARGET_MODULE. If SOURCE_RULES contains a name that does not correspond to * a rule in SOURCE_MODULE, or if it contains a different number of items than * TARGET_RULES, an error is issued. If LOCALIZE is specified, the rules will be * executed in TARGET_MODULE, with corresponding access to its module local * variables. */
LIST * builtin_import( FRAME * frame, int flags ){ LIST * source_module_list = lol_get( frame->args, 0 ); LIST * source_rules = lol_get( frame->args, 1 ); LIST * target_module_list = lol_get( frame->args, 2 ); LIST * target_rules = lol_get( frame->args, 3 ); LIST * localize = lol_get( frame->args, 4 );
module_t * target_module = bindmodule( list_empty( target_module_list ) ? 0 : list_front( target_module_list ) ); module_t * source_module = bindmodule( list_empty( source_module_list ) ? 0 : list_front( source_module_list ) );
LISTITER source_iter = list_begin( source_rules ); LISTITER const source_end = list_end( source_rules ); LISTITER target_iter = list_begin( target_rules ); LISTITER const target_end = list_end( target_rules );
for ( ; source_iter != source_end && target_iter != target_end; source_iter = list_next( source_iter ), target_iter = list_next( target_iter ) ) { RULE * r; RULE * imported;
if ( !source_module->rules || !(r = (RULE *)hash_find( source_module->rules, list_item( source_iter ) ) ) ) unknown_rule( frame, "IMPORT", source_module, list_item( source_iter ) );
imported = import_rule( r, target_module, list_item( target_iter ) ); if ( !list_empty( localize ) ) rule_localize( imported, target_module ); /* This rule is really part of some other module. Just refer to it here, * but do not let it out. */ imported->exported = 0; }
if ( source_iter != source_end || target_iter != target_end ) { backtrace_line( frame->prev ); printf( "import error: length of source and target rule name lists " "don't match!\n" ); printf( " source: " ); list_print( source_rules ); printf( "\n target: " ); list_print( target_rules ); printf( "\n" ); backtrace( frame->prev ); exit( 1 ); }
return L0;}
/* * builtin_export() - EXPORT ( MODULE ? : RULES * ) * * The EXPORT rule marks RULES from the SOURCE_MODULE as non-local (and thus * exportable). If an element of RULES does not name a rule in MODULE, an error * is issued. */
LIST * builtin_export( FRAME * frame, int flags ){ LIST * const module_list = lol_get( frame->args, 0 ); LIST * const rules = lol_get( frame->args, 1 ); module_t * const m = bindmodule( list_empty( module_list ) ? 0 : list_front( module_list ) );
LISTITER iter = list_begin( rules ); LISTITER const end = list_end( rules ); for ( ; iter != end; iter = list_next( iter ) ) { RULE * r; if ( !m->rules || !( r = (RULE *)hash_find( m->rules, list_item( iter ) ) ) ) unknown_rule( frame, "EXPORT", m, list_item( iter ) ); r->exported = 1; } return L0;}
/* * get_source_line() - get a frame's file and line number information * * This is the execution traceback information to be indicated for in debug * output or an error backtrace. */
static void get_source_line( FRAME * frame, char const * * file, int * line ){ if ( frame->file ) { char const * f = object_str( frame->file ); int l = frame->line; if ( !strcmp( f, "+" ) ) { f = "jambase.c"; l += 3; } *file = f; *line = l; } else { *file = "(builtin)"; *line = -1; }}
void print_source_line( FRAME * frame ){ char const * file; int line; get_source_line( frame, &file, &line ); if ( line < 0 ) printf( "(builtin):" ); else printf( "%s:%d:", file, line );}
/* * backtrace_line() - print a single line of error backtrace for the given * frame. */
void backtrace_line( FRAME * frame ){ if ( frame == 0 ) { printf( "(no frame):" ); } else { print_source_line( frame ); printf( " in %s\n", frame->rulename ); }}
/* * backtrace() - Print the entire backtrace from the given frame to the Jambase * which invoked it. */
void backtrace( FRAME * frame ){ if ( !frame ) return; while ( ( frame = frame->prev ) ) backtrace_line( frame );}
/* * builtin_backtrace() - A Jam version of the backtrace function, taking no * arguments and returning a list of quadruples: FILENAME LINE MODULE. RULENAME * describing each frame. Note that the module-name is always followed by a * period. */
LIST * builtin_backtrace( FRAME * frame, int flags ){ LIST * const levels_arg = lol_get( frame->args, 0 ); int levels = list_empty( levels_arg ) ? (int)( (unsigned int)(-1) >> 1 ) : atoi( object_str( list_front( levels_arg ) ) );
LIST * result = L0; for ( ; ( frame = frame->prev ) && levels; --levels ) { char const * file; int line; char buf[ 32 ]; string module_name[ 1 ]; get_source_line( frame, &file, &line ); sprintf( buf, "%d", line ); string_new( module_name ); if ( frame->module->name ) { string_append( module_name, object_str( frame->module->name ) ); string_append( module_name, "." ); } result = list_push_back( result, object_new( file ) ); result = list_push_back( result, object_new( buf ) ); result = list_push_back( result, object_new( module_name->value ) ); result = list_push_back( result, object_new( frame->rulename ) ); string_free( module_name ); } return result;}
/* * builtin_caller_module() - CALLER_MODULE ( levels ? ) * * If levels is not supplied, returns the name of the module of the rule which * called the one calling this one. If levels is supplied, it is interpreted as * an integer specifying a number of additional levels of call stack to traverse * in order to locate the module in question. If no such module exists, returns * the empty list. Also returns the empty list when the module in question is * the global module. This rule is needed for implementing module import * behavior. */
LIST * builtin_caller_module( FRAME * frame, int flags ){ LIST * const levels_arg = lol_get( frame->args, 0 ); int const levels = list_empty( levels_arg ) ? 0 : atoi( object_str( list_front( levels_arg ) ) );
int i; for ( i = 0; ( i < levels + 2 ) && frame->prev; ++i ) frame = frame->prev;
return frame->module == root_module() ? L0 : list_new( object_copy( frame->module->name ) );}
/* * Return the current working directory. * * Usage: pwd = [ PWD ] ; */
LIST * builtin_pwd( FRAME * frame, int flags ){ return list_new( object_copy( cwd() ) );}
/* * Adds targets to the list of target that jam will attempt to update. */
LIST * builtin_update( FRAME * frame, int flags ){ LIST * result = list_copy( targets_to_update() ); LIST * arg1 = lol_get( frame->args, 0 ); LISTITER iter = list_begin( arg1 ), end = list_end( arg1 ); clear_targets_to_update(); for ( ; iter != end; iter = list_next( iter ) ) mark_target_for_updating( object_copy( list_item( iter ) ) ); return result;}
extern int anyhow;int last_update_now_status;
/* Takes a list of target names and immediately updates them. * * Parameters: * 1. Target list. * 2. Optional file descriptor (converted to a string) for a log file where all * the related build output should be redirected. * 3. If specified, makes the build temporarily disable the -n option, i.e. * forces all needed out-of-date targets to be rebuilt. * 4. If specified, makes the build temporarily disable the -q option, i.e. * forces the build to continue even if one of the targets fails to build. */LIST * builtin_update_now( FRAME * frame, int flags ){ LIST * targets = lol_get( frame->args, 0 ); LIST * log = lol_get( frame->args, 1 ); LIST * force = lol_get( frame->args, 2 ); LIST * continue_ = lol_get( frame->args, 3 ); int status; int original_stdout = 0; int original_stderr = 0; int original_noexec = 0; int original_quitquick = 0;
if ( !list_empty( log ) ) { /* Temporarily redirect stdout and stderr to the given log file. */ int const fd = atoi( object_str( list_front( log ) ) ); original_stdout = dup( 0 ); original_stderr = dup( 1 ); dup2( fd, 0 ); dup2( fd, 1 ); }
if ( !list_empty( force ) ) { original_noexec = globs.noexec; globs.noexec = 0; }
if ( !list_empty( continue_ ) ) { original_quitquick = globs.quitquick; globs.quitquick = 0; }
status = make( targets, anyhow );
if ( !list_empty( force ) ) { globs.noexec = original_noexec; }
if ( !list_empty( continue_ ) ) { globs.quitquick = original_quitquick; }
if ( !list_empty( log ) ) { /* Flush whatever stdio might have buffered, while descriptions 0 and 1 * still refer to the log file. */ fflush( stdout ); fflush( stderr ); dup2( original_stdout, 0 ); dup2( original_stderr, 1 ); close( original_stdout ); close( original_stderr ); }
last_update_now_status = status;
return status ? L0 : list_new( object_copy( constant_ok ) );}
LIST * builtin_import_module( FRAME * frame, int flags ){ LIST * const arg1 = lol_get( frame->args, 0 ); LIST * const arg2 = lol_get( frame->args, 1 ); module_t * const m = list_empty( arg2 ) ? root_module() : bindmodule( list_front( arg2 ) ); import_module( arg1, m ); return L0;}
LIST * builtin_imported_modules( FRAME * frame, int flags ){ LIST * const arg0 = lol_get( frame->args, 0 ); OBJECT * const module = list_empty( arg0 ) ? 0 : list_front( arg0 ); return imported_modules( bindmodule( module ) );}
LIST * builtin_instance( FRAME * frame, int flags ){ LIST * arg1 = lol_get( frame->args, 0 ); LIST * arg2 = lol_get( frame->args, 1 ); module_t * const instance = bindmodule( list_front( arg1 ) ); module_t * const class_module = bindmodule( list_front( arg2 ) ); instance->class_module = class_module; module_set_fixed_variables( instance, class_module->num_fixed_variables ); return L0;}
LIST * builtin_sort( FRAME * frame, int flags ){ return list_sort( lol_get( frame->args, 0 ) );}
LIST * builtin_normalize_path( FRAME * frame, int flags ){ LIST * arg = lol_get( frame->args, 0 );
/* First, we iterate over all '/'-separated elements, starting from the end * of string. If we see a '..', we remove a preceeding path element. If we * see '.', we remove it. Removal is done by overwriting data using '\1' * characters. After the whole string has been processed, we do a second * pass, removing any entered '\1' characters. */
string in[ 1 ]; string out[ 1 ]; /* Last character of the part of string still to be processed. */ char * end; /* Working pointer. */ char * current; /* Number of '..' elements seen and not processed yet. */ int dotdots = 0; int rooted = 0; OBJECT * result = 0; LISTITER arg_iter = list_begin( arg ); LISTITER arg_end = list_end( arg );
/* Make a copy of input: we should not change it. Prepend a '/' before it as * a guard for the algorithm later on and remember whether it was originally * rooted or not. */ string_new( in ); string_push_back( in, '/' ); for ( ; arg_iter != arg_end; arg_iter = list_next( arg_iter ) ) { if ( object_str( list_item( arg_iter ) )[ 0 ] != '\0' ) { if ( in->size == 1 ) rooted = ( object_str( list_item( arg_iter ) )[ 0 ] == '/' ) || ( object_str( list_item( arg_iter ) )[ 0 ] == '\\' ); else string_append( in, "/" ); string_append( in, object_str( list_item( arg_iter ) ) ); } }
/* Convert \ into /. On Windows, paths using / and \ are equivalent, and we * want this function to obtain a canonic representation. */ for ( current = in->value, end = in->value + in->size; current < end; ++current ) if ( *current == '\\' ) *current = '/';
/* Now we remove any extra path elements by overwriting them with '\1' * characters and cound how many more unused '..' path elements there are * remaining. Note that each remaining path element with always starts with * a '/' character. */ for ( end = in->value + in->size - 1; end >= in->value; ) { /* Set 'current' to the next occurence of '/', which always exists. */ for ( current = end; *current != '/'; --current );
if ( current == end ) { /* Found a trailing or duplicate '/'. Remove it. */ *current = '\1'; } else if ( ( end - current == 1 ) && ( *( current + 1 ) == '.' ) ) { /* Found '/.'. Remove them all. */ *current = '\1'; *(current + 1) = '\1'; } else if ( ( end - current == 2 ) && ( *( current + 1 ) == '.' ) && ( *( current + 2 ) == '.' ) ) { /* Found '/..'. Remove them all. */ *current = '\1'; *(current + 1) = '\1'; *(current + 2) = '\1'; ++dotdots; } else if ( dotdots ) { memset( current, '\1', end - current + 1 ); --dotdots; } end = current - 1; }
string_new( out );
/* Now we know that we need to add exactly dotdots '..' path elements to the * front and that our string is either empty or has a '/' as its first * significant character. If we have any dotdots remaining then the passed * path must not have been rooted or else it is invalid we return an empty * list. */ if ( dotdots ) { if ( rooted ) { string_free( out ); string_free( in ); return L0; } do string_append( out, "/.." ); while ( --dotdots ); }
/* Now we actually remove all the path characters marked for removal. */ for ( current = in->value; *current; ++current ) if ( *current != '\1' ) string_push_back( out, *current );
/* Here we know that our string contains no '\1' characters and is either * empty or has a '/' as its initial character. If the original path was not * rooted and we have a non-empty path we need to drop the initial '/'. If * the original path was rooted and we have an empty path we need to add * back the '/'. */ result = object_new( out->size ? out->value + !rooted : ( rooted ? "/" : "." ) );
string_free( out ); string_free( in );
return list_new( result );}
LIST * builtin_native_rule( FRAME * frame, int flags ){ LIST * module_name = lol_get( frame->args, 0 ); LIST * rule_name = lol_get( frame->args, 1 );
module_t * module = bindmodule( list_front( module_name ) );
native_rule_t * np; if ( module->native_rules && (np = (native_rule_t *)hash_find( module->native_rules, list_front( rule_name ) ) ) ) { new_rule_body( module, np->name, np->procedure, 1 ); } else { backtrace_line( frame->prev ); printf( "error: no native rule \"%s\" defined in module \"%s.\"\n", object_str( list_front( rule_name ) ), object_str( module->name ) ); backtrace( frame->prev ); exit( 1 ); } return L0;}
LIST * builtin_has_native_rule( FRAME * frame, int flags ){ LIST * module_name = lol_get( frame->args, 0 ); LIST * rule_name = lol_get( frame->args, 1 ); LIST * version = lol_get( frame->args, 2 );
module_t * module = bindmodule( list_front( module_name ) );
native_rule_t * np; if ( module->native_rules && (np = (native_rule_t *)hash_find( module->native_rules, list_front( rule_name ) ) ) ) { int expected_version = atoi( object_str( list_front( version ) ) ); if ( np->version == expected_version ) return list_new( object_copy( constant_true ) ); } return L0;}
LIST * builtin_user_module( FRAME * frame, int flags ){ LIST * const module_name = lol_get( frame->args, 0 ); LISTITER iter = list_begin( module_name ); LISTITER const end = list_end( module_name ); for ( ; iter != end; iter = list_next( iter ) ) bindmodule( list_item( iter ) )->user_module = 1; return L0;}
LIST * builtin_nearest_user_location( FRAME * frame, int flags ){ FRAME * const nearest_user_frame = frame->module->user_module ? frame : frame->prev_user; if ( !nearest_user_frame ) return L0;
{ LIST * result = L0; char const * file; int line; char buf[ 32 ];
get_source_line( nearest_user_frame, &file, &line ); sprintf( buf, "%d", line ); result = list_push_back( result, object_new( file ) ); result = list_push_back( result, object_new( buf ) ); return result; }}
LIST * builtin_check_if_file( FRAME * frame, int flags ){ LIST * const name = lol_get( frame->args, 0 ); return file_is_file( list_front( name ) ) == 1 ? list_new( object_copy( constant_true ) ) : L0;}
LIST * builtin_md5( FRAME * frame, int flags ){ LIST * l = lol_get( frame->args, 0 ); char const * s = object_str( list_front( l ) );
md5_state_t state; md5_byte_t digest[ 16 ]; char hex_output[ 16 * 2 + 1 ];
int di;
md5_init( &state ); md5_append( &state, (md5_byte_t const *)s, strlen( s ) ); md5_finish( &state, digest );
for ( di = 0; di < 16; ++di ) sprintf( hex_output + di * 2, "%02x", digest[ di ] );
return list_new( object_new( hex_output ) );}
LIST * builtin_file_open( FRAME * frame, int flags ){ char const * name = object_str( list_front( lol_get( frame->args, 0 ) ) ); char const * mode = object_str( list_front( lol_get( frame->args, 1 ) ) ); int fd; char buffer[ sizeof( "4294967295" ) ];
if ( strcmp(mode, "w") == 0 ) fd = open( name, O_WRONLY|O_CREAT|O_TRUNC, 0666 ); else fd = open( name, O_RDONLY );
if ( fd != -1 ) { sprintf( buffer, "%d", fd ); return list_new( object_new( buffer ) ); } return L0;}
LIST * builtin_pad( FRAME * frame, int flags ){ OBJECT * string = list_front( lol_get( frame->args, 0 ) ); char const * width_s = object_str( list_front( lol_get( frame->args, 1 ) ) );
int current = strlen( object_str( string ) ); int desired = atoi( width_s ); if ( current >= desired ) return list_new( object_copy( string ) ); else { char * buffer = BJAM_MALLOC( desired + 1 ); int i; LIST * result;
strcpy( buffer, object_str( string ) ); for ( i = current; i < desired; ++i ) buffer[ i ] = ' '; buffer[ desired ] = '\0'; result = list_new( object_new( buffer ) ); BJAM_FREE( buffer ); return result; }}
LIST * builtin_precious( FRAME * frame, int flags ){ LIST * targets = lol_get( frame->args, 0 ); LISTITER iter = list_begin( targets ); LISTITER const end = list_end( targets ); for ( ; iter != end; iter = list_next( iter ) ) bindtarget( list_item( iter ) )->flags |= T_FLAG_PRECIOUS; return L0;}
LIST * builtin_self_path( FRAME * frame, int flags ){ extern char const * saved_argv0; char * p = executable_path( saved_argv0 ); if ( p ) { LIST * const result = list_new( object_new( p ) ); free( p ); return result; } return L0;}
LIST * builtin_makedir( FRAME * frame, int flags ){ LIST * const path = lol_get( frame->args, 0 ); return file_mkdir( object_str( list_front( path ) ) ) ? L0 : list_new( object_copy( list_front( path ) ) );}
#ifdef HAVE_PYTHON
LIST * builtin_python_import_rule( FRAME * frame, int flags ){ static int first_time = 1; char const * python_module = object_str( list_front( lol_get( frame->args, 0 ) ) ); char const * python_function = object_str( list_front( lol_get( frame->args, 1 ) ) ); OBJECT * jam_module = list_front( lol_get( frame->args, 2 ) ); OBJECT * jam_rule = list_front( lol_get( frame->args, 3 ) );
PyObject * pName; PyObject * pModule; PyObject * pDict; PyObject * pFunc;
if ( first_time ) { /* At the first invocation, we add the value of the global * EXTRA_PYTHONPATH to the sys.path Python variable. */ LIST * extra = 0; module_t * outer_module = frame->module; LISTITER iter, end;
first_time = 0;
extra = var_get( root_module(), constant_extra_pythonpath );
iter = list_begin( extra ), end = list_end( extra ); for ( ; iter != end; iter = list_next( iter ) ) { string buf[ 1 ]; string_new( buf ); string_append( buf, "import sys\nsys.path.append(\"" ); string_append( buf, object_str( list_item( iter ) ) ); string_append( buf, "\")\n" ); PyRun_SimpleString( buf->value ); string_free( buf ); } }
pName = PyString_FromString( python_module ); pModule = PyImport_Import( pName ); Py_DECREF( pName );
if ( pModule != NULL ) { pDict = PyModule_GetDict( pModule ); pFunc = PyDict_GetItemString( pDict, python_function );
if ( pFunc && PyCallable_Check( pFunc ) ) { module_t * m = bindmodule( jam_module ); new_rule_body( m, jam_rule, function_python( pFunc, 0 ), 0 ); } else { if ( PyErr_Occurred() ) PyErr_Print(); fprintf( stderr, "Cannot find function \"%s\"\n", python_function ); } Py_DECREF( pModule ); } else { PyErr_Print(); fprintf( stderr, "Failed to load \"%s\"\n", python_module ); } return L0;
}
#endif /* #ifdef HAVE_PYTHON */
void lol_build( LOL * lol, char const * * elements ){ LIST * l = L0; lol_init( lol );
while ( elements && *elements ) { if ( !strcmp( *elements, ":" ) ) { lol_add( lol, l ); l = L0; } else { l = list_push_back( l, object_new( *elements ) ); } ++elements; }
if ( l != L0 ) lol_add( lol, l );}
#ifdef HAVE_PYTHON
/* * Calls the bjam rule specified by name passed in 'args'. The name is looked up * in the context of bjam's 'python_interface' module. Returns the list of * strings returned by the rule. */
PyObject * bjam_call( PyObject * self, PyObject * args ){ FRAME inner[ 1 ]; LIST * result; PARSE * p; OBJECT * rulename;
/* Build up the list of arg lists. */ frame_init( inner ); inner->prev = 0; inner->prev_user = 0; inner->module = bindmodule( constant_python_interface );
/* Extract the rule name and arguments from 'args'. */
/* PyTuple_GetItem returns borrowed reference. */ rulename = object_new( PyString_AsString( PyTuple_GetItem( args, 0 ) ) ); { int i = 1; int size = PyTuple_Size( args ); for ( ; i < size; ++i ) { PyObject * a = PyTuple_GetItem( args, i ); if ( PyString_Check( a ) ) { lol_add( inner->args, list_new( object_new( PyString_AsString( a ) ) ) ); } else if ( PySequence_Check( a ) ) { LIST * l = 0; int s = PySequence_Size( a ); int i = 0; for ( ; i < s; ++i ) { /* PySequence_GetItem returns new reference. */ PyObject * e = PySequence_GetItem( a, i ); char * s = PyString_AsString( e ); if ( !s ) { printf( "Invalid parameter type passed from Python\n" ); exit( 1 ); } l = list_push_back( l, object_new( s ) ); Py_DECREF( e ); } lol_add( inner->args, l ); } } }
result = evaluate_rule( bindrule( rulename, inner->module), rulename, inner ); object_free( rulename );
frame_free( inner );
/* Convert the bjam list into a Python list result. */ { PyObject * const pyResult = PyList_New( list_length( result ) ); int i = 0; LISTITER iter = list_begin( result ); LISTITER const end = list_end( result ); for ( ; iter != end; iter = list_next( iter ) ) { PyList_SetItem( pyResult, i, PyString_FromString( object_str( list_item( iter ) ) ) ); i += 1; } list_free( result ); return pyResult; }}
/* * Accepts four arguments: * - module name * - rule name, * - Python callable. * - (optional) bjam language function signature. * Creates a bjam rule with the specified name in the specified module, which * will invoke the Python callable. */
PyObject * bjam_import_rule( PyObject * self, PyObject * args ){ char * module; char * rule; PyObject * func; PyObject * bjam_signature = NULL; module_t * m; RULE * r; OBJECT * module_name; OBJECT * rule_name;
if ( !PyArg_ParseTuple( args, "ssO|O:import_rule", &module, &rule, &func, &bjam_signature ) ) return NULL;
if ( !PyCallable_Check( func ) ) { PyErr_SetString( PyExc_RuntimeError, "Non-callable object passed to " "bjam.import_rule" ); return NULL; }
module_name = *module ? object_new( module ) : 0; m = bindmodule( module_name ); if ( module_name ) object_free( module_name ); rule_name = object_new( rule ); new_rule_body( m, rule_name, function_python( func, bjam_signature ), 0 ); object_free( rule_name );
Py_INCREF( Py_None ); return Py_None;}
/* * Accepts four arguments: * - an action name * - an action body * - a list of variable that will be bound inside the action * - integer flags. * Defines an action on bjam side. */
PyObject * bjam_define_action( PyObject * self, PyObject * args ){ char * name; char * body; module_t * m; PyObject * bindlist_python; int flags; LIST * bindlist = L0; int n; int i; OBJECT * name_str; FUNCTION * body_func;
if ( !PyArg_ParseTuple( args, "ssO!i:define_action", &name, &body, &PyList_Type, &bindlist_python, &flags ) ) return NULL;
n = PyList_Size( bindlist_python ); for ( i = 0; i < n; ++i ) { PyObject * next = PyList_GetItem( bindlist_python, i ); if ( !PyString_Check( next ) ) { PyErr_SetString( PyExc_RuntimeError, "bind list has non-string " "type" ); return NULL; } bindlist = list_push_back( bindlist, object_new( PyString_AsString( next ) ) ); }
name_str = object_new( name ); body_func = function_compile_actions( body, constant_builtin, -1 ); new_rule_actions( root_module(), name_str, body_func, bindlist, flags ); function_free( body_func ); object_free( name_str );
Py_INCREF( Py_None ); return Py_None;}
/* * Returns the value of a variable in root Jam module. */
PyObject * bjam_variable( PyObject * self, PyObject * args ){ char * name; LIST * value; PyObject * result; int i; OBJECT * varname; LISTITER iter; LISTITER end;
if ( !PyArg_ParseTuple( args, "s", &name ) ) return NULL;
varname = object_new( name ); value = var_get( root_module(), varname ); object_free( varname ); iter = list_begin( value ); end = list_end( value );
result = PyList_New( list_length( value ) ); for ( i = 0; iter != end; iter = list_next( iter ), ++i ) PyList_SetItem( result, i, PyString_FromString( object_str( list_item( iter ) ) ) );
return result;}
PyObject * bjam_backtrace( PyObject * self, PyObject * args ){ PyObject * result = PyList_New( 0 ); struct frame * f = frame_before_python_call;
for ( ; f = f->prev; ) { PyObject * tuple = PyTuple_New( 4 ); char const * file; int line; char buf[ 32 ]; string module_name[ 1 ];
get_source_line( f, &file, &line ); sprintf( buf, "%d", line ); string_new( module_name ); if ( f->module->name ) { string_append( module_name, object_str( f->module->name ) ); string_append( module_name, "." ); }
/* PyTuple_SetItem steals reference. */ PyTuple_SetItem( tuple, 0, PyString_FromString( file ) ); PyTuple_SetItem( tuple, 1, PyString_FromString( buf ) ); PyTuple_SetItem( tuple, 2, PyString_FromString( module_name->value ) ); PyTuple_SetItem( tuple, 3, PyString_FromString( f->rulename ) );
string_free( module_name );
PyList_Append( result, tuple ); Py_DECREF( tuple ); } return result;}
PyObject * bjam_caller( PyObject * self, PyObject * args ){ return PyString_FromString( frame_before_python_call->prev->module->name ? object_str( frame_before_python_call->prev->module->name ) : "" );}
#endif /* #ifdef HAVE_PYTHON */
#ifdef HAVE_POPEN
#if defined(_MSC_VER) || defined(__BORLANDC__) #define popen windows_popen_wrapper #define pclose _pclose
/* * This wrapper is a workaround for a funny _popen() feature on Windows * where it eats external quotes in some cases. The bug seems to be related * to the quote stripping functionality used by the Windows cmd.exe * interpreter when its /S is not specified. * * Cleaned up quote from the cmd.exe help screen as displayed on Windows XP * SP3: * * 1. If all of the following conditions are met, then quote characters on * the command line are preserved: * * - no /S switch * - exactly two quote characters * - no special characters between the two quote characters, where * special is one of: &<>()@^| * - there are one or more whitespace characters between the two quote * characters * - the string between the two quote characters is the name of an * executable file. * * 2. Otherwise, old behavior is to see if the first character is a quote * character and if so, strip the leading character and remove the last * quote character on the command line, preserving any text after the * last quote character. * * This causes some commands containing quotes not to be executed correctly. * For example: * * "\Long folder name\aaa.exe" --name="Jurko" --no-surname * * would get its outermost quotes stripped and would be executed as: * * \Long folder name\aaa.exe" --name="Jurko --no-surname * * which would report an error about '\Long' not being a valid command. * * cmd.exe help seems to indicate it would be enough to add an extra space * character in front of the command to avoid this but this does not work, * most likely due to the shell first stripping all leading whitespace * characters from the command. * * Solution implemented here is to quote the whole command in case it * contains any quote characters. Note thought this will not work correctly * should Windows ever 'fix' this feature. * (03.06.2008.) (Jurko) */ static FILE * windows_popen_wrapper( char const * command, char const * mode ) { int const extra_command_quotes_needed = !!strchr( command, '"' ); string quoted_command; FILE * result;
if ( extra_command_quotes_needed ) { string_new( "ed_command ); string_append( "ed_command, "\"" ); string_append( "ed_command, command ); string_append( "ed_command, "\"" ); command = quoted_command.value; }
result = _popen( command, "r" );
if ( extra_command_quotes_needed ) string_free( "ed_command );
return result; }#endif /* defined(_MSC_VER) || defined(__BORLANDC__) */
static char * rtrim( char * const s ){ char * p = s; while ( *p ) ++p; for ( --p; p >= s && isspace( *p ); *p-- = 0 ); return s;}
LIST * builtin_shell( FRAME * frame, int flags ){ LIST * command = lol_get( frame->args, 0 ); LIST * result = L0; string s; int ret; char buffer[ 1024 ]; FILE * p = NULL; int exit_status = -1; int exit_status_opt = 0; int no_output_opt = 0; int strip_eol_opt = 0;
/* Process the variable args options. */ { int a = 1; LIST * arg = lol_get( frame->args, a ); for ( ; !list_empty( arg ); arg = lol_get( frame->args, ++a ) ) { if ( !strcmp( "exit-status", object_str( list_front( arg ) ) ) ) exit_status_opt = 1; else if ( !strcmp( "no-output", object_str( list_front( arg ) ) ) ) no_output_opt = 1; else if ( !strcmp("strip-eol", object_str( list_front( arg ) ) ) ) strip_eol_opt = 1; } }
/* The following fflush() call seems to be indicated as a workaround for a * popen() bug on POSIX implementations related to synhronizing input * stream positions for the called and the calling process. */ fflush( NULL );
p = popen( object_str( list_front( command ) ), "r" ); if ( p == NULL ) return L0;
string_new( &s );
while ( ( ret = fread( buffer, sizeof( char ), sizeof( buffer ) - 1, p ) ) > 0 ) { buffer[ ret ] = 0; if ( !no_output_opt ) { if ( strip_eol_opt ) rtrim( buffer ); string_append( &s, buffer ); } }
exit_status = pclose( p );
/* The command output is returned first. */ result = list_new( object_new( s.value ) ); string_free( &s );
/* The command exit result next. */ if ( exit_status_opt ) { if ( WIFEXITED( exit_status ) ) exit_status = WEXITSTATUS( exit_status ); else exit_status = -1; sprintf( buffer, "%d", exit_status ); result = list_push_back( result, object_new( buffer ) ); }
return result;}
#else /* #ifdef HAVE_POPEN */
LIST * builtin_shell( FRAME * frame, int flags ){ return L0;}
#endif /* #ifdef HAVE_POPEN */12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970/* * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. * * This file is part of Jam - see jam.c for Copyright information. */
#ifndef JAM_BUILTINS_H# define JAM_BUILTINS_H
# include "frames.h"
/* * builtins.h - compile parsed jam statements */
void load_builtins();void init_set();void init_path();void init_regex();void init_property_set();void init_sequence();void init_order();
void property_set_done();
LIST *builtin_calc( FRAME * frame, int flags );LIST *builtin_depends( FRAME * frame, int flags );LIST *builtin_rebuilds( FRAME * frame, int flags );LIST *builtin_echo( FRAME * frame, int flags );LIST *builtin_exit( FRAME * frame, int flags );LIST *builtin_flags( FRAME * frame, int flags );LIST *builtin_glob( FRAME * frame, int flags );LIST *builtin_glob_recursive( FRAME * frame, int flags );LIST *builtin_subst( FRAME * frame, int flags );LIST *builtin_match( FRAME * frame, int flags );LIST *builtin_split_by_characters( FRAME * frame, int flags );LIST *builtin_hdrmacro( FRAME * frame, int flags );LIST *builtin_rulenames( FRAME * frame, int flags );LIST *builtin_varnames( FRAME * frame, int flags );LIST *builtin_delete_module( FRAME * frame, int flags );LIST *builtin_import( FRAME * frame, int flags );LIST *builtin_export( FRAME * frame, int flags );LIST *builtin_caller_module( FRAME * frame, int flags );LIST *builtin_backtrace( FRAME * frame, int flags );LIST *builtin_pwd( FRAME * frame, int flags );LIST *builtin_update( FRAME * frame, int flags );LIST *builtin_update_now( FRAME * frame, int flags );LIST *builtin_import_module( FRAME * frame, int flags );LIST *builtin_imported_modules( FRAME * frame, int flags );LIST *builtin_instance( FRAME * frame, int flags );LIST *builtin_sort( FRAME * frame, int flags );LIST *builtin_normalize_path( FRAME * frame, int flags );LIST *builtin_native_rule( FRAME * frame, int flags );LIST *builtin_has_native_rule( FRAME * frame, int flags );LIST *builtin_user_module( FRAME * frame, int flags );LIST *builtin_nearest_user_location( FRAME * frame, int flags );LIST *builtin_check_if_file( FRAME * frame, int flags );LIST *builtin_python_import_rule( FRAME * frame, int flags );LIST *builtin_shell( FRAME * frame, int flags );LIST *builtin_md5( FRAME * frame, int flags );LIST *builtin_file_open( FRAME * frame, int flags );LIST *builtin_pad( FRAME * frame, int flags );LIST *builtin_precious( FRAME * frame, int flags );LIST *builtin_self_path( FRAME * frame, int flags );LIST *builtin_makedir( FRAME * frame, int flags );
void backtrace( FRAME *frame );extern int last_update_now_status;
#endif1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798#!/usr/bin/python
# This script is used to bump the bjam version. It takes a single argument, e.g## ./bump_version.py 3.1.9## and updates all the necessary files.## Copyright 2006 Rene Rivera.# Copyright 2005-2006 Vladimir Prus.# Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
import osimport os.pathimport reimport stringimport sys
srcdir = os.path.abspath(os.path.dirname(__file__))docdir = os.path.abspath(os.path.join(srcdir, "..", "doc"))
def edit(file, *replacements): print(" '%s'..." % file) f = open(file, 'r') text = f.read() f.close() for (source, target) in replacements: text, n = re.compile(source, re.MULTILINE).subn(target, text) assert n > 0 f = open(file, 'w') f.write(text) f.close()
def make_edits(ver): ver03 = (list(ver) + [0] * 3)[0:3] ver02 = ver03[0:2]
join = lambda v, s : s.join(str(x) for x in v) dotJoin = lambda v : join(v, ".")
print("Setting version to %s" % str(ver03))
edit(os.path.join(srcdir, "boost-jam.spec"), ('^(Version:) .*$', '\\1 %s' % dotJoin(ver03)))
edit(os.path.join(srcdir, "build.jam"), ('^(_VERSION_ =).* ;$', '\\1 %s ;' % join(ver03, " ")))
edit(os.path.join(docdir, "bjam.qbk"), ('(\[version).*(\])', '\\1: %s\\2' % dotJoin(ver03)), ('(\[def :version:).*(\])', '\\1 %s\\2' % dotJoin(ver03)))
edit(os.path.join(srcdir, "patchlevel.h"), ('^(#define VERSION_MAJOR) .*$', '\\1 %s' % ver03[0]), ('^(#define VERSION_MINOR) .*$', '\\1 %s' % ver03[1]), ('^(#define VERSION_PATCH) .*$', '\\1 %s' % ver03[2]), ('^(#define VERSION_MAJOR_SYM) .*$', '\\1 "%02d"' % ver03[0]), ('^(#define VERSION_MINOR_SYM) .*$', '\\1 "%02d"' % ver03[1]), ('^(#define VERSION_PATCH_SYM) .*$', '\\1 "%02d"' % ver03[2]), ('^(#define VERSION) .*$', '\\1 "%s"' % dotJoin(ver)), ('^(#define JAMVERSYM) .*$', '\\1 "JAMVERSION=%s"' % dotJoin(ver02)))
def main(): if len(sys.argv) < 2: print("Expect new version as argument.") sys.exit(1) if len(sys.argv) > 3: print("Too many arguments.") sys.exit(1)
version = sys.argv[1].split(".") if len(version) > 3: print("Expect version argument in the format: <MAJOR>.<MINOR>.<PATCH>") sys.exit(1)
try: version = list(int(x) for x in version) except ValueError: print("Version values must be valid integers.") sys.exit(1)
while version and version[-1] == 0: version.pop()
if not version: print("At least one of the version values must be positive.") sys.exit()
make_edits(version)
if __name__ == '__main__': main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191/* * Copyright Vladimir Prus 2003. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */
#include "class.h"
#include "constants.h"#include "frames.h"#include "hash.h"#include "lists.h"#include "object.h"#include "rules.h"#include "strings.h"#include "variable.h"
#include <stdio.h>#include <stdlib.h>
static struct hash * classes = 0;
static void check_defined( LIST * class_names ){ LISTITER iter = list_begin( class_names ); LISTITER const end = list_end( class_names ); for ( ; iter != end; iter = list_next( iter ) ) { if ( !hash_find( classes, list_item( iter ) ) ) { printf( "Class %s is not defined\n", object_str( list_item( iter ) ) ); abort(); } }}
static OBJECT * class_module_name( OBJECT * declared_name ){ string name[ 1 ]; OBJECT * result;
string_new( name ); string_append( name, "class@" ); string_append( name, object_str( declared_name ) );
result = object_new( name->value ); string_free( name );
return result;}
struct import_base_data{ OBJECT * base_name; module_t * base_module; module_t * class_module;};
static void import_base_rule( void * r_, void * d_ ){ RULE * r = (RULE *)r_; RULE * ir1; RULE * ir2; struct import_base_data * d = (struct import_base_data *)d_; OBJECT * qname;
string qualified_name[ 1 ]; string_new ( qualified_name ); string_append ( qualified_name, object_str( d->base_name ) ); string_push_back( qualified_name, '.' ); string_append ( qualified_name, object_str( r->name ) ); qname = object_new( qualified_name->value ); string_free( qualified_name );
ir1 = import_rule( r, d->class_module, r->name ); ir2 = import_rule( r, d->class_module, qname );
object_free( qname );
/* Copy 'exported' flag. */ ir1->exported = ir2->exported = r->exported;
/* If we are importing a class method, localize it. */ if ( ( r->module == d->base_module ) || ( r->module->class_module && ( r->module->class_module == d->base_module ) ) ) { rule_localize( ir1, d->class_module ); rule_localize( ir2, d->class_module ); }}
/* * For each exported rule 'n', declared in class module for base, imports that * rule in 'class' as 'n' and as 'base.n'. Imported rules are localized and * marked as exported. */
static void import_base_rules( module_t * class_, OBJECT * base ){ OBJECT * module_name = class_module_name( base ); module_t * base_module = bindmodule( module_name ); LIST * imported; struct import_base_data d; d.base_name = base; d.base_module = base_module; d.class_module = class_; object_free( module_name );
if ( base_module->rules ) hashenumerate( base_module->rules, import_base_rule, &d );
imported = imported_modules( base_module ); import_module( imported, class_ ); list_free( imported );}
OBJECT * make_class_module( LIST * xname, LIST * bases, FRAME * frame ){ OBJECT * name = class_module_name( list_front( xname ) ); OBJECT * * pp; module_t * class_module = 0; module_t * outer_module = frame->module; int found;
if ( !classes ) classes = hashinit( sizeof( OBJECT * ), "classes" );
pp = (OBJECT * *)hash_insert( classes, list_front( xname ), &found ); if ( !found ) { *pp = object_copy( list_front( xname ) ); } else { printf( "Class %s already defined\n", object_str( list_front( xname ) ) ); abort(); } check_defined( bases );
class_module = bindmodule( name );
{ /* Initialize variables that Boost.Build inserts in every object. We want to avoid creating the object's hash if it isn't needed. */ int num = class_module->num_fixed_variables; module_add_fixed_var( class_module, constant_name, &num ); module_add_fixed_var( class_module, constant_class, &num ); module_set_fixed_variables( class_module, num ); }
var_set( class_module, constant_name, xname, VAR_SET ); var_set( class_module, constant_bases, bases, VAR_SET );
{ LISTITER iter = list_begin( bases ); LISTITER const end = list_end( bases ); for ( ; iter != end; iter = list_next( iter ) ) import_base_rules( class_module, list_item( iter ) ); }
return name;}
static void free_class( void * xclass, void * data ){ object_free( *(OBJECT * *)xclass );}
void class_done( void ){ if ( classes ) { hashenumerate( classes, free_class, (void *)0 ); hashdone( classes ); classes = 0; }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273/* * Copyright 1994 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */
/* * command.h - the CMD structure and routines to manipulate them * * Both ACTION and CMD contain a rule, targets, and sources. An * ACTION describes a rule to be applied to the given targets and * sources; a CMD is what actually gets executed by the shell. The * differences are due to: * * ACTIONS must be combined if 'actions together' is given. * ACTIONS must be split if 'actions piecemeal' is given. * ACTIONS must have current sources omitted for 'actions updated'. * * The CMD datatype holds a single command that is to be executed * against a target, and they can chain together to represent the * full collection of commands used to update a target. * * Structures: * * CMD - an action, ready to be formatted into a buffer and executed. * * External routines: * * cmd_new() - return a new CMD or 0 if too many args. * cmd_free() - delete CMD and its parts. * cmd_next() - walk the CMD chain. * cmd_release_targets_and_shell() - CMD forgets about its targets & shell. */
/* * CMD - an action, ready to be formatted into a buffer and executed. */
#ifndef COMMAND_SW20111118_H#define COMMAND_SW20111118_H
#include "lists.h"#include "rules.h"#include "strings.h"
typedef struct _cmd CMD;struct _cmd{ CMD * next; RULE * rule; /* rule->actions contains shell script */ LIST * shell; /* $(JAMSHELL) value */ LOL args; /* LISTs for $(<), $(>) */ string buf[ 1 ]; /* actual commands */ int noop; /* no-op commands should be faked instead of executed */};
CMD * cmd_new( RULE * rule, /* rule (referenced) */ LIST * targets, /* $(<) (ownership transferred) */ LIST * sources, /* $(>) (ownership transferred) */ LIST * shell /* $(JAMSHELL) (ownership transferred) */);
void cmd_release_targets_and_shell( CMD * );
void cmd_free( CMD * );
#define cmd_next( c ) ((c)->next)
#endif1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859/* * Copyright 1993, 2000 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */
/* This file is ALSO: * Copyright 2001-2004 David Abrahams. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) */
/* * compile.h - compile parsed jam statements */
#ifndef COMPILE_DWA20011022_H#define COMPILE_DWA20011022_H
#include "frames.h"#include "lists.h"#include "object.h"#include "rules.h"
void compile_builtins();
LIST * evaluate_rule( RULE * rule, OBJECT * rulename, FRAME * );LIST * call_rule( OBJECT * rulename, FRAME * caller_frame, ... );
/* Flags for compile_set(), etc */
#define ASSIGN_SET 0x00 /* = assign variable */#define ASSIGN_APPEND 0x01 /* += append variable */#define ASSIGN_DEFAULT 0x02 /* set only if unset */
/* Flags for compile_setexec() */
#define EXEC_UPDATED 0x01 /* executes updated */#define EXEC_TOGETHER 0x02 /* executes together */#define EXEC_IGNORE 0x04 /* executes ignore */#define EXEC_QUIETLY 0x08 /* executes quietly */#define EXEC_PIECEMEAL 0x10 /* executes piecemeal */#define EXEC_EXISTING 0x20 /* executes existing */
/* Conditions for compile_if() */
#define EXPR_NOT 0 /* ! cond */#define EXPR_AND 1 /* cond && cond */#define EXPR_OR 2 /* cond || cond */#define EXPR_EXISTS 3 /* arg */#define EXPR_EQUALS 4 /* arg = arg */#define EXPR_NOTEQ 5 /* arg != arg */#define EXPR_LESS 6 /* arg < arg */#define EXPR_LESSEQ 7 /* arg <= arg */#define EXPR_MORE 8 /* arg > arg */#define EXPR_MOREEQ 9 /* arg >= arg */#define EXPR_IN 10 /* arg in arg */
#endif1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283/* * Copyright 2002. Vladimir Prus * Copyright 2005. Rene Rivera * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */
#include "cwd.h"
#include "jam.h"#include "mem.h"#include "pathsys.h"
#include <assert.h>#include <errno.h>#include <limits.h>
/* MinGW on Windows declares PATH_MAX in limits.h */#if defined( NT ) && !defined( __GNUC__ )# include <direct.h># define PATH_MAX _MAX_PATH#else# include <unistd.h># if defined( __COMO__ )# include <linux/limits.h># endif#endif
#ifndef PATH_MAX# define PATH_MAX 1024#endif
static OBJECT * cwd_;
void cwd_init( void ){ int buffer_size = PATH_MAX; char * cwd_buffer = 0; int error;
assert( !cwd_ );
do { char * const buffer = BJAM_MALLOC_RAW( buffer_size ); cwd_buffer = getcwd( buffer, buffer_size ); error = errno; if ( cwd_buffer ) { /* We store the path using its canonical/long/key format. */ OBJECT * const cwd = object_new( cwd_buffer ); cwd_ = path_as_key( cwd ); object_free( cwd ); } buffer_size *= 2; BJAM_FREE_RAW( buffer ); } while ( !cwd_ && error == ERANGE );
if ( !cwd_ ) { perror( "can not get current working directory" ); exit( EXITBAD ); }}
OBJECT * cwd( void ){ assert( cwd_ ); return cwd_;}
void cwd_done( void ){ assert( cwd_ ); object_free( cwd_ ); cwd_ = NULL;}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */
/* This file is ALSO: * Copyright 2001-2004 David Abrahams. * Copyright 2005 Rene Rivera. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */
/* * filent.c - scan directories and archives on NT * * External routines: * file_mkdir() - create a directory * file_supported_fmt_resolution() - file modification timestamp resolution * * External routines called only via routines in filesys.c: * file_collect_dir_content_() - collects directory content information * file_dirscan_() - OS specific file_dirscan() implementation * file_query_() - query information about a path from the OS */
#include "jam.h"#ifdef OS_NT#include "filesys.h"
#include "object.h"#include "pathsys.h"#include "strings.h"
#ifdef __BORLANDC__# undef FILENAME /* cpp namespace collision */#endif
#define WIN32_LEAN_AND_MEAN#include <windows.h>
#include <assert.h>#include <ctype.h>#include <direct.h>#include <io.h>
/* * file_collect_dir_content_() - collects directory content information */
int file_collect_dir_content_( file_info_t * const d ){ PATHNAME f; string pathspec[ 1 ]; string pathname[ 1 ]; LIST * files = L0; int d_length;
assert( d ); assert( d->is_dir ); assert( list_empty( d->files ) );
d_length = strlen( object_str( d->name ) );
memset( (char *)&f, '\0', sizeof( f ) ); f.f_dir.ptr = object_str( d->name ); f.f_dir.len = d_length;
/* Prepare file search specification for the FindXXX() Windows API. */ if ( !d_length ) string_copy( pathspec, ".\\*" ); else { /* We can not simply assume the given folder name will never include its * trailing path separator or otherwise we would not support the Windows * root folder specified without its drive letter, i.e. '\'. */ char const trailingChar = object_str( d->name )[ d_length - 1 ] ; string_copy( pathspec, object_str( d->name ) ); if ( ( trailingChar != '\\' ) && ( trailingChar != '/' ) ) string_append( pathspec, "\\" ); string_append( pathspec, "*" ); }
/* The following code for collecting information about all files in a folder * needs to be kept synchronized with how the file_query() operation is * implemented (collects information about a single file). */ { /* FIXME: Avoid duplicate FindXXX Windows API calls here and in the code * determining a normalized path. */ WIN32_FIND_DATA finfo; HANDLE const findHandle = FindFirstFileA( pathspec->value, &finfo ); if ( findHandle == INVALID_HANDLE_VALUE ) { string_free( pathspec ); return -1; }
string_new( pathname ); do { OBJECT * pathname_obj;
f.f_base.ptr = finfo.cFileName; f.f_base.len = strlen( finfo.cFileName );
string_truncate( pathname, 0 ); path_build( &f, pathname );
pathname_obj = object_new( pathname->value ); path_register_key( pathname_obj ); files = list_push_back( files, pathname_obj ); { int found; file_info_t * const ff = file_info( pathname_obj, &found ); ff->is_dir = finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; ff->is_file = !ff->is_dir; ff->exists = 1; timestamp_from_filetime( &ff->time, &finfo.ftLastWriteTime ); } } while ( FindNextFile( findHandle, &finfo ) );
FindClose( findHandle ); }
string_free( pathname ); string_free( pathspec );
d->files = files; return 0;}
/* * file_dirscan_() - OS specific file_dirscan() implementation */
void file_dirscan_( file_info_t * const d, scanback func, void * closure ){ assert( d ); assert( d->is_dir );
/* Special case \ or d:\ : enter it */ { char const * const name = object_str( d->name ); if ( name[ 0 ] == '\\' && !name[ 1 ] ) { (*func)( closure, d->name, 1 /* stat()'ed */, &d->time ); } else if ( name[ 0 ] && name[ 1 ] == ':' && name[ 2 ] && !name[ 3 ] ) { /* We have just entered a 3-letter drive name spelling (with a * trailing slash), into the hash table. Now enter its two-letter * variant, without the trailing slash, so that if we try to check * whether "c:" exists, we hit it. * * Jam core has workarounds for that. Given: * x = c:\whatever\foo ; * p = $(x:D) ; * p2 = $(p:D) ; * There will be no trailing slash in $(p), but there will be one in * $(p2). But, that seems rather fragile. */ OBJECT * const dir_no_slash = object_new_range( name, 2 ); (*func)( closure, d->name, 1 /* stat()'ed */, &d->time ); (*func)( closure, dir_no_slash, 1 /* stat()'ed */, &d->time ); object_free( dir_no_slash ); } }}
/* * file_mkdir() - create a directory */
int file_mkdir( char const * const path ){ return _mkdir( path );}
/* * file_query_() - query information about a path from the OS * * The following code for collecting information about a single file needs to be * kept synchronized with how the file_collect_dir_content_() operation is * implemented (collects information about all files in a folder). */
int try_file_query_root( file_info_t * const info ){ WIN32_FILE_ATTRIBUTE_DATA fileData; char buf[ 4 ]; char const * const pathstr = object_str( info->name ); if ( !pathstr[ 0 ] ) { buf[ 0 ] = '.'; buf[ 1 ] = 0; } else if ( pathstr[ 0 ] == '\\' && ! pathstr[ 1 ] ) { buf[ 0 ] = '\\'; buf[ 1 ] = '\0'; } else if ( pathstr[ 1 ] == ':' ) { if ( !pathstr[ 2 ] ) { } else if ( !pathstr[ 2 ] || ( pathstr[ 2 ] == '\\' && !pathstr[ 3 ] ) ) { buf[ 0 ] = pathstr[ 0 ]; buf[ 1 ] = ':'; buf[ 2 ] = '\\'; buf[ 3 ] = '\0'; } else { return 0; } } else { return 0; } /* We have a root path */ if ( !GetFileAttributesExA( buf, GetFileExInfoStandard, &fileData ) ) { info->is_dir = 0; info->is_file = 0; info->exists = 0; timestamp_clear( &info->time ); } else { info->is_dir = fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; info->is_file = !info->is_dir; info->exists = 1; timestamp_from_filetime( &info->time, &fileData.ftLastWriteTime ); } return 1;}
void file_query_( file_info_t * const info ){ char const * const pathstr = object_str( info->name ); const char * dir; OBJECT * parent; file_info_t * parent_info;
if ( try_file_query_root( info ) ) return;
if ( ( dir = strrchr( pathstr, '\\' ) ) ) { parent = object_new_range( pathstr, dir - pathstr ); } else { parent = object_copy( constant_empty ); } parent_info = file_query( parent ); object_free( parent ); if ( !parent_info || !parent_info->is_dir ) { info->is_dir = 0; info->is_file = 0; info->exists = 0; timestamp_clear( &info->time ); } else { info->is_dir = 0; info->is_file = 0; info->exists = 0; timestamp_clear( &info->time ); if ( list_empty( parent_info->files ) ) file_collect_dir_content_( parent_info ); }}
/* * file_supported_fmt_resolution() - file modification timestamp resolution * * Returns the minimum file modification timestamp resolution supported by this * Boost Jam implementation. File modification timestamp changes of less than * the returned value might not be recognized. * * Does not take into consideration any OS or file system related restrictions. * * Return value 0 indicates that any value supported by the OS is also supported * here. */
void file_supported_fmt_resolution( timestamp * const t ){ /* On Windows we support nano-second file modification timestamp resolution, * just the same as the Windows OS itself. */ timestamp_init( t, 0, 0 );}
#endif /* OS_NT */123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180/* * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. * * This file is part of Jam - see jam.c for Copyright information. */
/* This file is ALSO: * Copyright 2001-2004 David Abrahams. * Copyright 2005 Rene Rivera. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) */
/* * fileunix.c - manipulate file names and scan directories on UNIX/AmigaOS * * External routines: * file_mkdir() - create a directory * file_supported_fmt_resolution() - file modification timestamp resolution * * External routines called only via routines in filesys.c: * file_collect_dir_content_() - collects directory content information * file_dirscan_() - OS specific file_dirscan() implementation * file_query_() - query information about a path from the OS */
#include "jam.h"#ifdef USE_FILEUNIX#include "filesys.h"
#include "object.h"#include "pathsys.h"#include "strings.h"
#include <assert.h>#include <stdio.h>#include <sys/stat.h> /* needed for mkdir() */
#if defined( sun ) || defined( __sun ) || defined( linux )# include <unistd.h> /* needed for read and close prototype */#endif
#if defined( OS_SEQUENT ) || \ defined( OS_DGUX ) || \ defined( OS_SCO ) || \ defined( OS_ISC )# define PORTAR 1#endif
#if defined( OS_RHAPSODY ) || defined( OS_MACOSX ) || defined( OS_NEXT )# include <sys/dir.h># include <unistd.h> /* need unistd for rhapsody's proper lseek */# define STRUCT_DIRENT struct direct#else# include <dirent.h># define STRUCT_DIRENT struct dirent#endif
/* * file_collect_dir_content_() - collects directory content information */
int file_collect_dir_content_( file_info_t * const d ){ LIST * files = L0; PATHNAME f; DIR * dd; STRUCT_DIRENT * dirent; string path[ 1 ]; char const * dirstr;
assert( d ); assert( d->is_dir ); assert( list_empty( d->files ) );
dirstr = object_str( d->name );
memset( (char *)&f, '\0', sizeof( f ) ); f.f_dir.ptr = dirstr; f.f_dir.len = strlen( dirstr );
if ( !*dirstr ) dirstr = ".";
if ( !( dd = opendir( dirstr ) ) ) return -1;
string_new( path ); while ( ( dirent = readdir( dd ) ) ) { OBJECT * name; f.f_base.ptr = dirent->d_name #ifdef old_sinix - 2 /* Broken structure definition on sinix. */ #endif ; f.f_base.len = strlen( f.f_base.ptr );
string_truncate( path, 0 ); path_build( &f, path ); name = object_new( path->value ); /* Immediately stat the file to preserve invariants. */ if ( file_query( name ) ) files = list_push_back( files, name ); else object_free( name ); } string_free( path );
closedir( dd );
d->files = files; return 0;}
/* * file_dirscan_() - OS specific file_dirscan() implementation */
void file_dirscan_( file_info_t * const d, scanback func, void * closure ){ assert( d ); assert( d->is_dir );
/* Special case / : enter it */ if ( !strcmp( object_str( d->name ), "/" ) ) (*func)( closure, d->name, 1 /* stat()'ed */, &d->time );}
/* * file_mkdir() - create a directory */
int file_mkdir( char const * const path ){#if defined(__MINGW32__) /* MinGW's mkdir() takes only one argument: the path. */ mkdir(path);#else /* Explicit cast to remove const modifiers and avoid related compiler * warnings displayed when using the intel compiler. */ return mkdir( (char *)path, 0777 );#endif}
/* * file_query_() - query information about a path from the OS */
void file_query_( file_info_t * const info ){ file_query_posix_( info );}
/* * file_supported_fmt_resolution() - file modification timestamp resolution * * Returns the minimum file modification timestamp resolution supported by this * Boost Jam implementation. File modification timestamp changes of less than * the returned value might not be recognized. * * Does not take into consideration any OS or file system related restrictions. * * Return value 0 indicates that any value supported by the OS is also supported * here. */
void file_supported_fmt_resolution( timestamp * const t ){ /* The current implementation does not support file modification timestamp * resolution of less than one second. */ timestamp_init( t, 1, 0 );}
#endif /* USE_FILEUNIX */1234567891011121314151617181920212223242526272829/* * Copyright 2001-2004 David Abrahams. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) */
#include "jam.h"#include "frames.h"
FRAME * frame_before_python_call;
void frame_init( FRAME * frame ){ frame->prev = 0; frame->prev_user = 0; lol_init( frame->args ); frame->module = root_module(); frame->rulename = "module scope"; frame->file = 0; frame->line = -1;}
void frame_free( FRAME * frame ){ lol_free( frame->args );}12345678910111213141516171819202122232425262728293031323334353637383940414243444546/* * Copyright 2011 Steven Watanabe * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) */
#ifndef FUNCTION_SW20111123_H#define FUNCTION_SW20111123_H
#include "object.h"#include "frames.h"#include "lists.h"#include "parse.h"#include "strings.h"
typedef struct _function FUNCTION;typedef struct _stack STACK;
STACK * stack_global( void );void stack_push( STACK * s, LIST * l );LIST * stack_pop( STACK * s );
FUNCTION * function_compile( PARSE * parse );FUNCTION * function_builtin( LIST * ( * func )( FRAME * frame, int flags ), int flags, const char * * args );void function_refer( FUNCTION * );void function_free( FUNCTION * );OBJECT * function_rulename( FUNCTION * );void function_set_rulename( FUNCTION *, OBJECT * );void function_location( FUNCTION *, OBJECT * *, int * );LIST * function_run( FUNCTION * function, FRAME * frame, STACK * s );
FUNCTION * function_compile_actions( const char * actions, OBJECT * file, int line );void function_run_actions( FUNCTION * function, FRAME * frame, STACK * s, string * out );
FUNCTION * function_bind_variables( FUNCTION * f, module_t * module, int * counter );FUNCTION * function_unbind_variables( FUNCTION * f );
void function_done( void );
#ifdef HAVE_PYTHON
FUNCTION * function_python( PyObject * function, PyObject * bjam_signature );
#endif
#endif12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */
/* * hash.h - simple in-memory hashing routines */
#ifndef BOOST_JAM_HASH_H#define BOOST_JAM_HASH_H
#include "object.h"
/* * An opaque struct representing an item in the hash table. The first element of * every struct stored in the table must be an OBJECT * which is treated as the * key. */typedef struct hashdata HASHDATA;
/* * hashinit() - initialize a hash table, returning a handle. * * Parameters: * datalen - item size * name - used for debugging */struct hash * hashinit( int datalen, char const * name );
/* * hash_free() - free a hash table, given its handle */void hash_free( struct hash * );void hashdone( struct hash * );
/* * hashenumerate() - call f(i, data) on each item, i in the hash table. The * enumeration order is unspecified. */void hashenumerate( struct hash *, void (* f)( void *, void * ), void * data );
/* * hash_insert() - insert a new item in a hash table, or return an existing one. * * Preconditions: * - hp must be a hash table created by hashinit() * - key must be an object created by object_new() * * Postconditions: * - if the key does not already exist in the hash table, *found == 0 and the * result will be a pointer to an uninitialized item. The key of the new * item must be set to a value equal to key before any further operations on * the hash table except hashdone(). * - if the key is present then *found == 1 and the result is a pointer to the * existing record. */HASHDATA * hash_insert( struct hash *, OBJECT * key, int * found );
/* * hash_find() - find a record in the table or NULL if none exists */HASHDATA * hash_find( struct hash *, OBJECT * key );
struct hashstats { int count; int num_items; int tab_size; int item_size; int sets; int num_hashes;};
void hashstats_init( struct hashstats * stats );void hashstats_add( struct hashstats * stats, struct hash * );void hashstats_print( struct hashstats * stats, char const * name );
#endif123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519/* * This file has been donated to Jam. */
/* * Craig W. McPheeters, Alias|Wavefront. * * hcache.c hcache.h - handle cacheing of #includes in source files. * * Create a cache of files scanned for headers. When starting jam, look for the * cache file and load it if present. When finished the binding phase, create a * new header cache. The cache contains files, their timestamps and the header * files found in their scan. During the binding phase of jam, look in the * header cache first for the headers contained in a file. If the cache is * present and valid, use its contents. This results in dramatic speedups with * large projects (e.g. 3min -> 1min startup for one project.) * * External routines: * hcache_init() - read and parse the local .jamdeps file. * hcache_done() - write a new .jamdeps file. * hcache() - return list of headers on target. Use cache or do a scan. * * The dependency file format is an ASCII file with 1 line per target. Each line * has the following fields: * @boundname@ timestamp_sec timestamp_nsec @file@ @file@ @file@ ... */
#ifdef OPT_HEADER_CACHE_EXT
#include "jam.h"#include "hcache.h"
#include "hash.h"#include "headers.h"#include "lists.h"#include "modules.h"#include "object.h"#include "parse.h"#include "regexp.h"#include "rules.h"#include "search.h"#include "timestamp.h"#include "variable.h"
typedef struct hcachedata HCACHEDATA ;
struct hcachedata{ OBJECT * boundname; timestamp time; LIST * includes; LIST * hdrscan; /* the HDRSCAN value for this target */ int age; /* if too old, we will remove it from cache */ HCACHEDATA * next;};
static struct hash * hcachehash = 0;static HCACHEDATA * hcachelist = 0;
static int queries = 0;static int hits = 0;
#define CACHE_FILE_VERSION "version 5"#define CACHE_RECORD_HEADER "header"#define CACHE_RECORD_END "end"
/* * Return the name of the header cache file. May return NULL. * * The user sets this by setting the HCACHEFILE variable in a Jamfile. We cache * the result so the user can not change the cache file during header scanning. */
static const char * cache_name( void ){ static OBJECT * name = 0; if ( !name ) { LIST * const hcachevar = var_get( root_module(), constant_HCACHEFILE );
if ( !list_empty( hcachevar ) ) { TARGET * const t = bindtarget( list_front( hcachevar ) );
pushsettings( root_module(), t->settings ); /* Do not expect the cache file to be generated, so pass 0 as the * third argument to search. Expect the location to be specified via * LOCATE, so pass 0 as the fourth arugment. */ object_free( t->boundname ); t->boundname = search( t->name, &t->time, 0, 0 ); popsettings( root_module(), t->settings );
name = object_copy( t->boundname ); } } return name ? object_str( name ) : 0;}
/* * Return the maximum age a cache entry can have before it is purged from the * cache. */
static int cache_maxage( void ){ int age = 100; LIST * const var = var_get( root_module(), constant_HCACHEMAXAGE ); if ( !list_empty( var ) ) { age = atoi( object_str( list_front( var ) ) ); if ( age < 0 ) age = 0; } return age;}
/* * Read a netstring. The caveat is that the string can not contain ASCII 0. The * returned value is as returned by object_new(). */
OBJECT * read_netstring( FILE * f ){ unsigned long len; static char * buf = NULL; static unsigned long buf_len = 0;
if ( fscanf( f, " %9lu", &len ) != 1 ) return NULL; if ( fgetc( f ) != (int)'\t' ) return NULL;
if ( len > 1024 * 64 ) return NULL; /* sanity check */
if ( len > buf_len ) { unsigned long new_len = buf_len * 2; if ( new_len < len ) new_len = len; buf = (char *)BJAM_REALLOC( buf, new_len + 1 ); if ( buf ) buf_len = new_len; }
if ( !buf ) return NULL;
if ( fread( buf, 1, len, f ) != len ) return NULL; if ( fgetc( f ) != (int)'\n' ) return NULL;
buf[ len ] = 0; return object_new( buf );}
/* * Write a netstring. */
void write_netstring( FILE * f, char const * s ){ if ( !s ) s = ""; fprintf( f, "%lu\t%s\n", (long unsigned)strlen( s ), s );}
void hcache_init(){ FILE * f; OBJECT * version = 0; int header_count = 0; const char * hcachename;
if ( hcachehash ) return;
hcachehash = hashinit( sizeof( HCACHEDATA ), "hcache" );
if ( !( hcachename = cache_name() ) ) return;
if ( !( f = fopen( hcachename, "rb" ) ) ) return;
version = read_netstring( f );
if ( !version || strcmp( object_str( version ), CACHE_FILE_VERSION ) ) goto bail;
while ( 1 ) { HCACHEDATA cachedata; HCACHEDATA * c; OBJECT * record_type = 0; OBJECT * time_secs_str = 0; OBJECT * time_nsecs_str = 0; OBJECT * age_str = 0; OBJECT * includes_count_str = 0; OBJECT * hdrscan_count_str = 0; int i; int count; LIST * l; int found;
cachedata.boundname = 0; cachedata.includes = 0; cachedata.hdrscan = 0;
record_type = read_netstring( f ); if ( !record_type ) { fprintf( stderr, "invalid %s\n", hcachename ); goto cleanup; } if ( !strcmp( object_str( record_type ), CACHE_RECORD_END ) ) { object_free( record_type ); break; } if ( strcmp( object_str( record_type ), CACHE_RECORD_HEADER ) ) { fprintf( stderr, "invalid %s with record separator <%s>\n", hcachename, record_type ? object_str( record_type ) : "<null>" ); goto cleanup; }
cachedata.boundname = read_netstring( f ); time_secs_str = read_netstring( f ); time_nsecs_str = read_netstring( f ); age_str = read_netstring( f ); includes_count_str = read_netstring( f );
if ( !cachedata.boundname || !time_secs_str || !time_nsecs_str || !age_str || !includes_count_str ) { fprintf( stderr, "invalid %s\n", hcachename ); goto cleanup; }
timestamp_init( &cachedata.time, atoi( object_str( time_secs_str ) ), atoi( object_str( time_nsecs_str ) ) ); cachedata.age = atoi( object_str( age_str ) ) + 1;
count = atoi( object_str( includes_count_str ) ); for ( l = L0, i = 0; i < count; ++i ) { OBJECT * const s = read_netstring( f ); if ( !s ) { fprintf( stderr, "invalid %s\n", hcachename ); list_free( l ); goto cleanup; } l = list_push_back( l, s ); } cachedata.includes = l;
hdrscan_count_str = read_netstring( f ); if ( !hdrscan_count_str ) { fprintf( stderr, "invalid %s\n", hcachename ); goto cleanup; }
count = atoi( object_str( hdrscan_count_str ) ); for ( l = L0, i = 0; i < count; ++i ) { OBJECT * const s = read_netstring( f ); if ( !s ) { fprintf( stderr, "invalid %s\n", hcachename ); list_free( l ); goto cleanup; } l = list_push_back( l, s ); } cachedata.hdrscan = l;
c = (HCACHEDATA *)hash_insert( hcachehash, cachedata.boundname, &found ) ; if ( !found ) { c->boundname = cachedata.boundname; c->includes = cachedata.includes; c->hdrscan = cachedata.hdrscan; c->age = cachedata.age; timestamp_copy( &c->time, &cachedata.time ); } else { fprintf( stderr, "can not insert header cache item, bailing on %s" "\n", hcachename ); goto cleanup; }
c->next = hcachelist; hcachelist = c;
++header_count;
object_free( record_type ); object_free( time_secs_str ); object_free( time_nsecs_str ); object_free( age_str ); object_free( includes_count_str ); object_free( hdrscan_count_str ); continue;
cleanup:
if ( record_type ) object_free( record_type ); if ( time_secs_str ) object_free( time_secs_str ); if ( time_nsecs_str ) object_free( time_nsecs_str ); if ( age_str ) object_free( age_str ); if ( includes_count_str ) object_free( includes_count_str ); if ( hdrscan_count_str ) object_free( hdrscan_count_str );
if ( cachedata.boundname ) object_free( cachedata.boundname ); if ( cachedata.includes ) list_free( cachedata.includes ); if ( cachedata.hdrscan ) list_free( cachedata.hdrscan );
goto bail; }
if ( DEBUG_HEADER ) printf( "hcache read from file %s\n", hcachename );
bail: if ( version ) object_free( version ); fclose( f );}
void hcache_done(){ FILE * f; HCACHEDATA * c; int header_count = 0; const char * hcachename; int maxage;
if ( !hcachehash ) return;
if ( !( hcachename = cache_name() ) ) goto cleanup;
if ( !( f = fopen( hcachename, "wb" ) ) ) goto cleanup;
maxage = cache_maxage();
/* Print out the version. */ write_netstring( f, CACHE_FILE_VERSION );
c = hcachelist; for ( c = hcachelist; c; c = c->next ) { LISTITER iter; LISTITER end; char time_secs_str[ 30 ]; char time_nsecs_str[ 30 ]; char age_str[ 30 ]; char includes_count_str[ 30 ]; char hdrscan_count_str[ 30 ];
if ( maxage == 0 ) c->age = 0; else if ( c->age > maxage ) continue;
sprintf( includes_count_str, "%lu", (long unsigned)list_length( c->includes ) ); sprintf( hdrscan_count_str, "%lu", (long unsigned)list_length( c->hdrscan ) ); sprintf( time_secs_str, "%lu", (long unsigned)c->time.secs ); sprintf( time_nsecs_str, "%lu", (long unsigned)c->time.nsecs ); sprintf( age_str, "%lu", (long unsigned)c->age );
write_netstring( f, CACHE_RECORD_HEADER ); write_netstring( f, object_str( c->boundname ) ); write_netstring( f, time_secs_str ); write_netstring( f, time_nsecs_str ); write_netstring( f, age_str ); write_netstring( f, includes_count_str ); for ( iter = list_begin( c->includes ), end = list_end( c->includes ); iter != end; iter = list_next( iter ) ) write_netstring( f, object_str( list_item( iter ) ) ); write_netstring( f, hdrscan_count_str ); for ( iter = list_begin( c->hdrscan ), end = list_end( c->hdrscan ); iter != end; iter = list_next( iter ) ) write_netstring( f, object_str( list_item( iter ) ) ); fputs( "\n", f ); ++header_count; } write_netstring( f, CACHE_RECORD_END );
if ( DEBUG_HEADER ) printf( "hcache written to %s. %d dependencies, %.0f%% hit rate\n", hcachename, header_count, queries ? 100.0 * hits / queries : 0 );
fclose ( f );
cleanup: for ( c = hcachelist; c; c = c->next ) { list_free( c->includes ); list_free( c->hdrscan ); object_free( c->boundname ); }
hcachelist = 0; if ( hcachehash ) hashdone( hcachehash ); hcachehash = 0;}
LIST * hcache( TARGET * t, int rec, regexp * re[], LIST * hdrscan ){ HCACHEDATA * c;
++queries;
if ( ( c = (HCACHEDATA *)hash_find( hcachehash, t->boundname ) ) ) { if ( !timestamp_cmp( &c->time, &t->time ) ) { LIST * const l1 = hdrscan; LIST * const l2 = c->hdrscan; LISTITER iter1 = list_begin( l1 ); LISTITER const end1 = list_end( l1 ); LISTITER iter2 = list_begin( l2 ); LISTITER const end2 = list_end( l2 ); while ( iter1 != end1 && iter2 != end2 ) { if ( !object_equal( list_item( iter1 ), list_item( iter2 ) ) ) iter1 = end1; else { iter1 = list_next( iter1 ); iter2 = list_next( iter2 ); } } if ( iter1 != end1 || iter2 != end2 ) { if ( DEBUG_HEADER ) { printf( "HDRSCAN out of date in cache for %s\n", object_str( t->boundname ) ); printf(" real : "); list_print( hdrscan ); printf( "\n cached: " ); list_print( c->hdrscan ); printf( "\n" ); }
list_free( c->includes ); list_free( c->hdrscan ); c->includes = L0; c->hdrscan = L0; } else { if ( DEBUG_HEADER ) printf( "using header cache for %s\n", object_str( t->boundname ) ); c->age = 0; ++hits; return list_copy( c->includes ); } } else { if ( DEBUG_HEADER ) printf ("header cache out of date for %s\n", object_str( t->boundname ) ); list_free( c->includes ); list_free( c->hdrscan ); c->includes = L0; c->hdrscan = L0; } } else { int found; c = (HCACHEDATA *)hash_insert( hcachehash, t->boundname, &found ); if ( !found ) { c->boundname = object_copy( t->boundname ); c->next = hcachelist; hcachelist = c; } }
/* 'c' points at the cache entry. Its out of date. */ { LIST * const l = headers1( L0, t->boundname, rec, re );
timestamp_copy( &c->time, &t->time ); c->age = 0; c->includes = list_copy( l ); c->hdrscan = list_copy( hdrscan );
return l; }}
#endif /* OPT_HEADER_CACHE_EXT */123456789101112131415161718192021/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */
/* * hdrmacro.h - parses header files for #define MACRO <filename> or * #define MACRO "filename" definitions */
#ifndef HDRMACRO_SW20111118_H#define HDRMACRO_SW20111118_H
#include "object.h"#include "rules.h"
void macro_headers( TARGET * );OBJECT * macro_header_get( OBJECT * macro_name );
#endif123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197/* * Copyright 1993, 2000 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. *//* This file is ALSO: * Copyright 2001-2004 David Abrahams. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) */
/* * headers.c - handle #includes in source files * * Using regular expressions provided as the variable $(HDRSCAN), headers() * searches a file for #include files and phonies up a rule invocation: * $(HDRRULE) <target> : <include files> ; * * External routines: * headers() - scan a target for include files and call HDRRULE * * Internal routines: * headers1() - using regexp, scan a file and build include LIST */
#include "jam.h"#include "headers.h"
#include "compile.h"#include "hdrmacro.h"#include "lists.h"#include "modules.h"#include "object.h"#include "parse.h"#include "rules.h"#include "subst.h"#include "variable.h"
#ifdef OPT_HEADER_CACHE_EXT# include "hcache.h"#endif
#ifndef OPT_HEADER_CACHE_EXTstatic LIST * headers1( LIST *, OBJECT * file, int rec, regexp * re[] );#endif
/* * headers() - scan a target for include files and call HDRRULE */
#define MAXINC 10
void headers( TARGET * t ){ LIST * hdrscan; LIST * hdrrule; #ifndef OPT_HEADER_CACHE_EXT LIST * headlist = L0; #endif regexp * re[ MAXINC ]; int rec = 0; LISTITER iter; LISTITER end;
hdrscan = var_get( root_module(), constant_HDRSCAN ); if ( list_empty( hdrscan ) ) return;
hdrrule = var_get( root_module(), constant_HDRRULE ); if ( list_empty( hdrrule ) ) return;
if ( DEBUG_HEADER ) printf( "header scan %s\n", object_str( t->name ) );
/* Compile all regular expressions in HDRSCAN */ iter = list_begin( hdrscan ); end = list_end( hdrscan ); for ( ; ( rec < MAXINC ) && iter != end; iter = list_next( iter ) ) { re[ rec++ ] = regex_compile( list_item( iter ) ); }
/* Doctor up call to HDRRULE rule */ /* Call headers1() to get LIST of included files. */ { FRAME frame[ 1 ]; frame_init( frame ); lol_add( frame->args, list_new( object_copy( t->name ) ) );#ifdef OPT_HEADER_CACHE_EXT lol_add( frame->args, hcache( t, rec, re, hdrscan ) );#else lol_add( frame->args, headers1( headlist, t->boundname, rec, re ) );#endif
if ( lol_get( frame->args, 1 ) ) { OBJECT * rulename = list_front( hdrrule ); /* The third argument to HDRRULE is the bound name of $(<). */ lol_add( frame->args, list_new( object_copy( t->boundname ) ) ); list_free( evaluate_rule( bindrule( rulename, frame->module ), rulename, frame ) ); }
/* Clean up. */ frame_free( frame ); }}
/* * headers1() - using regexp, scan a file and build include LIST. */
#ifndef OPT_HEADER_CACHE_EXTstatic#endifLIST * headers1( LIST * l, OBJECT * file, int rec, regexp * re[] ){ FILE * f; char buf[ 1024 ]; int i; static regexp * re_macros = 0;
#ifdef OPT_IMPROVED_PATIENCE_EXT static int count = 0; ++count; if ( ( ( count == 100 ) || !( count % 1000 ) ) && DEBUG_MAKE ) { printf( "...patience...\n" ); fflush( stdout ); }#endif
/* The following regexp is used to detect cases where a file is included * through a line like "#include MACRO". */ if ( re_macros == 0 ) { OBJECT * const re_str = object_new( "#[ \t]*include[ \t]*([A-Za-z][A-Za-z0-9_]*).*$" ); re_macros = regex_compile( re_str ); object_free( re_str ); }
if ( !( f = fopen( object_str( file ), "r" ) ) ) return l;
while ( fgets( buf, sizeof( buf ), f ) ) { for ( i = 0; i < rec; ++i ) if ( regexec( re[ i ], buf ) && re[ i ]->startp[ 1 ] ) { ( (char *)re[ i ]->endp[ 1 ] )[ 0 ] = '\0'; if ( DEBUG_HEADER ) printf( "header found: %s\n", re[ i ]->startp[ 1 ] ); l = list_push_back( l, object_new( re[ i ]->startp[ 1 ] ) ); }
/* Special treatment for #include MACRO. */ if ( regexec( re_macros, buf ) && re_macros->startp[ 1 ] ) { OBJECT * header_filename; OBJECT * macro_name;
( (char *)re_macros->endp[ 1 ] )[ 0 ] = '\0';
if ( DEBUG_HEADER ) printf( "macro header found: %s", re_macros->startp[ 1 ] );
macro_name = object_new( re_macros->startp[ 1 ] ); header_filename = macro_header_get( macro_name ); object_free( macro_name ); if ( header_filename ) { if ( DEBUG_HEADER ) printf( " resolved to '%s'\n", object_str( header_filename ) ); l = list_push_back( l, object_copy( header_filename ) ); } else { if ( DEBUG_HEADER ) printf( " ignored !!\n" ); } } }
fclose( f ); return l;}
void regerror( char const * s ){ printf( "re error %s\n", s );}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656/* * /+\ * +\ Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. * \+/ * * This file is part of jam. * * License is hereby granted to use this software and distribute it freely, as * long as this copyright notice is retained and modifications are clearly * marked. * * ALL WARRANTIES ARE HEREBY DISCLAIMED. */
/* This file is ALSO: * Copyright 2001-2004 David Abrahams. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */
/* * jam.c - make redux * * See Jam.html for usage information. * * These comments document the code. * * The top half of the code is structured such: * * jam * / | \ * +---+ | \ * / | \ * jamgram option \ * / | \ \ * / | \ \ * / | \ | * scan | compile make * | | / | \ / | \ * | | / | \ / | \ * | | / | \ / | \ * jambase parse | rules search make1 * | | | \ * | | | \ * | | | \ * builtins timestamp command execute * | * | * | * filesys * * * The support routines are called by all of the above, but themselves are * layered thus: * * variable|expand * / | | * / | | * / | | * lists | pathsys * \ | * \ hash * \ | * \ | * \ | * \ | * \ | * object * * Roughly, the modules are: * * builtins.c - jam's built-in rules * command.c - maintain lists of commands * compile.c - compile parsed jam statements * exec*.c - execute a shell script on a specific OS * file*.c - scan directories and archives on a specific OS * hash.c - simple in-memory hashing routines * hdrmacro.c - handle header file parsing for filename macro definitions * headers.c - handle #includes in source files * jambase.c - compilable copy of Jambase * jamgram.y - jam grammar * lists.c - maintain lists of strings * make.c - bring a target up to date, once rules are in place * make1.c - execute command to bring targets up to date * object.c - string manipulation routines * option.c - command line option processing * parse.c - make and destroy parse trees as driven by the parser * path*.c - manipulate file names on a specific OS * hash.c - simple in-memory hashing routines * regexp.c - Henry Spencer's regexp * rules.c - access to RULEs, TARGETs, and ACTIONs * scan.c - the jam yacc scanner * search.c - find a target along $(SEARCH) or $(LOCATE) * timestamp.c - get the timestamp of a file or archive member * variable.c - handle jam multi-element variables */
#include "jam.h"#include "patchlevel.h"
#include "builtins.h"#include "class.h"#include "compile.h"#include "constants.h"#include "filesys.h"#include "function.h"#include "hcache.h"#include "lists.h"#include "make.h"#include "object.h"#include "option.h"#include "output.h"#include "parse.h"#include "cwd.h"#include "rules.h"#include "scan.h"#include "search.h"#include "strings.h"#include "timestamp.h"#include "variable.h"
/* Macintosh is "special" */#ifdef OS_MAC# include <QuickDraw.h>#endif
/* And UNIX for this. */#ifdef unix# include <sys/utsname.h># include <signal.h>#endif
struct globs globs ={ 0, /* noexec */ 1, /* jobs */ 0, /* quitquick */ 0, /* newestfirst */ 0, /* pipes action stdout and stderr merged to action output */#ifdef OS_MAC { 0, 0 }, /* debug - suppress tracing output */#else { 0, 1 }, /* debug ... */#endif 0, /* output commands, not run them */ 0, /* action timeout */ 0 /* maximum buffer size zero is all output */};
/* Symbols to be defined as true for use in Jambase. */static char * othersyms[] = { OSMAJOR, OSMINOR, OSPLAT, JAMVERSYM, 0 };
/* Known for sure: * mac needs arg_enviro * OS2 needs extern environ */
#ifdef OS_MAC# define use_environ arg_environ# ifdef MPW QDGlobals qd;# endif#endif
/* on Win32-LCC */#if defined( OS_NT ) && defined( __LCC__ )# define use_environ _environ#endif
#if defined( __MWERKS__)# define use_environ _environ extern char * * _environ;#endif
#ifndef use_environ# define use_environ environ# if !defined( __WATCOM__ ) && !defined( OS_OS2 ) && !defined( OS_NT ) extern char **environ;# endif#endif
#if YYDEBUG != 0 extern int yydebug;#endif
#ifndef NDEBUGstatic void run_unit_tests(){# if defined( USE_EXECNT ) extern void execnt_unit_test(); execnt_unit_test();# endif string_unit_test();}#endif
int anyhow = 0;
#ifdef HAVE_PYTHON extern PyObject * bjam_call ( PyObject * self, PyObject * args ); extern PyObject * bjam_import_rule ( PyObject * self, PyObject * args ); extern PyObject * bjam_define_action( PyObject * self, PyObject * args ); extern PyObject * bjam_variable ( PyObject * self, PyObject * args ); extern PyObject * bjam_backtrace ( PyObject * self, PyObject * args ); extern PyObject * bjam_caller ( PyObject * self, PyObject * args );#endif
void regex_done();
char const * saved_argv0;
int main( int argc, char * * argv, char * * arg_environ ){ int n; char * s; struct bjam_option optv[ N_OPTS ]; char const * all = "all"; int status; int arg_c = argc; char * * arg_v = argv; char const * progname = argv[ 0 ]; module_t * environ_module;
saved_argv0 = argv[ 0 ];
BJAM_MEM_INIT();
#ifdef OS_MAC InitGraf( &qd.thePort );#endif
--argc; ++argv;
if ( getoptions( argc, argv, "-:l:m:d:j:p:f:gs:t:ano:qv", optv ) < 0 ) { printf( "\nusage: %s [ options ] targets...\n\n", progname );
printf( "-a Build all targets, even if they are current.\n" ); printf( "-dx Set the debug level to x (0-9).\n" ); printf( "-fx Read x instead of Jambase.\n" ); /* printf( "-g Build from newest sources first.\n" ); */ printf( "-jx Run up to x shell commands concurrently.\n" ); printf( "-lx Limit actions to x number of seconds after which they are stopped.\n" ); printf( "-mx Maximum target output saved (kb), default is to save all output.\n" ); printf( "-n Don't actually execute the updating actions.\n" ); printf( "-ox Write the updating actions to file x.\n" ); printf( "-px x=0, pipes action stdout and stderr merged into action output.\n" ); printf( "-q Quit quickly as soon as a target fails.\n" ); printf( "-sx=y Set variable x=y, overriding environment.\n" ); printf( "-tx Rebuild x, even if it is up-to-date.\n" ); printf( "-v Print the version of jam and exit.\n" ); printf( "--x Option is ignored.\n\n" );
exit( EXITBAD ); }
/* Version info. */ if ( ( s = getoptval( optv, 'v', 0 ) ) ) { printf( "Boost.Jam Version %s. %s.\n", VERSION, OSMINOR ); printf( " Copyright 1993-2002 Christopher Seiwald and Perforce " "Software, Inc.\n" ); printf( " Copyright 2001 David Turner.\n" ); printf( " Copyright 2001-2004 David Abrahams.\n" ); printf( " Copyright 2002-2008 Rene Rivera.\n" ); printf( " Copyright 2003-2008 Vladimir Prus.\n" ); return EXITOK; }
/* Pick up interesting options. */ if ( ( s = getoptval( optv, 'n', 0 ) ) ) { ++globs.noexec; globs.debug[ 2 ] = 1; }
if ( ( s = getoptval( optv, 'p', 0 ) ) ) { /* Undocumented -p3 (acts like both -p1 -p2) means separate pipe action * stdout and stderr. */ globs.pipe_action = atoi( s ); if ( globs.pipe_action < 0 || 3 < globs.pipe_action ) { printf( "Invalid pipe descriptor '%d', valid values are -p[0..3]." "\n", globs.pipe_action ); exit( EXITBAD ); } }
if ( ( s = getoptval( optv, 'q', 0 ) ) ) globs.quitquick = 1;
if ( ( s = getoptval( optv, 'a', 0 ) ) ) anyhow++;
if ( ( s = getoptval( optv, 'j', 0 ) ) ) { globs.jobs = atoi( s ); if ( globs.jobs < 1 || globs.jobs > MAXJOBS ) { printf( "Invalid value for the '-j' option, valid values are 1 " "through %d.\n", MAXJOBS ); exit( EXITBAD ); } }
if ( ( s = getoptval( optv, 'g', 0 ) ) ) globs.newestfirst = 1;
if ( ( s = getoptval( optv, 'l', 0 ) ) ) globs.timeout = atoi( s );
if ( ( s = getoptval( optv, 'm', 0 ) ) ) globs.max_buf = atoi( s ) * 1024; /* convert to kb */
/* Turn on/off debugging */ for ( n = 0; ( s = getoptval( optv, 'd', n ) ); ++n ) { int i;
/* First -d, turn off defaults. */ if ( !n ) for ( i = 0; i < DEBUG_MAX; ++i ) globs.debug[i] = 0;
i = atoi( s );
if ( ( i < 0 ) || ( i >= DEBUG_MAX ) ) { printf( "Invalid debug level '%s'.\n", s ); continue; }
/* n turns on levels 1-n. */ /* +n turns on level n. */ if ( *s == '+' ) globs.debug[ i ] = 1; else while ( i ) globs.debug[ i-- ] = 1; }
constants_init(); cwd_init();
{ PROFILE_ENTER( MAIN );
#ifdef HAVE_PYTHON { PROFILE_ENTER( MAIN_PYTHON ); Py_Initialize(); { static PyMethodDef BjamMethods[] = { {"call", bjam_call, METH_VARARGS, "Call the specified bjam rule."}, {"import_rule", bjam_import_rule, METH_VARARGS, "Imports Python callable to bjam."}, {"define_action", bjam_define_action, METH_VARARGS, "Defines a command line action."}, {"variable", bjam_variable, METH_VARARGS, "Obtains a variable from bjam's global module."}, {"backtrace", bjam_backtrace, METH_VARARGS, "Returns bjam backtrace from the last call into Python."}, {"caller", bjam_caller, METH_VARARGS, "Returns the module from which the last call into Python is made."}, {NULL, NULL, 0, NULL} };
Py_InitModule( "bjam", BjamMethods ); } PROFILE_EXIT( MAIN_PYTHON ); }#endif
#ifndef NDEBUG run_unit_tests();#endif#if YYDEBUG != 0 if ( DEBUG_PARSE ) yydebug = 1;#endif
/* Set JAMDATE. */ { timestamp current; timestamp_current( ¤t ); var_set( root_module(), constant_JAMDATE, list_new( outf_time( ¤t ) ), VAR_SET ); }
/* Set JAM_VERSION. */ var_set( root_module(), constant_JAM_VERSION, list_push_back( list_push_back( list_new( object_new( VERSION_MAJOR_SYM ) ), object_new( VERSION_MINOR_SYM ) ), object_new( VERSION_PATCH_SYM ) ), VAR_SET );
/* Set JAMUNAME. */#ifdef unix { struct utsname u;
if ( uname( &u ) >= 0 ) { var_set( root_module(), constant_JAMUNAME, list_push_back( list_push_back( list_push_back( list_push_back( list_new( object_new( u.sysname ) ), object_new( u.nodename ) ), object_new( u.release ) ), object_new( u.version ) ), object_new( u.machine ) ), VAR_SET ); } }#endif /* unix */
/* Set JAM_TIMESTAMP_RESOLUTION. */ { timestamp fmt_resolution[ 1 ]; file_supported_fmt_resolution( fmt_resolution ); var_set( root_module(), constant_JAM_TIMESTAMP_RESOLUTION, list_new( object_new( timestamp_timestr( fmt_resolution ) ) ), VAR_SET ); }
/* Load up environment variables. */
/* First into the global module, with splitting, for backward * compatibility. */ var_defines( root_module(), use_environ, 1 );
environ_module = bindmodule( constant_ENVIRON ); /* Then into .ENVIRON, without splitting. */ var_defines( environ_module, use_environ, 0 );
/* * Jam defined variables OS & OSPLAT. We load them after environment, so * that setting OS in environment does not change Jam's notion of the * current platform. */ var_defines( root_module(), othersyms, 1 );
/* Load up variables set on command line. */ for ( n = 0; ( s = getoptval( optv, 's', n ) ); ++n ) { char * symv[ 2 ]; symv[ 0 ] = s; symv[ 1 ] = 0; var_defines( root_module(), symv, 1 ); var_defines( environ_module, symv, 0 ); }
/* Set the ARGV to reflect the complete list of arguments of invocation. */ for ( n = 0; n < arg_c; ++n ) var_set( root_module(), constant_ARGV, list_new( object_new( arg_v[ n ] ) ), VAR_APPEND );
/* Initialize built-in rules. */ load_builtins();
/* Add the targets in the command line to the update list. */ for ( n = 1; n < arg_c; ++n ) { if ( arg_v[ n ][ 0 ] == '-' ) { char * f = "-:l:d:j:f:gs:t:ano:qv"; for ( ; *f; ++f ) if ( *f == arg_v[ n ][ 1 ] ) break; if ( ( f[ 1 ] == ':' ) && ( arg_v[ n ][ 2 ] == '\0' ) ) ++n; } else { OBJECT * const target = object_new( arg_v[ n ] ); mark_target_for_updating( target ); object_free( target ); } }
if ( list_empty( targets_to_update() ) ) mark_target_for_updating( constant_all );
/* Parse ruleset. */ { FRAME frame[ 1 ]; frame_init( frame ); for ( n = 0; ( s = getoptval( optv, 'f', n ) ); ++n ) { OBJECT * const filename = object_new( s ); parse_file( filename, frame ); object_free( filename ); }
if ( !n ) parse_file( constant_plus, frame ); }
status = yyanyerrors();
/* Manually touch -t targets. */ for ( n = 0; ( s = getoptval( optv, 't', n ) ); ++n ) { OBJECT * const target = object_new( s ); touch_target( target ); object_free( target ); }
/* If an output file is specified, set globs.cmdout to that. */ if ( ( s = getoptval( optv, 'o', 0 ) ) ) { if ( !( globs.cmdout = fopen( s, "w" ) ) ) { printf( "Failed to write to '%s'\n", s ); exit( EXITBAD ); } ++globs.noexec; }
/* The build system may set the PARALLELISM variable to override -j * options. */ { LIST * const p = var_get( root_module(), constant_PARALLELISM ); if ( !list_empty( p ) ) { int const j = atoi( object_str( list_front( p ) ) ); if ( j < 1 || j > MAXJOBS ) printf( "Invalid value of PARALLELISM: %s. Valid values " "are 1 through %d.\n", object_str( list_front( p ) ), MAXJOBS ); else globs.jobs = j; } }
/* KEEP_GOING overrides -q option. */ { LIST * const p = var_get( root_module(), constant_KEEP_GOING ); if ( !list_empty( p ) ) globs.quitquick = atoi( object_str( list_front( p ) ) ) ? 0 : 1; }
/* Now make target. */ { PROFILE_ENTER( MAIN_MAKE ); LIST * const targets = targets_to_update(); if ( !list_empty( targets ) ) status |= make( targets, anyhow ); else status = last_update_now_status; PROFILE_EXIT( MAIN_MAKE ); }
PROFILE_EXIT( MAIN ); }
if ( DEBUG_PROFILE ) profile_dump();
#ifdef OPT_HEADER_CACHE_EXT hcache_done();#endif
clear_targets_to_update();
/* Widely scattered cleanup. */ property_set_done(); file_done(); rules_done(); timestamp_done(); search_done(); class_done(); modules_done(); regex_done(); cwd_done(); path_done(); function_done(); list_done(); constants_done(); object_done();
/* Close cmdout. */ if ( globs.cmdout ) fclose( globs.cmdout );
#ifdef HAVE_PYTHON Py_Finalize();#endif
BJAM_MEM_CLOSE();
return status ? EXITBAD : EXITOK;}
/* * executable_path() */
#if defined(_WIN32)# define WIN32_LEAN_AND_MEAN# include <windows.h>char * executable_path( char const * argv0 ){ char buf[ 1024 ]; DWORD const ret = GetModuleFileName( NULL, buf, sizeof( buf ) ); return ( !ret || ret == sizeof( buf ) ) ? NULL : strdup( buf );}#elif defined(__APPLE__) /* Not tested */# include <mach-o/dyld.h>char *executable_path( char const * argv0 ){ char buf[ 1024 ]; uint32_t size = sizeof( buf ); return _NSGetExecutablePath( buf, &size ) ? NULL : strdup( buf );}#elif defined(sun) || defined(__sun) /* Not tested */# include <stdlib.h>char * executable_path( char const * argv0 ){ return strdup( getexecname() );}#elif defined(__FreeBSD__)# include <sys/sysctl.h>char * executable_path( char const * argv0 ){ int mib[ 4 ] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; char buf[ 1024 ]; size_t size = sizeof( buf ); sysctl( mib, 4, buf, &size, NULL, 0 ); return ( !size || size == sizeof( buf ) ) ? NULL : strndup( buf, size );}#elif defined(__linux__)# include <unistd.h>char * executable_path( char const * argv0 ){ char buf[ 1024 ]; ssize_t const ret = readlink( "/proc/self/exe", buf, sizeof( buf ) ); return ( !ret || ret == sizeof( buf ) ) ? NULL : strndup( buf, ret );}#elsechar * executable_path( char const * argv0 ){ /* If argv0 is an absolute path, assume it is the right absolute path. */ return argv0[ 0 ] == '/' ? strdup( argv0 ) : NULL;}#endif123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */
/* This file is ALSO: * Copyright 2001-2004 David Abrahams. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */
/* * jam.h - includes and globals for jam */
#ifndef JAM_H_VP_2003_08_01#define JAM_H_VP_2003_08_01
#ifdef HAVE_PYTHON#include <Python.h>#endif
/* Assume popen support is available unless known otherwise. */#define HAVE_POPEN 1
/* * Windows NT */
#ifdef NT
#include <ctype.h>#include <fcntl.h>#include <malloc.h>#ifndef __MWERKS__ #include <memory.h>#endif#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <string.h>#include <time.h>
#define OSMAJOR "NT=true"#define OSMINOR "OS=NT"#define OS_NT#define SPLITPATH ';'#define MAXLINE (undefined__see_execnt_c) /* max chars per command line */#define USE_EXECNT#define PATH_DELIM '\\'
/* AS400 cross-compile from NT. */
#ifdef AS400 #undef OSMINOR #undef OSMAJOR #define OSMAJOR "AS400=true" #define OSMINOR "OS=AS400" #define OS_AS400#endif
/* Metrowerks Standard Library on Windows. */
#ifdef __MSL__ #undef HAVE_POPEN#endif
#endif /* #ifdef NT */
/* * Windows MingW32 */
#ifdef __MINGW32__
#include <fcntl.h>#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <malloc.h>#include <memory.h>#include <signal.h>#include <string.h>#include <time.h>
#define OSMAJOR "MINGW=true"#define OSMINOR "OS=MINGW"#define OS_NT#define SPLITPATH ';'#define MAXLINE 996 /* max chars per command line */#define USE_EXECUNIX#define PATH_DELIM '\\'
#endif /* #ifdef MINGW */
/* * God fearing UNIX. */
#ifndef OSMINOR
#define OSMAJOR "UNIX=true"#define USE_EXECUNIX#define USE_FILEUNIX#define PATH_DELIM '/'
#ifdef _AIX #define unix #define MAXLINE 23552 /* 24k - 1k, max chars per command line */ #define OSMINOR "OS=AIX" #define OS_AIX #define NO_VFORK#endif#ifdef AMIGA #define OSMINOR "OS=AMIGA" #define OS_AMIGA#endif#ifdef __BEOS__ #define unix #define OSMINOR "OS=BEOS" #define OS_BEOS #define NO_VFORK#endif#ifdef __bsdi__ #define OSMINOR "OS=BSDI" #define OS_BSDI#endif#if defined (COHERENT) && defined (_I386) #define OSMINOR "OS=COHERENT" #define OS_COHERENT #define NO_VFORK#endif#if defined(__cygwin__) || defined(__CYGWIN__) #define OSMINOR "OS=CYGWIN" #define OS_CYGWIN#endif#if defined(__FreeBSD__) && !defined(__DragonFly__) #define OSMINOR "OS=FREEBSD" #define OS_FREEBSD#endif#ifdef __DragonFly__ #define OSMINOR "OS=DRAGONFLYBSD" #define OS_DRAGONFLYBSD#endif#ifdef __DGUX__ #define OSMINOR "OS=DGUX" #define OS_DGUX#endif#ifdef __hpux #define OSMINOR "OS=HPUX" #define OS_HPUX#endif#ifdef __OPENNT #define unix #define OSMINOR "OS=INTERIX" #define OS_INTERIX #define NO_VFORK#endif#ifdef __sgi #define OSMINOR "OS=IRIX" #define OS_IRIX #define NO_VFORK#endif#ifdef __ISC #define OSMINOR "OS=ISC" #define OS_ISC #define NO_VFORK#endif#ifdef linux #define OSMINOR "OS=LINUX" #define OS_LINUX#endif#ifdef __Lynx__ #define OSMINOR "OS=LYNX" #define OS_LYNX #define NO_VFORK #define unix#endif#ifdef __MACHTEN__ #define OSMINOR "OS=MACHTEN" #define OS_MACHTEN#endif#ifdef mpeix #define unix #define OSMINOR "OS=MPEIX" #define OS_MPEIX #define NO_VFORK#endif#ifdef __MVS__ #define unix #define OSMINOR "OS=MVS" #define OS_MVS#endif#ifdef _ATT4 #define OSMINOR "OS=NCR" #define OS_NCR#endif#ifdef __NetBSD__ #define unix #define OSMINOR "OS=NETBSD" #define OS_NETBSD #define NO_VFORK#endif#ifdef __QNX__ #define unix #ifdef __QNXNTO__ #define OSMINOR "OS=QNXNTO" #define OS_QNXNTO #else #define OSMINOR "OS=QNX" #define OS_QNX #define NO_VFORK #define MAXLINE 996 /* max chars per command line */ #endif#endif#ifdef NeXT #ifdef __APPLE__ #define OSMINOR "OS=RHAPSODY" #define OS_RHAPSODY #else #define OSMINOR "OS=NEXT" #define OS_NEXT #endif#endif#ifdef __APPLE__ #define unix #define OSMINOR "OS=MACOSX" #define OS_MACOSX#endif#ifdef __osf__ #ifndef unix #define unix #endif #define OSMINOR "OS=OSF" #define OS_OSF#endif#ifdef _SEQUENT_ #define OSMINOR "OS=PTX" #define OS_PTX#endif#ifdef M_XENIX #define OSMINOR "OS=SCO" #define OS_SCO #define NO_VFORK#endif#ifdef sinix #define unix #define OSMINOR "OS=SINIX" #define OS_SINIX#endif#ifdef sun #if defined(__svr4__) || defined(__SVR4) #define OSMINOR "OS=SOLARIS" #define OS_SOLARIS #else #define OSMINOR "OS=SUNOS" #define OS_SUNOS #endif#endif#ifdef ultrix #define OSMINOR "OS=ULTRIX" #define OS_ULTRIX#endif#ifdef _UNICOS #define OSMINOR "OS=UNICOS" #define OS_UNICOS#endif#if defined(__USLC__) && !defined(M_XENIX) #define OSMINOR "OS=UNIXWARE" #define OS_UNIXWARE#endif#ifdef __OpenBSD__ #define OSMINOR "OS=OPENBSD" #define OS_OPENBSD #define unix#endif#if defined (__FreeBSD_kernel__) && !defined(__FreeBSD__) #define OSMINOR "OS=KFREEBSD" #define OS_KFREEBSD#endif#ifndef OSMINOR #define OSMINOR "OS=UNKNOWN"#endif
/* All the UNIX includes */
#include <sys/types.h>
#ifndef OS_MPEIX #include <sys/file.h>#endif
#include <fcntl.h>#include <stdio.h>#include <ctype.h>#include <signal.h>#include <string.h>#include <time.h>#include <unistd.h>
#ifndef OS_QNX #include <memory.h>#endif
#ifndef OS_ULTRIX #include <stdlib.h>#endif
#if !defined( OS_BSDI ) && \ !defined( OS_FREEBSD ) && \ !defined( OS_DRAGONFLYBSD ) && \ !defined( OS_NEXT ) && \ !defined( OS_MACHTEN ) && \ !defined( OS_MACOSX ) && \ !defined( OS_RHAPSODY ) && \ !defined( OS_MVS ) && \ !defined( OS_OPENBSD ) #include <malloc.h>#endif
#endif /* #ifndef OSMINOR */
/* * OSPLAT definitions - suppressed when it is a one-of-a-kind. */
#if defined( _M_PPC ) || \ defined( PPC ) || \ defined( ppc ) || \ defined( __powerpc__ ) || \ defined( __ppc__ ) #define OSPLAT "OSPLAT=PPC"#endif
#if defined( _ALPHA_ ) || \ defined( __alpha__ ) #define OSPLAT "OSPLAT=AXP"#endif
#if defined( _i386_ ) || \ defined( __i386__ ) || \ defined( __i386 ) || \ defined( _M_IX86 ) #define OSPLAT "OSPLAT=X86"#endif
#if defined( __ia64__ ) || \ defined( __IA64__ ) || \ defined( __ia64 ) #define OSPLAT "OSPLAT=IA64"#endif
#if defined( __x86_64__ ) || \ defined( __amd64__ ) || \ defined( _M_AMD64 ) #define OSPLAT "OSPLAT=X86_64"#endif
#if defined( __sparc__ ) || \ defined( __sparc ) #define OSPLAT "OSPLAT=SPARC"#endif
#ifdef __mips__ #define OSPLAT "OSPLAT=MIPS"#endif
#ifdef __arm__ #define OSPLAT "OSPLAT=ARM"#endif
#ifdef __s390__ #define OSPLAT "OSPLAT=390"#endif
#ifdef __hppa #define OSPLAT "OSPLAT=PARISC"#endif
#ifndef OSPLAT #define OSPLAT ""#endif
/* * Jam implementation misc. */
#ifndef MAXLINE #define MAXLINE 102400 /* max chars per command line */#endif
#ifndef EXITOK #define EXITOK 0 #define EXITBAD 1#endif
#ifndef SPLITPATH #define SPLITPATH ':'#endif
/* You probably do not need to muck with these. */
#define MAXSYM 1024 /* longest symbol in the environment */#define MAXJPATH 1024 /* longest filename */
#define MAXJOBS 64 /* internally enforced -j limit */#define MAXARGC 32 /* words in $(JAMSHELL) */
/* Jam private definitions below. */
#define DEBUG_MAX 14
struct globs{ int noexec; int jobs; int quitquick; int newestfirst; /* build newest sources first */ int pipe_action; char debug[ DEBUG_MAX ]; FILE * cmdout; /* print cmds, not run them */ long timeout; /* number of seconds to limit actions to, * default 0 for no limit. */ int dart; /* output build and test results formatted for * Dart */ int max_buf; /* maximum amount of output saved from target * (kb) */};
extern struct globs globs;
#define DEBUG_MAKE ( globs.debug[ 1 ] ) /* show actions when executed */#define DEBUG_MAKEQ ( globs.debug[ 2 ] ) /* show even quiet actions */#define DEBUG_EXEC ( globs.debug[ 2 ] ) /* show text of actons */#define DEBUG_MAKEPROG ( globs.debug[ 3 ] ) /* show make0 progress */#define DEBUG_BIND ( globs.debug[ 3 ] ) /* show when files bound */
#define DEBUG_EXECCMD ( globs.debug[ 4 ] ) /* show execcmds()'s work */
#define DEBUG_COMPILE ( globs.debug[ 5 ] ) /* show rule invocations */
#define DEBUG_HEADER ( globs.debug[ 6 ] ) /* show result of header scan */#define DEBUG_BINDSCAN ( globs.debug[ 6 ] ) /* show result of dir scan */#define DEBUG_SEARCH ( globs.debug[ 6 ] ) /* show binding attempts */
#define DEBUG_VARSET ( globs.debug[ 7 ] ) /* show variable settings */#define DEBUG_VARGET ( globs.debug[ 8 ] ) /* show variable fetches */#define DEBUG_VAREXP ( globs.debug[ 8 ] ) /* show variable expansions */#define DEBUG_IF ( globs.debug[ 8 ] ) /* show 'if' calculations */#define DEBUG_LISTS ( globs.debug[ 9 ] ) /* show list manipulation */#define DEBUG_SCAN ( globs.debug[ 9 ] ) /* show scanner tokens */#define DEBUG_MEM ( globs.debug[ 9 ] ) /* show memory use */
#define DEBUG_PROFILE ( globs.debug[ 10 ] ) /* dump rule execution times */#define DEBUG_PARSE ( globs.debug[ 11 ] ) /* debug parsing */#define DEBUG_GRAPH ( globs.debug[ 12 ] ) /* debug dependencies */#define DEBUG_FATE ( globs.debug[ 13 ] ) /* show fate changes in make0() */
/* Everyone gets the memory definitions. */#include "mem.h"
/* They also get the profile functions. */#include "debug.h"
#endif123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373%token _BANG_t%token _BANG_EQUALS_t%token _AMPER_t%token _AMPERAMPER_t%token _LPAREN_t%token _RPAREN_t%token _PLUS_EQUALS_t%token _COLON_t%token _SEMIC_t%token _LANGLE_t%token _LANGLE_EQUALS_t%token _EQUALS_t%token _RANGLE_t%token _RANGLE_EQUALS_t%token _QUESTION_EQUALS_t%token _LBRACKET_t%token _RBRACKET_t%token ACTIONS_t%token BIND_t%token CASE_t%token CLASS_t%token DEFAULT_t%token ELSE_t%token EXISTING_t%token FOR_t%token IF_t%token IGNORE_t%token IN_t%token INCLUDE_t%token LOCAL_t%token MODULE_t%token ON_t%token PIECEMEAL_t%token QUIETLY_t%token RETURN_t%token RULE_t%token SWITCH_t%token TOGETHER_t%token UPDATED_t%token WHILE_t%token _LBRACE_t%token _BAR_t%token _BARBAR_t%token _RBRACE_t/* * Copyright 1993, 2000 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */
/* This file is ALSO: * Copyright 2001-2004 David Abrahams. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) */
/* * jamgram.yy - jam grammar * * 04/13/94 (seiwald) - added shorthand L0 for null list pointer * 06/01/94 (seiwald) - new 'actions existing' does existing sources * 08/23/94 (seiwald) - Support for '+=' (append to variable) * 08/31/94 (seiwald) - Allow ?= as alias for "default =". * 09/15/94 (seiwald) - if conditionals take only single arguments, so * that 'if foo == bar' gives syntax error (use =). * 02/11/95 (seiwald) - when scanning arguments to rules, only treat * punctuation keywords as keywords. All arg lists * are terminated with punctuation keywords. * * 09/11/00 (seiwald) - Support for function calls: * * Rules now return lists (LIST *), rather than void. * * New "[ rule ]" syntax evals rule into a LIST. * * Lists are now generated by compile_list() and * compile_append(), and any other rule that indirectly * makes a list, rather than being built directly here, * so that lists values can contain rule evaluations. * * New 'return' rule sets the return value, though * other statements also may have return values. * * 'run' production split from 'block' production so * that empty blocks can be handled separately. */
%token ARG STRING
%left _BARBAR_t _BAR_t%left _AMPERAMPER_t _AMPER_t%left _EQUALS_t _BANG_EQUALS_t IN_t%left _LANGLE_t _LANGLE_EQUALS_t _RANGLE_t _RANGLE_EQUALS_t%left _BANG_t
%{#include "jam.h"
#include "lists.h"#include "parse.h"#include "scan.h"#include "compile.h"#include "object.h"#include "rules.h"
# define YYMAXDEPTH 10000 /* for OSF and other less endowed yaccs */
# define F0 -1# define P0 (PARSE *)0# define S0 (OBJECT *)0
# define pappend( l,r ) parse_make( PARSE_APPEND,l,r,P0,S0,S0,0 )# define peval( c,l,r ) parse_make( PARSE_EVAL,l,r,P0,S0,S0,c )# define pfor( s,l,r,x ) parse_make( PARSE_FOREACH,l,r,P0,s,S0,x )# define pif( l,r,t ) parse_make( PARSE_IF,l,r,t,S0,S0,0 )# define pincl( l ) parse_make( PARSE_INCLUDE,l,P0,P0,S0,S0,0 )# define plist( s ) parse_make( PARSE_LIST,P0,P0,P0,s,S0,0 )# define plocal( l,r,t ) parse_make( PARSE_LOCAL,l,r,t,S0,S0,0 )# define pmodule( l,r ) parse_make( PARSE_MODULE,l,r,P0,S0,S0,0 )# define pclass( l,r ) parse_make( PARSE_CLASS,l,r,P0,S0,S0,0 )# define pnull() parse_make( PARSE_NULL,P0,P0,P0,S0,S0,0 )# define pon( l,r ) parse_make( PARSE_ON,l,r,P0,S0,S0,0 )# define prule( s,p ) parse_make( PARSE_RULE,p,P0,P0,s,S0,0 )# define prules( l,r ) parse_make( PARSE_RULES,l,r,P0,S0,S0,0 )# define pset( l,r,a ) parse_make( PARSE_SET,l,r,P0,S0,S0,a )# define pset1( l,r,t,a ) parse_make( PARSE_SETTINGS,l,r,t,S0,S0,a )# define psetc( s,p,a,l ) parse_make( PARSE_SETCOMP,p,a,P0,s,S0,l )# define psete( s,l,s1,f ) parse_make( PARSE_SETEXEC,l,P0,P0,s,s1,f )# define pswitch( l,r ) parse_make( PARSE_SWITCH,l,r,P0,S0,S0,0 )# define pwhile( l,r ) parse_make( PARSE_WHILE,l,r,P0,S0,S0,0 )
# define pnode( l,r ) parse_make( F0,l,r,P0,S0,S0,0 )# define psnode( s,l ) parse_make( F0,l,P0,P0,s,S0,0 )
%}
%%
run : /* empty */ /* do nothing */ | rules { parse_save( $1.parse ); } ;
/* * block - zero or more rules * rules - one or more rules * rule - any one of jam's rules * right-recursive so rules execute in order. */
block : null { $$.parse = $1.parse; } | rules { $$.parse = $1.parse; } ;
rules : rule { $$.parse = $1.parse; } | rule rules { $$.parse = prules( $1.parse, $2.parse ); } | LOCAL_t list assign_list_opt _SEMIC_t block { $$.parse = plocal( $2.parse, $3.parse, $5.parse ); } ;
null : /* empty */ { $$.parse = pnull(); } ;
assign_list_opt : _EQUALS_t list { $$.parse = $2.parse; $$.number = ASSIGN_SET; } | null { $$.parse = $1.parse; $$.number = ASSIGN_APPEND; } ;
arglist_opt : _LPAREN_t lol _RPAREN_t { $$.parse = $2.parse; } | { $$.parse = P0; } ;
local_opt : LOCAL_t { $$.number = 1; } | /* empty */ { $$.number = 0; } ;
rule : _LBRACE_t block _RBRACE_t { $$.parse = $2.parse; } | INCLUDE_t list _SEMIC_t { $$.parse = pincl( $2.parse ); } | ARG lol _SEMIC_t { $$.parse = prule( $1.string, $2.parse ); } | arg assign list _SEMIC_t { $$.parse = pset( $1.parse, $3.parse, $2.number ); } | arg ON_t list assign list _SEMIC_t { $$.parse = pset1( $1.parse, $3.parse, $5.parse, $4.number ); } | RETURN_t list _SEMIC_t { $$.parse = $2.parse; } | FOR_t local_opt ARG IN_t list _LBRACE_t block _RBRACE_t { $$.parse = pfor( $3.string, $5.parse, $7.parse, $2.number ); } | SWITCH_t list _LBRACE_t cases _RBRACE_t { $$.parse = pswitch( $2.parse, $4.parse ); } | IF_t expr _LBRACE_t block _RBRACE_t { $$.parse = pif( $2.parse, $4.parse, pnull() ); } | MODULE_t list _LBRACE_t block _RBRACE_t { $$.parse = pmodule( $2.parse, $4.parse ); } | CLASS_t lol _LBRACE_t block _RBRACE_t { $$.parse = pclass( $2.parse, $4.parse ); } | WHILE_t expr _LBRACE_t block _RBRACE_t { $$.parse = pwhile( $2.parse, $4.parse ); } | IF_t expr _LBRACE_t block _RBRACE_t ELSE_t rule { $$.parse = pif( $2.parse, $4.parse, $7.parse ); } | local_opt RULE_t ARG arglist_opt rule { $$.parse = psetc( $3.string, $5.parse, $4.parse, $1.number ); } | ON_t arg rule { $$.parse = pon( $2.parse, $3.parse ); } | ACTIONS_t eflags ARG bindlist _LBRACE_t { yymode( SCAN_STRING ); } STRING { yymode( SCAN_NORMAL ); } _RBRACE_t { $$.parse = psete( $3.string,$4.parse,$7.string,$2.number ); } ;
/* * assign - = or += */
assign : _EQUALS_t { $$.number = ASSIGN_SET; } | _PLUS_EQUALS_t { $$.number = ASSIGN_APPEND; } | _QUESTION_EQUALS_t { $$.number = ASSIGN_DEFAULT; } | DEFAULT_t _EQUALS_t { $$.number = ASSIGN_DEFAULT; } ;
/* * expr - an expression for if */expr : arg { $$.parse = peval( EXPR_EXISTS, $1.parse, pnull() ); } | expr _EQUALS_t expr { $$.parse = peval( EXPR_EQUALS, $1.parse, $3.parse ); } | expr _BANG_EQUALS_t expr { $$.parse = peval( EXPR_NOTEQ, $1.parse, $3.parse ); } | expr _LANGLE_t expr { $$.parse = peval( EXPR_LESS, $1.parse, $3.parse ); } | expr _LANGLE_EQUALS_t expr { $$.parse = peval( EXPR_LESSEQ, $1.parse, $3.parse ); } | expr _RANGLE_t expr { $$.parse = peval( EXPR_MORE, $1.parse, $3.parse ); } | expr _RANGLE_EQUALS_t expr { $$.parse = peval( EXPR_MOREEQ, $1.parse, $3.parse ); } | expr _AMPER_t expr { $$.parse = peval( EXPR_AND, $1.parse, $3.parse ); } | expr _AMPERAMPER_t expr { $$.parse = peval( EXPR_AND, $1.parse, $3.parse ); } | expr _BAR_t expr { $$.parse = peval( EXPR_OR, $1.parse, $3.parse ); } | expr _BARBAR_t expr { $$.parse = peval( EXPR_OR, $1.parse, $3.parse ); } | arg IN_t list { $$.parse = peval( EXPR_IN, $1.parse, $3.parse ); } | _BANG_t expr { $$.parse = peval( EXPR_NOT, $2.parse, pnull() ); } | _LPAREN_t expr _RPAREN_t { $$.parse = $2.parse; } ;
/* * cases - action elements inside a 'switch' * case - a single action element inside a 'switch' * right-recursive rule so cases can be examined in order. */
cases : /* empty */ { $$.parse = P0; } | case cases { $$.parse = pnode( $1.parse, $2.parse ); } ;
case : CASE_t ARG _COLON_t block { $$.parse = psnode( $2.string, $4.parse ); } ;
/* * lol - list of lists * right-recursive rule so that lists can be added in order. */
lol : list { $$.parse = pnode( P0, $1.parse ); } | list _COLON_t lol { $$.parse = pnode( $3.parse, $1.parse ); } ;
/* * list - zero or more args in a LIST * listp - list (in puncutation only mode) * arg - one ARG or function call */
list : listp { $$.parse = $1.parse; yymode( SCAN_NORMAL ); } ;
listp : /* empty */ { $$.parse = pnull(); yymode( SCAN_PUNCT ); } | listp arg { $$.parse = pappend( $1.parse, $2.parse ); } ;
arg : ARG { $$.parse = plist( $1.string ); } | _LBRACKET_t { yymode( SCAN_NORMAL ); } func _RBRACKET_t { $$.parse = $3.parse; } ;
/* * func - a function call (inside []) * This needs to be split cleanly out of 'rule' */
func : ARG lol { $$.parse = prule( $1.string, $2.parse ); } | ON_t arg ARG lol { $$.parse = pon( $2.parse, prule( $3.string, $4.parse ) ); } | ON_t arg RETURN_t list { $$.parse = pon( $2.parse, $4.parse ); } ;
/* * eflags - zero or more modifiers to 'executes' * eflag - a single modifier to 'executes' */
eflags : /* empty */ { $$.number = 0; } | eflags eflag { $$.number = $1.number | $2.number; } ;
eflag : UPDATED_t { $$.number = EXEC_UPDATED; } | TOGETHER_t { $$.number = EXEC_TOGETHER; } | IGNORE_t { $$.number = EXEC_IGNORE; } | QUIETLY_t { $$.number = EXEC_QUIETLY; } | PIECEMEAL_t { $$.number = EXEC_PIECEMEAL; } | EXISTING_t { $$.number = EXEC_EXISTING; } ;
/* * bindlist - list of variable to bind for an action */
bindlist : /* empty */ { $$.parse = pnull(); } | BIND_t list { $$.parse = $2.parse; } ;
FacebookAI/xlm-roberta-large/onnx/sentencepiece.bpe.modelAdded+3
mosesdecoder/contrib/memscore/Makefile.amAdded+24
mosesdecoder/contrib/memscore/aclocal.m4Added+851
mosesdecoder/contrib/memscore/config.h.inAdded+79
mosesdecoder/contrib/memscore/datastorage.hAdded+52
mosesdecoder/contrib/memscore/depcompAdded+530
mosesdecoder/contrib/memscore/install-shAdded+323
mosesdecoder/contrib/memscore/lexdecom.cppAdded+183
mosesdecoder/contrib/memscore/phraselm.cppAdded+63
mosesdecoder/contrib/memscore/phrasetable.hAdded+710
mosesdecoder/contrib/memscore/scorer-impl.hAdded+124
mosesdecoder/contrib/promix/README.mdAdded+66
mosesdecoder/contrib/promix/bleu.pyAdded+27
mosesdecoder/contrib/promix/coll.pyAdded+260
mosesdecoder/contrib/promix/main.pyAdded+112
mosesdecoder/contrib/promix/nbest.pyAdded+230
mosesdecoder/contrib/promix/test.pyAdded+25
mosesdecoder/contrib/promix/test_sampler.pyAdded+53
mosesdecoder/contrib/promix/test_train.pyAdded+306
mosesdecoder/contrib/promix/util.pyAdded+12
mosesdecoder/jam-files/boost-build/build/ac.jamAdded+198
mosesdecoder/jam-files/boost-build/build/project.jamAdded+1121
mosesdecoder/jam-files/boost-build/build/property-set.jamAdded+489
mosesdecoder/jam-files/boost-build/build/targets.jamAdded+1659
mosesdecoder/jam-files/boost-build/build/version.jamAdded+161
mosesdecoder/jam-files/boost-build/build/virtual-target.jamAdded+1317
mosesdecoder/jam-files/boost-build/util/assert.jamAdded+336
mosesdecoder/jam-files/boost-build/util/doc.jamAdded+997
mosesdecoder/jam-files/boost-build/util/numbers.jamAdded+218
mosesdecoder/jam-files/boost-build/util/regex.jamAdded+193
mosesdecoder/jam-files/engine/build.batAdded+565
mosesdecoder/jam-files/engine/builtins.cAdded+2354
mosesdecoder/jam-files/engine/builtins.hAdded+70
mosesdecoder/jam-files/engine/bump_version.pyAdded+98
mosesdecoder/jam-files/engine/class.cAdded+191
mosesdecoder/jam-files/engine/command.hAdded+73
mosesdecoder/jam-files/engine/compile.hAdded+59
mosesdecoder/jam-files/engine/cwd.cAdded+83
mosesdecoder/jam-files/engine/filent.cAdded+311
mosesdecoder/jam-files/engine/fileunix.cAdded+180
mosesdecoder/jam-files/engine/frames.cAdded+29
mosesdecoder/jam-files/engine/function.cAdded
mosesdecoder/jam-files/engine/function.hAdded+46
mosesdecoder/jam-files/engine/hash.hAdded+79
mosesdecoder/jam-files/engine/hcache.cAdded+519
mosesdecoder/jam-files/engine/hdrmacro.hAdded+21
mosesdecoder/jam-files/engine/headers.cAdded+197
mosesdecoder/jam-files/engine/jam.cAdded+656
mosesdecoder/jam-files/engine/jam.hAdded+475
mosesdecoder/jam-files/engine/jamgram.yAdded+373