MSVC Projects, Source Control and GUIDs

Further to my post on build events in MSVC, I’ve noticed that sometimes MSDEV sometimes re-orders the GUIDs in a solution file.

I know a mouse and he hasn’t got a house;
I don’t know why I call him Gerald.
He’s getting rather old, but he’s a good mouse.

I have a simple Python script (sort of attached) that can read these files and sort those GUID sections into order.

I can’t attach it on WordPress, so here it is quoted:

#!/usr/bin/python

import re
import sys
import os.path

s_hex = '[0-9A-F]'
s_guid = r'\{' + s_hex + '{8}' + '(?:' + '-' + s_hex + '{4}' + '){3}' + '-' + s_hex + '{12}' + r'\}'

s_guidline = r'^\s*' + s_guid + ' = ' + s_guid + '$'
r_guidline = re.compile (s_guidline)

if __name__ == '__main__':
  if len(sys.argv) == 2:
    fn = sys.argv[1]
  else:
    fn = 'myproject.sln'

  rf = open (fn, 'r')
  if rf:
    lines = rf.readlines()
    rf.close()

    fn_base, fn_ext = os.path.splitext (fn)
    wf = open (fn_base + '.sort_guids.stdout' + fn_ext, 'w')

    if wf:

      guidlines = []
      for line in lines:
        line = line.rstrip()
        m_guidline = r_guidline.match(line)
        if m_guidline:
          guidlines.append(line)
        else:
          if guidlines:
            guidlines.sort()
            for guidline in guidlines:
              print >> wf, guidline
            guidlines = []
          print >> wf, line
      if guidlines:
        guidlines.sort()
        for guidline in guidlines:
          print >> wf, guidline
        guidlines = []

      wf.close()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: