[rtems-tools commit] rtemstoolkit: Add support to return the system path split as paths.
Chris Johns
chrisj at rtems.org
Sun Mar 29 07:07:41 UTC 2015
Module: rtems-tools
Branch: master
Commit: b24951645db3105213ab3f9ce6ae52c84425a4fa
Changeset: http://git.rtems.org/rtems-tools/commit/?id=b24951645db3105213ab3f9ce6ae52c84425a4fa
Author: Chris Johns <chrisj at rtems.org>
Date: Sun Mar 29 18:06:00 2015 +1100
rtemstoolkit: Add support to return the system path split as paths.
Seacch the path for the program name if not found and set it as
an absolute path. This allow the prefix to be found.
---
linkers/rtems-tld.cpp | 2 +-
rtemstoolkit/rld-path.cpp | 18 ++++++++++++++++++
rtemstoolkit/rld-path.h | 6 ++++++
rtemstoolkit/rld.cpp | 22 ++++++++++++++++++++--
4 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/linkers/rtems-tld.cpp b/linkers/rtems-tld.cpp
index 0a25ca8..714c9ee 100644
--- a/linkers/rtems-tld.cpp
+++ b/linkers/rtems-tld.cpp
@@ -1497,7 +1497,7 @@ namespace rld
const std::string& trace,
const std::string& path)
{
- std::string sp = get_prefix ();
+ std::string sp = rld::get_prefix ();
rld::path::path_join (sp, "share", sp);
rld::path::path_join (sp, "rtems", sp);
diff --git a/rtemstoolkit/rld-path.cpp b/rtemstoolkit/rld-path.cpp
index 333c1c2..c848676 100644
--- a/rtemstoolkit/rld-path.cpp
+++ b/rtemstoolkit/rld-path.cpp
@@ -214,5 +214,23 @@ namespace rld
throw rld::error ("Not found", "unlinking: " + path);
}
}
+
+ void
+ get_system_path (paths& paths)
+ {
+ const char* path = ::getenv ("PATH");
+ strings ps;
+ rld::split (ps, path, RLD_PATHSTR_SEPARATOR);
+ if (ps.size ())
+ {
+ for (strings::iterator psi = ps.begin ();
+ psi != ps.end ();
+ ++psi)
+ {
+ if (check_directory (*psi))
+ paths.push_back (*psi);
+ }
+ }
+ }
}
}
diff --git a/rtemstoolkit/rld-path.h b/rtemstoolkit/rld-path.h
index d73c59b..80921a1 100644
--- a/rtemstoolkit/rld-path.h
+++ b/rtemstoolkit/rld-path.h
@@ -144,6 +144,12 @@ namespace rld
*/
void unlink (const std::string& path, bool not_present_error = false);
+ /**
+ * Return the system path as a set of strings.
+ *
+ * @param paths The split path paths.
+ */
+ void get_system_path (paths& paths);
}
}
diff --git a/rtemstoolkit/rld.cpp b/rtemstoolkit/rld.cpp
index c3368f9..b3e6fdc 100644
--- a/rtemstoolkit/rld.cpp
+++ b/rtemstoolkit/rld.cpp
@@ -235,7 +235,25 @@ namespace rld
void
set_progname (const std::string& progname_)
{
- progname = rld::path::path_abs (progname_);
+ if (rld::path::check_file (progname_))
+ progname = rld::path::path_abs (progname_);
+ else
+ {
+ rld::path::paths paths;
+ rld::path::get_system_path (paths);
+ for (rld::path::paths::const_iterator path = paths.begin ();
+ path != paths.end ();
+ ++path)
+ {
+ std::string pp;
+ rld::path::path_join (*path, progname_, pp);
+ if (rld::path::check_file (pp))
+ {
+ progname = rld::path::path_abs (pp);
+ break;
+ }
+ }
+ }
}
const std::string
@@ -262,7 +280,7 @@ namespace rld
std::string pp = get_program_path ();
if (rld::path::basename (pp) == "bin")
return rld::path::dirname (pp);
- return "";
+ return pp;
}
void
More information about the vc
mailing list