Repository: conan-io/conan

Issue:
conan install & conan build using option patterns
Guys I am experimenting an issue when I do `conan install`, `conan build` using option patterns.
Without using patterns, it is working fine.
`conan create` is working fine.
Let me show it with a couple of examples.

If you want to check it, the actual repo is: https://github.com/bitprim/bitprim-blockchain/tree/feature_compile_time_currencies

```
conan --version
Conan version 1.1.0
```

```
git clone ...
cd bitprim-blockchain
```

1.
`conan create . bitprim-blockchain/0.8@bitprim/experimental -o *:currency=BCH`
Prints from  CMakeLists.txt:

```
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    Bitprim Currency: BCH

```
Result: OK

2.
`conan create . bitprim-blockchain/0.8@bitprim/experimental -o *:currency=BTC`

```
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    Bitprim Currency: BTC
```
Result: OK

3. (BCH is the default currency)
`conan create . bitprim-blockchain/0.8@bitprim/experimental`

```
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    Bitprim Currency: BCH
```
Result: OK

4.
```
conan install .. -o bitprim-blockchain:currency=BCH
conan build ..
```

```
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    Bitprim Currency: BCH
```
Result: OK


5.
```
conan install .. -o currency=BCH
conan build ..
```

```
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    Bitprim Currency: BCH
```
Result: OK

6.
```
conan install .. -o *:currency=BCH
conan build ..
```

```
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    Bitprim Currency: BCH
```
Result: OK

7.
```
conan install .. -o bitprim-blockchain:currency=BTC
conan build ..
```

```
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    Bitprim Currency: BTC
```
Result: OK

8.
```
conan install .. -o currency=BTC
conan build ..
```

```
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    Bitprim Currency: BTC
```
Result: OK

9.
```
conan install .. -o *:currency=BTC
conan build ..
```

```
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    Bitprim Currency: BCH
```

**Result: Wrong behaviour?**




Discussion:
Guys, any news on this? Thanks! Still wrong in version 1.6
Sorry, we missed it. We will try to take a look for 1.7
Hi @fpelliccioni 

I would like to reproduce your steps if that is possible, but first one errors with:
```
  File "C:\Users\danimtb\repos\bitprim-blockchain\conanfile.py", line 21, in <module>
    from ci_utils import option_on_off, march_conan_manip, pass_march_to_compiler
ImportError: cannot import name 'option_on_off'
```

How can I install that ci_utils module?
Oh sorry. It is an old issue, some thing are changed.

Do a
git submodule init
And a
git submodule update

Before running the conan install.

(Sorry I am on the phone)


On Mon, Aug 13, 2018, 13:33 Daniel <notifications@github.com> wrote:

> Hi @fpelliccioni <https://github.com/fpelliccioni>
>
> I would like to reproduce your steps if that is possible, but first one
> errors with:
>
>   File "C:\Users\danimtb\repos\bitprim-blockchain\conanfile.py", line 21, in <module>
>     from ci_utils import option_on_off, march_conan_manip, pass_march_to_compiler
> ImportError: cannot import name 'option_on_off'
>
> How can I install that ci_utils module?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/conan-io/conan/issues/2538#issuecomment-412600217>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAQtEx6GUBhKPppn7LT1nwVK83i2CJ7Bks5uQbh7gaJpZM4SWfo3>
> .
>

Thanks @fpelliccioni 

Here is a reduced example of the issue:

```
$ conan info .. -o currency=BTC --graph graph.html

PROJECT: Detected microarchitecture (default): x86-64
PROJECT: Compiling for currency: BTC
boost/1.66.0@bitprim/stable: def config_options(self):
boost/1.66.0@bitprim/stable: def configure(self):
boost/1.66.0@bitprim/stable: def requirements(self):
bitprim-database/0.12.0@bitprim/prerelease: Provided microarchitecture (user defined): x86-64
bitprim-database/0.12.0@bitprim/prerelease: Compiling for currency: BTC
bitprim-core/0.12.0@bitprim/prerelease: Provided microarchitecture (user defined): x86-64
bitprim-core/0.12.0@bitprim/prerelease: Compiling for currency: BTC
secp256k1/0.6.0@bitprim/prerelease: Provided microarchitecture (user defined): x86-64
mpir/3.0.0@bitprim/stable: Detected microarchitecture: x86-64
mpir/3.0.0@bitprim/stable: 'x86-64' microarchitecture is not supported by MPIR, fall back to 'x86_64'
mpir/3.0.0@bitprim/stable: Compiling for microarchitecture: core2
bitprim-consensus/0.12.0@bitprim/prerelease: Provided microarchitecture (user defined): x86-64
bitprim-consensus/0.12.0@bitprim/prerelease: Compiling for currency: BTC
```
This works as expected.


```
$ conan info .. -o *:currency=BTC --graph graph.html

PROJECT: Detected microarchitecture (default): x86-64
PROJECT: Compiling for currency: BCH
boost/1.66.0@bitprim/stable: def config_options(self):
boost/1.66.0@bitprim/stable: def configure(self):
boost/1.66.0@bitprim/stable: def requirements(self):
bitprim-database/0.12.0@bitprim/prerelease: Provided microarchitecture (user defined): x86-64
bitprim-database/0.12.0@bitprim/prerelease: Compiling for currency: BCH
bitprim-core/0.12.0@bitprim/prerelease: Provided microarchitecture (user defined): x86-64
bitprim-core/0.12.0@bitprim/prerelease: Compiling for currency: BCH
secp256k1/0.6.0@bitprim/prerelease: Provided microarchitecture (user defined): x86-64
mpir/3.0.0@bitprim/stable: Detected microarchitecture: x86-64
mpir/3.0.0@bitprim/stable: 'x86-64' microarchitecture is not supported by MPIR, fall back to 'x86_64'
mpir/3.0.0@bitprim/stable: Compiling for microarchitecture: core2
bitprim-consensus/0.12.0@bitprim/prerelease: Provided microarchitecture (user defined): x86-64
bitprim-consensus/0.12.0@bitprim/prerelease: Compiling for currency: BCH
```
This does NOT

I am looking into it

Resolving patch:
diff --git a/conans/client/loader.py b/conans/client/loader.py
--- a/conans/client/loader.py
+++ b/conans/client/loader.py
@@ -54,6 +54,7 @@ def load_conan(self, conanfile_path, output, consumer=False, reference=None, loc
             result._env_values.update(self._env_values)
 
             if consumer:
+                self._user_options[result.name].update(self._user_options["*"])
                 self._user_options.descope_options(result.name)
                 result.options.initialize_upstream(self._user_options, local=local)
                 self._user_options.clear_unscoped_options()
diff --git a/conans/model/options.py b/conans/model/options.py
--- a/conans/model/options.py
+++ b/conans/model/options.py
@@ -483,9 +483,8 @@ def propagate_upstream(self, package_values, down_ref, own_ref, pattern_options)
 
 
 class Options(object):
-    """ all options of a package, both its own options and the upstream
-    ones.
-    Owned by conanfile
+    """ All options of a package, both its own options and the upstream ones.
+    Owned by ConanFile.
     """
     def __init__(self, options):
         assert isinstance(options, PackageOptions)


Test patch:
diff --git a/conans/test/integration/options_test.py b/conans/test/integration/options_test.py
--- a/conans/test/integration/options_test.py
+++ b/conans/test/integration/options_test.py
@@ -64,3 +64,59 @@ class ConanLib(ConanFile):
                       client.user_io.out)
         conaninfo = load(os.path.join(client.current_folder, CONANINFO))
         self.assertNotIn("zlib:shared=True", conaninfo)
+
+    def general_scope_options_test(self):
+        # https://github.com/conan-io/conan/issues/2538
+        client = TestClient()
+        conanfile_libA = """
+from conans import ConanFile
+
+class LibA(ConanFile):
+    name = "libA"
+    version = "0.1"
+    options = {"shared": [True, False]}
+    default_options= "shared=False"
+
+    def configure(self):
+        self.output.info("shared=%s" % self.options.shared)
+    """
+        conanfile_libB = """
+from conans import ConanFile
+
+class LibB(ConanFile):
+    name = "libB"
+    version = "0.1"
+    options = {"shared": [True, False]}
+    default_options= "shared=False"
+    requires = "libA/0.1@danimtb/testing"
+
+    def configure(self):
+        self.options["*"].shared = self.options.shared
+        self.output.info("shared=%s" % self.options.shared)
+    """
+        client.save({"conanfile_liba.py": conanfile_libA,
+                     "conanfile_libb.py": conanfile_libB})
+
+        for without_configure_line in [True, False]:
+            client.save({"conanfile_liba.py": conanfile_libA})
+
+            if without_configure_line:
+                client.save({"conanfile_libb.py": conanfile_libB.replace(
+                    "        self.options[\"*\"].shared = self.options.shared", "")})
+            else:
+                client.save({"conanfile_libb.py": conanfile_libB})
+
+            # Test info
+            client.run("export conanfile_liba.py danimtb/testing")
+            client.run("info conanfile_libb.py -o *:shared=True")
+            self.assertIn("PROJECT: shared=True", client.out)
+            self.assertIn("libA/0.1@danimtb/testing: shared=True", client.out)
+            # Test create
+            client.run("create conanfile_liba.py danimtb/testing -o *:shared=True")
+            client.run("create conanfile_libb.py danimtb/testing -o *:shared=True")
+            self.assertIn("libB/0.1@danimtb/testing: shared=True", client.out)
+            self.assertIn("libA/0.1@danimtb/testing: shared=True", client.out)
+            # Test install
+            client.run("install conanfile_libb.py -o *:shared=True")
+            self.assertIn("PROJECT: shared=True", client.out)
+            self.assertIn("libA/0.1@danimtb/testing: shared=True", client.out)