[llvm] c068e9c - [Support][CommandLine] Delete unused llvm::cl::ParseEnvrironmentOptions
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 31 10:48:18 PDT 2020
Author: Fangrui Song
Date: 2020-07-31T10:48:09-07:00
New Revision: c068e9c8c123e7f8c8f3feb57245a012ccd09ccf
URL: https://github.com/llvm/llvm-project/commit/c068e9c8c123e7f8c8f3feb57245a012ccd09ccf
DIFF: https://github.com/llvm/llvm-project/commit/c068e9c8c123e7f8c8f3feb57245a012ccd09ccf.diff
LOG: [Support][CommandLine] Delete unused llvm::cl::ParseEnvrironmentOptions
The function was added in 2003. It is not used and can be emulated with ParseCommandLineOptions.
Added:
Modified:
llvm/docs/CommandLine.rst
llvm/include/llvm/Support/CommandLine.h
llvm/lib/Support/CommandLine.cpp
llvm/unittests/Support/CommandLineTest.cpp
Removed:
################################################################################
diff --git a/llvm/docs/CommandLine.rst b/llvm/docs/CommandLine.rst
index ab2826d789f2f..431ebc0e67e67 100644
--- a/llvm/docs/CommandLine.rst
+++ b/llvm/docs/CommandLine.rst
@@ -1369,29 +1369,6 @@ The ``cl::ParseCommandLineOptions`` function requires two parameters (``argc``
and ``argv``), but may also take an optional third parameter which holds
`additional extra text`_ to emit when the ``-help`` option is invoked.
-.. _cl::ParseEnvironmentOptions:
-
-The ``cl::ParseEnvironmentOptions`` function
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-The ``cl::ParseEnvironmentOptions`` function has mostly the same effects as
-`cl::ParseCommandLineOptions`_, except that it is designed to take values for
-options from an environment variable, for those cases in which reading the
-command line is not convenient or desired. It fills in the values of all the
-command line option variables just like `cl::ParseCommandLineOptions`_ does.
-
-It takes four parameters: the name of the program (since ``argv`` may not be
-available, it can't just look in ``argv[0]``), the name of the environment
-variable to examine, and the optional `additional extra text`_ to emit when the
-``-help`` option is invoked.
-
-``cl::ParseEnvironmentOptions`` will break the environment variable's value up
-into words and then process them using `cl::ParseCommandLineOptions`_.
-**Note:** Currently ``cl::ParseEnvironmentOptions`` does not support quoting, so
-an environment variable containing ``-option "foo bar"`` will be parsed as three
-words, ``-option``, ``"foo``, and ``bar"``, which is
diff erent from what you
-would get from the shell with the same input.
-
The ``cl::SetVersionPrinter`` function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 466945e40a9ce..62e44aeefe9cf 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -71,13 +71,6 @@ bool ParseCommandLineOptions(int argc, const char *const *argv,
const char *EnvVar = nullptr,
bool LongOptionsUseDoubleDash = false);
-//===----------------------------------------------------------------------===//
-// ParseEnvironmentOptions - Environment variable option processing alternate
-// entry point.
-//
-void ParseEnvironmentOptions(const char *progName, const char *envvar,
- const char *Overview = "");
-
// Function pointer type for printing version information.
using VersionPrinterTy = std::function<void(raw_ostream &)>;
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 12ef0d511b147..4fba6a9ada2c0 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -1271,36 +1271,6 @@ bool cl::readConfigFile(StringRef CfgFile, StringSaver &Saver,
/*MarkEOLs*/ false, /*RelativeNames*/ true);
}
-/// ParseEnvironmentOptions - An alternative entry point to the
-/// CommandLine library, which allows you to read the program's name
-/// from the caller (as PROGNAME) and its command-line arguments from
-/// an environment variable (whose name is given in ENVVAR).
-///
-void cl::ParseEnvironmentOptions(const char *progName, const char *envVar,
- const char *Overview) {
- // Check args.
- assert(progName && "Program name not specified");
- assert(envVar && "Environment variable name missing");
-
- // Get the environment variable they want us to parse options out of.
- llvm::Optional<std::string> envValue = sys::Process::GetEnv(StringRef(envVar));
- if (!envValue)
- return;
-
- // Get program's "name", which we wouldn't know without the caller
- // telling us.
- SmallVector<const char *, 20> newArgv;
- BumpPtrAllocator A;
- StringSaver Saver(A);
- newArgv.push_back(Saver.save(progName).data());
-
- // Parse the value of the environment variable into a "command line"
- // and hand it off to ParseCommandLineOptions().
- TokenizeGNUCommandLine(*envValue, Saver, newArgv);
- int newArgc = static_cast<int>(newArgv.size());
- ParseCommandLineOptions(newArgc, &newArgv[0], StringRef(Overview));
-}
-
bool cl::ParseCommandLineOptions(int argc, const char *const *argv,
StringRef Overview, raw_ostream *Errs,
const char *EnvVar,
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index e8c2cef18e367..be8217b109627 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -45,8 +45,6 @@ class TempEnvVar {
EXPECT_EQ(nullptr, old_value) << old_value;
#if HAVE_SETENV
setenv(name, value, true);
-#else
-# define SKIP_ENVIRONMENT_TESTS
#endif
}
@@ -137,36 +135,6 @@ TEST(CommandLineTest, ModifyExisitingOption) {
ASSERT_EQ(cl::Hidden, TestOption.getOptionHiddenFlag()) <<
"Failed to modify option's hidden flag.";
}
-#ifndef SKIP_ENVIRONMENT_TESTS
-
-const char test_env_var[] = "LLVM_TEST_COMMAND_LINE_FLAGS";
-
-cl::opt<std::string> EnvironmentTestOption("env-test-opt");
-TEST(CommandLineTest, ParseEnvironment) {
- TempEnvVar TEV(test_env_var, "-env-test-opt=hello");
- EXPECT_EQ("", EnvironmentTestOption);
- cl::ParseEnvironmentOptions("CommandLineTest", test_env_var);
- EXPECT_EQ("hello", EnvironmentTestOption);
-}
-
-// This test used to make valgrind complain
-// ("Conditional jump or move depends on uninitialised value(s)")
-//
-// Warning: Do not run any tests after this one that try to gain access to
-// registered command line options because this will likely result in a
-// SEGFAULT. This can occur because the cl::opt in the test below is declared
-// on the stack which will be destroyed after the test completes but the
-// command line system will still hold a pointer to a deallocated cl::Option.
-TEST(CommandLineTest, ParseEnvironmentToLocalVar) {
- // Put cl::opt on stack to check for proper initialization of fields.
- StackOption<std::string> EnvironmentTestOptionLocal("env-test-opt-local");
- TempEnvVar TEV(test_env_var, "-env-test-opt-local=hello-local");
- EXPECT_EQ("", EnvironmentTestOptionLocal);
- cl::ParseEnvironmentOptions("CommandLineTest", test_env_var);
- EXPECT_EQ("hello-local", EnvironmentTestOptionLocal);
-}
-
-#endif // SKIP_ENVIRONMENT_TESTS
TEST(CommandLineTest, UseOptionCategory) {
StackOption<int> TestOption2("test-option", cl::cat(TestCategory));
More information about the llvm-commits
mailing list