Repository: conan-io/conan

Issue:
b2 generator doesn't specify transitive dependencies
Boost.Build targets created by files produced by b2 generator don't list their dependencies. As a result of that, if you `require` package `A` which depends on package `B`, and then you use a target for package `A`, you are likely to encounter a build error, because the build system is not aware of dependency between `A` and `B`.

Example project:

```python
# conanfile.py
from conans import ConanFile

class FoobarConan(ConanFile):
    name = 'foobar'
    version = '0.0.1'
    settings = 'arch', 'os', 'compiler'
    requires = 'boost_core/[>=1.68]@bincrafters/stable'
    build_requires = 'b2/4.0.0'

    generators = "b2"
    exports_sources = "jamroot.jam", "*.cpp"

    def build(self):
        self.run('b2')
```
```jam
# jamroot.jam
project foobar ;

# Boost.Core actually depends on Boost.Config
lib foobar : foobar.cpp /boost_core//libs ;
```
```c++
// foobar.cpp
#include <boost/core/null_deleter.hpp>
```

Relevant Conan version: 1.18.5

- [X] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [X] I've specified the Conan version, operating system version and any tool that can be relevant.
- [X] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.


Discussion:

Resolving patch:
diff --git a/conans/client/generators/b2.py b/conans/client/generators/b2.py
--- a/conans/client/generators/b2.py
+++ b/conans/client/generators/b2.py
@@ -130,15 +130,14 @@ def b2_targets_for_dep(self, name, info):
             return []
         name = name.lower()
         result = []
+        deps = ['/%s//libs' % dep for dep in info.public_deps]
         if info.libs:
             for lib in info.libs:
                 result += [self.conanbuildinfo_variation_lib_template.format(
-                    name=name, lib=lib, variation=self.b2_variation_id)]
-            result += [self.conanbuildinfo_variation_alias_template.format(
-                name=name, libs=" ".join(info.libs), variation=self.b2_variation_id)]
-        else:
-            result += [self.conanbuildinfo_variation_alias_template.format(
-                name=name, libs="", variation=self.b2_variation_id)]
+                    name=name, lib=lib, deps=" ".join(deps), variation=self.b2_variation_id)]
+            deps.extend(info.libs)
+        result += [self.conanbuildinfo_variation_alias_template.format(
+            name=name, libs=" ".join(deps), variation=self.b2_variation_id)]
 
         return result
 
@@ -413,7 +412,7 @@ def b2_toolset_version(self):
     conanbuildinfo_variation_lib_template = """\
 if $(__define_targets__) {{
     call-in-project $({name}-mod) : lib {lib}
-        :
+        : {deps}
         : <name>{lib} <search>$(libdirs({name},{variation})) $(requirements({name},{variation}))
         :
         : $(usage-requirements({name},{variation})) ;


Test patch:
diff --git a/conans/test/unittests/client/generators/b2_test.py b/conans/test/unittests/client/generators/b2_test.py
--- a/conans/test/unittests/client/generators/b2_test.py
+++ b/conans/test/unittests/client/generators/b2_test.py
@@ -298,7 +298,7 @@ def b2_test(self):
 # mypkg
 if $(__define_targets__) {
     call-in-project $(mypkg-mod) : lib MyLib1
-        :
+        : ''' + '''
         : <name>MyLib1 <search>$(libdirs(mypkg,32,x86,17,gnu,linux,gcc-6.3,release)) $(requirements(mypkg,32,x86,17,gnu,linux,gcc-6.3,release))
         :
         : $(usage-requirements(mypkg,32,x86,17,gnu,linux,gcc-6.3,release)) ;
@@ -315,7 +315,7 @@ def b2_test(self):
 # mypkg2
 if $(__define_targets__) {
     call-in-project $(mypkg2-mod) : lib MyLib2
-        :
+        : /MyPkg//libs
         : <name>MyLib2 <search>$(libdirs(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release)) $(requirements(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release))
         :
         : $(usage-requirements(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release)) ;
@@ -323,7 +323,7 @@ def b2_test(self):
 
 if $(__define_targets__) {
     call-in-project $(mypkg2-mod) : alias libs
-        : MyLib2
+        : /MyPkg//libs MyLib2
         : $(requirements(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release))
         :
         : $(usage-requirements(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release)) ;