New issue
Advanced search Search tips

Issue 662732 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Nov 2016
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 2
Type: Bug



Sign in to add a comment

gn: compiling one file in a target depending on bundle causes building the entire bundle

Reported by alshaba...@yandex-team.ru, Nov 6 2016

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14

Steps to reproduce the problem:
Using an example from tools/gn/example. Add

bundle_data("hello_bundle_data") {
  sources = [
    "$target_out_dir/../libhello_shared.so",
  ]
  outputs = [
    "{{bundle_executable_dir}}/hello_bundle",
  ]
  public_deps = [
    ":hello_shared",
  ]
}

create_bundle("hello_bundle") {
  public_deps = [
    ":hello_bundle_data",
  ]
}

executable("hello_depending_on_bundle") {
  sources = [
    "hello.cc",
  ]

  deps = [
    ":hello_bundle",
  ]
}

to root BUILD.gn. And add (taken from Chromium's build/toolchain/mac/BUILD.gn)

  tool("copy_bundle_data") {
    copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
    _copydir = "mkdir -p {{output}} && cd {{source}} && " +
               "pax -rwl . \"\$OLDPWD\"/{{output}}"
    command = "rm -rf {{output}} && if [[ -d {{source}} ]]; then " +
              _copydir + "; else " + copy_command + "; fi"

    description = "COPY_BUNDLE_DATA {{source}} {{output}}"
  }
  tool("compile_xcassets") {
    command = "xcrun actool --compile {{output}} {{inputs}}"

    description = "COMPILE_XCASSETS {{output}}"
  }

to toolchain/BUILD.gn.

Now, trying to compile hello.o from target hello:
> ninja -C out -t commands obj/hello.hello.o
g++ -MMD -MF obj/hello.hello.o.d     -c ../hello.cc -o obj/hello.hello.o

But compiling from target hello_depending_on_bundle:
> ninja -C out -t commands obj/hello_depending_on_bundle.hello.o
g++ -MMD -MF obj/libhello_shared.hello_shared.o.d -DHELLO_SHARED_IMPLEMENTATION    -c ../hello_shared.cc -o obj/libhello_shared.hello_shared.o
g++ -shared  -o ./libhello_shared.so -Wl,-soname=libhello_shared.so @libhello_shared.so.rsp
rm -rf ../../../../../../../hello_bundle && if [[ -d libhello_shared.so ]]; then mkdir -p ../../../../../../../hello_bundle && cd libhello_shared.so && pax -rwl . "$OLDPWD"/../../../../../../../hello_bundle; else ln -f libhello_shared.so ../../../../../../../hello_bundle 2>/dev/null || (rm -rf ../../../../../../../hello_bundle && cp -af libhello_shared.so ../../../../../../../hello_bundle); fi
touch obj/hello_bundle.stamp
g++ -MMD -MF obj/hello_depending_on_bundle.hello.o.d     -c ../hello.cc -o obj/hello_depending_on_bundle.hello.o

So, before compiling a single file, it builds a bundle, as opposed to the previous example where it doesn't build either library to compile a file.

This example is derived from real life: in Chromium targets unit_tests, browser_tests, interactive_ui_tests depend on Chromium Framework bundle. So, if you want to compile a single *_unittest.cc file, you'll need to wait for the entire Chromium Framework to get built.

What is the expected behavior?

What went wrong?
Compiling a file from a target depending on bundle causes bundle to get build.

Did this work before? N/A 

Chrome version:   Channel: n/a
OS Version: OS X 10.12.1
Flash Version: Shockwave Flash 23.0 r0
 
Labels: TE-NeedsTriageHelp
Components: Build
Labels: Build-Tools-GN
Owner: rsesek@chromium.org
Status: Assigned (was: Unconfirmed)
Assigning to rsesek@ to comment.
You're telling GN that in order to build hello.cc, :hello_bundle needs to be built first. GN/Ninja is doing exactly what it's told.

There's no (easy) way in what you've structured for GN to know that :hello_bundle is needed at link time but not at compile time.

If you wanted to avoid this, one way would be to move the stuff that didn't actually depend on :hello_bundle to a different target (like a :hello_sources source_set).

Owner: ----
Status: WontFix (was: Assigned)
i.e., this is working as expected. Feel free to reopen if you have other questions or comments.
I see, thanks! But just to be clear: hello.o from :hello depends on :hello_shared and it isn't built when compiling hello.o. So, for shared libraries GN knows that it's a link time dependency only?
Correct. 

I've made some notes to try and update the docs so that things are clearer.

Sign in to add a comment