This file is used by some clang tools to find compile options.
#include "builtintools.h"
#include "copy.h"
+#include "compilecommandsgenerator.h"
#include "pkgconfiggenerator.h"
#include "tar.h"
#include "vcxprojectgenerator.h"
add_tool(new Tar(builder));
add_tool(new PkgConfigGenerator(builder));
add_tool(new VcxProjectGenerator(builder));
+ add_tool(new CompileCommandsGenerator(builder));
}
--- /dev/null
+#include <msp/io/file.h>
+#include <msp/io/print.h>
+#include <msp/strings/utils.h>
+#include "builder.h"
+#include "compilecommandsgenerator.h"
+#include "compilecommandsjson.h"
+#include "objectfile.h"
+#include "sourcefile.h"
+
+using namespace std;
+using namespace Msp;
+
+CompileCommandsGenerator::CompileCommandsGenerator(Builder &b):
+ Tool(b, "CCJG")
+{ }
+
+Target *CompileCommandsGenerator::create_target(const list<Target *> &, const string &)
+{
+ throw logic_error("Not implemented");
+}
+
+Task *CompileCommandsGenerator::run(const Target &target) const
+{
+ const CompileCommandsJson &cmds = dynamic_cast<const CompileCommandsJson &>(target);
+ Worker *worker = new Worker(cmds);
+ return new InternalTask(worker);
+}
+
+
+CompileCommandsGenerator::Worker::Worker(const CompileCommandsJson &t):
+ target(t)
+{ }
+
+void CompileCommandsGenerator::Worker::main()
+{
+ Builder &builder = target.get_package()->get_builder();
+ const SourcePackage &spkg = *target.get_package();
+ string work_dir = c_escape(spkg.get_source_directory().str());
+
+ IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
+ IO::print(out, "[");
+
+ bool first = true;
+ const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
+ for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+ if(i->second->is_buildable() && i->second->get_package()==&spkg)
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(i->second))
+ {
+ FS::Path src_path = obj->get_source().get_path();
+ Task *task = i->second->build();
+ if(!first)
+ out.put(',');
+ IO::print(out, "\n\t{\n");
+ IO::print(out, "\t\t\"file\": \"%s\"\n", src_path);
+ IO::print(out, "\t\t\"command\": \"%s\"\n", c_escape(task->get_command()));
+ IO::print(out, "\t\t\"directory\": \"%s\"\n", work_dir);
+ IO::print(out, "\t}");
+ delete task;
+ first = false;
+ }
+
+ IO::print(out, "\n]\n");
+
+ status = Task::SUCCESS;
+}
--- /dev/null
+#ifndef COMPILECOMMANDSGENERATOR_H_
+#define COMPILECOMMANDSGENERATOR_H_
+
+#include "internaltask.h"
+#include "tool.h"
+
+class CompileCommandsJson;
+
+class CompileCommandsGenerator: public Tool
+{
+private:
+ class Worker: public InternalTask::Worker
+ {
+ private:
+ const CompileCommandsJson ⌖
+
+ public:
+ Worker(const CompileCommandsJson &);
+
+ private:
+ virtual void main();
+ };
+
+public:
+ CompileCommandsGenerator(Builder &);
+
+ virtual Target *create_target(const std::list<Target *> &, const std::string &);
+ virtual Task *run(const Target &) const;
+};
+
+#endif
--- /dev/null
+#include "builder.h"
+#include "package.h"
+#include "compilecommandsjson.h"
+#include "objectfile.h"
+
+CompileCommandsJson::CompileCommandsJson(Builder &b, const SourcePackage &p):
+ FileTarget(b, p, p.get_source_directory()/("compile_commands.json"))
+{
+ tool = &builder.get_toolchain().get_tool("CCJG");
+}
+
+void CompileCommandsJson::find_dependencies()
+{
+ const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
+ for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+ if(i->second->is_buildable() && i->second->get_package()==package && dynamic_cast<ObjectFile *>(i->second))
+ i->second->prepare();
+}
--- /dev/null
+#ifndef COMPILECOMMANDSJSON_H_
+#define COMPILECOMMANDSJSON_H_
+
+#include "sourcepackage.h"
+#include "filetarget.h"
+
+class CompileCommandsJson: public FileTarget
+{
+private:
+
+public:
+ CompileCommandsJson(Builder &, const SourcePackage &);
+
+ virtual const char *get_type() const { return "CompileCommandsJson"; }
+
+protected:
+ virtual void find_dependencies();
+};
+
+#endif
#include "binarycomponent.h"
#include "binarypackage.h"
#include "builder.h"
+#include "compilecommandsjson.h"
#include "datapackcomponent.h"
#include "file.h"
#include "installcomponent.h"
if(arch.get_system()=="windows")
new VcxProjectFile(builder, *this);
+
+ new CompileCommandsJson(builder, *this);
}
void SourcePackage::save_caches()