if sys.version_info > (3, 0): print'Freeline only support Python 2.7+ now. Please use the correct version of Python for freeline.'exit()
parser = get_parser()
args = parser.parse_args()
freeline = Freeline()
freeline.call(args=args)
if 'cleanBuild' in args and args.cleanBuild:
is_build_all_projects = args.all 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:
self._command = CleanAllCacheCommand(self._config['build_cache_dir']) else:
from freeline_build import FreelineBuildCommand
self._command = FreelineBuildCommand(self._config, task_engine=self._task_engine)
if self._dispatch_policy.is_need_clean_build( self._config, file_changed_dict): self._setup_clean_builder(file_changed_dict)
from build_commands import CleanBuildCommand self._build_command = CleanBuildCommand(self._builder) else: # only flush changed list when your project need a incremental build.
Logger.debug('file changed list:')
Logger.debug(file_changed_dict) self._setup_inc_builder(file_changed_dict)
from build_commands import IncrementalBuildCommand self._build_command = IncrementalBuildCommand(self._builder) self._build_command.execute()
if last_apk_build_time == 0: Logger.debug('final apk not found, need a clean build.' return True
if file_changed_dict['build_info']['is_root_config_changed']: Logger.debug('find root build.gradle changed, need a clean build.') return True
file_count = 0 need_clean_build_projects = set()
for dir_name, bundle_dict in file_changed_dict['projects'].iteritems(): count = len(bundle_dict['src']) Logger.debug('find {} has {} java files modified.'.format(dir_name, count)) file_count += count
if len(bundle_dict['config']) > 0 or len(bundle_dict['manifest']) > 0: need_clean_build_projects.add(dir_name) Logger.debug('find {} has build.gradle or manifest file modified.'.format(dir_name))
is_need_clean_build = file_count > 20 or len(need_clean_build_projects) > 0
if is_need_clean_build: if file_count > 20: Logger.debug( 'project has {}(>20) java files modified so that it need a clean build.'.format(file_count)) else: Logger.debug('project need a clean build.') else: Logger.debug('project just need a incremental build.')
def generate_sorted_build_tasks(self):
"""
sort build tasks according to the module's dependency
:return: None
"""
for module in self._all_modules:
task = android_tools.AndroidIncrementalBuildTask(module, self.__setup_inc_command(module))
self._tasks_dictionary[module] = task
for module in self._all_modules:
task = self._tasks_dictionary[module]
for dep in self._module_dependencies[module]:
task.add_parent_task(self._tasks_dictionary[dep])
def calculate_task_depth(task):
depth = []
parent_task_queue = Queue.Queue()
parent_task_queue.put(task) while not parent_task_queue.empty():
parent_task = parent_task_queue.get() if parent_task.name not in depth:
depth.append(parent_task.name)
for parent in parent_task.parent_tasks: if parent.name not in depth:
parent_task_queue.put(parent) return len(depth)
在具体执行时根据depth对task进行了排序
depth_array.sort() for depth in depth_array:
tasks = self.tasks_depth_dict[depth] for task in tasks: self.debug("depth: {}, task: {}".format(depth, task)) self.sorted_tasks.append(task)
self._logger.set_sorted_tasks(self.sorted_tasks)
for task in self.sorted_tasks: self.pool.add_task(ExecutableTask(task, self))
然后每个task执行时会判断parent是否执行完成
while not self.task.is_all_parent_finished():
# self.debug('{} waiting...'.format(self.task.name))
self.task.wait()