Bug 236240 - [Flatpak SDK] Add a wrapper for clangd
Summary: [Flatpak SDK] Add a wrapper for clangd
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Martin Robinson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-07 07:55 PST by Martin Robinson
Modified: 2022-02-20 04:34 PST (History)
3 users (show)

See Also:


Attachments
Patch (16.61 KB, patch)
2022-02-07 08:08 PST, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (16.10 KB, patch)
2022-02-08 04:56 PST, Martin Robinson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Robinson 2022-02-07 07:55:07 PST
A wrapper for clangd would make it easier to launch the clangd necessary for processing WebKit source code. The main issue is that the build relies on a sandboxed build directory and headers from the Flatpak SDK.
Comment 1 Martin Robinson 2022-02-07 08:08:36 PST
Created attachment 451101 [details]
Patch
Comment 2 Martin Robinson 2022-02-07 08:11:19 PST
The way to use this script is to set your IDE's clang binary path to <WebKitSourceDirectory>/Tools/flatpak/webkit-flatpak and then pass the --enable-config and --<platform> arguments. For instance, I have this working by installing coc and coc-clangd for vim and then the contents of my local coc configuration (":CocLocalConfig") are:

{
    "clangd.arguments": [
        "--enable-config",
        "--gtk"
    ],
    "clangd.path": "/home/martin/WebKit/Tools/flatpak/webkit-clangd"
}

The first indexing for this takes a while, but eventually you should have real-time compilation errors and completion.
Comment 3 Philippe Normand 2022-02-08 04:16:00 PST
Comment on attachment 451101 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=451101&action=review

> Tools/ChangeLog:32
> +2022-02-07  Martin Robinson  <mrobinson@webkit.org>
> +
> +        [Flatpak SDK] Add a wrapper for clangd
> +        https://bugs.webkit.org/show_bug.cgi?id=236240
> +
> +        Reviewed by NOBODY (OOPS!).
> +
> +        * flatpak/webkit-clangd: Added.

Double changelog!

> Tools/flatpak/flatpakutils.py:37
> +import toml

EWS chokes on this :(

> Tools/flatpak/webkit-clangd:20
> +import flatpakutils

What will call this script? Will it have the Tools/flatpak directory listed in PYTHONPATH?
Comment 4 Martin Robinson 2022-02-08 04:56:48 PST
Created attachment 451238 [details]
Patch
Comment 5 Martin Robinson 2022-02-08 04:58:57 PST
(In reply to Philippe Normand from comment #3)
> Comment on attachment 451101 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=451101&action=review
> 
> > Tools/ChangeLog:32
> > +2022-02-07  Martin Robinson  <mrobinson@webkit.org>
> > +
> > +        [Flatpak SDK] Add a wrapper for clangd
> > +        https://bugs.webkit.org/show_bug.cgi?id=236240
> > +
> > +        Reviewed by NOBODY (OOPS!).
> > +
> > +        * flatpak/webkit-clangd: Added.
> 
> Double changelog!

Whoops. Fixed.

> 
> > Tools/flatpak/flatpakutils.py:37
> > +import toml
> 
> EWS chokes on this :(

Ah, odd. I've fixed this. It's because these imports are from the webkitpy directory.

> > Tools/flatpak/webkit-clangd:20
> > +import flatpakutils
> 
> What will call this script? Will it have the Tools/flatpak directory listed
> in PYTHONPATH?

The way this generally works is that you set up your editor or IDE to start clangd. Both Visual Studio Code and Vim (via coc-clangd) have settings for this. The connection to clangd runs in the background via your editor and it provides real-time information like completions and compilation errors.
Comment 6 EWS 2022-02-09 08:00:12 PST
Committed r289470 (247013@main): <https://commits.webkit.org/247013@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 451238 [details].
Comment 7 Radar WebKit Bug Importer 2022-02-09 08:01:19 PST
<rdar://problem/88689997>
Comment 8 Philippe Normand 2022-02-20 04:06:54 PST
Comment on attachment 451238 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=451238&action=review

> Tools/flatpak/flatpakutils.py:595
> -            os.environ["FLATPAK_USER_DIR"] = FLATPAK_USER_DIR_PATH + ".Local"
> +            os.environ["FLATPAK_USER_DIR"] = os.path.join(FLATPAK_USER_DIR_PATH, ".Local")

This is not correct actually, an invalid path is computed:

>>> os.path.join("/foo/bar", ".bas")
'/foo/bar/.bas'

I'll submit a follow-up patch.