Patrick Mézard avatar Patrick Mézard committed c4e7664

csharp: handle assembly version number

Comments (0)

Files changed (3)

csharp/PhoneNumbers/PhoneNumbers.csproj

   <Target Name="AfterBuild">
   </Target>
   -->
+  <PropertyGroup>
+    <PreBuildEvent>python $(SolutionDir)\lib\version.py</PreBuildEvent>
+  </PropertyGroup>
 </Project>

csharp/PhoneNumbers/Properties/AssemblyInfo.cs

 [assembly: AssemblyTitle("PhoneNumbers")]
 [assembly: AssemblyDescription("")]
 [assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Warner Brothers Movie World")]
+[assembly: AssemblyCompany("")]
 [assembly: AssemblyProduct("PhoneNumbers")]
-[assembly: AssemblyCopyright("Copyright © Warner Brothers Movie World 2011")]
+[assembly: AssemblyCopyright("")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
 
 //
 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+// [assembly: AssemblyVersion("4.4.0.1")]
+[assembly: AssemblyVersion("4.4.0.1")]
+[assembly: AssemblyFileVersion("4.4.0.1")]

csharp/lib/version.py

+# Update assembly version number based on Java pom.xml file
+import os, re, subprocess
+
+def getjavaver(rootdir):
+    # Extract from pom file
+    pompath = os.path.join(rootdir, 'java', 'pom.xml')
+    data = file(pompath, 'rb').read()
+    m = re.search(r'<version>(\d+.\d+)-SNAPSHOT</version>', data)
+    if not m:
+        raise Exception('cannot extract version number from pom file')
+    return tuple(int(p) for p in m.group(1).split('.'))[:2]
+
+asmfile = 'csharp/PhoneNumbers/Properties/AssemblyInfo.cs'
+
+def getcsharpprevbuild(rootdir):
+    asmpath = os.path.join(rootdir, asmfile)
+    p = subprocess.Popen(['hg', 'cat', '--rev', '.', asmpath],
+                         shell=True,
+                         stdout=subprocess.PIPE)
+    stdout = p.communicate()[0]
+    if p.returncode:
+        raise Exception('hg cat failed')
+    m = re.search(r'AssemblyVersion\("(\d+\.\d+\.\d+\.\d+)', stdout)
+    if not m:
+        raise Exception('cannot extract version from AssemblyInfo.cs')
+    build = int(m.group(1).split('.')[3])
+    return build
+
+def updatecsharpver(rootdir, ver):
+    asmpath = os.path.join(rootdir, asmfile)
+    data = file(asmpath, 'rb').read()
+    ver = (ver + (0, 0, 0, 0))[:4]
+    ver = '.'.join(str(p) for p in ver)
+    rewritten, n = re.subn(r'((?:AssemblyVersion|AssemblyFileVersion)\(")([^"]+)',
+                           r'\g<1>' + ver, data)
+    if not n:
+        raise Exception('cannot extract version from AssemblyInfo.cs')
+    if rewritten != data:
+        print 'Updating to', ver
+        file(asmpath, 'wb').write(rewritten)
+
+if __name__ == '__main__':
+    rootdir = os.path.join(os.path.dirname(__file__), '../..')
+    ver = getjavaver(rootdir)
+    build = getcsharpprevbuild(rootdir)
+    ver = ver[:2] + (0, build + 1)
+    updatecsharpver(rootdir, ver)
+    
+    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.