PSA: Undefined Grit variables will cause build errors moving forward

147 views
Skip to first unread message

Demetrios Papadopoulos

unread,
Apr 27, 2022, 6:25:06 PM4/27/22
to Chromium-dev, rbpotter, ddo...@chromium.org
Hi chromium-dev,

What's changing?
Previously, undefined Grit variables in <if expr="..."> statements would silently be treated as False (see code here)

After this CL lands, undefined variables will cause a build error instead (also see crbug.com/1316544).

Why?
The previous behavior is fragile and has been the source of several bugs over time. Example types of bugs that were previously not caught at build time:
  • typos
  • confusion of GN and Grit variables which don't always match, for example is_mac (GN) vs is_macosx (Grit)
  • obsolete references to removed/renamed Grit variables
Example bugs that would have been caught at build time with the new checks: crbug.com/1317459crbug.com/1319668cl/3595220, cl/3600260

Example error (condensed)
[12492/32900] ACTION //chrome/browser:resources_grit(//build/toolchain/linux:clang_x64)
...
AssertionError: undefined Grit variable found: foo

As a follow-up, I plan to improve the error message to also mention the name of the file that contains the undefined variable, but that requires a bit of plumbing and I did not want to block the addition of the new check on it. The path to the failing target is already a good indication of where to look for the undefined variable.

I expect the new behavior to prevent <if expr>-related bugs from entering the codebase as well as save time that would previously be spent on debugging why a certain string/resource/piece-of-code is missing unexpectedly on a certain platform. Feel free to comment on the bug or here if you have any concerns or questions.

Thank you,
Demetrios

David Dorwin

unread,
Apr 27, 2022, 8:43:09 PM4/27/22
to dpa...@chromium.org, Chromium-dev, rbpotter
Thank you for taking the initiative to fix this and all the cases that were blocking it!

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAPUSrA3XRCdb0O-Y42LdFcJpEmkQa0Uhacn5hy5ZuJq2etVk-Q%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages