mirror of
				https://github.com/Ryujinx/Opentk.git
				synced 2025-11-04 08:35:00 +00:00 
			
		
		
		
	Generate both build timestamp and version information
This commit is contained in:
		
							parent
							
								
									216a9778ab
								
							
						
					
					
						commit
						881015646f
					
				| 
						 | 
					@ -49,7 +49,7 @@
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
  <Target Name="Build">
 | 
					  <Target Name="Build">
 | 
				
			||||||
    <Exec Command="makensis opentk.nsi" />
 | 
					    <Exec Command="makensis opentk.nsi" />
 | 
				
			||||||
    <ReadLinesFromFile File="../../Version.txt">
 | 
					    <ReadLinesFromFile File="../../Timestamp.txt">
 | 
				
			||||||
      <Output TaskParameter="Lines" ItemName="Version" />
 | 
					      <Output TaskParameter="Lines" ItemName="Version" />
 | 
				
			||||||
    </ReadLinesFromFile>
 | 
					    </ReadLinesFromFile>
 | 
				
			||||||
    <Move SourceFiles=".\opentk.exe" DestinationFiles="@(Version->'../../opentk-%(Identity).exe')" />
 | 
					    <Move SourceFiles=".\opentk.exe" DestinationFiles="@(Version->'../../opentk-%(Identity).exe')" />
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,7 +51,7 @@
 | 
				
			||||||
    <!-- Zip the copy of the source tree -->
 | 
					    <!-- Zip the copy of the source tree -->
 | 
				
			||||||
    <Exec Command="7z a -tzip opentk.zip ../../* -xr!opentk*.zip -xr!opentk*.exe -xr!.* -xr!obj -xr!bin -xr!Documentation/Source -xr!Automation -xr!*.suo -xr!*.pidb -xr!*.userprefs -xr!*vshost.exe* -xr!*.log" />
 | 
					    <Exec Command="7z a -tzip opentk.zip ../../* -xr!opentk*.zip -xr!opentk*.exe -xr!.* -xr!obj -xr!bin -xr!Documentation/Source -xr!Automation -xr!*.suo -xr!*.pidb -xr!*.userprefs -xr!*vshost.exe* -xr!*.log" />
 | 
				
			||||||
    <!-- Copy the zip file to the root directory and add a date stamp -->
 | 
					    <!-- Copy the zip file to the root directory and add a date stamp -->
 | 
				
			||||||
    <ReadLinesFromFile File="../../Version.txt">
 | 
					    <ReadLinesFromFile File="../../Timestamp.txt">
 | 
				
			||||||
      <Output TaskParameter="Lines" ItemName="Version" />
 | 
					      <Output TaskParameter="Lines" ItemName="Version" />
 | 
				
			||||||
    </ReadLinesFromFile>
 | 
					    </ReadLinesFromFile>
 | 
				
			||||||
    <Move SourceFiles=".\opentk.zip" DestinationFiles="@(Version->'..\..\opentk-%(Identity).zip')" />
 | 
					    <Move SourceFiles=".\opentk.zip" DestinationFiles="@(Version->'..\..\opentk-%(Identity).zip')" />
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,6 +62,7 @@
 | 
				
			||||||
    <WarningLevel>4</WarningLevel>
 | 
					    <WarningLevel>4</WarningLevel>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
  <Target Name="BeforeBuild">
 | 
					  <Target Name="BeforeBuild">
 | 
				
			||||||
 | 
					    <Delete Files="..\..\Timestamp.txt" />
 | 
				
			||||||
    <Delete Files="..\..\Version.txt" />
 | 
					    <Delete Files="..\..\Version.txt" />
 | 
				
			||||||
  </Target>
 | 
					  </Target>
 | 
				
			||||||
  <Target Name="AfterBuild">
 | 
					  <Target Name="AfterBuild">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,44 +56,41 @@ namespace Build.UpdateVersion
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            DateTime now = DateTime.UtcNow;
 | 
					            DateTime now = DateTime.UtcNow;
 | 
				
			||||||
            GenerateVersionInfo(now, Path.Combine(RootDirectory, "Version.txt"));
 | 
					            string timestamp = now.ToString("u").Split(' ')[0];
 | 
				
			||||||
            GenerateAssemblyInfo(now, Path.Combine(SourceDirectory, "GlobalAssemblyInfo.cs"));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        static void GenerateVersionInfo(DateTime now, string file)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            string version = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (System.IO.File.Exists(file))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                string[] lines = System.IO.File.ReadAllLines(file);
 | 
					 | 
				
			||||||
                if (lines.Length > 0 && !String.IsNullOrEmpty(lines[0]))
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    version = lines[0];
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // If the file does not exist, create it.
 | 
					 | 
				
			||||||
            if (version == null)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                version = now.ToString("u").Split(' ')[0];
 | 
					 | 
				
			||||||
                System.IO.File.WriteAllLines(file, new string[] { version });
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        static void GenerateAssemblyInfo(DateTime now, string file)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Build number is defined as the number of days since 1/1/2010.
 | 
					            // Build number is defined as the number of days since 1/1/2010.
 | 
				
			||||||
            // Revision number is defined as the fraction of the current day, expressed in seconds.
 | 
					 | 
				
			||||||
            double timespan = now.Subtract(new DateTime(2010, 1, 1)).TotalDays;
 | 
					            double timespan = now.Subtract(new DateTime(2010, 1, 1)).TotalDays;
 | 
				
			||||||
            string build = ((int)timespan).ToString();
 | 
					            string build = ((int)timespan).ToString();
 | 
				
			||||||
 | 
					            // Revision number is defined as the number of (git/svn/bzr) commits,
 | 
				
			||||||
 | 
					            // or as the fraction of the current day, expressed in seconds, in case the
 | 
				
			||||||
 | 
					            // working directory is not under source control.
 | 
				
			||||||
 | 
					            string revision = RetrieveRevisionNumber(now);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            string revision = RetrieveGitRevision() ?? RetrieveSvnRevision() ?? RetrieveBzrRevision() ?? RetrieveSeconds(timespan);
 | 
					            string major = Major;
 | 
				
			||||||
            revision = revision.Trim();
 | 
					            string minor = Minor;
 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            Console.WriteLine("Build timestamp was: " + build);
 | 
					 | 
				
			||||||
            Console.WriteLine("Revision detected was: " + revision);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Version is defined as {Major}.{Minor}.{Build}.{Revision}
 | 
				
			||||||
 | 
					            string version = String.Format("{0}.{1}.{2}.{3}", major, minor, build, revision);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Console.WriteLine("API compatibility key: {0}.{1}", major, minor);
 | 
				
			||||||
 | 
					            Console.WriteLine("Build date: {0}", timestamp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            GenerateTimestamp(timestamp, Path.Combine(RootDirectory, "Timestamp.txt"));
 | 
				
			||||||
 | 
					            GenerateVersion(version, Path.Combine(RootDirectory, "Version.txt"));
 | 
				
			||||||
 | 
					            GenerateAssemblyInfo(major, minor, version, Path.Combine(SourceDirectory, "GlobalAssemblyInfo.cs"));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static void GenerateTimestamp(string timestamp, string file)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            System.IO.File.WriteAllLines(file, new string[] { timestamp });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static void GenerateVersion(string version, string file)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            File.WriteAllLines(file, new string[] { version });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static void GenerateAssemblyInfo(string major, string minor, string version, string file)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
            File.WriteAllLines(file, new string[]
 | 
					            File.WriteAllLines(file, new string[]
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                "// This file is auto-generated through Source/Build.Tasks/GenerateAssemblyInfo.cs.",
 | 
					                "// This file is auto-generated through Source/Build.Tasks/GenerateAssemblyInfo.cs.",
 | 
				
			||||||
| 
						 | 
					@ -109,11 +106,19 @@ namespace Build.UpdateVersion
 | 
				
			||||||
                "[assembly: AssemblyProduct(\"The Open Toolkit Library\")]",
 | 
					                "[assembly: AssemblyProduct(\"The Open Toolkit Library\")]",
 | 
				
			||||||
                "[assembly: AssemblyCopyright(\"Copyright © 2006 - 2013 the Open Toolkit Library\")]",
 | 
					                "[assembly: AssemblyCopyright(\"Copyright © 2006 - 2013 the Open Toolkit Library\")]",
 | 
				
			||||||
                "[assembly: AssemblyTrademark(\"OpenTK\")]",
 | 
					                "[assembly: AssemblyTrademark(\"OpenTK\")]",
 | 
				
			||||||
                String.Format("[assembly: AssemblyVersion(\"{0}.{1}.0.0\")]", Major, Minor),
 | 
					                String.Format("[assembly: AssemblyVersion(\"{0}.{1}.0.0\")]", major, minor),
 | 
				
			||||||
                String.Format("[assembly: AssemblyFileVersion(\"{0}.{1}.{2}.{3}\")]", Major, Minor, build, revision),
 | 
					                String.Format("[assembly: AssemblyFileVersion(\"{0}\")]", version),
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static string RetrieveRevisionNumber(DateTime now)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            double timespan = now.Subtract(new DateTime(2010, 1, 1)).TotalDays;
 | 
				
			||||||
 | 
					            string revision = RetrieveGitRevision() ?? RetrieveSvnRevision() ?? RetrieveBzrRevision() ?? RetrieveSeconds(timespan);
 | 
				
			||||||
 | 
					            revision = revision.Trim();
 | 
				
			||||||
 | 
					            return revision;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        static string RetrieveSeconds(double timespan)
 | 
					        static string RetrieveSeconds(double timespan)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            string revision = ((int)((timespan - (int)timespan) * UInt16.MaxValue)).ToString();
 | 
					            string revision = ((int)((timespan - (int)timespan) * UInt16.MaxValue)).ToString();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue