Boost logo

Boost-Build :

From: Thomas Witt (witt_at_[hidden])
Date: 2002-03-08 18:37:15


Attached is a new version of the template feature patch for boost-base.jam
(current cvs).
This patch should enable full template functionality as mentioned in the
documentation. Please note that I did only perform basic testing. Bugs are
quite likely. I posted it now since I won't have time to work on it during
the next week. Unfortunately I will have to go skiing :-).

I tried to reduce code duplication this time, though there are still some open
issues. I suspect there might be a better solution for grist-templates and
add-path rules. Rene could you have a look into this ? I can't do better now.

Regarding the name, you mentioned base and prototype.

Rene your reason for using prototype instead of template were C++ templates. I
think with regard to language analogy prototype might be even more
problematic. IIRC in C/C++ we have function prototypes and there is a
prototype pattern as well. The purpose of both function prototype and
function pattern is different from template-targets purpose. Basically
prototypes are not extended.

What I like about base is that template-targets behave like base-classes. What
I do not like about base is that to me it is already to much overloaded. With
regard to overloading only static can be worse :-).

I propose we go with strict scoping for now and gather some experience. We can
always relax scoping if we feel its needed.

As mentioned earlier I won't have e-mail access from sunday until monday 18th.

Thomas --------------Boundary-00=_3MHOMDN5WOBOHA0JQ0RL Content-Type: text/x-diff;
charset="us-ascii";
name="boost-base.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="boost-base.patch"

--- boost-base.jam Fri Mar 8 23:57:52 2002
+++ boost-base-template.jam Fri Mar 8 23:48:16 2002
@@ -78,6 +78,7 @@

SHARED_TYPES = DLL ;
STATIC_TYPES = LIB ;
+TEMPLATE_TYPES = TEMPLATE ;

# detect-build-tools <tools-name> : <detection-command>
#
@@ -1086,7 +1087,7 @@
#
# <lib>libtest.a <dll>libtest.so <exe>test.app README.TXT <pyd>test.so
#
-rule expand-source-names ( sources + )
+rule expand-source-names ( sources * )
{
local x-sources = ;
for local source in $(sources)
@@ -1143,12 +1144,64 @@
return $(x-targets) ;
}

+# dependencies ( target-id )
+#
+# returns all dependencies (lib, dll, template) for the given target-id
+#
+rule dependencies ( target-id )
+{
+ return $(gTARGET_LIBS($(target-id))) $(gTARGET_DLLS($(target-id))) $(gTARGET_TEMPLATES($(target-id))) ;
+}
+
+# rule grist-templates templates ...
+#
+# Returns a list of target-ids for the given template
+# pathes.
+#
+rule grist-templates ( templates * )
+{
+ local result ;
+
+ for local lib-path in $(templates)
+ {
+ local new-subdir = TOP [ top-relative-tokens [ directory-of $(lib-path) ] ] ;
+
+ # protect global variables from being permanently set by SubDir
+ local [ protect-subdir ] ;
+
+ # Enter the dependee subproject
+ SubDir $(new-subdir) ;
+
+ result += [ FGristFiles $(lib-path:D=) ] ;
+ }
+
+ return $(result) ;
+}
+
+# rule add-path ( path : sources * )
+#
+# returns sources with path added
+#
+rule add-path ( path : sources * )
+{
+ local processed ;
+
+ for local target in $(sources)
+ {
+ processed += [ tokens-to-simple-path $(path) [ split-path $(target) ] ] ;
+ }
+
+ return $(processed) ;
+}
+
# declare-local-target name : sources : requirements : local-BUILD : target-type
#
# declares a subproject-local target of the given name and target-type. This is
# all top-level rules which declare targets should eventually go through here.
-rule declare-local-target ( target : sources + : requirements * : default-build * : target-type )
+rule declare-local-target ( target : sources * : requirements * : default-build * : target-type )
{
+ Echo declare-local-target $(target) $(target-type) ;
+
# We expand out the name of the target and sources
local x-target = [ expand-target-names $(target) : $(target-type) ] ;
local x-sources = [ expand-source-names $(sources) ] ;
@@ -1170,28 +1223,51 @@

# Add the specified requirements to any requirements given by the target
# type, and the corresponding <target-type> property.
+ # template targets do not have a <target-type> property.
+
+ local target-type-property ;
+
+ if $(target-type) in $(TEMPLATE_TYPES)
+ {
+ target-type-property = ;
+ }
+ else
+ {
+ target-type-property = <target-type>$(target-type) ;
+ }
+
gTARGET_REQUIREMENTS($(target-id))
- = $(requirements) $(gTARGET_TYPE_REQUIREMENTS($(target-type))) <target-type>$(target-type) ;
+ = $(requirements) $(gTARGET_TYPE_REQUIREMENTS($(target-type))) $(target-type-property) ;
+
local libs ;
local dlls ;
+ local templates ;
for local source in [ select-gristed $(x-sources) ]
{
local grist = [ SUBST $(source:G) (<)(.*)(>) $2 ] ;
+ local dependency = $(source:G=) ;
+
if $(gTARGET_TYPE_ID($(grist))) in $(STATIC_TYPES)
{
- libs += $(source:G=) ;
+ libs += $(dependency) ;
}
if $(gTARGET_TYPE_ID($(grist))) in $(SHARED_TYPES)
{
- dlls += $(source:G=) ;
+ dlls += $(dependency) ;
+ }
+ if $(gTARGET_TYPE_ID($(grist))) in $(TEMPLATE_TYPES)
+ {
+ templates += $(dependency) ;
}
}
- gTARGET_LIBS($(target-id)) = $(libs) ;
- gTARGET_DLLS($(target-id)) = $(dlls) ;
-
+ gTARGET_LIBS($(target-id)) = $(libs) ;
+ gTARGET_DLLS($(target-id)) = $(dlls) ;
+ gTARGET_TEMPLATES($(target-id)) = $(templates) ;
+ gTARGET_DEFAULT_BUILD($(target-id)) = $(default-build) ;
+
gTARGET_SOURCES($(target-id))
= [ FGristFiles
- [ difference $(x-sources:G=) : $(gTARGET_LIBS($(target-id))) $(gTARGET_DLLS($(target-id))) ] ] ;
+ [ difference $(x-sources:G=) : [ dependencies $(target-id) ] ] ] ;

}
else if $(gTARGET_TYPE($(target-id))) != $(target-type)
@@ -1200,17 +1276,39 @@
"$(gTARGET_TYPE($(target-id)))" "$(target-type)" ;
}

- # Supress the regular build of this target
- local suppress = [ get-values <suppress> : $(default-build) ] ;
- local gSUPPRESS_FAKE_TARGETS = $(suppress[1]) ;
-
- declare-fake-targets $(target) : $(target-id) ;

- # Just gather information if we are including a library's Jamfile for a
- # dependent target. Don't generate build instructions here.
- if ! $(gIN_LIB_INCLUDE)
+ # Evaluate template dependencies.
+ # library dependency handling is deferred until the
+ # build targets are created.
+ #
+ dependent-include $(gTARGET_TEMPLATES($(target-id))) ;
+
+ for local template in $(gTARGET_TEMPLATES($(target-id)))
{
- main-target $(target-id) : $(default-build) ;
+ local template-path = [ directory-of $(template) ] ;
+ local template-id = [ grist-templates $(template) ] ;
+
+ gTARGET_SOURCES($(target-id)) = [ add-path $(template-path) : $(gTARGET_SOURCES($(template-id))) ] $(gTARGET_SOURCES($(target-id))) ;
+ gTARGET_LIBS($(target-id)) = [ add-path $(template-path) : $(gTARGET_LIBS($(template-id))) ] $(gTARGET_LIBS($(target-id))) ;
+ gTARGET_DLLS($(target-id)) = [ add-path $(template-path) : $(gTARGET_DLLS($(template-id))) ] $(gTARGET_DLLS($(target-id))) ;
+ gTARGET_REQUIREMENTS($(target-id)) = $(gTARGET_REQUIREMENTS($(template-id))) $(gTARGET_REQUIREMENTS($(target-id))) ;
+ gTARGET_DEFAULT_BUILD($(target-id)) = $(gTARGET_DEFAULT_BUILD($(template-id))) $(gTARGET_DEFAULT_BUILD($(target-id))) ;
+ }
+
+ if ! $(target-type) in $(TEMPLATE_TYPES)
+ {
+ # Supress the regular build of this target
+ local suppress = [ get-values <suppress> : $(default-build) ] ;
+ local gSUPPRESS_FAKE_TARGETS = $(suppress[1]) ;
+
+ declare-fake-targets $(target) : $(target-id) ;
+
+ # Just gather information if we are including a library's Jamfile for a
+ # dependent target. Don't generate build instructions here.
+ if ! $(gIN_LIB_INCLUDE)
+ {
+ main-target $(target-id) : $(gTARGET_DEFAULT_BUILD($(target-id))) ;
+ }
}
return $(gTARGET_FILES($(target-id))) ;
}
@@ -1613,6 +1711,8 @@
# Generates requested subvariant build instructions for the given main target
rule main-target
{
+ Echo main-target $(<) $(>) ;
+
local subvariants = [ expand-target-subvariants $(<) : $(>) : $(TOOLS) : BUILD ] ;

# include each jamfile describing a dependee target.
@@ -1657,6 +1757,15 @@
rule lib ( target : sources + : requirements * : default-build * )
{
declare-local-target $(target) : $(sources) : $(requirements) : $(default-build) : LIB ;
+}
+
+gTARGET_TYPE_ID(template) = TEMPLATE ;
+# template target : sources : requirements : local-build
+#
+# Declare a template target.
+rule template ( target : sources * : requirements * : default-build * )
+{
+ declare-local-target $(target) : $(sources) : $(requirements) : $(default-build) : TEMPLATE ;
}

# unit-test target : sources : requirements : local-build
 --------------Boundary-00=_3MHOMDN5WOBOHA0JQ0RL--


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk