Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into esri
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Aug 4, 2020
2 parents e82713f + 8532000 commit 5966d81
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 56 deletions.
3 changes: 1 addition & 2 deletions io/private/ept/TileContents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ void TileContents::readZstandard()
}
#else
void TileContents::readZstandard()
{
}
{}
#endif // PDAL_HAVE_ZSTD

void TileContents::readAddon(const Addon& addon)
Expand Down
30 changes: 30 additions & 0 deletions pdal/PDALUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
#include <pdal/Options.hpp>
#include <pdal/util/FileUtils.hpp>

#ifndef _WIN32
#include <dlfcn.h>
#endif

using namespace std;

namespace pdal
Expand Down Expand Up @@ -401,5 +405,31 @@ double computeHausdorff(PointViewPtr srcView, PointViewPtr candView)
return (std::max)(maxDistSrcToCand, maxDistCandToSrc);
}


std::string dllDir()
{
std::string s;

#ifdef _WIN32
HMODULE hm = NULL;

if (GetModuleHandleEx(
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCSTR)&dllDir, &hm))
{
char path[MAX_PATH];
DWORD cnt = GetModuleFileNameA(hm, path, sizeof(path));
if (cnt > 0 && cnt < MAX_PATH)
s = path;
}
#else
Dl_info info;
if (dladdr((const void *)dllDir, &info))
s = info.dli_fname;
#endif
return FileUtils::getDirectory(s);
}

} // namespace Utils
} // namespace pdal
1 change: 1 addition & 0 deletions pdal/PDALUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ inline void writeProgress(int fd, const std::string& type,
#endif
}

std::string dllDir();
std::string PDAL_DLL toJSON(const MetadataNode& m);
void PDAL_DLL toJSON(const MetadataNode& m, std::ostream& o);
std::istream PDAL_DLL *openFile(const std::string& path, bool asBinary = true);
Expand Down
17 changes: 7 additions & 10 deletions pdal/PluginDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
****************************************************************************/

#include <pdal/PluginDirectory.hpp>
#include <pdal/util/Algorithm.hpp>
#include <pdal/util/FileUtils.hpp>
#include <pdal/pdal_config.hpp>

Expand All @@ -53,14 +54,15 @@ StringList pluginSearchPaths()
searchPaths = Utils::split2(envOverride, Utils::pathListSeparator);
else
{
StringList standardPaths { ".", "./lib", "../lib", "./bin", "../bin" };
for (std::string& s : standardPaths)
StringList possiblePaths { ".", "./lib", "../lib", "./bin", "../bin", Utils::dllDir(),
Config::pluginInstallPath() };

for (std::string s : possiblePaths)
{
if (FileUtils::toAbsolutePath(s) !=
FileUtils::toAbsolutePath(Config::pluginInstallPath()))
s = FileUtils::toCanonicalPath(s);
if (s.size() && !Utils::contains(searchPaths, s))
searchPaths.push_back(s);
}
searchPaths.push_back(Config::pluginInstallPath());
}
return searchPaths;
}
Expand Down Expand Up @@ -137,11 +139,6 @@ PluginDirectory::PluginDirectory()
}
}

StringList PluginDirectory::test_pluginSearchPaths()
{
return pluginSearchPaths();
}

std::string PluginDirectory::test_validPlugin(const std::string& path,
const StringList& types)
{
Expand Down
1 change: 0 additions & 1 deletion pdal/PluginDirectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class PluginDirectory

private:
static PluginDirectory *m_instance;
PDAL_DLL static StringList test_pluginSearchPaths();
PDAL_DLL static std::string test_validPlugin(const std::string& path,
const StringList& types);
};
Expand Down
16 changes: 9 additions & 7 deletions pdal/util/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,26 @@ std::string getcwd()
}


/***
// Non-boost alternative. Requires file existence.
std::string toAbsolutePath(const std::string& filename)
std::string toCanonicalPath(std::string filename)
{
std::string result;

#ifdef _WIN32
char buf[MAX_PATH]
filename = addTrailingSlash(filename);
char buf[MAX_PATH];
if (GetFullPathName(filename.c_str(), MAX_PATH, buf, NULL))
result = buf;
#else
char buf[PATH_MAX];
if (realpath(filename.c_str(), buf))
char *buf = realpath(filename.c_str(), NULL);
if (buf)
{
result = buf;
free(buf);
}
#endif
return result;
}
***/


// if the filename is an absolute path, just return it
// otherwise, make it absolute (relative to current working dir) and return that
Expand Down
10 changes: 10 additions & 0 deletions pdal/util/FileUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ namespace FileUtils
*/
PDAL_DLL bool isDirectory(const std::string& path);

/**
Return the path with all ".", ".." and symbolic links removed.
The file must exist.
\param filename Name of file to convert to canonical path.
\return Canonical version of provided filename, or empty string.
*/
PDAL_DLL std::string toCanonicalPath(std::string filename);


/**
If the filename is an absolute path, just return it otherwise,
make it absolute (relative to current working dir) and return it.
Expand Down
41 changes: 5 additions & 36 deletions test/unit/PluginManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ struct DummyPlugin : Filter

static PF_ExitFunc initPlugin() // PF_InitFunc
{
PluginInfo pi { "filters.dummytest", "A dummy plugin registered at run-time", "http://somewhere" };
PluginInfo pi {
"filters.dummytest",
"A dummy plugin registered at run-time",
"http://somewhere"
};
pdal::PluginManager<Stage>::registerPlugin<DummyPlugin>(pi);
}

Expand All @@ -81,41 +85,6 @@ TEST(PluginManagerTest, CreateObject)
EXPECT_NE(p.get(), nullptr);
}

TEST(PluginManagerTest, SearchPaths)
{
std::string curPath;
int set = Utils::getenv("PDAL_DRIVER_PATH", curPath);
Utils::unsetenv("PDAL_DRIVER_PATH");

StringList paths = PluginDirectory::test_pluginSearchPaths();
EXPECT_TRUE(Utils::contains(paths, "./lib"));
EXPECT_TRUE(Utils::contains(paths, "../lib"));
EXPECT_TRUE(Utils::contains(paths, "../bin"));
EXPECT_TRUE(Utils::contains(paths, Config::pluginInstallPath()));

#ifdef _WIN32
Utils::setenv("PDAL_DRIVER_PATH", "C:\foo\bar;D:\baz");
#else
Utils::setenv("PDAL_DRIVER_PATH", "/foo/bar://baz");
#endif
paths = PluginDirectory::test_pluginSearchPaths();
EXPECT_EQ(paths.size(), 2U);

#ifdef _WIN32
EXPECT_TRUE(Utils::contains(paths, "C:\foo\bar"));
EXPECT_TRUE(Utils::contains(paths, "D:\baz"));
#else
EXPECT_TRUE(Utils::contains(paths, "/foo/bar"));
EXPECT_TRUE(Utils::contains(paths, "//baz"));
#endif
Utils::setenv("PDAL_DRIVER_PATH", "/this/is/a/path");
paths = PluginDirectory::test_pluginSearchPaths();
EXPECT_EQ(paths.size(), 1U);
EXPECT_TRUE(Utils::contains(paths, "/this/is/a/path"));

if (set == 0)
Utils::setenv("PDAL_DRIVER_PATH", curPath);
}

TEST(PluginManagerTest, validnames)
{
Expand Down

0 comments on commit 5966d81

Please sign in to comment.