summaryrefslogtreecommitdiffhomepage
path: root/ymake.cpp
blob: cc3e00e2ccb9fa04a622bb1908f6b40db22b10fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "ymake.h"

#include "file.h"
#include "Builder.h"
#include "MakefileReader.h"

#include <algorithm>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <iterator>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/process.hpp>

#include <fmt/format.h>

#include <libreichwein/file.h>
#include <libreichwein/stringhelper.h>

namespace fs = std::filesystem;
namespace bp = boost::process;
namespace pt = boost::property_tree;
using namespace std::string_literals;

namespace {
 void usage()
 {
  std::cout << "Usage: ymake [<action>]" << std::endl;
  std::cout << "       with <action> one of:" << std::endl;
  std::cout << "         build (same as no action specified)" << std::endl;
  std::cout << "         clean" << std::endl;
  std::cout << "         test" << std::endl;
 }

}

int ymake(int argc, char* argv[])
{
 try {
  pt::ptree ptree{MakefileReader{}.read(".")};

  std::string action{"default"};

  if (argc == 1) { // default action
  } else if (argc == 2) {
   action = argv[1];
  } else {
   std::cerr << "Invalid arguments." << std::endl;
   usage();
   exit(1);
  }

  if (action == "default" || action == "build") { // build
   Builder builder(ptree, "build");
   builder.build();
  } else if (action == "clean") {
   Builder builder(ptree, "*");
   builder.clean();
  } else if (action == "test") {
   Builder builder(ptree, "test");
   builder.build();
   builder.run_tests();
  } else if (action == "install") {
   throw std::runtime_error("unimplemented");
  } else if (action == "rebuild") {
   throw std::runtime_error("unimplemented");
  } else if (action == "run") {
   throw std::runtime_error("unimplemented");
  } else {
   std::cerr << "Invalid action: " << action << std::endl;
   usage();
   exit(1);
  }

 } catch (const std::exception& ex) {
  std::cerr << "ymake: " << ex.what() << std::endl;
  return 1;
 }

 return 0;
}