Repository: conan-io/conan

Issue:
[bug] conan_build_info `--skip-env` flag behaves counterintuitively
The [`--skip-env` flag is True by default](https://github.com/conan-io/conan/blob/d42ec055d459489c184b160cafbd3f200ceb6d41/conans/build_info/command.py#L83).  This means the `--skip-env` arg must be added to **not** skip the capturing of env vars.

I think either the default value or the name of the arg should be changed to avoid confusion.

### Environment Details (include every applicable attribute)
  * Operating System+version: Windows 10
  * Compiler+version: n/a
  * Conan version: 1.20.4
  * Python version: 3.7.3

### Steps to reproduce (Include if Applicable)
run `conan_build_info --v2 create buildinfo.json --lockfile=conan.lock` 
and env info is **not** captured.

run `conan_build_info --v2 create buildinfo.json --skip-env --lockfile=conan.lock` 
and env info is captured


Discussion:
Hi @GordonJess,
You are right, it's counterintuitive, we'll fix it for the next release.
Thanks a lot for reporting. 

Resolving patch:
diff --git a/conans/build_info/build_info.py b/conans/build_info/build_info.py
--- a/conans/build_info/build_info.py
+++ b/conans/build_info/build_info.py
@@ -37,12 +37,9 @@ def _parse_profile(contents):
 
 
 class BuildInfoCreator(object):
-    def __init__(self, output, build_info_file, lockfile, multi_module=True, skip_env=True,
-                 user=None, password=None, apikey=None):
+    def __init__(self, output, build_info_file, lockfile, user=None, password=None, apikey=None):
         self._build_info_file = build_info_file
         self._lockfile = lockfile
-        self._multi_module = multi_module
-        self._skip_env = skip_env
         self._user = user
         self._password = password
         self._apikey = apikey
@@ -116,7 +113,7 @@ def _get_metadata_artifacts(self, metadata, request_path, use_id=False, name_for
 
         return set([Artifact(k, **v) for k, v in ret.items()])
 
-    def _get_recipe_artifacts(self, pref, add_prefix, use_id):
+    def _get_recipe_artifacts(self, pref, is_dependency):
         r = self.parse_pref(pref)
         if r.get("user") and r.get("channel"):
             ref = "{name}/{version}@{user}/{channel}#{rrev}".format(**r)
@@ -125,15 +122,15 @@ def _get_recipe_artifacts(self, pref, add_prefix, use_id):
         reference = ConanFileReference.loads(ref)
         package_layout = self._conan_cache.package_layout(reference)
         metadata = package_layout.load_metadata()
-        name_format = "{} :: {{}}".format(self._get_reference(pref)) if add_prefix else "{}"
+        name_format = "{} :: {{}}".format(self._get_reference(pref)) if is_dependency else "{}"
         if r.get("user") and r.get("channel"):
             url = "{user}/{name}/{version}/{channel}/{rrev}/export".format(**r)
         else:
             url = "_/{name}/{version}/_/{rrev}/export".format(**r)
 
-        return self._get_metadata_artifacts(metadata, url, name_format=name_format, use_id=use_id)
+        return self._get_metadata_artifacts(metadata, url, name_format=name_format, use_id=is_dependency)
 
-    def _get_package_artifacts(self, pref, add_prefix, use_id):
+    def _get_package_artifacts(self, pref, is_dependency):
         r = self.parse_pref(pref)
         if r.get("user") and r.get("channel"):
             ref = "{name}/{version}@{user}/{channel}#{rrev}".format(**r)
@@ -142,12 +139,12 @@ def _get_package_artifacts(self, pref, add_prefix, use_id):
         reference = ConanFileReference.loads(ref)
         package_layout = self._conan_cache.package_layout(reference)
         metadata = package_layout.load_metadata()
-        name_format = "{} :: {{}}".format(self._get_package_reference(pref)) if add_prefix else "{}"
+        name_format = "{} :: {{}}".format(self._get_package_reference(pref)) if is_dependency else "{}"
         if r.get("user") and r.get("channel"):
             url = "{user}/{name}/{version}/{channel}/{rrev}/package/{pid}/{prev}".format(**r)
         else:
             url = "_/{name}/{version}/_/{rrev}/package/{pid}/{prev}".format(**r)
-        arts = self._get_metadata_artifacts(metadata, url, name_format=name_format, use_id=use_id,
+        arts = self._get_metadata_artifacts(metadata, url, name_format=name_format, use_id=is_dependency,
                                             package_id=r["pid"])
         return arts
 
@@ -156,7 +153,7 @@ def process_lockfile(self):
 
         def _gather_deps(node_uid, contents, func):
             node_content = contents["graph_lock"]["nodes"].get(node_uid)
-            artifacts = func(node_content["pref"], add_prefix=True, use_id=True)
+            artifacts = func(node_content["pref"], is_dependency=True)
             for _, id_node in node_content.get("requires", {}).items():
                 artifacts.update(_gather_deps(id_node, contents, func))
             return artifacts
@@ -172,17 +169,15 @@ def _gather_deps(node_uid, contents, func):
                 recipe_key = self._get_reference(pref)
                 modules[recipe_key]["id"] = recipe_key
                 modules[recipe_key]["artifacts"].update(
-                    self._get_recipe_artifacts(pref, add_prefix=not self._multi_module,
-                                               use_id=False))
+                    self._get_recipe_artifacts(pref, is_dependency=False))
                 # TODO: what about `python_requires`?
                 # TODO: can we associate any properties to the recipe? Profile/options may be different per lockfile
 
                 # Create module for the package_id
-                package_key = self._get_package_reference(pref) if self._multi_module else recipe_key
+                package_key = self._get_package_reference(pref)
                 modules[package_key]["id"] = package_key
                 modules[package_key]["artifacts"].update(
-                    self._get_package_artifacts(pref, add_prefix=not self._multi_module,
-                                                use_id=False))
+                    self._get_package_artifacts(pref, is_dependency=False))
 
                 # Recurse requires
                 if node.get("requires"):
@@ -208,12 +203,6 @@ def create(self):
                "buildAgent": {"name": "Conan Client", "version": "1.X"},
                "modules": list(modules.values())}
 
-        if not self._skip_env:
-            excluded = ["secret", "key", "password"]
-            environment = {"buildInfo.env.{}".format(k): v for k, v in os.environ.items() if
-                           k not in excluded}
-            ret["properties"] = environment
-
         def dump_custom_types(obj):
             if isinstance(obj, set):
                 artifacts = [{k: v for k, v in o._asdict().items() if v is not None} for o in obj]
@@ -224,10 +213,8 @@ def dump_custom_types(obj):
             f.write(json.dumps(ret, indent=4, default=dump_custom_types))
 
 
-def create_build_info(output, build_info_file, lockfile, multi_module, skip_env, user, password,
-                      apikey):
-    bi = BuildInfoCreator(output, build_info_file, lockfile, multi_module, skip_env, user, password,
-                          apikey)
+def create_build_info(output, build_info_file, lockfile, user, password, apikey):
+    bi = BuildInfoCreator(output, build_info_file, lockfile, user, password, apikey)
     bi.create()
 
 
diff --git a/conans/build_info/command.py b/conans/build_info/command.py
--- a/conans/build_info/command.py
+++ b/conans/build_info/command.py
@@ -77,11 +77,6 @@ def runv2():
     parser_create.add_argument("build_info_file", type=str,
                                help="build info json for output")
     parser_create.add_argument("--lockfile", type=str, required=True, help="input lockfile")
-    parser_create.add_argument("--multi-module", nargs="?", default=True,
-                               help="if enabled, the module_id will be identified by the "
-                                    "recipe reference plus the package ID")
-    parser_create.add_argument("--skip-env", nargs="?", default=True,
-                               help="capture or not the environment")
     parser_create.add_argument("--user", type=str, nargs="?", default=None, help="user")
     parser_create.add_argument("--password", type=str, nargs="?", default=None, help="password")
     parser_create.add_argument("--apikey", type=str, nargs="?", default=None, help="apikey")
@@ -118,8 +113,8 @@ def check_credential_arguments():
             stop_build_info(output)
         if args.subcommand == "create":
             check_credential_arguments()
-            create_build_info(output, args.build_info_file, args.lockfile, args.multi_module,
-                              args.skip_env, args.user, args.password, args.apikey)
+            create_build_info(output, args.build_info_file, args.lockfile,
+                              args.user, args.password, args.apikey)
         if args.subcommand == "update":
             update_build_info(args.buildinfo, args.output_file)
         if args.subcommand == "publish":


Test patch:
diff --git a/conans/test/integration/test_build_info_creation.py b/conans/test/integration/test_build_info_creation.py
--- a/conans/test/integration/test_build_info_creation.py
+++ b/conans/test/integration/test_build_info_creation.py
@@ -116,14 +116,14 @@ def package(self):
         run()
 
         user_channel = "@" + user_channel if len(user_channel) > 2 else user_channel
-        with open(os.path.join(client.current_folder, "buildinfo1.json")) as f:
-            buildinfo = json.load(f)
-            self.assertEqual(buildinfo["name"], "MyBuildName")
-            self.assertEqual(buildinfo["number"], "42")
-            ids_list = [item["id"] for item in buildinfo["modules"]]
-            self.assertTrue("PkgB/0.1{}".format(user_channel) in ids_list)
-            self.assertTrue("PkgB/0.1{}:09f152eb7b3e0a6e15a2a3f464245864ae8f8644".format(
-                user_channel) in ids_list)
+        f = client.load("buildinfo1.json")
+        buildinfo = json.loads(f)
+        self.assertEqual(buildinfo["name"], "MyBuildName")
+        self.assertEqual(buildinfo["number"], "42")
+        ids_list = [item["id"] for item in buildinfo["modules"]]
+        self.assertTrue("PkgB/0.1{}".format(user_channel) in ids_list)
+        self.assertTrue("PkgB/0.1{}:09f152eb7b3e0a6e15a2a3f464245864ae8f8644".format(
+            user_channel) in ids_list)
 
         sys.argv = ["conan_build_info", "--v2", "update",
                     os.path.join(client.current_folder, "buildinfo1.json"),
@@ -131,17 +131,17 @@ def package(self):
                     "--output-file", os.path.join(client.current_folder, "mergedbuildinfo.json")]
         run()
 
-        with open(os.path.join(client.current_folder, "mergedbuildinfo.json")) as f:
-            buildinfo = json.load(f)
-            self.assertEqual(buildinfo["name"], "MyBuildName")
-            self.assertEqual(buildinfo["number"], "42")
-            ids_list = [item["id"] for item in buildinfo["modules"]]
-            self.assertTrue("PkgC/0.1{}".format(user_channel) in ids_list)
-            self.assertTrue("PkgB/0.1{}".format(user_channel) in ids_list)
-            self.assertTrue("PkgC/0.1{}:09f152eb7b3e0a6e15a2a3f464245864ae8f8644".format(
-                user_channel) in ids_list)
-            self.assertTrue("PkgB/0.1{}:09f152eb7b3e0a6e15a2a3f464245864ae8f8644".format(
-                user_channel) in ids_list)
+        f = client.load("mergedbuildinfo.json")
+        buildinfo = json.loads(f)
+        self.assertEqual(buildinfo["name"], "MyBuildName")
+        self.assertEqual(buildinfo["number"], "42")
+        ids_list = [item["id"] for item in buildinfo["modules"]]
+        self.assertTrue("PkgC/0.1{}".format(user_channel) in ids_list)
+        self.assertTrue("PkgB/0.1{}".format(user_channel) in ids_list)
+        self.assertTrue("PkgC/0.1{}:09f152eb7b3e0a6e15a2a3f464245864ae8f8644".format(
+            user_channel) in ids_list)
+        self.assertTrue("PkgB/0.1{}:09f152eb7b3e0a6e15a2a3f464245864ae8f8644".format(
+            user_channel) in ids_list)
 
         sys.argv = ["conan_build_info", "--v2", "publish",
                     os.path.join(client.current_folder, "mergedbuildinfo.json"), "--url",