Skip to content

Commit

Permalink
+ support wait for debugger while full build (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
lomanyong committed Nov 10, 2016
1 parent 8880f4c commit 165ebb2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion freeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def call(self, args=None):
def get_parser():
parser = ArgumentParser()
parser.add_argument('-v', '--version', action='store_true', help='show version')
# parser.add_argument('-b', '--build', action='store_true', help='freeline build')
parser.add_argument('-f', '--cleanBuild', action='store_true', help='force to execute a clean build')
parser.add_argument('-w', '--wait', action='store_true', help='make application wait for debugger')
parser.add_argument('-a', '--all', action='store_true',
help="together with '-f', freeline will force to clean build all projects.")
parser.add_argument('-c', '--clean', action='store_true', help='clean cache directory and workspace')
Expand Down
14 changes: 12 additions & 2 deletions freeline_core/android_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@


class InstallApkTask(Task):
def __init__(self, adb, config):
def __init__(self, adb, config, wait_for_debugger=False):
Task.__init__(self, 'install_apk_task')
self._adb = adb
self._wait_for_debugger = wait_for_debugger

def __init_attributes(self):
# reload freeline config
Expand All @@ -41,6 +42,7 @@ def execute(self):
self.__init_attributes()
self._check_connection()
self._install_apk()
self._debug_app()
self._launch_application()

def _check_connection(self):
Expand Down Expand Up @@ -74,10 +76,18 @@ def _install_apk(self):
if 'Failure' in output:
raise FreelineException('install apk to device failed.', '{}\n{}'.format(output, err))

def _debug_app(self):
if self._wait_for_debugger:
adb_args = [Builder.get_adb(self._config), 'shell', 'am', 'set-debug-app', '-w', self._package]
self.debug('make application wait for debugger: {}'.format(' '.join(adb_args)))
cexec(adb_args, callback=None)

def _launch_application(self):
if self._package and self._launcher:
adb_args = [self._adb, 'shell', 'am', 'start', '-n', self._package + '/' + self._launcher]
self.debug('start to launch application {}/{}'.format(self._package, self._launcher))
cexec([self._adb, 'shell', 'am', 'start', '-n', self._package + '/' + self._launcher], callback=None)
self.debug(' '.join(adb_args))
cexec(adb_args, callback=None)


class ConnectDeviceTask(SyncTask):
Expand Down
11 changes: 6 additions & 5 deletions freeline_core/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def call_command(self, args):

if 'cleanBuild' in args and args.cleanBuild:
is_build_all_projects = args.all
self._setup_clean_build_command(is_build_all_projects)
wait_for_debugger = args.wait
self._setup_clean_build_command(is_build_all_projects, wait_for_debugger)
elif 'version' in args and args.version:
version()
elif 'clean' in args and args.clean:
Expand All @@ -66,17 +67,17 @@ def _join_logger_worker(self):
if not self._args.version: # and not self._args.init:
self._logger_worker.join()

def _setup_clean_build_command(self, is_build_all_projects):
self._builder = self._setup_clean_builder(is_build_all_projects)
def _setup_clean_build_command(self, is_build_all_projects, wait_for_debugger):
self._builder = self._setup_clean_builder(is_build_all_projects, wait_for_debugger)
from build_commands import CleanBuildCommand
self._command = CleanBuildCommand(self._builder)

def _setup_clean_builder(self, is_build_all_projects):
def _setup_clean_builder(self, is_build_all_projects, wait_for_debugger):
if 'project_type' in self._config:
ptype = self._config['project_type']
if ptype == 'gradle':
from gradle_clean_build import GradleCleanBuilder
return GradleCleanBuilder(self._config, self._task_engine)
return GradleCleanBuilder(self._config, self._task_engine, wait_for_debugger=wait_for_debugger)

return None

Expand Down
5 changes: 3 additions & 2 deletions freeline_core/gradle_clean_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@


class GradleCleanBuilder(CleanBuilder):
def __init__(self, config, task_engine, project_info=None):
def __init__(self, config, task_engine, project_info=None, wait_for_debugger=False):
CleanBuilder.__init__(self, config, task_engine, builder_name='gradle_clean_builder')
self._root_task = None
self._project_info = project_info
self._wait_for_debugger = wait_for_debugger

def check_build_environment(self):
CleanBuilder.check_build_environment(self)
Expand All @@ -36,7 +37,7 @@ def generate_sorted_build_tasks(self):
# 3. install / clean cache
# 4. build base res / generate project info cache
build_task = GradleCleanBuildTask(self._config)
install_task = InstallApkTask(self._adb, self._config)
install_task = InstallApkTask(self._adb, self._config, wait_for_debugger=self._wait_for_debugger)
clean_all_cache_task = CleanAllCacheTask(self._config['build_cache_dir'], ignore=[
'stat_cache.json', 'apktime', 'jar_dependencies.json', 'resources_dependencies.json', 'public_keeper.xml',
'assets_dependencies.json', 'freeline_annotation_info.json'])
Expand Down

0 comments on commit 165ebb2

Please sign in to comment.