Skip to content

Commit b4ac16b

Browse files
Remove unneeded cmake-build-dir option, we already have output
1 parent a7694ff commit b4ac16b

File tree

8 files changed

+31
-47
lines changed

8 files changed

+31
-47
lines changed

tools/cmake/mbed_generate_configuration.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ if(MBED_NEED_TO_RECONFIGURE)
8989
--mbed-os-path ${CMAKE_CURRENT_LIST_DIR}/../..
9090
--output-dir ${CMAKE_CURRENT_BINARY_DIR}
9191
--program-path ${CMAKE_SOURCE_DIR}
92-
--cmake-build-dir ${CMAKE_BINARY_DIR}
9392
${APP_CONFIG_ARGUMENT}
9493
${CUSTOM_TARGET_ARGUMENT})
9594

tools/python/mbed_tools/build/_internal/templates/mbed_config.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set(MBED_GREENTEA_TEST_RESET_TIMEOUT "{{forced_reset_timeout}}")
1515

1616
# JSON files used to generate this config. If any of these change, the Python config generation
1717
# scripts must be rerun.
18-
set(CONFIG_JSON_SOURCE_FILES {% for json_source in json_sources %}
18+
set(CONFIG_JSON_SOURCE_FILES {% for json_source in json_sources | sort %}
1919
"{{json_source.as_posix()}}"
2020
{%- endfor %}
2121
)

tools/python/mbed_tools/cli/configure.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
help="The toolchain you are using to build your app.",
2626
)
2727
@click.option("-m", "--mbed-target", required=True, help="A build target for an Mbed-enabled device, eg. K64F")
28-
@click.option("-o", "--output-dir", type=click.Path(), default=None, help="Path to output directory.")
28+
@click.option("-o", "--output-dir",
29+
type=click.Path(path_type=pathlib.Path),
30+
required=True,
31+
help="Path to output directory (CMake binary dir)")
2932
@click.option(
3033
"-p",
3134
"--program-path",
@@ -39,18 +42,14 @@
3942
@click.option(
4043
"--app-config", type=click.Path(), default=None, help="Path to application configuration file.",
4144
)
42-
@click.option(
43-
"--cmake-build-dir", type=click.Path(path_type=pathlib.Path), help="Path to CMake build dir", required=True
44-
)
4545
def configure(
4646
toolchain: str,
4747
mbed_target: str,
4848
program_path: str,
4949
mbed_os_path: str,
50-
output_dir: str,
50+
output_dir: pathlib.Path,
5151
custom_targets_json: str,
52-
app_config: str,
53-
cmake_build_dir: pathlib.Path
52+
app_config: str
5453
) -> None:
5554
"""Exports a mbed_config.cmake file to build directory in the program root.
5655
@@ -69,16 +68,13 @@ def configure(
6968
mbed_os_path: the path to the local Mbed OS directory
7069
output_dir: the path to the output directory
7170
app_config: the path to the application configuration file
72-
cmake_build_dir: Path to CMake build dir
7371
"""
7472
if mbed_os_path is None:
75-
program = MbedProgram.from_existing(pathlib.Path(program_path), cmake_build_dir)
73+
program = MbedProgram.from_existing(pathlib.Path(program_path), output_dir)
7674
else:
77-
program = MbedProgram.from_existing(pathlib.Path(program_path), cmake_build_dir, pathlib.Path(mbed_os_path).resolve())
75+
program = MbedProgram.from_existing(pathlib.Path(program_path), output_dir, pathlib.Path(mbed_os_path).resolve())
7876
if custom_targets_json is not None:
7977
program.files.custom_targets_json = pathlib.Path(custom_targets_json)
80-
if output_dir is not None:
81-
program.files.cmake_build_dir = pathlib.Path(output_dir)
8278
if app_config is not None:
8379
program.files.app_config_file = pathlib.Path(app_config)
8480

tools/python/mbed_tools/project/_internal/project_data.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ def from_new(cls, root_path: Path) -> "MbedProgramFiles":
9999
)
100100

101101
@classmethod
102-
def from_existing(cls, root_path: Path, build_subdir: Path) -> "MbedProgramFiles":
102+
def from_existing(cls, root_path: Path, build_dir: Path) -> "MbedProgramFiles":
103103
"""Create MbedProgramFiles from a directory containing an existing program.
104104
105105
Args:
106106
root_path: The path containing the MbedProgramFiles.
107-
build_subdir: The subdirectory of BUILD_DIR to use for CMake build.
107+
build_dir: The directory to use for CMake build.
108108
"""
109109
app_config: Optional[Path] = None
110110
if (root_path / APP_CONFIG_FILE_NAME_JSON5).exists():
@@ -126,13 +126,12 @@ def from_existing(cls, root_path: Path, build_subdir: Path) -> "MbedProgramFiles
126126
cmakelists_file = root_path / CMAKELISTS_FILE_NAME
127127
if not cmakelists_file.exists():
128128
logger.warning("No CMakeLists.txt found in the program root.")
129-
cmake_build_dir = root_path / BUILD_DIR / build_subdir
130129

131130
return cls(
132131
app_config_file=app_config,
133132
mbed_os_ref=mbed_os_file,
134133
cmakelists_file=cmakelists_file,
135-
cmake_build_dir=cmake_build_dir,
134+
cmake_build_dir=build_dir,
136135
custom_targets_json=custom_targets_json,
137136
)
138137

tools/python/mbed_tools/project/mbed_program.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ def from_new(cls, dir_path: Path) -> "MbedProgram":
6868

6969
@classmethod
7070
def from_existing(
71-
cls, dir_path: Path, build_subdir: Path, mbed_os_path: Path = None, check_mbed_os: bool = True,
71+
cls, dir_path: Path, build_dir: Path, mbed_os_path: Path = None, check_mbed_os: bool = True,
7272
) -> "MbedProgram":
7373
"""Create an MbedProgram from an existing program directory.
7474
7575
Args:
7676
dir_path: Directory containing an Mbed program.
77-
build_subdir: The subdirectory for the CMake build tree.
77+
build_dir: The directory for the CMake build tree.
7878
mbed_os_path: Directory containing Mbed OS.
7979
check_mbed_os: If True causes an exception to be raised if the Mbed OS source directory does not
8080
exist.
@@ -89,7 +89,7 @@ def from_existing(
8989
program_root = dir_path
9090

9191
logger.info(f"Found existing Mbed program at path '{program_root}'")
92-
program = MbedProgramFiles.from_existing(program_root, build_subdir)
92+
program = MbedProgramFiles.from_existing(program_root, build_dir)
9393

9494
try:
9595
mbed_os = MbedOS.from_existing(mbed_os_path, check_mbed_os)

tools/python/python_tests/mbed_tools/cli/test_configure.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class TestConfigureCommand(TestCase):
1515
@mock.patch("mbed_tools.cli.configure.generate_config")
1616
@mock.patch("mbed_tools.cli.configure.MbedProgram")
1717
def test_generate_config_called_with_correct_arguments(self, program, generate_config):
18-
CliRunner().invoke(configure, ["-m", "k64f", "-t", "gcc_arm", "--cmake-build-dir", "build"])
18+
CliRunner().invoke(configure, ["-m", "k64f", "-t", "gcc_arm", "-o", "some_output_dir"])
1919

2020
generate_config.assert_called_once_with("K64F", "GCC_ARM", program.from_existing())
2121

2222
@mock.patch("mbed_tools.cli.configure.generate_config")
2323
@mock.patch("mbed_tools.cli.configure.MbedProgram")
2424
def test_generate_config_called_with_mbed_os_path(self, program, generate_config):
25-
CliRunner().invoke(configure, ["-m", "k64f", "-t", "gcc_arm", "--mbed-os-path", "./extern/mbed-os", "--cmake-build-dir", "build"])
25+
CliRunner().invoke(configure, ["-m", "k64f", "-t", "gcc_arm", "--mbed-os-path", "./extern/mbed-os", "-o", "some_output_dir"])
2626

2727
generate_config.assert_called_once_with("K64F", "GCC_ARM", program.from_existing())
2828

@@ -32,49 +32,39 @@ def test_custom_targets_location_used_when_passed(self, program, generate_config
3232
program = program.from_existing()
3333
custom_targets_json_path = pathlib.Path("custom", "custom_targets.json")
3434
CliRunner().invoke(
35-
configure, ["-t", "gcc_arm", "-m", "k64f", "--custom-targets-json", custom_targets_json_path, "--cmake-build-dir", "build"]
35+
configure, ["-t", "gcc_arm", "-m", "k64f", "--custom-targets-json", custom_targets_json_path, "-o", "some_output_dir"]
3636
)
3737

3838
generate_config.assert_called_once_with("K64F", "GCC_ARM", program)
3939
self.assertEqual(program.files.custom_targets_json, custom_targets_json_path)
4040

41-
@mock.patch("mbed_tools.cli.configure.generate_config")
42-
@mock.patch("mbed_tools.cli.configure.MbedProgram")
43-
def test_custom_output_directory_used_when_passed(self, program, generate_config):
44-
program = program.from_existing()
45-
output_dir = pathlib.Path("build")
46-
CliRunner().invoke(configure, ["-t", "gcc_arm", "-m", "k64f", "-o", output_dir, "--cmake-build-dir", "build"])
47-
48-
generate_config.assert_called_once_with("K64F", "GCC_ARM", program)
49-
self.assertEqual(program.files.cmake_build_dir, output_dir)
50-
5141
@mock.patch("mbed_tools.cli.configure.generate_config")
5242
@mock.patch("mbed_tools.cli.configure.MbedProgram")
5343
def test_app_config_used_when_passed(self, program, generate_config):
5444
program = program.from_existing()
5545
app_config_path = pathlib.Path("alternative_config.json")
5646
CliRunner().invoke(
57-
configure, ["-t", "gcc_arm", "-m", "k64f", "--app-config", app_config_path, "--cmake-build-dir", "build"]
47+
configure, ["-t", "gcc_arm", "-m", "k64f", "--app-config", app_config_path, "-o", "some_output_dir"]
5848
)
5949

6050
generate_config.assert_called_once_with("K64F", "GCC_ARM", program)
6151
self.assertEqual(program.files.app_config_file, app_config_path)
6252

6353
@mock.patch("mbed_tools.cli.configure.generate_config")
6454
@mock.patch("mbed_tools.cli.configure.MbedProgram")
65-
def test_cmake_build_dir_passed(self, program, generate_config):
55+
def test_output_dir_passed(self, program, generate_config):
6656
test_program = program.from_existing()
6757
program.reset_mock() # clear call count from previous line
6858

6959
toolchain = "gcc_arm"
7060
target = "k64f"
7161

7262
CliRunner().invoke(
73-
configure, ["-t", toolchain, "-m", target, "--cmake-build-dir", "some-build-dir"]
63+
configure, ["-t", toolchain, "-m", target, "-o", "some_output_dir"]
7464
)
7565

7666
program.from_existing.assert_called_once_with(
7767
pathlib.Path("."),
78-
pathlib.Path("some-build-dir")
68+
pathlib.Path("some_output_dir")
7969
)
8070
generate_config.assert_called_once_with("K64F", "GCC_ARM", test_program)

tools/python/python_tests/mbed_tools/project/test_mbed_program.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from mbed_tools.project import MbedProgram
1111
from mbed_tools.project.exceptions import ExistingProgram, ProgramNotFound, MbedOSNotFound
1212
from mbed_tools.project.mbed_program import _find_program_root, parse_url
13-
from mbed_tools.project._internal.project_data import MbedProgramFiles
13+
from mbed_tools.project._internal.project_data import MbedProgramFiles, BUILD_DIR
1414
from python_tests.mbed_tools.project.factories import make_mbed_program_files, make_mbed_os_files
1515

1616

@@ -40,7 +40,7 @@ def test_from_new_local_dir_generates_valid_program_creating_directory(self, tmp
4040

4141
program = from_new_set_target_toolchain(program_root)
4242

43-
assert program.files == MbedProgramFiles.from_existing(program_root, DEFAULT_BUILD_SUBDIR)
43+
assert program.files == MbedProgramFiles.from_existing(program_root, program_root / BUILD_DIR / DEFAULT_BUILD_SUBDIR)
4444

4545
def test_from_new_local_dir_generates_valid_program_creating_directory_in_cwd(self, tmp_path):
4646
old_cwd = os.getcwd()
@@ -52,7 +52,7 @@ def test_from_new_local_dir_generates_valid_program_creating_directory_in_cwd(se
5252

5353
program = from_new_set_target_toolchain(program_root)
5454

55-
assert program.files == MbedProgramFiles.from_existing(program_root, DEFAULT_BUILD_SUBDIR)
55+
assert program.files == MbedProgramFiles.from_existing(program_root, program_root / BUILD_DIR / DEFAULT_BUILD_SUBDIR)
5656
finally:
5757
os.chdir(old_cwd)
5858

@@ -64,29 +64,29 @@ def test_from_new_local_dir_generates_valid_program_existing_directory(self, tmp
6464

6565
program = from_new_set_target_toolchain(program_root)
6666

67-
assert program.files == MbedProgramFiles.from_existing(program_root, DEFAULT_BUILD_SUBDIR)
67+
assert program.files == MbedProgramFiles.from_existing(program_root, program_root / BUILD_DIR / DEFAULT_BUILD_SUBDIR)
6868

6969
def test_from_existing_raises_if_path_is_not_a_program(self, tmp_path):
7070
fs_root = pathlib.Path(tmp_path, "foo")
7171
fs_root.mkdir()
7272
program_root = fs_root / "programfoo"
7373

7474
with pytest.raises(ProgramNotFound):
75-
MbedProgram.from_existing(program_root, DEFAULT_BUILD_SUBDIR)
75+
MbedProgram.from_existing(program_root, program_root / BUILD_DIR / DEFAULT_BUILD_SUBDIR)
7676

7777
def test_from_existing_raises_if_no_mbed_os_dir_found_and_check_mbed_os_is_true(self, tmp_path):
7878
fs_root = pathlib.Path(tmp_path, "foo")
7979
make_mbed_program_files(fs_root)
8080

8181
with pytest.raises(MbedOSNotFound):
82-
MbedProgram.from_existing(fs_root, DEFAULT_BUILD_SUBDIR, check_mbed_os=True)
82+
MbedProgram.from_existing(fs_root, fs_root / BUILD_DIR / DEFAULT_BUILD_SUBDIR, check_mbed_os=True)
8383

8484
def test_from_existing_returns_valid_program(self, tmp_path):
8585
fs_root = pathlib.Path(tmp_path, "foo")
8686
make_mbed_program_files(fs_root)
8787
make_mbed_os_files(fs_root / "mbed-os")
8888

89-
program = MbedProgram.from_existing(fs_root, DEFAULT_BUILD_SUBDIR)
89+
program = MbedProgram.from_existing(fs_root, fs_root / BUILD_DIR / DEFAULT_BUILD_SUBDIR)
9090

9191
assert program.files.app_config_file.exists()
9292
assert program.mbed_os.root.exists()
@@ -98,7 +98,7 @@ def test_from_existing_with_mbed_os_path_returns_valid_program(self, tmp_path):
9898
make_mbed_program_files(fs_root)
9999
make_mbed_os_files(mbed_os_path)
100100

101-
program = MbedProgram.from_existing(fs_root, DEFAULT_BUILD_SUBDIR, mbed_os_path)
101+
program = MbedProgram.from_existing(fs_root, fs_root / BUILD_DIR / DEFAULT_BUILD_SUBDIR, mbed_os_path)
102102

103103
assert program.files.app_config_file.exists()
104104
assert program.mbed_os.root.exists()

tools/python/python_tests/mbed_tools/regression/test_configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ def test_generate_config_called_with_correct_arguments(self):
5656
pathlib.Path(tmpDirPath / "cmake-build-debug").mkdir()
5757

5858
result = CliRunner().invoke(
59-
configure, ["-m", "Target", "-t", "gcc_arm", "-p", tmpDir, "--cmake-build-dir", str(tmpDirPath / "cmake-build-debug")], catch_exceptions=False
59+
configure, ["-m", "Target", "-t", "gcc_arm", "-p", tmpDir, "-o", str(tmpDirPath / "cmake-build-debug")], catch_exceptions=False
6060
)
6161
self.assertIn("mbed_config.cmake has been generated and written to", result.output)

0 commit comments

Comments
 (0)