Vowpal Wabbit
make_config_h.cs
Go to the documentation of this file.
1 using System;
2 using System.IO;
3 using System.ComponentModel;
4 using System.Diagnostics;
5 
6 public class Program
7 {
8  private const string VersionFilePath = @"..\version.txt";
9 
10  private static Process StartGitRevParse()
11  {
12  Process gitProcess = new Process();
13 
14  try
15  {
16  gitProcess.StartInfo.FileName = "git";
17  gitProcess.StartInfo.Arguments = "rev-parse --short HEAD";
18  gitProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(VersionFilePath);
19  gitProcess.StartInfo.UseShellExecute = false; // Should we use ShellExec()?
20  gitProcess.StartInfo.CreateNoWindow = true;
21 
22  gitProcess.StartInfo.RedirectStandardOutput = true;
23 
24  gitProcess.Start();
25 
26  }
27  catch (Win32Exception)
28  {
29  gitProcess = null;
30  }
31 
32  return gitProcess;
33  }
34 
35  public static void Main(string[] args)
36  {
37  using (Process p = StartGitRevParse())
38  try
39  {
40  string[] lines = File.ReadAllLines("..\\version.txt");
41 
42  if(lines.Length < 1)
43  {
44  throw new Exception("version.txt first line should contain the version number.");
45  }
46 
47  string version = lines[0].Trim();
48 
49  string gitCommit = String.Empty;
50 
51  if (p != null)
52  {
53  gitCommit = p.StandardOutput.ReadToEnd().Trim();
54 
55  // Needed?
56  p.WaitForExit();
57  }
58 
59  string config = "#define PACKAGE_VERSION \"" + version + "\"\n"
60  + "#define COMMIT_VERSION \"" + gitCommit + "\"\n";
61 
62  if (!File.Exists("config.h") ||
63  string.CompareOrdinal(File.ReadAllText("config.h"), config) != 0)
64  {
65  File.WriteAllText("config.h", config);
66  }
67  }
68  catch (Exception e)
69  {
70  Console.Error.WriteLine(e.ToString());
71  Environment.Exit(1);
72  }
73  }
74 }
const version_struct version(PACKAGE_VERSION)
const string VersionFilePath
Definition: make_config_h.cs:8
static Process StartGitRevParse()
static void Main(string[] args)