From 6baedc137079752318ab9ea7af6a69be589d9c5a Mon Sep 17 00:00:00 2001
From: Aimee Linden <aimee@lindenlab.com>
Date: Wed, 18 Aug 2010 12:30:26 +0100
Subject: [PATCH] VWR-20748 (SNOW-520) FIXED Make develop.py play nicely with
 express editions of Visual Studio

---
 doc/contributions.txt |  1 +
 indra/develop.py      | 51 +++++++++++++++++++++++++++++++++++++++----
 2 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/doc/contributions.txt b/doc/contributions.txt
index b49a3649d5f..f2f1d5af3fa 100644
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -521,6 +521,7 @@ Robin Cornelius
 	SNOW-484
 	SNOW-506
 	SNOW-514
+	SNOW-520
 	SNOW-585
 	VWR-2488
 	VWR-9557
diff --git a/indra/develop.py b/indra/develop.py
index 63df0e983ae..3c88bb8a017 100755
--- a/indra/develop.py
+++ b/indra/develop.py
@@ -76,6 +76,7 @@ class PlatformSetup(object):
     distcc = True
     cmake_opts = []
     word_size = 32
+    using_express = False
 
     def __init__(self):
         self.script_dir = os.path.realpath(
@@ -497,9 +498,17 @@ def _get_generator(self):
                     self._generator = version
                     print 'Building with ', self.gens[version]['gen']
                     break
-            else:
-                print >> sys.stderr, 'Cannot find a Visual Studio installation!'
-                sys.exit(1)
+                else:
+                    print >> sys.stderr, 'Cannot find a Visual Studio installation, testing for express editions'
+                    for version in 'vc80 vc90 vc71'.split():
+                        if self.find_visual_studio_express(version):
+                            self._generator = version
+                            self.using_express = True
+                            print 'Building with ', self.gens[version]['gen'] , "Express edition"
+                            break
+                        else:
+                            print >> sys.stderr, 'Cannot find any Visual Studio installation'
+                            sys.exit(1)
         return self._generator
 
     def _set_generator(self, gen):
@@ -562,6 +571,28 @@ def find_visual_studio(self, gen=None):
             
         return ''
 
+    def find_visual_studio_express(self, gen=None):
+        if gen is None:
+            gen = self._generator
+        gen = gen.lower()
+        try:
+            import _winreg
+            key_str = (r'SOFTWARE\Microsoft\VCEXpress\%s\Setup\VC' %
+                       self.gens[gen]['ver'])
+            value_str = (r'ProductDir')
+            print ('Reading VS environment from HKEY_LOCAL_MACHINE\%s\%s' %
+                   (key_str, value_str))
+            print key_str
+
+            reg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
+            key = _winreg.OpenKey(reg, key_str)
+            value = _winreg.QueryValueEx(key, value_str)[0]+"IDE"
+            print 'Found: %s' % value
+            return value
+        except WindowsError, err:
+            print >> sys.stderr, "Didn't find ", self.gens[gen]['gen']
+            return ''
+
     def get_build_cmd(self):
         if self.incredibuild:
             config = self.build_type
@@ -572,6 +603,17 @@ def get_build_cmd(self):
             cmd = "%(bin)s %(prj)s.sln /build /cfg=%(cfg)s" % {'prj': self.project_name, 'cfg': config, 'bin': executable}
             return (executable, cmd)
 
+        environment = self.find_visual_studio()
+        if environment == '':
+            environment = self.find_visual_studio_express()
+            if environment == '':
+                print >> sys.stderr, "Something went very wrong during build stage, could not find a Visual Studio installation."
+            else:
+                build_dirs=self.build_dirs();
+                print >> sys.stderr, "\nSolution generation complete, it can can now be found in:", build_dirs[0]
+                print >> sys.stderr, "\nPlease see https://wiki.secondlife.com/wiki/Microsoft_Visual_Studio#Extra_steps_for_Visual_Studio_Express_editions for express specific information"
+                exit(0)
+
         # devenv.com is CLI friendly, devenv.exe... not so much.
         executable = '%sdevenv.com' % (self.find_visual_studio(),)
         cmd = ('"%s" %s.sln /build %s' % 
@@ -603,7 +645,8 @@ def run_cmake(self, args=[]):
         '''Override to add the vstool.exe call after running cmake.'''
         PlatformSetup.run_cmake(self, args)
         if self.unattended == 'OFF':
-            self.run_vstool()
+            if self.using_express == False:
+                self.run_vstool()
 
     def run_vstool(self):
         for build_dir in self.build_dirs():
-- 
GitLab