[p4] Adding a Changelist # to C++ code...?

Peter Weldon peter.weldon at lollotec.com
Thu Feb 21 09:51:09 PST 2008

On 2/21/08, Troughton, Robert <rtroughton at midway.com> wrote:
> This sounds good. Is there a way to have it automatically generate that
> header file, though?

No p4 does not have a c++ header output option.

My question, really, is how to use this to create a header... I guess I
> could write a little app which takes the output from this and parses
> it...? But is there a better way?

If you want a header file you will need a script. A header file is not ideal
though as it will cause a recompile of all dependent files and a relink for
ever change regardless of whether any code was touched by the change e.g. a
data file is updated but no code.

Perhaps an alternative is to dump the changelist data to a file and read the
file at runtime. The data can be dumped out using the -ztag option for easy
parsing or if you already have the code to read python or ruby marshalled
data with -G (python marshalling) or -R (ruby marshalling).
Either way if your build system uses timestamp based dependency checking
preserving the existing file if it has not changed will prevent any unneeded
- Generate the changelist header file / data file in a temp location
- Compare it to the existing file, replace existing file with new file if
they differ

Placing perforce commands within the build script always has the down side
that should the server not be available or is very busy everyone attempting
to build is affected. You don't want the builds to break or be unresponsive
because the server is unavailable.

Capturing the changelist data when the sync is performed as opposed to when
the build is performed is a good solution that does not have this problem,
but does not accommodate ad hoc syncing easily.

More information about the perforce-user mailing list