We've talked about changing this several times.I did it this way originally because that's what I thought GYP did. It turns out GYP seems to do this because many of the root targets list wildcards deps (GN doesn't support these) like 'content/content.gyp:*' that effectively brings in all targets into the build whether you reference them in the dependency tree or not. The result is that I think people expect to be able to write random tests or helper targets and have them appear as possible things to run Ninja with.GN now has several ways to control this. GN generates a target called "all" where if you want to build everything GN saw in the build (in the default toolchain) Ninja will build that. It has a separate concept of the default target where if you make a target called "//:default" it will mark that as the default target in Ninja so when you build with no explicit target that set of stuff will get built. The Chrome build does not set a default target, so the automatically-produced "all" target becomes the default.We could make a default target and get the behavior you want, but "all" would still exist and refer to everything, and it would be broken. I think the "all" target actually matches the GYP behavior. If you do "ninja all" in a GYP target, I suspect you'll get similar errors (Dirk can probably confirm, I think he implemented GN's current "all" behavior). I think the ability to write a target and being able to build it (as long as GN knows about that file) is generally what people on our team expect so I would personally prefer not to change it.There's a separate question about whether we should add a default target that's more like what you want. I'm not convinced. It's confusing to have a target be broken in the "all" build. In GYP I believe there are a bunch of bitrotted targets that are never compiled because we never build it's version of "all" on any bot (I think, Dirk may have to correct me).
This also masks some other problems. In the "jpeg" problematic patch you linked, there is only one target in that BUILD file (there are two configs there too, but they seem to be only referenced by that target). Theoretically this file should never get loaded in an iOS build. So somebody is referring to jpeg, probably a target somewhere else that shouldn't be compiled on iOS, etc. This suggests there are large portions of the build being brought in inappropriately on iOS.I think this is actually the important bit here. When we're loading build files inappropriately on some platforms, we should just stop doing that rather than trying to define default targets such that those targets are no-ops.When a file is inappropriate on iOS (or any other platform) we should addassert(!is_ios)at the top. Now it's clear to people editing the file that this isn't an iOS thing, and also tells people immediately when they screw up and bring a file in that shouldn't. When there is a file with some targets that are appropriate for iOS, and some targets that aren't, we should wrap those in conditionals that clearly document the platforms they're appropriate for. Now it's also clear which parts of the file refer to a given platform.The property that the current setup forces us to do this seems to be a benefit rather than a bug, and I don't think we should be wallpapering over targets that don't compile on some platforms: If it's not obvious to GN, it's not obvious to people editing the file either).
On Sun, Apr 17, 2016 at 1:19 PM, Brett Wilson <bre...@chromium.org> wrote:We've talked about changing this several times.I did it this way originally because that's what I thought GYP did. It turns out GYP seems to do this because many of the root targets list wildcards deps (GN doesn't support these) like 'content/content.gyp:*' that effectively brings in all targets into the build whether you reference them in the dependency tree or not. The result is that I think people expect to be able to write random tests or helper targets and have them appear as possible things to run Ninja with.GN now has several ways to control this. GN generates a target called "all" where if you want to build everything GN saw in the build (in the default toolchain) Ninja will build that. It has a separate concept of the default target where if you make a target called "//:default" it will mark that as the default target in Ninja so when you build with no explicit target that set of stuff will get built. The Chrome build does not set a default target, so the automatically-produced "all" target becomes the default.We could make a default target and get the behavior you want, but "all" would still exist and refer to everything, and it would be broken. I think the "all" target actually matches the GYP behavior. If you do "ninja all" in a GYP target, I suspect you'll get similar errors (Dirk can probably confirm, I think he implemented GN's current "all" behavior). I think the ability to write a target and being able to build it (as long as GN knows about that file) is generally what people on our team expect so I would personally prefer not to change it.There's a separate question about whether we should add a default target that's more like what you want. I'm not convinced. It's confusing to have a target be broken in the "all" build. In GYP I believe there are a bunch of bitrotted targets that are never compiled because we never build it's version of "all" on any bot (I think, Dirk may have to correct me).(The clobber bots all build all. Some trybots do build all. The clang tot builds all build all. This works fine. However, 'all' in gyp isn't all targets. That's for historical reasons and I consider it a bug in gyp (https://bugs.chromium.org/p/chromium/issues/detail?id=503241). Not that this is terribly important for the discussion at hand :-) )The android build uses to have a default target that wasn't 'all' long ago. We changed that because it was confusing, for the reasons you mention.This also masks some other problems. In the "jpeg" problematic patch you linked, there is only one target in that BUILD file (there are two configs there too, but they seem to be only referenced by that target). Theoretically this file should never get loaded in an iOS build. So somebody is referring to jpeg, probably a target somewhere else that shouldn't be compiled on iOS, etc. This suggests there are large portions of the build being brought in inappropriately on iOS.I think this is actually the important bit here. When we're loading build files inappropriately on some platforms, we should just stop doing that rather than trying to define default targets such that those targets are no-ops.When a file is inappropriate on iOS (or any other platform) we should addassert(!is_ios)at the top. Now it's clear to people editing the file that this isn't an iOS thing, and also tells people immediately when they screw up and bring a file in that shouldn't. When there is a file with some targets that are appropriate for iOS, and some targets that aren't, we should wrap those in conditionals that clearly document the platforms they're appropriate for. Now it's also clear which parts of the file refer to a given platform.The property that the current setup forces us to do this seems to be a benefit rather than a bug, and I don't think we should be wallpapering over targets that don't compile on some platforms: If it's not obvious to GN, it's not obvious to people editing the file either).I agree with all of this.