What's the best way to add non-source files to a GN project and make them visible in IDEs?

34 views
Skip to first unread message

BogDan Vatra

unread,
Apr 4, 2026, 10:39:18 AM (11 days ago) Apr 4
to gn-dev
Hi,

I added GN support to QtCreator (https://codereview.qt-project.org/c/qt-creator/qt-creator/+/723530) (by [ab]using `gn gen --ide=json`) .
It's almost perfect, the only major thing that is missing now is a way to add non-source files to a target .

My first instinct was to use `group` like :
```
group("docs") {
 source= [ "README.md"]
}
```
But GN refuse to work: `BUILD.gn:2: error: ERROR at //BUILD.gn:2:10: Assignment had no effect.` Then I stumbled on this https://groups.google.com/a/chromium.org/g/gn-dev/c/6AlH5x-Hzrs which complains about group source/input.

The gemini suggested this:
```
group("docs") { 
 data = [ "README.md"] 
}
```
But the `data` files list is present in the `project.json`....

So what's the correct way to add non-source files to a GN project?

Takuto Ikuta (生田 拓人)

unread,
Apr 6, 2026, 2:56:19 AM (9 days ago) Apr 6
to BogDan Vatra, gn-dev
Hi BogDan,

GN manages build dependencies, but does any build action depend on README.md?
If so, it's better to use the inputs or sources variable with an action. Otherwise, you don't need to write any files in the project in BUILD.gn.

Thanks,
Takuto

To unsubscribe from this group and stop receiving emails from it, send an email to gn-dev+un...@chromium.org.


--
Takuto Ikuta
Software Engineer in Tokyo
Chrome Ops (chrome browser build team)

BogDan Vatra

unread,
Apr 6, 2026, 3:28:50 AM (9 days ago) Apr 6
to Takuto Ikuta (生田 拓人), gn-dev
Hi,

No, README.md is a simple file that doesn't affect the build at all. But I really like to have it visible in my IDE to be able to quickly open it.
Most of the build systems out there have this functionality...
QtCreator doesn't add all the files from your project to the Project Tree (which IMHO is a really nice feature as it keeps the tree cleaner), only those that are explicitly added to your build system files, that's why adding arbitrary files to a group will be a nice to have feature.

Thanks,
BogDan.

Takuto Ikuta (生田 拓人)

unread,
Apr 6, 2026, 4:13:42 AM (9 days ago) Apr 6
to BogDan Vatra, gn-dev
Hi,

I don't know much about QtCreator, but I think other IDEs use Git to manage files under a repository as project files?
Other than that, I think the current GN lacks a feature to add arbitrary files in the JSON file for IDEs.

Dirk Pranke

unread,
Apr 6, 2026, 4:17:05 PM (9 days ago) Apr 6
to BogDan Vatra, gn-dev, Takuto Ikuta (生田 拓人)
The way I would expect this to work, you would declare your files as `data = ["README.md"]` either as part of another target or as a standalone target, e.g.:

    group("files") {
      data = [ "README.md" ]
    }

If I do that, and then run `gn desc //out //:files runtime_deps`, it will output "../README.md" (as I'd expect).

Annoyingly, however, if I run `gn gen --ide=json`, the README.md file is not included. And, if I declare a dependency on the target with `data_deps=["files"]` in some other target, it looks like `data_deps` are being merged into the regular `deps` in the JSON file.

The first thing is not entirely surprising to me; we've never made a concerted effort to ensure that the JSON file contains everything. However, it should, so this is just an enhancement request and it should be an easy fix if anyone wants to make it. If no one volunteers, I can probably do it soonish.

The second thing (data_deps being merged) seems like a bug to me, but maybe there's a reason for it that someone else knows?

-- Dirk

Aaron Wood

unread,
Apr 6, 2026, 4:27:35 PM (9 days ago) Apr 6
to Dirk Pranke, BogDan Vatra, gn-dev, Takuto Ikuta (生田 拓人)
One thing I did in the Fuchsia build (albeir for another issue), was to create a "group_with_inputs()" template, which just ran `touch ${outputs[0]}", and then could take inputs/sources as well as all the deps list variations.  I used this to ensure that lists of files we were passing into other contexts were valid outputs created by the stated dependencies, or were source files.

BogDan Vatra

unread,
Apr 14, 2026, 1:10:56 AM (yesterday) Apr 14
to gn-dev, aaro...@google.com, BogDan Vatra, gn-dev, tik...@google.com, dpr...@chromium.org
Hi,

What's the conclusion? :)
Shall I create a patch that exposes the `data` property of a `group` target to `project.json`?

Or is better to have a dedicated "target" for this kind of things i.e.:
```
data("docs") {
  sources = [ "README.md"] 
}
```

BogDan.

Takuto Ikuta (生田 拓人)

unread,
Apr 14, 2026, 2:20:56 AM (yesterday) Apr 14
to BogDan Vatra, gn-dev, aaro...@google.com, dpr...@chromium.org
On Tue, Apr 14, 2026 at 2:10 PM BogDan Vatra <taipan...@gmail.com> wrote:
Hi,

What's the conclusion? :)
Shall I create a patch that exposes the `data` property of a `group` target to `project.json`?


OK, I can review the patch if you made that works for the project.json.

BogDan Vatra

unread,
Apr 14, 2026, 2:48:40 AM (yesterday) Apr 14
to gn-dev, tik...@google.com, gn-dev, aaro...@google.com, dpr...@chromium.org, BogDan Vatra
Hi,

Adding data is it's a super easy 3 LOC fix :)

```
diff --git a/src/gn/desc_builder.cc b/src/gn/desc_builder.cc
index 8c6d897e..1823520d 100644
--- a/src/gn/desc_builder.cc
+++ b/src/gn/desc_builder.cc
@@ -391,6 +391,10 @@ class TargetDescBuilder : public BaseDescBuilder {
      }
    }
 
+    if (what(variables::kData) && !target_->data().empty())
+      res->SetWithoutPathExpansion(variables::kData,
+                                   RenderValue(target_->data()));
+
    if (what(variables::kSources) && !target_->sources().empty())
      res->SetWithoutPathExpansion(variables::kSources,
                                   RenderValue(target_->sources()));


```

Pretty please can you create the patch & push it for me?

Cheers,
BogDan.

BogDan Vatra

unread,
Apr 14, 2026, 4:02:07 AM (yesterday) Apr 14
to gn-dev, BogDan Vatra, tik...@google.com, gn-dev, aaro...@google.com, dpr...@chromium.org
Reply all
Reply to author
Forward
0 new messages