Compare commits
No commits in common. "main" and "0.4.1" have entirely different histories.
|
@ -2,7 +2,7 @@
|
||||||
:doctype: manpage
|
:doctype: manpage
|
||||||
:Author: tastytea
|
:Author: tastytea
|
||||||
:Email: tastytea@tastytea.de
|
:Email: tastytea@tastytea.de
|
||||||
:Date: 2019-10-10
|
:Date: 2019-10-01
|
||||||
:Revision: 0.0.0
|
:Revision: 0.0.0
|
||||||
:man source: compilescript
|
:man source: compilescript
|
||||||
:man version: {revision}
|
:man version: {revision}
|
||||||
|
@ -40,9 +40,6 @@ The compiler invocation looks like this: <configured compiler> <source file>
|
||||||
Delete old cache files. You can configure the timespan after which a file is
|
Delete old cache files. You can configure the timespan after which a file is
|
||||||
considered old with the config option _clean_after_hours_.
|
considered old with the config option _clean_after_hours_.
|
||||||
|
|
||||||
*--compiler* _command_::
|
|
||||||
Override compiler command. Note that *--compiler*=_command_ does NOT work.
|
|
||||||
|
|
||||||
*--version*::
|
*--version*::
|
||||||
Print version, copyright and license.
|
Print version, copyright and license.
|
||||||
|
|
||||||
|
|
48
src/main.cpp
48
src/main.cpp
|
@ -25,7 +25,6 @@
|
||||||
#include <experimental/filesystem>
|
#include <experimental/filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -60,8 +59,6 @@ public:
|
||||||
void run(const string &filename, char *argv[]);
|
void run(const string &filename, char *argv[]);
|
||||||
//! Print version, copyright and license.
|
//! Print version, copyright and license.
|
||||||
void print_version();
|
void print_version();
|
||||||
//! Set compiler command.
|
|
||||||
void set_compiler(const string &command);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Compilescript::Compilescript()
|
Compilescript::Compilescript()
|
||||||
|
@ -174,11 +171,18 @@ string Compilescript::compile(const string &filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::getline(in, buf);
|
std::getline(in, buf);
|
||||||
const std::regex re("^(//|#|;) ?compilescript:");
|
if (buf.substr(0, 17) == "// compilescript:")
|
||||||
std::smatch match;
|
|
||||||
if (std::regex_search(buf, match, re))
|
|
||||||
{
|
{
|
||||||
compiler_arguments = match.suffix();
|
compiler_arguments = buf.substr(17);
|
||||||
|
}
|
||||||
|
else if (buf.substr(0, 16) == "//compilescript:")
|
||||||
|
{
|
||||||
|
compiler_arguments = buf.substr(16);
|
||||||
|
}
|
||||||
|
else if ((buf.substr(0, 15) == "#compilescript:") ||
|
||||||
|
(buf.substr(0, 15) == ";compilescript:"))
|
||||||
|
{
|
||||||
|
compiler_arguments = buf.substr(15);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -208,7 +212,7 @@ string Compilescript::compile(const string &filename)
|
||||||
|
|
||||||
const string command = _compiler + " " + source.string() + " "
|
const string command = _compiler + " " + source.string() + " "
|
||||||
+ compiler_arguments + " -o " + binary.string();
|
+ compiler_arguments + " -o " + binary.string();
|
||||||
int ret = std::system(command.c_str()); // NOLINT(cert-env33-c)
|
int ret = std::system(command.c_str()); // NOLINT Doesn't apply here.
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Compilation failed.");
|
throw std::runtime_error("Compilation failed.");
|
||||||
|
@ -220,7 +224,7 @@ string Compilescript::compile(const string &filename)
|
||||||
|
|
||||||
void Compilescript::run(const string &filename, char *argv[])
|
void Compilescript::run(const string &filename, char *argv[])
|
||||||
{
|
{
|
||||||
execvp(filename.c_str(), argv);
|
execvp(filename.c_str(), &argv[1]); // NOLINT We know that argv[1] exists.
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compilescript::print_version()
|
void Compilescript::print_version()
|
||||||
|
@ -233,11 +237,6 @@ void Compilescript::print_version()
|
||||||
"\nand you are welcome to redistribute it under certain conditions.\n";
|
"\nand you are welcome to redistribute it under certain conditions.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compilescript::set_compiler(const string &command)
|
|
||||||
{
|
|
||||||
_compiler = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const vector<string> args(argv, argv + argc);
|
const vector<string> args(argv, argv + argc);
|
||||||
|
@ -250,8 +249,7 @@ int main(int argc, char *argv[])
|
||||||
if (args.size() <= 1)
|
if (args.size() <= 1)
|
||||||
{
|
{
|
||||||
cerr << "usage: " << args[0]
|
cerr << "usage: " << args[0]
|
||||||
<< " [file|--cleanup|--version|--compiler command] "
|
<< " [file|--cleanup|--version] [arguments]\n";
|
||||||
<< "[arguments]\n";
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (args[1] == "--cleanup")
|
if (args[1] == "--cleanup")
|
||||||
|
@ -264,25 +262,9 @@ int main(int argc, char *argv[])
|
||||||
App.print_version();
|
App.print_version();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (args[1] == "--compiler")
|
|
||||||
{
|
|
||||||
if (args.size() <= 3)
|
|
||||||
{
|
|
||||||
cerr << "Error: You need to specify a command.\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
App.set_compiler(args[2]);
|
|
||||||
const string binary = App.compile(args[3]);
|
|
||||||
// We know that argv[3] exists.
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
|
||||||
App.run(binary, &argv[3]);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const string binary = App.compile(args[1]);
|
const string binary = App.compile(args[1]);
|
||||||
// We know that argv[1] exists.
|
App.run(binary, argv);
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
|
||||||
App.run(binary, &argv[1]);
|
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
|
|
Reference in New Issue