Skip to content

Commit

Permalink
[Support][CommandLine] Delete unused llvm::cl::ParseEnvrironmentOptions
Browse files Browse the repository at this point in the history
The function was added in 2003. It is not used and can be emulated with ParseCommandLineOptions.
  • Loading branch information
MaskRay committed Jul 31, 2020
1 parent 93fd8db commit c068e9c
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 92 deletions.
23 changes: 0 additions & 23 deletions llvm/docs/CommandLine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 different from what you
would get from the shell with the same input.

The ``cl::SetVersionPrinter`` function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
7 changes: 0 additions & 7 deletions llvm/include/llvm/Support/CommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &)>;

Expand Down
30 changes: 0 additions & 30 deletions llvm/lib/Support/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 0 additions & 32 deletions llvm/unittests/Support/CommandLineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit c068e9c

Please sign in to comment.