mirror of
				https://github.com/Z3Prover/z3
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	Refactor `mk_all_assembly_infos() to use the configure_file()`
				
					
				
			function. The old implementation was buggy under Python 3.5 and unsafe (not using with statements on calls to ``open()``).
This commit is contained in:
		
							parent
							
								
									f3d94db889
								
							
						
					
					
						commit
						81c98cf3ee
					
				
					 2 changed files with 15 additions and 34 deletions
				
			
		| 
						 | 
					@ -2582,42 +2582,23 @@ def mk_version_dot_h(major, minor, build, revision):
 | 
				
			||||||
    if VERBOSE:
 | 
					    if VERBOSE:
 | 
				
			||||||
        print("Generated '%s'" % os.path.join(c.src_dir, 'version.h'))
 | 
					        print("Generated '%s'" % os.path.join(c.src_dir, 'version.h'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Generate AssemblyInfo.cs files with the right version numbers by using AssemblyInfo files as a template
 | 
					# Generate AssemblyInfo.cs files with the right version numbers by using ``AssemblyInfo.cs.in`` files as a template
 | 
				
			||||||
def mk_all_assembly_infos(major, minor, build, revision):
 | 
					def mk_all_assembly_infos(major, minor, build, revision):
 | 
				
			||||||
    for c in get_components():
 | 
					    for c in get_components():
 | 
				
			||||||
        if c.has_assembly_info():
 | 
					        if c.has_assembly_info():
 | 
				
			||||||
            assembly = os.path.join(c.src_dir, c.assembly_info_dir, 'AssemblyInfo')
 | 
					            assembly_info_template = os.path.join(c.src_dir, c.assembly_info_dir, 'AssemblyInfo.cs.in')
 | 
				
			||||||
            if os.path.exists(assembly):
 | 
					            assembly_info_output = assembly_info_template[:-3]
 | 
				
			||||||
                # It is a CS file
 | 
					            assert assembly_info_output.endswith('.cs')
 | 
				
			||||||
                mk_assembly_info_version(assembly, major, minor, build, revision)
 | 
					            if os.path.exists(assembly_info_template):
 | 
				
			||||||
 | 
					                configure_file(assembly_info_template, assembly_info_output,
 | 
				
			||||||
 | 
					                               { 'VER_MAJOR': str(major),
 | 
				
			||||||
 | 
					                                 'VER_MINOR': str(minor),
 | 
				
			||||||
 | 
					                                 'VER_BUILD': str(build),
 | 
				
			||||||
 | 
					                                 'VER_REVISION': str(revision),
 | 
				
			||||||
 | 
					                               }
 | 
				
			||||||
 | 
					                              )
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                raise MKException("Failed to find assembly info file 'AssemblyInfo' at '%s'" % os.path.join(c.src_dir, c.assembly_info_dir))
 | 
					                raise MKException("Failed to find assembly template info file '%s'" % assembly_info_template)
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Generate version number in the given 'AssemblyInfo.cs' file using 'AssemblyInfo' as a template.
 | 
					 | 
				
			||||||
def mk_assembly_info_version(assemblyinfo, major, minor, build, revision):
 | 
					 | 
				
			||||||
    ver_pat   = re.compile('[assembly: AssemblyVersion\("[\.\d]*"\) *')
 | 
					 | 
				
			||||||
    fver_pat  = re.compile('[assembly: AssemblyFileVersion\("[\.\d]*"\) *')
 | 
					 | 
				
			||||||
    fin  = open(assemblyinfo, 'r')
 | 
					 | 
				
			||||||
    tmp  = '%s.cs' % assemblyinfo
 | 
					 | 
				
			||||||
    fout = open(tmp, 'w')
 | 
					 | 
				
			||||||
    num_updates = 0
 | 
					 | 
				
			||||||
    for line in fin:
 | 
					 | 
				
			||||||
        if ver_pat.match(line):
 | 
					 | 
				
			||||||
            fout.write('[assembly: AssemblyVersion("%s.%s.%s.%s")]\n' % (major, minor, build, revision))
 | 
					 | 
				
			||||||
            num_updates = num_updates + 1
 | 
					 | 
				
			||||||
        elif fver_pat.match(line):
 | 
					 | 
				
			||||||
            fout.write('[assembly: AssemblyFileVersion("%s.%s.%s.%s")]\n' % (major, minor, build, revision))
 | 
					 | 
				
			||||||
            num_updates = num_updates + 1
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            fout.write(line)
 | 
					 | 
				
			||||||
    # if VERBOSE:
 | 
					 | 
				
			||||||
    #    print("%s version numbers updated at '%s'" % (num_updates, assemblyinfo))
 | 
					 | 
				
			||||||
    assert num_updates == 2, "unexpected number of version number updates"
 | 
					 | 
				
			||||||
    fin.close()
 | 
					 | 
				
			||||||
    fout.close()
 | 
					 | 
				
			||||||
    if VERBOSE:
 | 
					 | 
				
			||||||
        print("Updated '%s'" % assemblyinfo)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
ADD_TACTIC_DATA=[]
 | 
					ADD_TACTIC_DATA=[]
 | 
				
			||||||
ADD_PROBE_DATA=[]
 | 
					ADD_PROBE_DATA=[]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,5 +34,5 @@ using System.Security.Permissions;
 | 
				
			||||||
// You can specify all the values or you can default the Build and Revision Numbers 
 | 
					// You can specify all the values or you can default the Build and Revision Numbers 
 | 
				
			||||||
// by using the '*' as shown below:
 | 
					// by using the '*' as shown below:
 | 
				
			||||||
// [assembly: AssemblyVersion("4.2.0.0")]
 | 
					// [assembly: AssemblyVersion("4.2.0.0")]
 | 
				
			||||||
[assembly: AssemblyVersion("4.3.2.0")]
 | 
					[assembly: AssemblyVersion("@VER_MAJOR@.@VER_MINOR@.@VER_BUILD@.@VER_REVISION@")]
 | 
				
			||||||
[assembly: AssemblyFileVersion("4.3.2.0")]
 | 
					[assembly: AssemblyFileVersion("@VER_MAJOR@.@VER_MINOR@.@VER_BUILD@.@VER_REVISION@")]
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue