Advise requested - large namespace change and folder change strategy

192 views
Skip to first unread message

Dan Murphy

unread,
Nov 3, 2025, 4:33:01 PMNov 3
to Chromium-dev
Hey all,

We have long standing bugs to do the following:
- change all `web_app::` namespaces to `webapps::` namespaces
- change all `web_applications` folders to `webapps`.

This has always seemed pretty non-trivial and difficult. But - interested if others have had to do something similar in the past, and what that was like / what worked & didn't work.

I was thinking for the namespace change there could be a two-phase thing, where I could start by having all header files add a 'using webapps;' in the web_apps namespace, then do a change that modifies all of the namespaces (but not callers) and keep the `namespace web_app{ using webapps: }` code in each header, and then do a git-cl-split for the final change to update all callers?

Any nice way to do these in a git-cl-split compatible way? Or other ideas?

Dan

Dmitrii Kuragin

unread,
Nov 28, 2025, 10:16:11 PMNov 28
to dmu...@google.com, Chromium-dev
There `move_source_file.py` which allows to rename.move files and it has some documentation here: https://source.chromium.org/chromium/chromium/src/+/main:docs/ios/working_with_files.md;l=125?q=move_source_file

For the namespace renaming, you can utilize the compilation database generated via src/tools/clang/scripts/generate_compdb.py and `clang-change-namespace` which comes from LibTooling: https://clang.llvm.org/extra/clang-change-namespace.html

I think you can mix and match and get those 2 things done separately. If they end-up trivial refactorings without manual changes, it should be easier to get a global approval. Othersie, you can find the problematic places and fix them first, and submit the large-scale change as a single PR.

--
--
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 visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CA%2B4qT32OD6%2BrzP%3D4CMiWiKUfxEJOZY1%3DL4H-iV2QBChWFJRzCA%40mail.gmail.com.

Daniel Cheng

unread,
Nov 29, 2025, 12:44:16 AMNov 29
to kur...@chromium.org, dmu...@google.com, Chromium-dev
Introducing shims to allow both names to work is a good idea.

To actually update code to use the new namespace, you shouldn't need clang tooling. For simpler tasks, I have a script that runs ninja in a loop and uses regex to figure out what needs to be searched and replaced to fix the build. So in this case, it should be a simple matter of deleting the compatibility `using webapps;` statements and running the autofix script using the `apply_did_you_mean_fixes` helper that's already in the file.


It does mean you need to run the script across all build configurations that you care about: typically, that's Windows+Mac+Linux+Android+CrOS with DCHECKs on, potentially official builds as well, and occasionally, some of the more esoteric ChromeOS/Fuchsia/Android bots. But the script does a good job of getting you 99.9% of the way there, so just a few manual fixes are needed.

Daniel

Harald Alvestrand

unread,
Nov 29, 2025, 3:35:35 AMNov 29
to dmu...@google.com, Chromium-dev, Evan Shrubsole
Evan Shrubsole (CCed) completed a similar task for WebRTC a few months ago.
He might have some advice to give and some tools to share.



--

Dmitrii Kuragin

unread,
Nov 29, 2025, 12:46:46 PMNov 29
to h...@google.com, dmu...@google.com, Chromium-dev, Evan Shrubsole
As an option one can also replace all of 

namespace web_applications {

with

namespace web_applications = web_apps;  // TODO
namespace web_apps {

so, you fix it all within web apps folder and the rest of the code works well. Then, slowly replace it everywhere it is used. Yes, I think you can have alias before the actual declaration.

Nico Weber

unread,
Nov 29, 2025, 2:19:32 PMNov 29
to kur...@chromium.org, h...@google.com, dmu...@google.com, Chromium-dev, Evan Shrubsole
Since nobody mentioned it yet, there's also tools/git/mffr.py ("multi file find replace").

Dmitrii Kuragin

unread,
Dec 1, 2025, 9:38:02 AMDec 1
to Evan Shrubsole, Nico Weber, h...@google.com, dmu...@google.com, Chromium-dev
Did you push the code for the Clang transformer? There is directly for various clang-based LSCs in Chrime. Might be useful to have an example there.

WDYT?

I also want to mention a tool I’m exploring, which is developed by former Google folks who works on LSCs and the namespace renaming is a trivial job with that :) see BrontoSource: 

On Mon, Dec 1, 2025 at 12:20 AM Evan Shrubsole <es...@google.com> wrote:
Hello,

As mentioned I made a similar change in WebRTC this year - consolidating all declarations into 1 namespace, where there was previously 3.

There are some open source tools that are mentioned in this thread from Clang, ClangChangeNamespace which could be run across all of the files in the compdb, and then re-export the symbols to the old namespace somehow (either "using namespace" or aliasing all decls in the old namespace). The tricky part was changing usages of declarations referenced with the old namespace in a safe way since there are some gotchas (forward declarations, templates etc.). If you can do this all one-shot, one CL or small CL chain which moves symbols to the old namespace then this works fine.

For WebRTC earlier this year using some custom Clang AST transformers. This was because changes were made file-by-file and I needed to automate fixing old namespace specifiers. 

Feel free to reach out if you have any questions.

Cheers,
Evan
Reply all
Reply to author
Forward
0 new messages