This is an archive of the discontinued LLVM Phabricator instance.

[clang] [Driver] Disable default configs via envvar during testing
ClosedPublic

Authored by mgorny on Sep 29 2022, 1:47 PM.

Details

Summary

Add support for a CLANG_NO_DEFAULT_CONFIG envvar that works like
the --no-default-config option when set to a non-empty value. Use it
to disable loading system configuration files during the test suite
runs.

Configuration files can change the driver behavior in extensive ways,
and it is neither really possible nor feasible to account for or undo
the effects of even the most common configuration uses. Therefore,
the most reasonable option seems to be to ignore configuration files
while running the majority of tests (with the notable exception of tests
for configuration file support).

Due to the diversity of ways that %clang is used in the test suite,
including using it to copy or symlink the clang executable, as well to
call -cc1 and -cc1as modes, it is not feasible to pass the explicit
options to disable config loading either. Using an environment variable
has the advantage of being easily applied across the test suite
and easily unset for default configuration file loading tests.

Diff Detail

Event Timeline

mgorny created this revision.Sep 29 2022, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 29 2022, 1:47 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
mgorny requested review of this revision.Sep 29 2022, 1:47 PM

I'm not sure if we should be documenting this in the user manual, or if it should be considered an internal-use envvar.

The concept LGTM.

clang/lib/Driver/Driver.cpp
1073

Looking at LLDB_LAUNCH_FLAG_DISABLE_ASLR/LIBCLANG_DISABLE_PCH_VALIDATION, they don't check whether the value is non-empty.

mgorny added inline comments.Sep 29 2022, 11:08 PM
clang/lib/Driver/Driver.cpp
1073

Well, my personal experience tells me that it's sometimes non-trivial to unset var while setting it to empty value is easier, e.g.:

# undo global
CLANG_NO_DEFAULT_CONFIG= clang ...
# vs. env -u (not in POSIX)
env -u CLANG_NO_DEFAULT_CONFIG ...
MaskRay accepted this revision.Sep 29 2022, 11:09 PM
This revision is now accepted and ready to land.Sep 29 2022, 11:09 PM

during testing

This part of the subject is probably not needed. I think exposing the idea to user can probably be useful, too.

during testing

This part of the subject is probably not needed. I think exposing the idea to user can probably be useful, too.

Sure but the larger part of the commit is actually about disabling them in the test suite ;-).

Thanks for all the reviews.

A more flexible way is to implement support for environment variable like CL and _CL (https://learn.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=msvc-170 ). They could be used to deliver --no-default-config and would have wide usage than just this one.

MaskRay requested changes to this revision.Sep 29 2022, 11:38 PM

Wait. The effect can be achieved today with CCC_OVERRIDE_OPTIONS=+--no-default-config

This revision now requires changes to proceed.Sep 29 2022, 11:38 PM
MaskRay accepted this revision.Sep 29 2022, 11:39 PM

But CCC_OVERRIDE_OPTIONS=+--no-default-config leaves an annoying notice, so I guess introducing a new environment variable is still fine.

This revision is now accepted and ready to land.Sep 29 2022, 11:39 PM
This revision was landed with ongoing or failed builds.Sep 30 2022, 12:12 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 30 2022, 12:12 AM