Repository: ARMmbed/mbed-tools

Issue:
`mbed-tools configure` generates `mbed_config.cmake` under `develop`, and doesn't have a `-b` option
From the PR description and commit msg, it says that configs and builds should now live under `cmake_build/TARGET/PROFILE/TOOLCHAIN`, but this line makes `mbed-tools configure` always generate the `mbed_config.cmake` under `cmake_build/TARGET/develop/TOOLCHAIN`. Why is this?

_Originally posted by @wmmc88 in https://github.com/ARMmbed/mbed-tools/pull/175#discussion_r606712097_

Discussion:
LDong-Arm: I first made the fix locally while working on #292 (`--app-config`) as they are quite similar, but decided to not include this there as more time was needed to add a test. Now it's done here.
codecov[bot]: # [Codecov](https://codecov.io/gh/ARMmbed/mbed-tools/pull/293?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ARMmbed) Report
> Merging [#293](https://codecov.io/gh/ARMmbed/mbed-tools/pull/293?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ARMmbed) (71eea10) into [master](https://codecov.io/gh/ARMmbed/mbed-tools/commit/4047136e0052c97bc5e19a04de65425a29edca5a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ARMmbed) (4047136) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/ARMmbed/mbed-tools/pull/293/graphs/tree.svg?width=650&height=150&src=pr&token=QFRIdRv91G&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ARMmbed)](https://codecov.io/gh/ARMmbed/mbed-tools/pull/293?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ARMmbed)

```diff
@@           Coverage Diff           @@
##           master     #293   +/-   ##
=======================================
  Coverage   97.08%   97.08%           
=======================================
  Files          92       92           
  Lines        2781     2782    +1     
=======================================
+ Hits         2700     2701    +1     
  Misses         81       81           
```


| [Impacted Files](https://codecov.io/gh/ARMmbed/mbed-tools/pull/293?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ARMmbed) | Coverage Δ | |
|---|---|---|
| [src/mbed\_tools/cli/configure.py](https://codecov.io/gh/ARMmbed/mbed-tools/pull/293/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ARMmbed#diff-c3JjL21iZWRfdG9vbHMvY2xpL2NvbmZpZ3VyZS5weQ==) | `100.00% <100.00%> (ø)` | |

LDong-Arm: @ARMmbed/mbed-os-core 
rwalton-arm: Travis timed out. Could you force push to trigger it again?
LDong-Arm: > Travis timed out. Could you force push to trigger it again?

Done. Waiting for CI to finish.

Patch:
diff --git a/news/262.bugfix b/news/262.bugfix
new file mode 100644
index 0000000..a438a13
--- /dev/null
+++ b/news/262.bugfix
@@ -0,0 +1,1 @@
+Add `-b`, `--profile` to the `configure` subcommand for specifying build profile.
diff --git a/src/mbed_tools/cli/configure.py b/src/mbed_tools/cli/configure.py
index 360c389..24b49d8 100644
--- a/src/mbed_tools/cli/configure.py
+++ b/src/mbed_tools/cli/configure.py
@@ -25,6 +25,7 @@ from mbed_tools.build import generate_config
     help="The toolchain you are using to build your app.",
 )
 @click.option("-m", "--mbed-target", required=True, help="A build target for an Mbed-enabled device, eg. K64F")
+@click.option("-b", "--profile", default="develop", help="The build type (release, develop or debug).")
 @click.option("-o", "--output-dir", type=click.Path(), default=None, help="Path to output directory.")
 @click.option(
     "-p",
@@ -42,6 +43,7 @@ from mbed_tools.build import generate_config
 def configure(
     toolchain: str,
     mbed_target: str,
+    profile: str,
     program_path: str,
     mbed_os_path: str,
     output_dir: str,
@@ -61,12 +63,13 @@ def configure(
         custom_targets_json: the path to custom_targets.json
         toolchain: the toolchain you are using (eg. GCC_ARM, ARM)
         mbed_target: the target you are building for (eg. K64F)
+        profile: The Mbed build profile (debug, develop or release).
         program_path: the path to the local Mbed program
         mbed_os_path: the path to the local Mbed OS directory
         output_dir: the path to the output directory
         app_config: the path to the application configuration file
     """
-    cmake_build_subdir = pathlib.Path(mbed_target.upper(), "develop", toolchain.upper())
+    cmake_build_subdir = pathlib.Path(mbed_target.upper(), profile.lower(), toolchain.upper())
     if mbed_os_path is None:
         program = MbedProgram.from_existing(pathlib.Path(program_path), cmake_build_subdir)
     else:


Test patch:
diff --git a/tests/cli/test_build.py b/tests/cli/test_build.py
index d680ee9..42e5852 100644
--- a/tests/cli/test_build.py
+++ b/tests/cli/test_build.py
@@ -186,6 +186,29 @@ class TestBuildCommand(TestCase):
             generate_config.assert_called_once_with(target.upper(), toolchain.upper(), program)
             self.assertEqual(program.files.app_config_file, app_config_path)
 
+    def test_profile_used_when_passed(
+        self, generate_config, mbed_program, build_project, generate_build_system
+    ):
+        program = mbed_program.from_existing()
+        mbed_program.reset_mock()  # clear call count from previous line
+
+        with mock_project_directory(program, mbed_config_exists=True, build_tree_exists=True):
+            generate_config.return_value = [mock.MagicMock(), mock.MagicMock()]
+
+            toolchain = "gcc_arm"
+            target = "k64f"
+            profile = "release"
+
+            runner = CliRunner()
+            runner.invoke(build, ["-t", toolchain, "-m", target, "--profile", profile])
+
+            mbed_program.from_existing.assert_called_once_with(
+                pathlib.Path(os.getcwd()),
+                pathlib.Path(target.upper(), profile, toolchain.upper())
+            )
+            generate_config.assert_called_once_with(target.upper(), toolchain.upper(), program)
+            generate_build_system.assert_called_once_with(program.root, program.files.cmake_build_dir, profile)
+
     def test_build_folder_removed_when_clean_flag_passed(
         self, generate_config, mbed_program, build_project, generate_build_system
     ):
diff --git a/tests/cli/test_configure.py b/tests/cli/test_configure.py
index 2ae90b1..0483e99 100644
--- a/tests/cli/test_configure.py
+++ b/tests/cli/test_configure.py
@@ -59,3 +59,23 @@ class TestConfigureCommand(TestCase):
 
         generate_config.assert_called_once_with("K64F", "GCC_ARM", program)
         self.assertEqual(program.files.app_config_file, app_config_path)
+
+    @mock.patch("mbed_tools.cli.configure.generate_config")
+    @mock.patch("mbed_tools.cli.configure.MbedProgram")
+    def test_profile_used_when_passed(self, program, generate_config):
+        test_program = program.from_existing()
+        program.reset_mock()  # clear call count from previous line
+
+        toolchain = "gcc_arm"
+        target = "k64f"
+        profile = "release"
+
+        CliRunner().invoke(
+            configure, ["-t", toolchain, "-m", target, "--profile", profile]
+        )
+
+        program.from_existing.assert_called_once_with(
+            pathlib.Path("."),
+            pathlib.Path(target.upper(), profile, toolchain.upper())
+        )
+        generate_config.assert_called_once_with("K64F", "GCC_ARM", test_program)