List Info

Thread: Re: Pre-parsing source files before building




Re: Pre-parsing source files before building
country flaguser name
United States
2007-08-23 12:34:02
The order DOES matter for me, because when I parse these generated files, the names of the resulting files are the same. I parse them "in-place" so to speak.

Is the only way to get this to work is to rename them once parsed? Or can I force GenFiles to run before Main?

Thanks
Chris


Craig Allsop <cjamallsopgmail.com&gt; wrote:
Hi Chris,

The GenFile rule is designed to run a tool that can process a source
into another source. You just have to make sure that the output target
is your input target for the Main. Order isn't important because Jam
creates an in-memory dependency tree before it determines what to
update, thus your dependencies must be correct. Try just this:

GenFile out_genfile1.c : tool genfile1.c ;
Main target : out_genfile1.c ;

Here, out_genfile1.c is preprocessed by "tool" from genfile1.c - on
windows it will expect to find tool.exe - so you can replace the name
with your custom tool. Put your tool in the same directory for now and
try the above. Once you have that working, you can move on and process
your list of genfile's by calling GenFile for each one.

Craig.


On 8/23/07, Chris yahoo.com> wrote:
>; Maybe I should have been more specific.
>
> srcfile1.c and genfile1.c are not related. genfile1.c etc are output by a
> design tool that we use.
>
> Here is another example of something I tried.
>;
>
> rule PreParse
&gt; {
> Depends $(1) : $(2) ;
> }
>
>; actions PreParse
&gt; {
> #just a place holder for the script I need to run
> echo "Preparsing!"
> }
>
>; rule AuxSrc
>; {
> Depends $(1) : $(2) ;
> PreParse $(1) : $(2) ;
> Objects $(2) ;
> }
>
>; rule BuildLib
&gt; {
> Depends $(1) : $(2:S=.OBJ) ;
> }
>
>; actions BuildLib
&gt; {
> $(AR) r $(AUXLIB) $(AUXOBJ)
> }
>
>; AuxSrc $(AUXLIB) : $(AUXSRC) ;
> BuildLib $(AUXLIB) : $(AUXSRC) ;
> Main $(LINKTARGET) : $(SRC) ;
> Convert $(FINALTARGET) : $(LINKTARGET) ;
>
>;
> This didn't work, because the source files were being compiled before the
> PreParse rule was being invoked. No matter what I did, I couldn't get the
> PreParse action to run before the Objects was invoked.
&gt;
> I think the problem is that when the source files are generated, they're
&gt; newer than the target, so the tool assumes they need to built - which is
> true, except that I need to do this other step to them first.
>;
> I feel like I'm close, but there is some fundamental idea I'm missing. Any
> more ideas?
>;
> Thanks
>; Chris
>
>
> Craig Allsop gmail.com> wrote:
>; Hi Chris,
>;
> I'm assuming srcfile1.c is converted to genfile1.c and then linked in
> the final program? So to make it easier to write in jam, can we just
> add a gen prefix for the generated files so that srcfile1.c is
> converted to gensrcfile1.c? Therefore you would do this...
&gt;
> LINKTARGET = flash.hex
> FINALTARGET = app.bin
&gt; MAINSRC = srcfile1.c srcfile2.c ;
> for i in $(MAINSRC)
> {
> # this will run: yourpreparsetoolhere outfile infile
>; GenFile gen$(i) : yourpreparsetoolhere $(i) ;
> }
> Main $(LINKTARGET) : gen$(MAINSRC) ;
> Convert $(FINALTARGET) : $(LINKTARGET) ;
> Depends all : $(FINALTARGET) ;
>
>; Only pass the generated sources to Main, gen$(MAINSRC) will be
> expanded to prefix all source with "gen". If you have others you don't
> then just list with as extras.
&gt;
> Hope that helps.
>;
> Craig.
>;
> On 8/21/07, Chris wrote:
>; > We have a tool which generates some of our source files. Unfortunately,
> the
> > files need to be touched up a bit before our cranky compiler can use them.
> I
> > am trying to make this pre-parsing an automated part of the jam build
> > process, but I'm having some trouble finding the right magic words to make
> > it work. The problem seems to be that the files may already exist and need
> > not be parsed again if they have not changed from the previous build. I'm
> > having a hard time coming up with a rule/dependencies that can detect if
> > generated source files are newer than the final target and run the
> > pre-parsing script on them before compiling them. The script we have
> > automatically fixes all of the generated files, so it only needs to run
> > once.
> >
> > Here's what I have so far, which seems to work except for the pre-parsing
> > step. AUXSRC are the sources generated by the tool. There are custom
>; actions
&gt; > for Cc and Link to deal with our stupid compiler. I can detail those if
> > someone thinks it necessary, but for brevity they are omitted here. The
> > "Convert" rule/action handles converting the linker output to our download
&gt; > format.
&gt; >
> > LINKTARGET = flash.hex
> > FINALTARGET = app.bin
&gt; > MAINSRC = srcfile1.c srcfile2.c ;
> > AUXSRC = genfile1.c genfile2.c ;
> > SRC = $(MAINSRC) $(AUXSRC) ;
> >
> > Main $(LINKTARGET) : $(SRC) ;
> > Convert $(FINALTARGET) : $(LINKTARGET) ;
> > Depends all : $(FINALTARGET) ;
> >
> >
> > Thanks,
&gt; > Chris
> >
> > ________________________________
> > Yahoo! oneSearch: Finally, mobile search that gives answers, not web
> links.
>; > _______________________________________________
> > jamming mailing list - jammingperforce.com
> > http://maillist.perforce.com/mailman/listinfo/jamming
> >
> >
>
>
>
&gt; ________________________________
> Moody friends. Drama queens. Your life? Nope! - their life, your story.
>; Play Sims Stories at Yahoo! Games.
>;
>
gmail.com>
yahoo.com>



"Gee, Thanks. You made me appreciate life by showing me how badly my funeral will suck." - Bender, Futurama

&#32;


Moody friends. Drama queens. Your life? Nope! - their life, your story.
Play Sims Stories at Yahoo! Games.
Re: Pre-parsing source files before building
user name
2007-08-23 17:47:23
Hi Chris,

Ok, order matters for in-place parsing but I wouldn't
recommend
parsing them in-place because it adds unnecessary
complexity. How will
jam know the difference between a converted file and one
which is not
each time your run it? What is wrong with the intermediate
files as
many tools use them e.g. yacc? The nice thing about GenFile
is you can
build your pre-parsing tool before pre-parsing. You can tell
jam to
output them to an intermediate directory if you don't like
them in the
source folder ... anyway ...

Ok, assuming you *really* want to do this, I would set a
variable on
your obj targets and use this variable to construct the
pre-parsing
action of the source file when Cc action runs. So here we
go...

1. Create a rule to set a variable on your objs, we'll set
it's value
to the name of your tool that pre-parses the files... you
can hide
this in your jamrules.

rule PreParse
{
	PP on [ FGristFiles $(<:S=$(SUFOBJ)) ] = yourpptool.exe
;
}

2. Call this rule on your genfile sources in your jamfile:

PreParse $(AUXSRC) ;

3. Copy and modify the Cc actions so that when PP is set, it
will be
called to preparse your source file before it is compiled.
Hide this
in your jamrules as well.

	actions Cc
	{
            $(PP)$(SPACE)$(>)
	    $(CC) /c /Fo$(<) $(CCFLAGS) $(CCDEFS) $(CCHDRS)
/I$(STDHDRS) $(>)
	}


4. Add the definition of SPACE to your jamrules as well..

SPACE = " " ;

Explanation: For the files with PP set, jam will expand the
initial
line and call your tool to do the in-place conversion (which
it will
have to do always since you don't know if it needs doing or
not -
which is my problem with this - but anyway it will work for
you) and
thus running your tool prior to compiling it to an obj. For
those
files which do not have PP set, jam will expand the line to
blank by
multiplication (see docs) not executing anything at all,
then compile
the file to obj.

If you have C++ sources you'll need the same mod on it's
actions.

Hope it helps, let me know how you go.

Cheers,
Craig.

On 8/24/07, Chris <syndicate_dragonyahoo.com> wrote:
> The order DOES matter for me, because when I parse
these generated files,
> the names of the resulting files are the same. I parse
them "in-place" so to
> speak.
>
> Is the only way to get this to work is to rename them
once parsed? Or can I
> force GenFiles to run before Main?
>
> Thanks
> Chris
_______________________________________________
jamming mailing list  -  jammingperforce.com
http://maillist.perforce.com/mailman/listinfo/jamming

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )