12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include "LinkStep.h"
-
- #include <string>
- #include <fstream>
-
- #include "sys.h"
- #include "logger.h"
- #include "globals.h"
- #include "BXParser.h"
-
- bool LinkStep::checkHasChanged(const std::string &outDir) {
- std::string targetPath = toolchain::targetFilePath(type_, path_, outDir);
- if (!sys::fileExists(targetPath)) {
- return true;
- }
-
- std::string confPath = this->confPath(outDir);
- if (!sys::fileExists(confPath)) {
- return true;
- }
-
- BXVariables cachedVariables;
- try {
- bufio::IFStream f(confPath);
- BXParser parser(f);
- parser.parse(cachedVariables);
- } catch (BXParseError &err) {
- logger::log(confPath + ": " + err.what());
- return true;
- }
-
- auto commandIt = cachedVariables.find("command");
- if (commandIt == cachedVariables.end()) {
- logger::log(confPath + ": Missing 'command' field");
- return true;
- }
-
- if (linkCommand(outDir) != commandIt->second) {
- return true;
- }
-
- return false;
- }
-
- void LinkStep::doBuild(const std::string &outDir) {
- logger::log("Link " + path_);
- std::vector<std::string> command = linkCommand(outDir);
- std::string dirPath = sys::dirname(outDir + '/' + path_);
-
- BXVariables newCachedVars = {
- { "command", command},
- };
-
- bufio::OFStream f(confPath(outDir));
- BXWriter writer(f);
- writer.write(newCachedVars);
-
- sys::mkdirp(dirPath);
- sys::ProcConf conf;
- conf.print = global::verbose >= 1;
- sys::execute(command, conf);
- }
-
- std::vector<std::string> &LinkStep::linkCommand(const std::string &outDir) {
- if (hasLinkCommand_) {
- return linkCommand_;
- }
-
- std::vector<std::string> objs;
- for (auto &dep: deps_) {
- for (auto &obj: dep->publicObjects(outDir)) {
- objs.push_back(obj);
- }
- }
-
- // TODO: Don't use FileType::CXX hard-coded here
- linkCommand_ = toolchain::getLinkCommand(
- publicLDFlags(outDir), publicLDLibs(outDir),
- toolchain::FileType::CXX, type_, objs, path_, outDir);
- hasLinkCommand_ = true;
- return linkCommand_;
- }
|