From 9348a05289a432106e87c98b0777db619515968e Mon Sep 17 00:00:00 2001 From: Yong Date: Mon, 5 Dec 2016 14:51:39 +0800 Subject: [PATCH] * fix arguments length out of limit for Windows (#382) --- freeline_core/android_tools.py | 6 +++++ freeline_core/gradle_inc_build.py | 38 +++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/freeline_core/android_tools.py b/freeline_core/android_tools.py index 09b9af1..464984e 100755 --- a/freeline_core/android_tools.py +++ b/freeline_core/android_tools.py @@ -259,6 +259,12 @@ def get_patch_classes_cache_dir(self): os.makedirs(cache_dir) return cache_dir + def get_module_cache_dir(self): + cache_dir = os.path.join(self._cache_dir, self._module_name) + if not os.path.exists(cache_dir): + os.makedirs(cache_dir) + return cache_dir + @staticmethod def get_r_file_path(target_dir): for dirpath, dirnames, files in os.walk(target_dir): diff --git a/freeline_core/gradle_inc_build.py b/freeline_core/gradle_inc_build.py index d6a042d..8631aeb 100755 --- a/freeline_core/gradle_inc_build.py +++ b/freeline_core/gradle_inc_build.py @@ -635,20 +635,21 @@ def _should_run_databinding_apt(self): return False def _generate_java_compile_args(self, extra_javac_args_enabled=False): - javacargs = [self._javac, '-encoding', 'UTF-8', '-g'] + javacargs = [self._javac] + arguments = ['-encoding', 'UTF-8', '-g'] if not self._is_retrolambda_enabled: - javacargs.extend(['-target', '1.7', '-source', '1.7']) + arguments.extend(['-target', '1.7', '-source', '1.7']) - javacargs.append('-cp') - javacargs.append(os.pathsep.join(self._classpaths)) + arguments.append('-cp') + arguments.append(os.pathsep.join(self._classpaths)) for fpath in self._changed_files['src']: - javacargs.append(fpath) + arguments.append(fpath) if extra_javac_args_enabled: if 'apt' in self._changed_files: for fpath in self._changed_files['apt']: - javacargs.append(fpath) + arguments.append(fpath) filter_tags = [] if self._is_databinding_enabled: @@ -663,12 +664,29 @@ def _generate_java_compile_args(self, extra_javac_args_enabled=False): if 'apt' in self._changed_files and fpath in self._changed_files['apt']: continue self.debug('add apt related file: {}'.format(fpath)) - javacargs.append(fpath) + arguments.append(fpath) - javacargs.extend(self._extra_javac_args) + arguments.extend(self._extra_javac_args) - javacargs.append('-d') - javacargs.append(self._finder.get_patch_classes_cache_dir()) + arguments.append('-d') + arguments.append(self._finder.get_patch_classes_cache_dir()) + + # ref: https://support.microsoft.com/en-us/kb/830473 + if is_windows_system(): + arguments_length = sum(map(len, arguments)) + if arguments_length > 8000: + argument_file_path = os.path.join(self._finder.get_module_cache_dir(), 'javac_args_file') + self.debug('arguments length: {} > 8000, save args to {}'.format(arguments_length, argument_file_path)) + + if os.path.exists(argument_file_path): + os.remove(argument_file_path) + + arguments_content = ' '.join(arguments) + self.debug('javac arguments: ' + arguments_content) + write_file_content(argument_file_path, arguments_content) + arguments = ['@{}'.format(argument_file_path)] + + javacargs.extend(arguments) return javacargs def _get_apt_related_files(self, filter_tags=None):