CBMC
ms_cl_version.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Visual Studio CL version numbering scheme
4 
5 Author: Daniel Kroening, 2018
6 
7 \*******************************************************************/
8 
9 #include "ms_cl_version.h"
10 
11 #include <util/run.h>
12 #include <util/string2int.h>
13 #include <util/string_utils.h>
14 #include <util/tempfile.h>
15 
16 #include <fstream>
17 
18 void ms_cl_versiont::get(const std::string &executable)
19 {
20  // stdout will have the help output, we just want to discard it
21  temporary_filet tmp_file_out("goto-cl.", ".out");
22  // stderr has the version string
23  temporary_filet tmp_file_err("goto-cl.", ".err");
24  const int result =
25  run(executable, {executable}, "", tmp_file_out(), tmp_file_err());
26 
27  v_major = v_minor = 0;
29 
30  if(result >= 0)
31  {
32  std::ifstream in(tmp_file_err());
33  std::string line;
34 
35  if(std::getline(in, line))
36  {
37  // Example:
38  //
39  // NOLINTNEXTLINE (whitespace/braces)
40  // Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
41  auto split = split_string(line, ' ');
42  if(split.size() > 3)
43  {
44  if(split.back() == "x86" || split.back() == "80x86")
46  else if(split.back() == "x64")
48  else if(split.back() == "ARM")
50  else
52 
53  auto split_v = split_string(split[split.size() - 3], '.');
54 
55  if(split_v.size() >= 2)
56  {
57  v_major = safe_string2unsigned(split_v[0]);
58  v_minor = safe_string2unsigned(split_v[1]);
59  }
60  }
61  }
62  }
63 }
64 
65 bool ms_cl_versiont::is_at_least(unsigned _major, unsigned _minor) const
66 {
67  return v_major > _major || (v_major == _major && v_minor >= _minor);
68 }
69 
70 std::ostream &operator<<(std::ostream &out, const ms_cl_versiont &v)
71 {
72  out << v.v_major << '.' << v.v_minor;
73 
74  switch(v.target)
75  {
77  out << " x86";
78  break;
80  out << " x64";
81  break;
83  out << " ARM";
84  break;
86  break;
87  }
88 
89  return out;
90 }
void get(const std::string &executable)
unsigned v_minor
Definition: ms_cl_version.h:22
enum ms_cl_versiont::targett target
bool is_at_least(unsigned v_major, unsigned v_minor=0) const
unsigned v_major
Definition: ms_cl_version.h:22
std::ostream & operator<<(std::ostream &out, const ms_cl_versiont &v)
int run(const std::string &what, const std::vector< std::string > &argv)
Definition: run.cpp:48
unsigned safe_string2unsigned(const std::string &str, int base)
Definition: string2int.cpp:16
void split_string(const std::string &s, char delim, std::vector< std::string > &result, bool strip, bool remove_empty)