From 55fd36e15b3e0111985d5cb8a1fc36d1f90f9b6e Mon Sep 17 00:00:00 2001 From: tsnider Date: Fri, 21 Sep 2018 09:56:52 -0400 Subject: [PATCH 1/5] Move build functionality from grid-tied. --- src/ccstudiodss/build.py | 83 ++++++++++++++++++++++++++++++++++++++++ src/ccstudiodss/cli.py | 4 ++ src/ccstudiodss/utils.py | 8 +++- 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/ccstudiodss/build.py diff --git a/src/ccstudiodss/build.py b/src/ccstudiodss/build.py new file mode 100644 index 0000000..39d0dee --- /dev/null +++ b/src/ccstudiodss/build.py @@ -0,0 +1,83 @@ +import os +import subprocess +import tempfile + +import click + +import ccstudiodss.utils + + +build_type_choices = ('incremental', 'full', 'clean') + +DSS_PROJECT_ROOT = 'DSS_PROJECT_ROOT' +project_root_option = click.option( + '--project-root', + type=click.Path(exists=True, file_okay=False, resolve_path=True), + envvar=DSS_PROJECT_ROOT, + help=( + 'Directory containing the .project file' + ' (${})'.format(DSS_PROJECT_ROOT) + ), +) + + +DSS_PROJECT_NAME = 'DSS_PROJECT_NAME' +project_name_option = click.option( + '--project-name', + type=str, + envvar=DSS_PROJECT_NAME, + help=( + 'Project name used for build artifacts' + ' (${})'.format(DSS_PROJECT_NAME) + ), +) + + +@click.command() +@click.option('--target', required=True) +@click.option( + '--build-type', + type=click.Choice(build_type_choices), + default=build_type_choices[0], + show_default=True, +) +@project_root_option +@project_name_option +def cli(target, build_type, project_root, project_name): + """Build the project using Code Composer Studio + """ + if project_name is None: + project_name = pathlib.Path(project_root).parts[-1] + + with tempfile.TemporaryDirectory() as d: + base_command = ( + os.fspath(ccstudiodss.utils.find_executable()), + '-noSplash', + '-data', d, + ) + + try: + subprocess.run( + [ + *base_command, + '-application', 'com.ti.ccstudio.apps.projectImport', + '-ccs.location', str(project_root), + '-ccs.renameTo', project_name, + ], + check=True, + ) + except subprocess.CalledProcessError: + pass + + for this_build_type in (build_type, 'incremental'): + completed_process = subprocess.run( + [ + *base_command, + '-application', 'com.ti.ccstudio.apps.projectBuild', + '-ccs.projects', project_name, + '-ccs.configuration', target, + '-ccs.buildType', this_build_type, + ], + ) + + completed_process.check_returncode() diff --git a/src/ccstudiodss/cli.py b/src/ccstudiodss/cli.py index ba87762..2577dd2 100644 --- a/src/ccstudiodss/cli.py +++ b/src/ccstudiodss/cli.py @@ -6,6 +6,7 @@ import ccstudiodss.api import ccstudiodss.utils +import ccstudiodss.build @click.group() @@ -80,3 +81,6 @@ def docs(ccs_base_path, open_): webbrowser.open(path) else: click.echo(path) + + +cli.add_command(ccstudiodss.build.cli, name='build') diff --git a/src/ccstudiodss/utils.py b/src/ccstudiodss/utils.py index 5eba817..b3dde49 100644 --- a/src/ccstudiodss/utils.py +++ b/src/ccstudiodss/utils.py @@ -16,7 +16,7 @@ class BasePathError(Exception): pathlib.Path(os.sep)/'opt'/'ti'/'ccsv{}'.format(version)/'ccs_base' for version in versions ), - *( # in case the ccsv8 or such gets doubled up + *( pathlib.Path(os.sep)/'opt'/'ti'/'ccsv{}'.format(version)/'ccsv{}'.format(version)/'ccs_base' for version in versions ), @@ -24,7 +24,7 @@ class BasePathError(Exception): pathlib.Path.home()/'ti'/'ccsv{}'.format(version)/'ccs_base' for version in versions ), - *( # in case the ccsv8 or such gets doubled up + *( pathlib.Path.home()/'ti'/'ccsv{}'.format(version)/'ccsv{}'.format(version)/'ccs_base' for version in versions ), @@ -59,3 +59,7 @@ def find_base_path(): raise BasePathError('Unable to find base path in: {}'.format( ', '.join(repr(str(path)) for path in base_paths), )) + + +def find_executable(): + return find_base_path().parents[0]/'eclipse'/'ccstudio' From a0e76743f9de5d9ee580469a2397b28c359e9af1 Mon Sep 17 00:00:00 2001 From: tsnider Date: Fri, 21 Sep 2018 09:57:16 -0400 Subject: [PATCH 2/5] Add Eclipse/Pydev project files. --- .project | 17 +++++++++++++++++ .pydevproject | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 .project create mode 100644 .pydevproject diff --git a/.project b/.project new file mode 100644 index 0000000..73e7ab7 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + ccstudiodss + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/.pydevproject b/.pydevproject new file mode 100644 index 0000000..98114ac --- /dev/null +++ b/.pydevproject @@ -0,0 +1,5 @@ + + +python +python interpreter + From dc1db2a0226c4d8e4562a2720dc59e1f62fd8d23 Mon Sep 17 00:00:00 2001 From: tsnider Date: Fri, 21 Sep 2018 15:12:53 -0400 Subject: [PATCH 3/5] Improve build organization. --- src/ccstudiodss/api.py | 41 ++++++++++++++++++ src/ccstudiodss/build.py | 83 ------------------------------------ src/ccstudiodss/cli.py | 91 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 125 insertions(+), 90 deletions(-) delete mode 100644 src/ccstudiodss/build.py diff --git a/src/ccstudiodss/api.py b/src/ccstudiodss/api.py index 6eacd0e..181abf5 100644 --- a/src/ccstudiodss/api.py +++ b/src/ccstudiodss/api.py @@ -1,6 +1,8 @@ import contextlib import os import pathlib +import subprocess +import tempfile import attr import javabridge @@ -103,3 +105,42 @@ def run(self): def restart(self): self.debug_session.target.reset() self.debug_session.target.runAsynch() + +def build(target, build_type, project_root, project_name): + if project_name is None: + project_name = pathlib.Path(project_root).parts[-1] + + with tempfile.TemporaryDirectory() as d: + base_command = ( + os.fspath(ccstudiodss.utils.find_executable()), + '-noSplash', + '-data', d, + ) + + try: + subprocess.run( + [ + *base_command, + '-application', 'com.ti.ccstudio.apps.projectImport', + '-ccs.location', str(project_root), + '-ccs.renameTo', project_name, + ], + check=True, + ) + except subprocess.CalledProcessError: + pass + + for this_build_type in (build_type, 'incremental'): + completed_process = subprocess.run( + [ + *base_command, + '-application', 'com.ti.ccstudio.apps.projectBuild', + '-ccs.projects', project_name, + '-ccs.configuration', target, + '-ccs.buildType', this_build_type, + ], + ) + + completed_process.check_returncode() + + return pathlib.Path(project_root)/target/(project_name + '.out') diff --git a/src/ccstudiodss/build.py b/src/ccstudiodss/build.py deleted file mode 100644 index 39d0dee..0000000 --- a/src/ccstudiodss/build.py +++ /dev/null @@ -1,83 +0,0 @@ -import os -import subprocess -import tempfile - -import click - -import ccstudiodss.utils - - -build_type_choices = ('incremental', 'full', 'clean') - -DSS_PROJECT_ROOT = 'DSS_PROJECT_ROOT' -project_root_option = click.option( - '--project-root', - type=click.Path(exists=True, file_okay=False, resolve_path=True), - envvar=DSS_PROJECT_ROOT, - help=( - 'Directory containing the .project file' - ' (${})'.format(DSS_PROJECT_ROOT) - ), -) - - -DSS_PROJECT_NAME = 'DSS_PROJECT_NAME' -project_name_option = click.option( - '--project-name', - type=str, - envvar=DSS_PROJECT_NAME, - help=( - 'Project name used for build artifacts' - ' (${})'.format(DSS_PROJECT_NAME) - ), -) - - -@click.command() -@click.option('--target', required=True) -@click.option( - '--build-type', - type=click.Choice(build_type_choices), - default=build_type_choices[0], - show_default=True, -) -@project_root_option -@project_name_option -def cli(target, build_type, project_root, project_name): - """Build the project using Code Composer Studio - """ - if project_name is None: - project_name = pathlib.Path(project_root).parts[-1] - - with tempfile.TemporaryDirectory() as d: - base_command = ( - os.fspath(ccstudiodss.utils.find_executable()), - '-noSplash', - '-data', d, - ) - - try: - subprocess.run( - [ - *base_command, - '-application', 'com.ti.ccstudio.apps.projectImport', - '-ccs.location', str(project_root), - '-ccs.renameTo', project_name, - ], - check=True, - ) - except subprocess.CalledProcessError: - pass - - for this_build_type in (build_type, 'incremental'): - completed_process = subprocess.run( - [ - *base_command, - '-application', 'com.ti.ccstudio.apps.projectBuild', - '-ccs.projects', project_name, - '-ccs.configuration', target, - '-ccs.buildType', this_build_type, - ], - ) - - completed_process.check_returncode() diff --git a/src/ccstudiodss/cli.py b/src/ccstudiodss/cli.py index 2577dd2..3706cae 100644 --- a/src/ccstudiodss/cli.py +++ b/src/ccstudiodss/cli.py @@ -6,7 +6,48 @@ import ccstudiodss.api import ccstudiodss.utils -import ccstudiodss.build + + +build_type_choices = ('incremental', 'full', 'clean') + +DSS_PROJECT_ROOT = 'DSS_PROJECT_ROOT' +project_root_option = click.option( + '--project-root', + type=click.Path(exists=True, file_okay=False, resolve_path=True), + envvar=DSS_PROJECT_ROOT, + help=( + 'Directory containing the .project file' + ' (${})'.format(DSS_PROJECT_ROOT) + ), +) + + +DSS_PROJECT_NAME = 'DSS_PROJECT_NAME' +project_name_option = click.option( + '--project-name', + type=str, + envvar=DSS_PROJECT_NAME, + help=( + 'Project name used for build artifacts' + ' (${})'.format(DSS_PROJECT_NAME) + ), +) + + +def default_base_path(): + base_path = ccstudiodss.utils.find_base_path() + if base_path is None: + return {'required': True} + + return {'default': base_path} + +ccs_base_path_option = click.option( + '--ccs-base-path', + type=click.Path(exists=True, file_okay=False), + show_default=True, + **default_base_path(), + help='CCS base directory, e.g. /ti/ccsv8/ccs_base' +) @click.group() @@ -34,11 +75,6 @@ def default_ccxml(): **default_ccxml(), ) -ccs_base_path_option = click.option( - '--ccs-base-path', - type=click.Path(exists=True, file_okay=False), -) - @cli.command() @click.option( @@ -82,5 +118,46 @@ def docs(ccs_base_path, open_): else: click.echo(path) +build_type_option = click.option( + '--build-type', + type=click.Choice(build_type_choices), + default=build_type_choices[0], + show_default=True, +) + +target_option = click.option('--target', required=True) +@cli.command() +@target_option +@build_type_option +@project_root_option +@project_name_option +def build(target, build_type, project_root, project_name): + """Build the project using Code Composer Studio + """ + ccstudiodss.api.build( + target=target, + build_type=build_type, + project_root=project_root, + project_name=project_name, + ) + + +GRIDTIED_CCXML = 'GRIDTIED_CCXML' + +def create_ccxml_option(project_root): + paths = list(project_root.glob('*.ccxml')) + if len(paths) != 1: + default_or_required = {'required': True} + else: + default_or_required = {'default': paths[0]} + + ccxml_option = click.option( + '--ccxml', + type=click.Path(exists=True, dir_okay=False), + envvar=GRIDTIED_CCXML, + **default_or_required, + help='.ccxml device configuration file (${})'.format(GRIDTIED_CCXML), + show_default=True, + ) -cli.add_command(ccstudiodss.build.cli, name='build') + return ccxml_option From 0641a7d5924b5ba1686f6b7f70ec881b1b6e998d Mon Sep 17 00:00:00 2001 From: tsnider Date: Tue, 25 Sep 2018 18:14:54 -0400 Subject: [PATCH 4/5] Move build type to api @altendky --- src/ccstudiodss/api.py | 4 ++++ src/ccstudiodss/cli.py | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ccstudiodss/api.py b/src/ccstudiodss/api.py index 181abf5..05949de 100644 --- a/src/ccstudiodss/api.py +++ b/src/ccstudiodss/api.py @@ -1,14 +1,18 @@ + import contextlib import os import pathlib import subprocess import tempfile +from enum import Enum +from collections import namedtuple as ntup import attr import javabridge import ccstudiodss.utils +build_type_choices = ('incremental', 'full', 'clean') def add_jars(base_path=None): if base_path is None: diff --git a/src/ccstudiodss/cli.py b/src/ccstudiodss/cli.py index 3706cae..ab63fb5 100644 --- a/src/ccstudiodss/cli.py +++ b/src/ccstudiodss/cli.py @@ -8,8 +8,6 @@ import ccstudiodss.utils -build_type_choices = ('incremental', 'full', 'clean') - DSS_PROJECT_ROOT = 'DSS_PROJECT_ROOT' project_root_option = click.option( '--project-root', @@ -120,8 +118,8 @@ def docs(ccs_base_path, open_): build_type_option = click.option( '--build-type', - type=click.Choice(build_type_choices), - default=build_type_choices[0], + type=click.Choice(ccstudiodss.api.build_type_choices), + default=ccstudiodss.api.build_type_choices[0], show_default=True, ) From d40c09e04721160a71d4e78288a8dc114e472995 Mon Sep 17 00:00:00 2001 From: tsnider Date: Tue, 25 Sep 2018 20:45:14 -0400 Subject: [PATCH 5/5] Remove unused imports --- src/ccstudiodss/api.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ccstudiodss/api.py b/src/ccstudiodss/api.py index 05949de..f73fb0f 100644 --- a/src/ccstudiodss/api.py +++ b/src/ccstudiodss/api.py @@ -4,8 +4,6 @@ import pathlib import subprocess import tempfile -from enum import Enum -from collections import namedtuple as ntup import attr import javabridge