Vuo 2.4.4
Loading...
Searching...
No Matches
VuoModuleCompiler.cc
Go to the documentation of this file.
1
10#include "VuoModuleCompiler.hh"
11
12#include "VuoCompilerIssue.hh"
13#include "VuoFileUtilities.hh"
14#include <dlfcn.h>
15
19map<string, VuoModuleCompiler::Factory> *VuoModuleCompiler::factories;
20
24void VuoModuleCompiler::loadAllModuleCompilers(void)
25{
26 factories = new map<string, VuoModuleCompiler::Factory>;
27
28 vector<string> compilerPaths;
29 string vuoFrameworkPath = VuoFileUtilities::getVuoFrameworkPath();
30 if (vuoFrameworkPath.empty())
31 compilerPaths.push_back(VUO_BUILD_DIR "/lib/libVuoCModuleCompiler.dylib");
32 else
33 {
34 set<VuoFileUtilities::File *> files = VuoFileUtilities::findFilesInDirectory(vuoFrameworkPath + "/Helpers/ModuleCompiler", set<string>{"dylib"});
35 for (VuoFileUtilities::File *file : files)
36 {
37 compilerPaths.push_back(file->path());
38 delete file;
39 }
40 }
41
42 for (const string &compilerPath : compilerPaths)
43 {
44 void *handle = dlopen(compilerPath.c_str(), RTLD_NOW);
45 if (! handle)
46 VUserLog("Warning: The module compiler '%s' couldn't be loaded : %s", compilerPath.c_str(), dlerror());
47 }
48}
49
56{
57 auto existingFactory = factories->find(type);
58 if (existingFactory != factories->end())
59 {
60 VUserLog("Warning: A VuoModuleCompiler for type '%s' is already registered. Ignoring the duplicate.", type.c_str());
61 return;
62 }
63
64 (*factories)[type] = factory;
65}
66
71VuoModuleCompiler * VuoModuleCompiler::newModuleCompiler(const string &type, const string &moduleKey, const string &sourcePath,
72 const VuoModuleCompilerSettings &settings,
73 std::function<VuoCompilerType *(const string &)> getVuoType)
74{
75 static once_flag once;
76 std::call_once(once, []() {
77 loadAllModuleCompilers();
78 });
79
80 auto factory = factories->find(type);
81 if (factory != factories->end())
82 {
83 VuoModuleCompiler *moduleCompiler = factory->second(moduleKey, sourcePath, settings);
84 if (moduleCompiler)
85 {
86 moduleCompiler->getVuoType = getVuoType;
87 return moduleCompiler;
88 }
89 }
90
91 return nullptr;
92}
93
97VuoModuleCompiler::VuoModuleCompiler(const string &moduleKey, const string &sourcePath, const VuoModuleCompilerSettings &settings) :
98 moduleKey(moduleKey),
99 sourcePath(sourcePath),
100 settings(settings)
101{
102}
103
104VuoModuleCompiler::~VuoModuleCompiler(void)
105{
106}
107
112{
113 VuoCompilerIssue issue(VuoCompilerIssue::Error, "generating header", sourcePath, "", "This source file type doesn't use headers.");
114 issue.setModuleKey(moduleKey);
115 issues->append(issue);
116
117 return "";
118}
119
126{
127 VuoCompilerType *type = getVuoType(typeName);
128
129 if (type)
130 vuoTypes[typeName] = type;
131
132 return type;
133}