From f9c65a70daf9326457531d72794284cc8933e695 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Fri, 21 May 2021 12:08:26 +0100 Subject: [PATCH 01/11] Add basic project setup tool Grabs the boilerplate and customises it a little --- src/ttblit/__init__.py | 2 ++ src/ttblit/tool/setup.py | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/ttblit/tool/setup.py diff --git a/src/ttblit/__init__.py b/src/ttblit/__init__.py index a859ae0..e7e8ac7 100644 --- a/src/ttblit/__init__.py +++ b/src/ttblit/__init__.py @@ -10,6 +10,7 @@ from .tool.metadata import metadata_cli from .tool.packer import pack_cli from .tool.relocs import relocs_cli +from .tool.setup import setup_cli @click.group() @@ -33,6 +34,7 @@ def main(debug, verbose): main.add_command(metadata_cli) main.add_command(pack_cli) main.add_command(relocs_cli) +main.add_command(setup_cli) @main.command(help='Print version and exit') diff --git a/src/ttblit/tool/setup.py b/src/ttblit/tool/setup.py new file mode 100644 index 0000000..be46d65 --- /dev/null +++ b/src/ttblit/tool/setup.py @@ -0,0 +1,51 @@ +import os +import logging +import pathlib +import re +import shutil +import subprocess + +import click + +@click.command('setup', help='Setup a project') +@click.option('--project-name', prompt=True) +@click.option('--author-name', prompt=True) +@click.option('--sdk-path', type=pathlib.Path, default=lambda: os.path.expanduser('~/32blit-sdk'), prompt='32Blit SDK path') +@click.option('--git/--no-git', prompt='Initialise a Git repository?', default=True) +def setup_cli(project_name, author_name, sdk_path, git): + if not (sdk_path / '32blit.toolchain').exists(): + if click.confirm(f'32Blit SDK not found at "{sdk_path}", would you like to install it?', abort=True): + click.echo('Installing SDK...') + + project_name_clean = re.sub(r'[^a-z0-9]+', '-', project_name.lower()).strip('-') + project_path = pathlib.Path.cwd() / project_name_clean + + if project_path.exists(): + logging.critical(f'A project already exists at {project_path}!') + raise click.Abort() + + # get the boilerplate + click.echo('Downloading boilerplate...') + subprocess.run(['git', 'clone', '--depth', '1', 'https://github.com/32blit/32blit-boilerplate', project_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + # de-git it (using the template on GitHub also removes the history) + shutil.rmtree(pathlib.Path(project_name_clean) / '.git') + + # do some editing + cmakelists = open(project_path / 'CMakeLists.txt').read() + cmakelists = cmakelists.replace('project(game)', f'project({project_name_clean})') + open(project_path / 'CMakeLists.txt', 'w').write(cmakelists) + + metadata = open(project_path / 'metadata.yml').read() + metadata = metadata.replace('game title', project_name).replace('you', author_name) + open(project_path / 'metadata.yml', 'w').write(metadata) + + licence = open(project_path / 'LICENSE').read() + licence = licence.replace('', author_name) + open(project_path / 'LICENSE', 'w').write(licence) + + # re-git it if we want a git repo + if git: + subprocess.run(['git', 'init'], cwd=project_path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + subprocess.run(['git', 'add', '.'], cwd=project_path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + subprocess.run(['git', 'commit', '-m', 'Initial commit'], cwd=project_path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) From 6ad411311e8864033b0dfcb8f6e053bf80f99603 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Fri, 21 May 2021 12:09:20 +0100 Subject: [PATCH 02/11] Attempt to verify the evnironment before setup prompts --- src/ttblit/tool/setup.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/ttblit/tool/setup.py b/src/ttblit/tool/setup.py index be46d65..74d3b45 100644 --- a/src/ttblit/tool/setup.py +++ b/src/ttblit/tool/setup.py @@ -7,7 +7,45 @@ import click -@click.command('setup', help='Setup a project') +# check environment before prompting +class SetupCommand(click.Command): + def parse_args(self, ctx, args): + logging.info("Checking for prerequisites...") + + # command/name/required version + prereqs = [ + (['git', '--version'], 'Git', None), + (['cmake', '--version'], 'CMake', [3, 9]), + (['arm-none-eabi-gcc', '--version'], 'GCC Arm Toolchain', [7, 3]) + ] + + failed = False + + for command, name, version in prereqs: + try: + result = subprocess.run(command, stdout=subprocess.PIPE, text=True) + + version_str = ".".join([str(x) for x in version]) if version else 'any' + found_version_str = re.search(r'[0-9]+\.[0-9\.]+', result.stdout).group(0) + + if version: + found_version_list = [int(x) for x in found_version_str.split('.')[:len(version)]] + if found_version_list < version: + logging.critical(f'Found {name} version {found_version_str}, {version_str} is required!') + failed = True + + logging.info(f'Found {name} version {found_version_str} (required {version_str})') + except: + logging.critical(f'Could not find {name}!') + failed = True + + if failed: + click.echo('\nCheck the documentation for info on installing.\nhttps://github.com/32blit/32blit-sdk#you-will-need') + raise click.Abort() + + super().parse_args(ctx, args) + +@click.command('setup', help='Setup a project', cls=SetupCommand) @click.option('--project-name', prompt=True) @click.option('--author-name', prompt=True) @click.option('--sdk-path', type=pathlib.Path, default=lambda: os.path.expanduser('~/32blit-sdk'), prompt='32Blit SDK path') From 45ef4bb08b20e64b1ae15438d1773772f36f1adf Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Fri, 21 May 2021 12:24:06 +0100 Subject: [PATCH 03/11] Actually install the sdk --- src/ttblit/tool/setup.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ttblit/tool/setup.py b/src/ttblit/tool/setup.py index 74d3b45..124773c 100644 --- a/src/ttblit/tool/setup.py +++ b/src/ttblit/tool/setup.py @@ -45,6 +45,16 @@ def parse_args(self, ctx, args): super().parse_args(ctx, args) +def install_sdk(sdk_path): + click.echo('Installing SDK...') + subprocess.run(['git', 'clone', 'https://github.com/32blit/32blit-sdk', sdk_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + # checkout the latest release + # TODO: could do something with the GitHub API and download the release? + result = subprocess.run(['git', 'describe', '--tags', '--abbrev=0'], cwd=sdk_path, text=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + latest_tag = result.stdout.strip() + result = subprocess.run(['git', 'checkout', latest_tag], cwd=sdk_path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + @click.command('setup', help='Setup a project', cls=SetupCommand) @click.option('--project-name', prompt=True) @click.option('--author-name', prompt=True) @@ -52,8 +62,8 @@ def parse_args(self, ctx, args): @click.option('--git/--no-git', prompt='Initialise a Git repository?', default=True) def setup_cli(project_name, author_name, sdk_path, git): if not (sdk_path / '32blit.toolchain').exists(): - if click.confirm(f'32Blit SDK not found at "{sdk_path}", would you like to install it?', abort=True): - click.echo('Installing SDK...') + click.confirm(f'32Blit SDK not found at "{sdk_path}", would you like to install it?', abort=True) + install_sdk(sdk_path) project_name_clean = re.sub(r'[^a-z0-9]+', '-', project_name.lower()).strip('-') project_path = pathlib.Path.cwd() / project_name_clean From 87e71ad65454ecf14842308e7141baa74c222848 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Fri, 21 May 2021 12:35:09 +0100 Subject: [PATCH 04/11] Optionally generate VS code config --- src/ttblit/tool/setup.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ttblit/tool/setup.py b/src/ttblit/tool/setup.py index 124773c..fdef133 100644 --- a/src/ttblit/tool/setup.py +++ b/src/ttblit/tool/setup.py @@ -4,6 +4,7 @@ import re import shutil import subprocess +import textwrap import click @@ -55,12 +56,36 @@ def install_sdk(sdk_path): latest_tag = result.stdout.strip() result = subprocess.run(['git', 'checkout', latest_tag], cwd=sdk_path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) +def vscode_config(project_path, sdk_path): + (project_path / '.vscode').mkdir() + + open(project_path / '.vscode' / 'settings.json','w').write(textwrap.dedent( + ''' + { + "cmake.configureSettings": { + "32BLIT_DIR": "{sdk_path}" + }, + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" + } + '''.replace('{sdk_path}', str(sdk_path)))) + + open(project_path / '.vscode' / 'cmake-kits.json','w').write(textwrap.dedent( + ''' + [ + { + "name": "32blit", + "toolchainFile": "{sdk_path}/32blit.toolchain" + } + ] + '''.replace('{sdk_path}', str(sdk_path)))) + @click.command('setup', help='Setup a project', cls=SetupCommand) @click.option('--project-name', prompt=True) @click.option('--author-name', prompt=True) @click.option('--sdk-path', type=pathlib.Path, default=lambda: os.path.expanduser('~/32blit-sdk'), prompt='32Blit SDK path') @click.option('--git/--no-git', prompt='Initialise a Git repository?', default=True) -def setup_cli(project_name, author_name, sdk_path, git): +@click.option('--vscode/--no-vscode', prompt='Create VS Code configuration?', default=True) +def setup_cli(project_name, author_name, sdk_path, git, vscode): if not (sdk_path / '32blit.toolchain').exists(): click.confirm(f'32Blit SDK not found at "{sdk_path}", would you like to install it?', abort=True) install_sdk(sdk_path) @@ -97,3 +122,6 @@ def setup_cli(project_name, author_name, sdk_path, git): subprocess.run(['git', 'init'], cwd=project_path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.run(['git', 'add', '.'], cwd=project_path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.run(['git', 'commit', '-m', 'Initial commit'], cwd=project_path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + if vscode: + vscode_config(project_path, sdk_path) From 23419fc076b9d60f829bd362a51d55d1edae94e0 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Fri, 21 May 2021 12:49:46 +0100 Subject: [PATCH 05/11] Optionally generate VS config Yay, repetition --- src/ttblit/tool/setup.py | 78 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/ttblit/tool/setup.py b/src/ttblit/tool/setup.py index fdef133..6403915 100644 --- a/src/ttblit/tool/setup.py +++ b/src/ttblit/tool/setup.py @@ -79,13 +79,87 @@ def vscode_config(project_path, sdk_path): ] '''.replace('{sdk_path}', str(sdk_path)))) +def visualstudio_config(project_path, sdk_path): + open(project_path / 'CMakeSettings.json','w').write(textwrap.dedent( + ''' + { + "configurations": [ + { + "name": "x64-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${projectDir}\\\\out\\\\build\\\\${name}", + "installRoot": "${projectDir}\\\\out\\\\install\\\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "variables": [ + { + "name": "32BLIT_DIR", + "value": "{sdk_path}", + "type": "PATH" + } + ] + }, + { + "name": "x64-Release", + "generator": "Ninja", + "configurationType": "Release", + "buildRoot": "${projectDir}\\\\out\\\\build\\\\${name}", + "installRoot": "${projectDir}\\\\out\\\\install\\\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64_x64" ], + "variables": [ + { + "name": "32BLIT_DIR", + "value": "{sdk_path}", + "type": "PATH" + } + ] + }, + { + "name": "32Blit-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "buildRoot": "${projectDir}\\\\out\\\\build\\\\${name}", + "installRoot": "${projectDir}\\\\out\\\\install\\\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "gcc-arm" ], + "variables": [], + "cmakeToolchain": "{sdk_path}/32blit.toolchain", + "intelliSenseMode": "linux-gcc-arm" + }, + { + "name": "32Blit-Release", + "generator": "Ninja", + "configurationType": "Release", + "buildRoot": "${projectDir}\\\\out\\\\build\\\\${name}", + "installRoot": "${projectDir}\\\\out\\\\install\\\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "cmakeToolchain": "{sdk_path}/32blit.toolchain", + "inheritEnvironments": [ "gcc-arm" ], + "variables": [], + "intelliSenseMode": "linux-gcc-arm" + } + ] + } + '''.replace('{sdk_path}', str(sdk_path)))) + @click.command('setup', help='Setup a project', cls=SetupCommand) @click.option('--project-name', prompt=True) @click.option('--author-name', prompt=True) @click.option('--sdk-path', type=pathlib.Path, default=lambda: os.path.expanduser('~/32blit-sdk'), prompt='32Blit SDK path') @click.option('--git/--no-git', prompt='Initialise a Git repository?', default=True) @click.option('--vscode/--no-vscode', prompt='Create VS Code configuration?', default=True) -def setup_cli(project_name, author_name, sdk_path, git, vscode): +@click.option('--visualstudio/--no-visualstudio', prompt='Create Visual Studio configuration?') +def setup_cli(project_name, author_name, sdk_path, git, vscode, visualstudio): if not (sdk_path / '32blit.toolchain').exists(): click.confirm(f'32Blit SDK not found at "{sdk_path}", would you like to install it?', abort=True) install_sdk(sdk_path) @@ -125,3 +199,5 @@ def setup_cli(project_name, author_name, sdk_path, git, vscode): if vscode: vscode_config(project_path, sdk_path) + if visualstudio: + visualstudio_config(project_path, sdk_path) \ No newline at end of file From 5ecd5935db9ed4edb45fa84854dc9ba9163be6f9 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Fri, 21 May 2021 16:00:21 +0100 Subject: [PATCH 06/11] Fix some windows path issues --- src/ttblit/tool/setup.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ttblit/tool/setup.py b/src/ttblit/tool/setup.py index 6403915..7b73cf1 100644 --- a/src/ttblit/tool/setup.py +++ b/src/ttblit/tool/setup.py @@ -3,6 +3,7 @@ import pathlib import re import shutil +import stat import subprocess import textwrap @@ -48,7 +49,7 @@ def parse_args(self, ctx, args): def install_sdk(sdk_path): click.echo('Installing SDK...') - subprocess.run(['git', 'clone', 'https://github.com/32blit/32blit-sdk', sdk_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + subprocess.run(['git', 'clone', 'https://github.com/32blit/32blit-sdk', str(sdk_path)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # checkout the latest release # TODO: could do something with the GitHub API and download the release? @@ -131,7 +132,7 @@ def visualstudio_config(project_path, sdk_path): "ctestCommandArgs": "", "inheritEnvironments": [ "gcc-arm" ], "variables": [], - "cmakeToolchain": "{sdk_path}/32blit.toolchain", + "cmakeToolchain": "{sdk_path}\\\\32blit.toolchain", "intelliSenseMode": "linux-gcc-arm" }, { @@ -143,14 +144,14 @@ def visualstudio_config(project_path, sdk_path): "cmakeCommandArgs": "", "buildCommandArgs": "", "ctestCommandArgs": "", - "cmakeToolchain": "{sdk_path}/32blit.toolchain", + "cmakeToolchain": "{sdk_path}\\\\32blit.toolchain", "inheritEnvironments": [ "gcc-arm" ], "variables": [], "intelliSenseMode": "linux-gcc-arm" } ] } - '''.replace('{sdk_path}', str(sdk_path)))) + '''.replace('{sdk_path}', str(sdk_path).replace('\\', '\\\\')))) @click.command('setup', help='Setup a project', cls=SetupCommand) @click.option('--project-name', prompt=True) @@ -173,10 +174,14 @@ def setup_cli(project_name, author_name, sdk_path, git, vscode, visualstudio): # get the boilerplate click.echo('Downloading boilerplate...') - subprocess.run(['git', 'clone', '--depth', '1', 'https://github.com/32blit/32blit-boilerplate', project_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + subprocess.run(['git', 'clone', '--depth', '1', 'https://github.com/32blit/32blit-boilerplate', str(project_path)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # de-git it (using the template on GitHub also removes the history) - shutil.rmtree(pathlib.Path(project_name_clean) / '.git') + def remove_readonly(func, path, _): + os.chmod(path, stat.S_IWRITE) + func(path) + + shutil.rmtree(pathlib.Path(project_name_clean) / '.git', onerror=remove_readonly) # do some editing cmakelists = open(project_path / 'CMakeLists.txt').read() From c4d0eff2fa4f222115bda31ab255ba90bdb29218 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Mon, 24 May 2021 15:26:59 +0100 Subject: [PATCH 07/11] Fix windows paths in generated VS Code config --- src/ttblit/tool/setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ttblit/tool/setup.py b/src/ttblit/tool/setup.py index 7b73cf1..aefd9d5 100644 --- a/src/ttblit/tool/setup.py +++ b/src/ttblit/tool/setup.py @@ -68,7 +68,7 @@ def vscode_config(project_path, sdk_path): }, "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" } - '''.replace('{sdk_path}', str(sdk_path)))) + '''.replace('{sdk_path}', str(sdk_path).replace('\\', '\\\\')))) open(project_path / '.vscode' / 'cmake-kits.json','w').write(textwrap.dedent( ''' @@ -78,7 +78,7 @@ def vscode_config(project_path, sdk_path): "toolchainFile": "{sdk_path}/32blit.toolchain" } ] - '''.replace('{sdk_path}', str(sdk_path)))) + '''.replace('{sdk_path}', str(sdk_path).replace('\\', '\\\\')))) def visualstudio_config(project_path, sdk_path): open(project_path / 'CMakeSettings.json','w').write(textwrap.dedent( From 7d16254a30f2aa0422d0402c5017de452e8e1b49 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Mon, 24 May 2021 15:27:59 +0100 Subject: [PATCH 08/11] Test that generated configs parse Usually because a windows path isn't escaped right --- src/tests/test_setup.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/tests/test_setup.py diff --git a/src/tests/test_setup.py b/src/tests/test_setup.py new file mode 100644 index 0000000..e533474 --- /dev/null +++ b/src/tests/test_setup.py @@ -0,0 +1,39 @@ +import json +import pathlib +import tempfile + +def test_visualstudio_windows(): + from ttblit.tool.setup import visualstudio_config + + with tempfile.TemporaryDirectory() as dir: + project_path = pathlib.Path(dir) + sdk_path = pathlib.PureWindowsPath('C:\\Users\\A User\\32blit-sdk') + + visualstudio_config(project_path, sdk_path) + + # check that the generated config parses + conf_path = project_path / 'CMakeSettings.json' + assert conf_path.exists() + + json.load(open(conf_path)) + + +def test_vscode_windows(): + from ttblit.tool.setup import vscode_config + + with tempfile.TemporaryDirectory() as dir: + project_path = pathlib.Path(dir) + sdk_path = pathlib.PureWindowsPath('C:\\Users\\A User\\32blit-sdk') + + vscode_config(project_path, sdk_path) + + # check that the generated config parses + conf_path = project_path / '.vscode' / 'settings.json' + assert conf_path.exists() + + json.load(open(conf_path)) + + conf_path = project_path / '.vscode' / 'cmake-kits.json' + assert conf_path.exists() + + json.load(open(conf_path)) From a704f566e1dec35ead94404a7deb34ff2972d010 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Mon, 24 May 2021 14:23:12 +0100 Subject: [PATCH 09/11] Add test for Setup tool --- .github/workflows/test-setup.yml | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/test-setup.yml diff --git a/.github/workflows/test-setup.yml b/.github/workflows/test-setup.yml new file mode 100644 index 0000000..fd29524 --- /dev/null +++ b/.github/workflows/test-setup.yml @@ -0,0 +1,61 @@ +name: Runtime Tests - Setup + +on: + push: + pull_request: + +env: + BUILD_TYPE: Release + +jobs: + test: + strategy: + matrix: + include: + - os: ubuntu-20.04 + name: Ubuntu / STM32 + cache-key: stm32 + release-suffix: STM32 + cmake-args: -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/32blit-sdk/32blit.toolchain -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + apt-packages: ccache gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib python3-setuptools + + runs-on: ${{matrix.os}} + + steps: + # Linux deps + - name: Install Dependencies + if: runner.os == 'Linux' + run: | + sudo apt update && sudo apt install ${{matrix.apt-packages}} + + - uses: actions/checkout@v2 + - name: Grab the SDK + uses: actions/checkout@v2 + with: + repository: 32blit/32blit-sdk + path: 32blit-sdk + + - name: Install 32Blit Tools + working-directory: src + run: | + python3 setup.py install --user + + - name: Test Setup Tool + run: | + python3 -m ttblit setup --project-name Test --author-name Test --sdk-path=$GITHUB_WORKSPACE/32blit-sdk --git --vscode --visualstudio + + - name: Create Build Environment + run: cmake -E make_directory ${{runner.workspace}}/build + + - name: Configure CMake + shell: bash + working-directory: ${{runner.workspace}}/build + run: cmake $GITHUB_WORKSPACE/test -DCMAKE_BUILD_TYPE=$BUILD_TYPE ${{matrix.cmake-args}} + + - name: Build + working-directory: ${{runner.workspace}}/build + shell: bash + run: | + ccache --zero-stats || true + cmake --build . --config $BUILD_TYPE -j 2 + ccache --show-stats || true \ No newline at end of file From e867fa4915858a570db4438b6e5a55c502b4a74b Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Mon, 24 May 2021 15:42:07 +0100 Subject: [PATCH 10/11] Extra feed back at the end --- src/ttblit/tool/setup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ttblit/tool/setup.py b/src/ttblit/tool/setup.py index aefd9d5..3d745fa 100644 --- a/src/ttblit/tool/setup.py +++ b/src/ttblit/tool/setup.py @@ -205,4 +205,8 @@ def remove_readonly(func, path, _): if vscode: vscode_config(project_path, sdk_path) if visualstudio: - visualstudio_config(project_path, sdk_path) \ No newline at end of file + visualstudio_config(project_path, sdk_path) + + click.echo(f'\nYour new project has been created in: {project_path}!') + + click.echo(f'If using CMake directly, make sure to pass -DCMAKE_TOOLCHAIN_FILE={sdk_path / "32blit.toolchain"} (building for the device)\nor -D32BLIT_DIR={sdk_path} when calling cmake.') \ No newline at end of file From 8e5dc982d662e4418d6bdd913c641add677da49f Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Mon, 24 May 2021 15:48:50 +0100 Subject: [PATCH 11/11] Find the VS provided Arm toolchain This is enough to find all the tools if you're running in a developer command prompt. --- src/ttblit/tool/setup.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ttblit/tool/setup.py b/src/ttblit/tool/setup.py index 3d745fa..8aea2f3 100644 --- a/src/ttblit/tool/setup.py +++ b/src/ttblit/tool/setup.py @@ -16,16 +16,24 @@ def parse_args(self, ctx, args): # command/name/required version prereqs = [ - (['git', '--version'], 'Git', None), - (['cmake', '--version'], 'CMake', [3, 9]), - (['arm-none-eabi-gcc', '--version'], 'GCC Arm Toolchain', [7, 3]) + ('git --version', 'Git', None), + ('cmake --version', 'CMake', [3, 9]), + ('arm-none-eabi-gcc --version', 'GCC Arm Toolchain', [7, 3]) ] + # adjust path to dectct the VS Arm toolchain + path = os.getenv('PATH') + vs_dir = os.getenv('VSInstallDir') + + if vs_dir: + path = ';'.join([path, vs_dir + 'Linux\\gcc_arm\\bin']) + print(path) + failed = False for command, name, version in prereqs: try: - result = subprocess.run(command, stdout=subprocess.PIPE, text=True) + result = subprocess.run(command, stdout=subprocess.PIPE, text=True, shell=True, env={'PATH': path}) version_str = ".".join([str(x) for x in version]) if version else 'any' found_version_str = re.search(r'[0-9]+\.[0-9\.]+', result.stdout).group(0)