Skip to content

Commit af6050d

Browse files
committed
jit: fix some hardcoded paths
1 parent 74ed8c2 commit af6050d

2 files changed

Lines changed: 90 additions & 41 deletions

File tree

src/plugins/score-plugin-jit/JitCpp/JitPlatform.hpp

Lines changed: 72 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,58 @@ static inline std::string locateSDK()
122122
#endif
123123
}
124124

125+
struct located_sdk
126+
{
127+
std::string path;
128+
enum
129+
{
130+
none, // Nothing was found
131+
platform, // Building against /usr/include, useful for dev builds
132+
official // The SDK obtained from official score releases
133+
} sdk_kind
134+
= none;
135+
136+
// Do we use the score source dir or the headers from the SDK
137+
#if !SCORE_FHS_BUILD
138+
static constexpr bool deploying = true;
139+
#else
140+
static constexpr bool deploying = false;
141+
#endif
142+
};
143+
144+
inline located_sdk locateSDKWithFallback()
145+
{
146+
located_sdk ret;
147+
ret.path = locateSDK();
148+
if(ret.path.empty())
149+
ret.sdk_kind = located_sdk::none;
150+
if(ret.path.starts_with("/usr") || ret.path.starts_with("/Applications"))
151+
ret.sdk_kind = located_sdk::official;
152+
else
153+
ret.sdk_kind = located_sdk::platform;
154+
155+
{
156+
QDir dir(QString::fromStdString(ret.path));
157+
if(!dir.exists())
158+
ret.sdk_kind = located_sdk::none;
159+
160+
if(!dir.cd("include") || !dir.cd("c++"))
161+
{
162+
qDebug() << "Unable to locate standard headers, fallback to /usr";
163+
ret.path = "/usr";
164+
dir.setPath("/usr");
165+
if(!dir.cd("include") || !dir.cd("c++"))
166+
{
167+
qDebug() << "Unable to locate any standard headers, install C++ development "
168+
"toolchain";
169+
throw std::runtime_error("Unable to compile");
170+
}
171+
ret.sdk_kind = located_sdk::platform;
172+
}
173+
}
174+
return ret;
175+
}
176+
125177
static inline void
126178
populateCompileOptions(std::vector<std::string>& args, CompilerOptions opts)
127179
{
@@ -580,29 +632,9 @@ static inline auto getPotentialTriples()
580632
*/
581633
static inline void populateIncludeDirs(std::vector<std::string>& args)
582634
{
583-
auto sdk = locateSDK();
635+
auto sdk_location = locateSDKWithFallback();
636+
auto& sdk = sdk_location.path;
584637
auto qsdk = QString::fromStdString(sdk);
585-
std::cerr << "\nLooking for sdk in: " << sdk << "\n";
586-
qDebug() << "Looking for sdk in: " << qsdk;
587-
588-
bool sdk_found = true;
589-
590-
{
591-
QDir dir(qsdk);
592-
if(!dir.cd("include") || !dir.cd("c++"))
593-
{
594-
qDebug() << "Unable to locate standard headers, fallback to /usr";
595-
qsdk = "/usr";
596-
sdk = "/usr";
597-
dir.setPath("/usr");
598-
if(!dir.cd("include") || !dir.cd("c++"))
599-
{
600-
qDebug() << "Unable to locate standard headers++";
601-
throw std::runtime_error("Unable to compile");
602-
}
603-
sdk_found = false;
604-
}
605-
}
606638

607639
qDebug() << "SDK located: " << qsdk;
608640
std::string llvm_lib_version = SCORE_LLVM_VERSION;
@@ -699,12 +731,27 @@ static inline void populateIncludeDirs(std::vector<std::string>& args)
699731
///build/score.AppDir/usr/include/
700732

701733
auto include = [&](const std::string& path) {
702-
args.push_back("-isystem" + sdk + "/include/" + path);
734+
std::string path_to_include = sdk + "/include/" + path;
735+
auto qpath = QString::fromStdString(path_to_include);
736+
if(!QFileInfo{qpath}.isDir())
737+
{
738+
qDebug() << "Trying to include non-existent path: " << qpath;
739+
}
740+
else
741+
{
742+
args.push_back("-isystem" + sdk + "/include/" + path);
743+
}
703744
};
704745

705746
#if defined(__linux__)
706-
include("x86_64-linux-gnu"); // #debian
747+
// #debian
748+
#if defined(__x86_64__)
749+
include("x86_64-linux-gnu");
750+
#else
751+
include("aarch64-linux-gnu");
707752
#endif
753+
#endif
754+
708755
// include(""); // /usr/include
709756
std::string qt_folder = "qt";
710757
if(QFile::exists(qsdk + "/include/qt6/QtCore"))
@@ -745,16 +792,9 @@ static inline void populateIncludeDirs(std::vector<std::string>& args)
745792
include(qt_folder + "/QtShaderTools");
746793
include(qt_folder + "/QtShaderTools/" + qt_version);
747794
include(qt_folder + "/QtShaderTools/" + qt_version + "/QtShaderTools");
748-
include(qt_folder + "/QtSerialBus");
749795
include(qt_folder + "/QtSerialPort");
750796

751-
#if !SCORE_FHS_BUILD
752-
bool deploying = true;
753-
#else
754-
bool deploying = false;
755-
#endif
756-
757-
if(deploying && sdk_found)
797+
if(sdk_location.sdk_kind == located_sdk::official && sdk_location.deploying)
758798
{
759799
include("score");
760800
}

src/plugins/score-plugin-jit/JitCpp/MetadataGenerator.hpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#pragma once
2+
#include <JitCpp/JitPlatform.hpp>
3+
24
#include <score/tools/File.hpp>
35

46
#include <QDir>
@@ -238,28 +240,35 @@ static void loadCMakeAddon(const QString& addon, AddonData& data, QString cm)
238240
}
239241
}
240242

243+
auto sdk_location = locateSDKWithFallback();
244+
auto qsdk = QString::fromStdString(sdk_location.path);
245+
QString prototypes_folders;
246+
if(sdk_location.sdk_kind == located_sdk::official && sdk_location.deploying)
247+
{
248+
prototypes_folders = qsdk + "/lib/cmake/score";
249+
}
250+
else
251+
{
252+
prototypes_folders
253+
= QString::fromUtf8(SCORE_ROOT_SOURCE_DIR) + "/src/plugins/score-plugin-avnd/";
254+
}
255+
241256
for(auto& gp : groups)
242257
{
243258
auto avnd_plugin_version = gp.version.toUtf8();
244259
auto avnd_plugin_uuid = gp.uuid.toUtf8();
245260
avnd_plugin_uuid.removeIf([](char c) { return c == '"'; });
246261
auto avnd_base_target = gp.base_target.toUtf8();
247262

248-
QFile proto_file = QFile(
249-
"/home/jcelerier/ossia/score/src/plugins/score-plugin-avnd/"
250-
"prototype.cpp.in");
263+
QFile proto_file = QFile(prototypes_folders + "/prototype.cpp.in");
251264
proto_file.open(QIODevice::ReadOnly);
252265
auto proto = proto_file.readAll();
253266

254-
QFile cpp_proto_file = QFile(
255-
"/home/jcelerier/ossia/score/src/plugins/score-plugin-avnd/"
256-
"plugin_prototype.cpp.in");
267+
QFile cpp_proto_file = QFile(prototypes_folders + "/plugin_prototype.cpp.in");
257268
cpp_proto_file.open(QIODevice::ReadOnly);
258269
auto cpp_proto = cpp_proto_file.readAll();
259270

260-
QFile hpp_proto_file = QFile(
261-
"/home/jcelerier/ossia/score/src/plugins/score-plugin-avnd/"
262-
"plugin_prototype.hpp.in");
271+
QFile hpp_proto_file = QFile(prototypes_folders + "/plugin_prototype.hpp.in");
263272
hpp_proto_file.open(QIODevice::ReadOnly);
264273
auto hpp_proto = hpp_proto_file.readAll();
265274

0 commit comments

Comments
 (0)