Ok, thanks! I'm not dealing with UTF-8 so I don't think Process::GetEnv will work. I was looking for something that caches calls to getenv so checks could be put into tight(-ish) loops without too much performance impact. Would such a utility be of interest to the community? -David Reid Kleckner via llvm-dev <llvm-dev at lists.llvm.org> writes:> llvm::Process::GetEnv looks like it does the right thing. > > I think we added it to deal with Unicode on Windows, though. We have > plenty of calls to getenv that are mostly looking for '1', '0', or > variable presence, and they pretty much work. > > On Wed, Sep 5, 2018 at 2:12 PM David Greene via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > Is there an LLVM-ish way to handle environment variables? > Specifically, > I want to check existence and/or value of an environment variable > and > take appropriate action. > > I was kind of surprised that LLVM doesn't seem to have any > special/optimized way to deal with environment variables. The one > Stackoverflow I found on it suggested using getenv(). > > Thanks! > > -David > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> On Sep 6, 2018, at 7:09 AM, David Greene via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Ok, thanks! I'm not dealing with UTF-8 so I don't think Process::GetEnv > will work. I was looking for something that caches calls to getenv so > checks could be put into tight(-ish) loops without too much performance > impact.Sorry for the snarky answer but we already have that: // outside of loop bool enableFooBar = getenv("ENABLE_FOO_BAR"); while (...) { // it's not getting re-checked every loop iteration: enableFooBar; } Generally we don't really look at env vars today (I think for clang you can mostly affect some search paths with them) and IMO it is a good thing to force being explicit on the command line instead... - Matthias> > -David > > Reid Kleckner via llvm-dev <llvm-dev at lists.llvm.org> writes: > >> llvm::Process::GetEnv looks like it does the right thing. >> >> I think we added it to deal with Unicode on Windows, though. We have >> plenty of calls to getenv that are mostly looking for '1', '0', or >> variable presence, and they pretty much work. >> >> On Wed, Sep 5, 2018 at 2:12 PM David Greene via llvm-dev >> <llvm-dev at lists.llvm.org> wrote: >> >> Is there an LLVM-ish way to handle environment variables? >> Specifically, >> I want to check existence and/or value of an environment variable >> and >> take appropriate action. >> >> I was kind of surprised that LLVM doesn't seem to have any >> special/optimized way to deal with environment variables. The one >> Stackoverflow I found on it suggested using getenv(). >> >> Thanks! >> >> -David >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Yes, but in your example getenv is called every time enableFooBar needs to be initialized. What if your code is itself wrapped inside another loop you can't see (for example, the PassManager invoking passes)? Maybe I'm being overly pedantic. We use a lot of environment variables in our compiler because it's really super annoying and takes a lot of developer time to have to update customer Makefiles to include the debugging options we want to use to debug customer problems. These are huge customer codes with often many Makefiles which may be generated by custom tools we don't understand at all. :) It's much easier to use the compiler flags that are in the Makefiles and set some environment variables to override things during "make." It seems odd that cl::ParseEnvironmentOptions exists but there is no "official" way to get at environment variables. If this isn't something the community wants or needs, that's fine. I was just asking if a contribution would be welcomed if we end up developing something. -David Matthias Braun <mbraun at apple.com> writes:>> On Sep 6, 2018, at 7:09 AM, David Greene via llvm-dev <llvm-dev at lists.llvm.org> wrote: >> >> Ok, thanks! I'm not dealing with UTF-8 so I don't think Process::GetEnv >> will work. I was looking for something that caches calls to getenv so >> checks could be put into tight(-ish) loops without too much performance >> impact. > > Sorry for the snarky answer but we already have that: > > // outside of loop > bool enableFooBar = getenv("ENABLE_FOO_BAR"); > while (...) { > // it's not getting re-checked every loop iteration: > enableFooBar; > } > > Generally we don't really look at env vars today (I think for clang > you can mostly affect some search paths with them) and IMO it is a > good thing to force being explicit on the command line instead... > > - Matthias > >> >> -David >> >> Reid Kleckner via llvm-dev <llvm-dev at lists.llvm.org> writes: >> >>> llvm::Process::GetEnv looks like it does the right thing. >>> >>> I think we added it to deal with Unicode on Windows, though. We have >>> plenty of calls to getenv that are mostly looking for '1', '0', or >>> variable presence, and they pretty much work. >>> >>> On Wed, Sep 5, 2018 at 2:12 PM David Greene via llvm-dev >>> <llvm-dev at lists.llvm.org> wrote: >>> >>> Is there an LLVM-ish way to handle environment variables? >>> Specifically, >>> I want to check existence and/or value of an environment variable >>> and >>> take appropriate action. >>> >>> I was kind of surprised that LLVM doesn't seem to have any >>> special/optimized way to deal with environment variables. The one >>> Stackoverflow I found on it suggested using getenv(). >>> >>> Thanks! >>> >>> -David >>> _______________________________________________ >>> LLVM Developers mailing list >>> llvm-dev at lists.llvm.org >>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>> >>> _______________________________________________ >>> LLVM Developers mailing list >>> llvm-dev at lists.llvm.org >>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev