<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>280610</bug_id>
          
          <creation_ts>2024-09-30 04:32:35 -0700</creation_ts>
          <short_desc>[GLib] Centralize handling of environment variables</short_desc>
          <delta_ts>2024-09-30 05:21:05 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Platform</component>
          <version>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=192405</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Adrian Perez">aperez</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bugs-noreply</cc>
    
    <cc>cgarcia</cc>
    
    <cc>fujii</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2064200</commentid>
    <comment_count>0</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2024-09-30 04:32:35 -0700</bug_when>
    <thetext>In the GLib (WPE + GTK) ports we have a number of toggles and tweaks that may
be applied at runtime using environment variables. While mostly intended for
development, end-users are asked sometimes to use them for complementing bug
reports and/or trying workarounds for their issues.

Currently, each call site which makes use of an environment variable handles
reading the environment variable and parsing, resulting in code duplication
and lack of consistency, e.g. some locations will accept &quot;0&quot; and &quot;1&quot; as boolean
flags, others &quot;0&quot; and any non-zero value; and error-checking also varies wildly.

We would like to have a WTF::Environment (or similarly named) class defining
the base structure and common code used to get and parse environment variable
values. An additional YAML source file would describes which environment
variables are available, the types of the values they accept, what are their
default values if undefined (or cannot be parsed), and an optional short
description. Then, we would generate C++ code from the YAML file that adds
getter functions to the Environment class.

If the above sounds familiar, it&apos;s because the idea is inspired by how
“Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml” is used to
describe feature flags =)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2064209</commentid>
    <comment_count>1</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2024-09-30 05:03:52 -0700</bug_when>
    <thetext>I am aware of bug #192405 where there was been a previous attempt at
doing something similar. Contrary to that attempt, I&apos;d say we want to
have a smaller scope but approach things in a different way:

 - Cover only the GLib ports. Other ports may want to adopt the mechanism,
   but we would rather have something earlier and help out later

 - Only handle *getting* values from the environment. All of them
   would be read and parsed at once as soon the Environment instance
   is created, defaults applied, and warnings emitted on stderr for
   invalid values.

 - Avoid using strings and parsing on each callsite, whenever possible,
   solved by generating the accessors from the YAML description. This is
   one more reason to have the types declared in the YAML.   

 - Avoid each callsite having to handle the case where a variable
   is not defined in the environment. If a default value is declared
   in the YAML source, then use it as fallback (like in the example
   above):

     // Default value used if not present in the environment.
     bool useTimer = Environment::singleton().WEBKIT_FORCE_VBLANK_TIMER;

   If there is no default then the type is wrapped in std::optional, e.g.

     // No default value declared in the YAML description.
     if (auto address = Environment::singleton().WEBKIT_INSPECTOR_SERVER)
         WTF_ALWAYS_LOG(&quot;Env var was defined, value: &quot; &lt;&lt; *address);

 - Start porting over a few uses of [g_]getenv() to the new mechanism,
   and then incrementally port more code, instead of trying to solve all
   cases in one go.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2064210</commentid>
    <comment_count>2</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2024-09-30 05:11:50 -0700</bug_when>
    <thetext>Ah, and with the describe-in-YAML-then-generate we could also produce
documentation automatically, and have things like this page from the
old wiki always up-to-date:

   https://trac.webkit.org/wiki/EnvironmentVariables

;-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2064213</commentid>
    <comment_count>3</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2024-09-30 05:21:05 -0700</bug_when>
    <thetext>JSC has https://github.com/WebKit/WebKit/blob/main/Source/JavaScriptCore/runtime/OptionsList.h</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>