Преглед на файлове

verbosity levels

feature/dependency-graph
Martin Dørum преди 4 години
родител
ревизия
70b607d0ad
променени са 6 файла, в които са добавени 16 реда и са изтрити 17 реда
  1. 1
    1
      src/globals.cc
  2. 1
    1
      src/globals.h
  3. 3
    5
      src/main.cc
  4. 4
    4
      src/sys.cc
  5. 1
    1
      src/sys.h
  6. 6
    5
      src/toolchain.cc

+ 1
- 1
src/globals.cc Целия файл



namespace global { namespace global {


bool verbose = false;
int verbose = 0;


} }

+ 1
- 1
src/globals.h Целия файл



namespace global { namespace global {


extern bool verbose;
extern int verbose;


} }

+ 3
- 5
src/main.cc Целия файл

return 0; return 0;


case 'v': case 'v':
global::verbose = true;
global::verbose += 1;
break; break;


case 'o': case 'o':


// Change directory? // Change directory?
if (workDir.size() > 0) { if (workDir.size() > 0) {
if (global::verbose) {
fprintf(stderr, "Entering directory '%s'\n", workDir.c_str());
}
fprintf(stderr, "Entering directory '%s'\n", workDir.c_str());


if (chdir(workDir.c_str()) < 0) { if (chdir(workDir.c_str()) < 0) {
perror(workDir.c_str()); perror(workDir.c_str());
case Action::BUILD: case Action::BUILD:
// TODO: Support more types than BINARY // TODO: Support more types than BINARY
if (!compileAndLink(sources, outDir, jobs, target, toolchain::TargetType::BINARY)) { if (!compileAndLink(sources, outDir, jobs, target, toolchain::TargetType::BINARY)) {
logger::log("Nothing to do.\n");
logger::log("Nothing to do.");
} }
break; break;



+ 4
- 4
src/sys.cc Целия файл

#include <sys/wait.h> #include <sys/wait.h>
#include <stdexcept> #include <stdexcept>


#include "globals.h"
#include "logger.h" #include "logger.h"
#include "globals.h"


namespace sys { namespace sys {


argv.push_back("mkdir"); argv.push_back("mkdir");
argv.push_back("-p"); argv.push_back("-p");
argv.push_back(path.c_str()); argv.push_back(path.c_str());
execute(argv, nullptr);
execute(argv, nullptr, global::verbose >= 2);
} }


void execute(std::vector<const char *> &args, std::string *output) {
if (global::verbose) {
void execute(std::vector<const char *> &args, std::string *output, bool print) {
if (print) {
std::string str; std::string str;
for (size_t i = 0; i < args.size(); ++i) { for (size_t i = 0; i < args.size(); ++i) {
if (i == 0) { if (i == 0) {

+ 1
- 1
src/sys.h Целия файл

FileInfo fileInfo(const std::string &path); FileInfo fileInfo(const std::string &path);
bool fileExists(const std::string &path); bool fileExists(const std::string &path);
void mkdirp(const std::string &path); void mkdirp(const std::string &path);
void execute(std::vector<const char *> &args, std::string *output);
void execute(std::vector<const char *> &args, std::string *output, bool print);


} }

+ 6
- 5
src/toolchain.cc Целия файл

#include <errno.h> #include <errno.h>


#include "sys.h" #include "sys.h"
#include "globals.h"


namespace toolchain { namespace toolchain {




// Execute $(PKG_CONFIG) --cflags $(PKGS) // Execute $(PKG_CONFIG) --cflags $(PKGS)
std::string output; std::string output;
sys::execute(argv, &output);
sys::execute(argv, &output, global::verbose >= 2);
parseWhitespaceSeparated(output, flags); parseWhitespaceSeparated(output, flags);
} }




// Execute $(PKG_CONFIG) --libs $(PKGS) // Execute $(PKG_CONFIG) --libs $(PKGS)
std::string output; std::string output;
sys::execute(argv, &output);
sys::execute(argv, &output, global::verbose >= 2);
parseWhitespaceSeparated(output, flags); parseWhitespaceSeparated(output, flags);
} }




// Execute $(compiler) $(flags) -MM $< // Execute $(compiler) $(flags) -MM $<
std::string output; std::string output;
sys::execute(argv, &output);
sys::execute(argv, &output, global::verbose >= 2);


size_t idx = output.find(':'); size_t idx = output.find(':');
if (idx != std::string::npos) { if (idx != std::string::npos) {
argv.push_back(sourcePath.c_str()); argv.push_back(sourcePath.c_str());


// Execute $(compiler) $(flags) -o $@ -c $< // Execute $(compiler) $(flags) -o $@ -c $<
sys::execute(argv, nullptr);
sys::execute(argv, nullptr, global::verbose >= 1);
} }


void link( void link(
} }


// Execute $(compiler) $(ldflags) -o $@ $(objs) $(ldlibs) // Execute $(compiler) $(ldflags) -o $@ $(objs) $(ldlibs)
sys::execute(argv, nullptr);
sys::execute(argv, nullptr, global::verbose >= 1);
} }


} }

Loading…
Отказ
Запис