Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

gn public/sources does not have the intended effect?

80 views
Skip to first unread message

Erik Chen

unread,
May 31, 2024, 2:44:08 PM5/31/24
to gn-dev
I wanted to use gn public/sources to separate between the public interface for a "feature", and the private interface (only used by tests). However, public/sources does not distinguish between test targets and production targets. Thus I end up with the following situation:

// This does not work because the unit test for foo_impl.h cannot depend on foo_impl.h

target (foo) {
public = [ foo.h ]
sources = [foo.cc, foo_impl.h, foo_impl.cc]
}

// This works, but the public/sources distinction is not useful since it's just .h vs .cc files, and including .cc files is already disallowed by style.

target (foo_public) {
  public = [foo.h]
  sources = [foo.cc]
  deps = [:foo_impl]
}
target (foo_impl) {
  public = [foo_impl.h]
  sources = [foo_impl.cc]
}

Brett Wilson

unread,
May 31, 2024, 3:13:46 PM5/31/24
to Erik Chen, gn-dev
Did you see the "friend" tag? You can list other targets that can use your private files which might help with your test.

Brett

Erik Chen

unread,
May 31, 2024, 6:07:07 PM5/31/24
to Brett Wilson, gn-dev
Perfect! This is exactly what I was looking for. Thanks :)
Reply all
Reply to author
Forward
0 new messages