[Mesa-dev] [PATCH v2 13/23] mesa: Autogenerate most of format_pack.c

Samuel Iglesias Gonsálvez siglesias at igalia.com
Wed Dec 3 08:14:16 PST 2014


On Wednesday, December 03, 2014 03:44:19 PM Samuel Iglesias Gonsálvez wrote:
> On Wednesday, December 03, 2014 03:29:46 PM Samuel Iglesias Gonsálvez wrote:
> > On Wednesday, December 03, 2014 11:34:10 AM Emil Velikov wrote:
> > > On 03/12/14 11:30, Emil Velikov wrote:
> > > > Hi Iago,
> > > > 
> > > > On 01/12/14 11:04, Iago Toral Quiroga wrote:
> > > >> From: Jason Ekstrand <jason.ekstrand at intel.com>
> > > >> 
> > > >> We were auto-generating it before.  The problem was that the
> > > >> autogeneration
> > > >> tool we were using was called "copy, paste, and edit".  Let's use a
> > > >> more
> > > >> sensible solution.
> > > >> 
> > > >> Signed-off-by: Jason Ekstrand <jason.ekstrand at intel.com>
> > > >> 
> > > >> v2 by Samuel Iglesias <siglesias at igalia.com>
> > > >> - Remove format_pack.c as it is now autogenerated
> > > >> - Add usage of INDENT_FLAGS in Makefile.am
> > > >> - Remove trailing blank line
> > > >> 
> > > >> v3 by Samuel Iglesias <siglesias at igalia.com>
> > > >> - Merge format_convert.py into format_parser.py
> > > >> 
> > > >>    - Adapt pack_*_* function generations
> > > >> 
> > > >> - Fix out-of-tree build
> > > >> 
> > > >> Signed-off-by: Samuel Iglesias Gonsalvez <siglesias at igalia.com>
> > > >> ---
> > > >> 
> > > >>  src/mesa/Makefile.am             |   14 +
> > > >>  src/mesa/Makefile.sources        |    2 +-
> > > >>  src/mesa/main/format_pack.c      | 2982
> > > >>  --------------------------------------
> > > >>  src/mesa/main/format_pack.c.mako
> > > >>  
> > > >>  |  897 ++++++++++++
> > > >>  
> > > >>  src/mesa/main/format_parser.py   |   71 +
> > > >>  src/mesa/main/run_mako.py        |    7 +
> > > >>  6 files changed, 990 insertions(+), 2983 deletions(-)
> > > >>  delete mode 100644 src/mesa/main/format_pack.c
> > > >>  create mode 100644 src/mesa/main/format_pack.c.mako
> > > >>  create mode 100644 src/mesa/main/run_mako.py
> > > >> 
> > > >> diff --git a/src/mesa/Makefile.am b/src/mesa/Makefile.am
> > > >> index 932db4f..849c9da 100644
> > > >> --- a/src/mesa/Makefile.am
> > > >> +++ b/src/mesa/Makefile.am
> > > >> @@ -19,6 +19,8 @@
> > > >> 
> > > >>  # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > > >>  OTHER
> > > >>  DEALINGS # IN THE SOFTWARE.
> > > >> 
> > > >> +BUILDDIR_ABSOLUTE_PATH = $(PWD)
> > > >> +
> > > > 
> > > > You should not need this new variable. Additionally I'm suspecting
> > > > this
> > > > is the reason between the build hickups you/Jason are seeing.
> > > > 
> > > >>  SUBDIRS = . main/tests
> > > >>  
> > > >>  if HAVE_X11_DRIVER
> > > >> 
> > > >> @@ -66,6 +68,7 @@ BUILT_SOURCES = \
> > > >> 
> > > >>  	main/get_hash.h \
> > > >>  	
> > > >>          main/format_info.c \
> > > >>  	
> > > >>  	$(BUILDDIR)main/git_sha1.h \
> > > >> 
> > > >> +	$(BUILDDIR)main/format_pack.c \
> > > >> 
> > > >>  	$(BUILDDIR)program/program_parse.tab.c \
> > > >>  	$(BUILDDIR)program/lex.yy.c
> > > >>  
> > > >>  CLEANFILES = \
> > > >> 
> > > >> @@ -89,6 +92,17 @@ main/format_info.c: main/formats.csv
> > > >> 
> > > >>                  \>>
> > > >>                  
> > > >>                     $< > $@.tmp;
> > > >>                     \
> > > >>  	
> > > >>  	mv $@.tmp $@;
> > > >> 
> > > >> +$(BUILDDIR)main/format_pack.c: main/format_pack.c.mako
> > > >> main/formats.csv
> > > >> \
> > > >> +                               main/run_mako.py
> > > >> main/format_parser.py
> > > >> +	$(AM_V_GEN)set -e;						\
> > > >> +	cd $(srcdir);							\
> > > >> +	$(PYTHON2) $(PYTHON_FLAGS) main/run_mako.py			\
> > > >> +                   main/format_pack.c.mako main/formats.csv >		\
> > > >> +			$(BUILDDIR_ABSOLUTE_PATH)/$@.tmp;		\
> > > >> +	cd $(BUILDDIR_ABSOLUTE_PATH);					\
> > > >> +	cat $@.tmp | $(INDENT) $(INDENT_FLAGS) > $@;                    \
> > > >> +        rm $@.tmp;
> > > >> +
> > > > 
> > > > Can you prefix the files in the srcdir, and drop the tmp file (pipe
> > > > directly into indent). It will make the above ~1/2 the size and a bit
> > > > easier to follow :)
> > > 
> > > Completely forgot, please add a couple of mines into the scons build
> > > while you're here. src/mapi/shared-glapi/SConscript could serve as an
> > > example.
> > 
> > This is my first time modifying a SConscript file. Looking at what was
> > done
> > for format_info.c, I think that the following modification is enough to
> > have format_pack.c autogenerated:
> > 
> > format_pack = env.CodeGenerate(
> > 
> >       target = 'main/format_pack.c',
> >       script = 'main/run_mako.py',
> >       template = 'main/format_pack.c.mako',
> >       source = 'main/formats.csv',
> >       command = python_cmd + ' $SCRIPT ' + ' $TEMPLATE $SOURCE | ' +
> >       
> >                 '$INDENT $INDENT_FLAGS > $TARGET'
> > 
> > )
> > 
> > I did a 80-char line wrap (it was not my email client), I suppose this is
> > valid in SConscript, right? scons -f SConscript did not complain about it.
> 
> Comparing with the SConscript you told me,  I did a couple of small
> modifications to my previous code:
> 
> format_pack = env.CodeGenerate(
>       target = 'main/format_pack.c',
>       script = 'main/run_mako.py',
>       source = 'main/format_pack.c.mako main/formats.csv',
>       command = python_cmd + ' $SCRIPT ' + ' $SOURCE | ' + \
>               '$INDENT $INDENT_FLAGS > $TARGET'
> )
> 
> I think this is more or less what we need but, if someone with more
> experience on SConscript files sees a better way, it would be great to
> learn how to do it.
> 
> I'm going to do some tests to check that this is building properly.
> 

I finally found a way of generating format_pack.c and format_unpack.c with 
scons using env.CodeGenerate().

As env.CodeGenerate() only uses one 'source' argument (it fails if you run
what I wrote above), I ended up renaming format_pack.c.mako and
format_unpack.c.mako to be python scripts with the template content inline.

Now, they auto-generate format_{pack,unpack}.c files by themselves using the 
python mako module. Thanks to that, run_mako.py can be removed and both 
SConscript and Makefile.am modifications are simpler.

Any other idea/suggestion would be helpful.

Sam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20141203/9cafc7b8/attachment.sig>


More information about the mesa-dev mailing list