intel: Convert getenv() to os_get_option()
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

os_get_option() is a wrapper for getenv() that checks properties in
Android. It should be a no-op for other OS but will allow full use of
env vars in Android.

The environment variable names are automatically renamed by
os_get_option() and the order of precedence thus becomes:

1. getenv (non-Android)
2. debug.mesa.* (Android)
3. vendor.mesa.* (Android)
4. mesa.* (Android, as a fallback for older versions)

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37587>
This commit is contained in:
Tim Van Patten 2025-09-25 15:15:24 -06:00
parent 75292ae7e4
commit f90e0f0797
21 changed files with 31 additions and 30 deletions

View file

@ -57,7 +57,7 @@ void
intel_measure_init(struct intel_measure_device *device)
{
static bool once = false;
const char *env = getenv("INTEL_MEASURE");
const char *env = os_get_option("INTEL_MEASURE");
if (unlikely(!once)) {
once = true;
memset(&config, 0, sizeof(struct intel_measure_config));

View file

@ -409,7 +409,7 @@ void elk_dump_shader_bin(void *assembly, int start_offset, int end_offset,
bool elk_try_override_assembly(struct elk_codegen *p, int start_offset,
const char *identifier)
{
const char *read_path = getenv("INTEL_SHADER_ASM_READ_PATH");
const char *read_path = os_get_option("INTEL_SHADER_ASM_READ_PATH");
if (!read_path) {
return false;
}

View file

@ -94,7 +94,7 @@ INSTANTIATE_TEST_SUITE_P(
static bool
validate(struct elk_codegen *p)
{
const bool print = getenv("TEST_DEBUG");
const bool print = os_get_option("TEST_DEBUG");
struct elk_disasm_info *disasm = elk_disasm_initialize(p->isa, NULL);
if (print) {

View file

@ -110,7 +110,7 @@ instruction(elk_bblock_t *block, int num)
static bool
cmod_propagation(elk_fs_visitor *v)
{
const bool print = getenv("TEST_DEBUG");
const bool print = os_get_option("TEST_DEBUG");
if (print) {
fprintf(stderr, "= Before =\n");

View file

@ -48,7 +48,7 @@ struct FSCombineConstantsTest : public ::testing::Test {
elk_fs_visitor *shader;
bool opt_combine_constants(elk_fs_visitor *s) {
const bool print = getenv("TEST_DEBUG");
const bool print = os_get_option("TEST_DEBUG");
if (print) {
fprintf(stderr, "= Before =\n");

View file

@ -99,7 +99,7 @@ instruction(elk_bblock_t *block, int num)
static bool
copy_propagation(elk_fs_visitor *v)
{
const bool print = getenv("TEST_DEBUG");
const bool print = os_get_option("TEST_DEBUG");
if (print) {
fprintf(stderr, "= Before =\n");

View file

@ -32,7 +32,7 @@ public:
void
PredicatedBreakTest::SetUp()
{
debug = getenv("TEST_DEBUG");
debug = os_get_option("TEST_DEBUG");
mem_ctx = ralloc_context(NULL);
@ -69,7 +69,7 @@ PredicatedBreakTest::TearDown()
bool
PredicatedBreakTest::elk_opt_predicated_break(elk_fs_visitor *s)
{
const bool print = getenv("TEST_DEBUG");
const bool print = os_get_option("TEST_DEBUG");
if (print) {
fprintf(stderr, "= Before =\n");

View file

@ -137,7 +137,7 @@ instruction(elk_bblock_t *block, int num)
static bool
cmod_propagation(vec4_visitor *v)
{
const bool print = getenv("TEST_DEBUG");
const bool print = os_get_option("TEST_DEBUG");
if (print) {
fprintf(stderr, "= Before =\n");

View file

@ -118,7 +118,7 @@ void copy_propagation_vec4_test::TearDown()
static void
copy_propagation(vec4_visitor *v)
{
const bool print = getenv("TEST_DEBUG");
const bool print = os_get_option("TEST_DEBUG");
if (print) {
fprintf(stderr, "instructions before:\n");

View file

@ -117,7 +117,7 @@ void dead_code_eliminate_vec4_test::TearDown()
static void
dead_code_eliminate(vec4_visitor *v)
{
const bool print = getenv("TEST_DEBUG");
const bool print = os_get_option("TEST_DEBUG");
if (print) {
fprintf(stderr, "instructions before:\n");

View file

@ -121,7 +121,7 @@ void register_coalesce_vec4_test::TearDown()
static void
_register_coalesce(vec4_visitor *v, const char *func)
{
const bool print = getenv("TEST_DEBUG");
const bool print = os_get_option("TEST_DEBUG");
if (print) {
printf("%s: instructions before:\n", func);

View file

@ -107,7 +107,7 @@ INSTANTIATE_TEST_SUITE_P(
static bool
validate(struct brw_codegen *p, char **error = nullptr)
{
const bool print = getenv("TEST_DEBUG");
const bool print = os_get_option("TEST_DEBUG");
struct disasm_info *disasm = disasm_initialize(p->isa, NULL);
struct inst_group *group = disasm_new_inst_group(disasm, 0);

View file

@ -43,7 +43,7 @@ EXPECT_PROGRESS_RESULT(bool should_progress, PASS pass, brw_shader *s)
brw_validate(*s);
if (progress != should_progress || getenv("TEST_DEBUG")) {
if (progress != should_progress || os_get_option("TEST_DEBUG")) {
fprintf(stderr, "= Before =\n"
"%s\n"
"\n"

View file

@ -61,7 +61,7 @@ intel_batch_decode_ctx_init(struct intel_batch_decode_ctx *ctx,
ctx->get_state_size = get_state_size;
ctx->user_data = user_data;
ctx->fp = fp;
ctx->flags = parse_enable_string(getenv("INTEL_DECODE"), flags, debug_control);
ctx->flags = parse_enable_string(os_get_option("INTEL_DECODE"), flags, debug_control);
ctx->max_vbo_decoded_lines = -1; /* No limit! */
ctx->engine = INTEL_ENGINE_CLASS_RENDER;
@ -75,7 +75,7 @@ intel_batch_decode_ctx_init(struct intel_batch_decode_ctx *ctx,
ctx->stats =
_mesa_hash_table_create(NULL, _mesa_hash_string, _mesa_key_string_equal);
const char *filters = getenv("INTEL_DECODE_FILTERS");
const char *filters = os_get_option("INTEL_DECODE_FILTERS");
if (filters != NULL) {
ctx->filters =
_mesa_hash_table_create(NULL, _mesa_hash_string, _mesa_key_string_equal);

View file

@ -254,9 +254,9 @@ static void
process_intel_debug_variable_once(void)
{
BITSET_ZERO(intel_debug);
parse_debug_bitset(getenv("INTEL_DEBUG"), debug_control);
parse_debug_bitset(os_get_option("INTEL_DEBUG"), debug_control);
intel_simd = parse_debug_string(getenv("INTEL_SIMD_DEBUG"), simd_control);
intel_simd = parse_debug_string(os_get_option("INTEL_SIMD_DEBUG"), simd_control);
intel_debug_batch_frame_start =
debug_get_num_option("INTEL_DEBUG_BATCH_FRAME_START", 0);
intel_debug_batch_frame_stop =

View file

@ -1441,7 +1441,7 @@ scan_for_force_probe(int pci_id, bool *force_on, bool *force_off)
*force_on = false;
*force_off = false;
const char *env = getenv("INTEL_FORCE_PROBE");
const char *env = os_get_option("INTEL_FORCE_PROBE");
if (env == NULL)
return;
@ -1860,7 +1860,7 @@ intel_device_info_update_after_hwconfig(struct intel_device_info *devinfo)
bool
intel_get_device_info_from_fd(int fd, struct intel_device_info *devinfo, int min_ver, int max_ver)
{
if (NULL != getenv("INTEL_STUB_GPU_JSON")) {
if (NULL != os_get_option("INTEL_STUB_GPU_JSON")) {
/* This call will succeed when shim-drm has been initialized with a
* serialized intel_device_info structure.
*/

View file

@ -77,7 +77,7 @@ bool IntelDriver::init_perfcnt()
perf = std::make_unique<IntelPerf>(drm_device.fd);
const char *metric_set_name = getenv("INTEL_PERFETTO_METRIC_SET");
const char *metric_set_name = os_get_option("INTEL_PERFETTO_METRIC_SET");
struct intel_perf_query_info *default_query = nullptr;
selected_query = nullptr;

View file

@ -208,7 +208,7 @@ isl_drm_modifier_get_score(const struct intel_device_info *devinfo,
* and don't want to provide a default value either, so we don't
* use debug_get_num_option() here.
*/
const char *mod_str = getenv("INTEL_MODIFIER_OVERRIDE");
const char *mod_str = os_get_option("INTEL_MODIFIER_OVERRIDE");
if (mod_str != NULL) {
return modifier == strtoul(mod_str, NULL, 0);
}

View file

@ -14,6 +14,7 @@
#include <unistd.h>
#include "util/os_file.h"
#include "util/os_misc.h"
#include "util/ralloc.h"
#include "util/u_dynarray.h"
@ -126,7 +127,7 @@ diff(context *ctx, slice a, slice b)
fclose(file_a.f);
fclose(file_b.f);
const char *diff_cmd = getenv("MDA_DIFF_COMMAND");
const char *diff_cmd = os_get_option("MDA_DIFF_COMMAND");
if (!diff_cmd) {
if (ctx->diff.mode == DIFF_UNIFIED) {
diff_cmd = ralloc_asprintf(mem_ctx, "git diff --no-index --color-words -U%d -- %%s %%s | tail -n +5", ctx->diff.param);
@ -1092,10 +1093,10 @@ static pid_t
setup_pager()
{
if (!isatty(STDOUT_FILENO) ||
getenv("NO_PAGER"))
os_get_option("NO_PAGER"))
return 0;
const char *term = getenv("TERM");
const char *term = os_get_option("TERM");
if (!term || !strcmp(term, "dumb"))
return 0;
@ -1119,7 +1120,7 @@ setup_pager()
dup2(pipefd[0], STDIN_FILENO);
close(pipefd[0]);
const char *pager = getenv("PAGER");
const char *pager = os_get_option("PAGER");
if (pager && *pager)
execlp(pager, pager, NULL);

View file

@ -428,7 +428,7 @@ maybe_init(int fd)
initialized = true;
const char *config_path = getenv("INTEL_DUMP_GPU_CONFIG");
const char *config_path = os_get_option("INTEL_DUMP_GPU_CONFIG");
fail_if(config_path == NULL, "INTEL_DUMP_GPU_CONFIG is not set\n");
config = fopen(config_path, "r");

View file

@ -557,20 +557,20 @@ void
drm_shim_driver_init(void)
{
i915.device_id = 0;
const char *json_dev_str = getenv("INTEL_STUB_GPU_JSON");
const char *json_dev_str = os_get_option("INTEL_STUB_GPU_JSON");
if (json_dev_str != NULL) {
if (!intel_device_info_from_json(json_dev_str, &i915.devinfo))
return;
i915.device_id = i915.devinfo.pci_device_id;
i915_device_from_json = true;
} else {
const char *device_id_str = getenv("INTEL_STUB_GPU_DEVICE_ID");
const char *device_id_str = os_get_option("INTEL_STUB_GPU_DEVICE_ID");
if (device_id_str != NULL) {
/* Set as 0 if strtoul fails */
i915.device_id = strtoul(device_id_str, NULL, 16);
}
if (i915.device_id == 0) {
const char *user_platform = getenv("INTEL_STUB_GPU_PLATFORM");
const char *user_platform = os_get_option("INTEL_STUB_GPU_PLATFORM");
/* Use SKL if nothing is specified. */
i915.device_id = intel_device_name_to_pci_device_id(user_platform ?: "skl");
}