Manipulating target names

View: New views
2 Messages — Rating Filter:   Alert me  

Manipulating target names

by Johan Larsson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I need to add an IDL compiler to my bjam project. The invocation itself is simple; a one-liner with the IDL file as input will produce five new files, three headers and two sources. The sources are then to be used to compile a library.

For this purpose, I created a generator (after finding some examples on this mailing list):
# omniidl.jam

import generators ;
import type ;

type.register IDL : idl ;

generators.register-standard omniidl.omniidl
  : IDL
  : CPP(T%Caller) CPP(T%Dispatcher)
  ;

rule omniidl ( targets +  : source : properties * : d * : e * )
{
}

actions omniidl
{
  <idl invocation command> -C ./ $(>)
}

# end of omniidl.jam

The problem:
The IDL files are named as interfaces, which means they have a filename according to the pattern I*.idl. The generated files get the following patterns:
I*.h
T*Caller.cpp
T*Caller.h
T*Dispatcher.cpp
T*Dispatcher.h

That I/T prefix is giving me problems. If I try to invoke the omniidl rule above with the complete filename (IExample.idl), bjam expects the ORB to output TIExampleCaller.cpp and TIExampleDispatcher.cpp, when it actually generates TExampleCaller.cpp and TExampleDispatcher.cpp. If I try to adapt the generator to accept target names without the prefix and generate them after the fact, it complains about source files not existing.

Is there an elegant way to solve this? The best solution would be if I could remove the first letter of the target name string when I register the generator, but I have no idea how to do this.

Thank you for your time.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build

Parent Message unknown Re: Manipulating target names

by Johan Larsson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I solved it - after some work. I created a custom generator, posted below in case anyone else needs something similar.

The pattern matching in particular was troublesome to figure out. "egrep style regexp", as the docs put it, didn't say much; particularly regarding the way MATCH divides its matched strings into different elements of the return value. Perhaps there is a nicer way to deal with prefixes in bjam?

# omniidl.jam

import generators ;
import type ;
import "class" : new ;

type.register IDL : idl ;

class idl-generator : generator
{
    # Determine the name of the produced target from the
    # names of the sources.
    rule determine-output-name ( sources + )
    {
        # The simple case if when a name
        # of source has single dot. Then, we take the part before
        # dot. Several dots can be caused by:
        # - Using source file like a.host.cpp
        # - A type which suffix has a dot. Say, we can
        #   type 'host_cpp' with extension 'host.cpp'.
        # In the first case, we want to take the part till the last
        # dot. In the second case -- no sure, but for now take
        # the part till the last dot too.
        name = [ utility.basename [ $(sources[1]).name ] ] ;

        for local s in $(sources[2])
        {
            local n2 = [ utility.basename [ $(s).name ] ] ;
            if $(n2) != $(name)
            {
                error "$(self.id): source targets have different names: cannot determine target name" ;
            }
        }

        # Names of sources includes an I. Strip it!
        name = $(name:D=) ;
        #match the first letter I. Put it in m[1].
        #Then match everything else. Put it in m[2].
        local m = [ MATCH (^[I]?)(.*) : $(name) ] ;
        return T$(m[2]) ;
    }
}

generators.register
  [ new idl-generator omniidl.omniidl : IDL : CPP(%Caller) CPP(%Dispatcher) ] ;

rule omniidl ( targets +  : source : properties * : d * : e * )
{
}

#Hrrrmmm... make this nicer. And a LOT more general.
actions omniidl
{
  <idl invocation command> -C ./ $(>)
  cp *.h bin/gcc/xxx/link-static
  cp *.cpp bin/gcc/xxx/link-static
}

# end of omniidl.jam

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build