summaryrefslogtreecommitdiffstats
path: root/source/core/slang-command-line.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-12-03 11:45:01 -0500
committerGitHub <noreply@github.com>2021-12-03 11:45:01 -0500
commitda6be80f18014a3972eedf05099cd0066e9eae04 (patch)
tree687cb3853e1794b9478ee2a7b0503590f00f4669 /source/core/slang-command-line.cpp
parentf4b86ff23c825f5e776a401f89302bfcd358aae8 (diff)
Split out ExecutableLocation (#2041)
* #include an absolute path didn't work - because paths were taken to always be relative. * Split out ExecutableLocation. * Fixes for changes to ExecutableLocation. * Fix issues around Process on windows. * Improve comments. Kick CI.
Diffstat (limited to 'source/core/slang-command-line.cpp')
-rw-r--r--source/core/slang-command-line.cpp90
1 files changed, 80 insertions, 10 deletions
diff --git a/source/core/slang-command-line.cpp b/source/core/slang-command-line.cpp
index 419c031ab..973bb46d0 100644
--- a/source/core/slang-command-line.cpp
+++ b/source/core/slang-command-line.cpp
@@ -11,6 +11,63 @@
namespace Slang {
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ExecutableLocation !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+
+void ExecutableLocation::set(const String& dir, const String& name)
+{
+ if (dir.getLength() == 0)
+ {
+ set(name);
+ }
+ else
+ {
+ set(Path::combine(dir, name));
+ }
+}
+
+void ExecutableLocation::set(const String& nameOrPath)
+{
+ // See if input looks like a path
+ if (Path::hasPath(nameOrPath))
+ {
+ // If it is a path we may want to add a suffix
+ const auto suffix = Process::getExecutableSuffix();
+
+ if (suffix.getLength() == 0 || nameOrPath.endsWith(suffix))
+ {
+ setPath(nameOrPath);
+ }
+ else
+ {
+ // If on target that has suffix make sure name has the suffix
+ StringBuilder builder;
+ builder << nameOrPath;
+ builder << suffix;
+ setPath(builder.ProduceString());
+ }
+ }
+ else
+ {
+ // If we don't have a parent, we assume it is just a naem
+ setName(nameOrPath);
+ }
+}
+
+void ExecutableLocation::append(StringBuilder& out) const
+{
+ if (m_type == Type::Unknown)
+ {
+ out << "(unknown)";
+ }
+ else
+ {
+ auto escapeHandler = Process::getEscapeHandler();
+ StringEscapeUtil::appendMaybeQuoted(escapeHandler, m_pathOrName.getUnownedSlice(), out);
+ }
+}
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CommandLine !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+
void CommandLine::addPrefixPathArg(const char* prefix, const String& path, const char* pathPostfix)
{
StringBuilder builder;
@@ -23,23 +80,29 @@ void CommandLine::addPrefixPathArg(const char* prefix, const String& path, const
addArg(builder.ProduceString());
}
-void CommandLine::setExecutable(const String& dir, const String& name)
+void CommandLine::append(StringBuilder& out) const
{
- StringBuilder builder;
- Path::combineIntoBuilder(dir.getUnownedSlice(), name.getUnownedSlice(), builder);
- builder << Process::getExecutableSuffix();
- setExecutablePath(builder.ProduceString());
+ m_executableLocation.append(out);
+
+ if (m_args.getCount())
+ {
+ out << " ";
+ appendArgs(out);
+ }
}
-void CommandLine::append(StringBuilder& out) const
+void CommandLine::appendArgs(StringBuilder& out) const
{
auto escapeHandler = Process::getEscapeHandler();
- StringEscapeUtil::appendMaybeQuoted(escapeHandler, m_executable.getUnownedSlice(), out);
-
- for (const auto& arg : m_args)
+ const Int argCount = m_args.getCount();
+ for (Index i = 0; i < argCount; ++i)
{
- out << " ";
+ const auto& arg = m_args[i];
+ if (i > 0)
+ {
+ out << " ";
+ }
StringEscapeUtil::appendMaybeQuoted(escapeHandler, arg.getUnownedSlice(), out);
}
}
@@ -51,4 +114,11 @@ String CommandLine::toString() const
return buf.ProduceString();
}
+String CommandLine::toStringArgs() const
+{
+ StringBuilder buf;
+ appendArgs(buf);
+ return buf.ProduceString();
+}
+
} // namespace Slang