Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build subcommand for building project #1

Merged
merged 5 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ccstudiodss</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let adding these slide. :]

5 changes: 5 additions & 0 deletions .pydevproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
</pydev_project>
41 changes: 41 additions & 0 deletions src/ccstudiodss/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import contextlib
import os
import pathlib
import subprocess
import tempfile

import attr
import javabridge
Expand Down Expand Up @@ -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')
91 changes: 86 additions & 5 deletions src/ccstudiodss/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,48 @@
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)
),
)


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()
def cli():
pass
Expand All @@ -33,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(
Expand Down Expand Up @@ -80,3 +117,47 @@ def docs(ccs_base_path, open_):
webbrowser.open(path)
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,
)

return ccxml_option
8 changes: 6 additions & 2 deletions src/ccstudiodss/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ 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
),
*(
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
),
Expand Down Expand Up @@ -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'