Add messaging to extension loading in the HAL (#1926)

This commit is contained in:
Thad House
2019-10-09 22:25:02 -07:00
committed by Peter Johnson
parent d169d6be9e
commit 46303a8221

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -7,8 +7,10 @@
#include "hal/Extensions.h"
#include <wpi/Path.h>
#include <wpi/SmallString.h>
#include <wpi/StringRef.h>
#include <wpi/raw_ostream.h>
#include "hal/HAL.h"
@@ -43,6 +45,9 @@ extern "C" {
int HAL_LoadOneExtension(const char* library) {
int rc = 1; // It is expected and reasonable not to find an extra simulation
wpi::outs() << "HAL Extensions: Attempting to load: "
<< wpi::sys::path::stem(library) << "\n";
wpi::outs().flush();
HTYPE handle = DLOPEN(library);
#if !defined(WIN32) && !defined(_WIN32)
if (!handle) {
@@ -53,17 +58,31 @@ int HAL_LoadOneExtension(const char* library) {
#else
libraryName += ".so";
#endif
wpi::outs() << "HAL Extensions: Trying modified name: "
<< wpi::sys::path::stem(libraryName);
wpi::outs().flush();
handle = DLOPEN(libraryName.c_str());
}
#endif
if (!handle) return rc;
if (!handle) {
wpi::outs() << "HAL Extensions: Failed to load library\n";
wpi::outs().flush();
return rc;
}
auto init = reinterpret_cast<halsim_extension_init_func_t*>(
DLSYM(handle, "HALSIM_InitExtension"));
if (init) rc = (*init)();
if (rc != 0) DLCLOSE(handle);
if (rc != 0) {
wpi::outs() << "HAL Extensions: Failed to load extension\n";
wpi::outs().flush();
DLCLOSE(handle);
} else {
wpi::outs() << "HAL Extensions: Successfully loaded extension\n";
wpi::outs().flush();
}
return rc;
}
@@ -71,7 +90,11 @@ int HAL_LoadExtensions(void) {
int rc = 1;
wpi::SmallVector<wpi::StringRef, 2> libraries;
const char* e = std::getenv("HALSIM_EXTENSIONS");
if (!e) return rc;
if (!e) {
wpi::outs() << "HAL Extensions: No extensions found\n";
wpi::outs().flush();
return rc;
}
wpi::StringRef env{e};
env.split(libraries, DELIM, -1, false);
for (auto& libref : libraries) {