diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp index e02dfbdeb1..e3060a24b9 100644 --- a/tools/gn2bp/Android.bp.swp +++ b/tools/gn2bp/Android.bp.swp @@ -7224,8 +7224,6 @@ cc_genrule { "--header-path " + "$(genDir)/components/cronet/android/cronet_jni_registration.h " + "--manual_jni_registration " + - " " + - " " + ";sed -i -e 's/OUT_SOONG_.TEMP_SBOX_.*_OUT/GEN/g' " + "$(genDir)/components/cronet/android/cronet_jni_registration.h", out: [ @@ -7535,8 +7533,6 @@ cc_genrule { "--header-path " + "$(genDir)/components/cronet/android/cronet_jni_registration.h " + "--manual_jni_registration " + - " " + - " " + ";sed -i -e 's/OUT_SOONG_.TEMP_SBOX_.*_OUT/GEN/g' " + "$(genDir)/components/cronet/android/cronet_jni_registration.h", out: [ @@ -7846,8 +7842,6 @@ cc_genrule { "--header-path " + "$(genDir)/components/cronet/android/cronet_jni_registration.h " + "--manual_jni_registration " + - " " + - " " + ";sed -i -e 's/OUT_SOONG_.TEMP_SBOX_.*_OUT/GEN/g' " + "$(genDir)/components/cronet/android/cronet_jni_registration.h", out: [ @@ -8157,8 +8151,6 @@ cc_genrule { "--header-path " + "$(genDir)/components/cronet/android/cronet_jni_registration.h " + "--manual_jni_registration " + - " " + - " " + ";sed -i -e 's/OUT_SOONG_.TEMP_SBOX_.*_OUT/GEN/g' " + "$(genDir)/components/cronet/android/cronet_jni_registration.h", out: [ @@ -8594,7 +8586,6 @@ cc_genrule { "$(location chrome/VERSION) " + "-e " + "VERSION_FULL='\"%s.%s.%s.%s\" % (MAJOR,MINOR,BUILD,PATCH)' " + - " " + "-o " + "$(out) " + "$(location components/cronet/version.h.in)", @@ -8620,7 +8611,6 @@ cc_genrule { "$(location chrome/VERSION) " + "-e " + "VERSION_FULL='\"%s.%s.%s.%s\" % (MAJOR,MINOR,BUILD,PATCH)' " + - " " + "-o " + "$(out) " + "$(location components/cronet/version.h.in)", @@ -8646,7 +8636,6 @@ cc_genrule { "$(location chrome/VERSION) " + "-e " + "VERSION_FULL='\"%s.%s.%s.%s\" % (MAJOR,MINOR,BUILD,PATCH)' " + - " " + "-o " + "$(out) " + "$(location components/cronet/version.h.in)", @@ -8672,7 +8661,6 @@ cc_genrule { "$(location chrome/VERSION) " + "-e " + "VERSION_FULL='\"%s.%s.%s.%s\" % (MAJOR,MINOR,BUILD,PATCH)' " + - " " + "-o " + "$(out) " + "$(location components/cronet/version.h.in)", diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp index 10fc1a8121..fe2e924d9e 100755 --- a/tools/gn2bp/gen_android_bp +++ b/tools/gn2bp/gen_android_bp @@ -630,19 +630,35 @@ class BaseActionSanitizer(): # - flags (--flag) # - value args (--arg value) # - list args (--arg value1 --arg value2) + # Note that the set of list args contains the set of value args. + # value args must have exactly one arg value pair but list args could have one arg value pair. + # This is because list args with one arg value pair and value args can not be distinguished only + # from the desc.json # Some functions provide special implementations for each type, while others # work on all of them. def _has_arg(self, arg): return arg in self.target.args - # Whether an arg has multiple occurences (e.g. see argparse action='append') - def _is_list_arg(self, arg): - return operator.countOf(arg, self.target.args) > 1 + def _get_arg_indices(self, target_arg): + return [i for i, arg in enumerate(self.target.args) if arg == target_arg] + # Whether an arg value pair appears once or more times + def _is_list_arg(self, arg): + indices = self._get_arg_indices(arg) + return len(indices) > 0 and all([not self.target.args[i + 1].startswith('--') for i in indices]) + + def _update_list_arg(self, arg, func, throw_if_absent = True): + if self._should_fail_silently(arg, throw_if_absent): + return + assert(self._is_list_arg(arg)) + indices = self._get_arg_indices(arg) + for i in indices: + self._set_arg_at(i + 1, func(self.target.args[i + 1])) + + # Whether an arg value pair appears exactly once def _is_value_arg(self, arg): - # TODO: we'll probably need a set of helper functions to deal with append - # args as well. - assert(not self._is_list_arg(arg)) + if operator.countOf(self.target.args, arg) != 1: + return False i = self.target.args.index(arg) return not self.target.args[i + 1].startswith('--') @@ -697,6 +713,10 @@ class BaseActionSanitizer(): filepath = re.sub('^gen', '$(genDir)', filepath) return filepath + # Iterate through all the args and apply function + def _update_all_args(self, func): + self.target.args = [func(arg) for arg in self.target.args] + def get_args(self): return self.target.args @@ -712,6 +732,13 @@ class WriteBuildFlagHeaderSanitizer(BaseActionSanitizer): return super().get_args() class JniGeneratorSanitizer(BaseActionSanitizer): + def _add_location_tag_to_filepath(self, arg): + if not arg.endswith('.class'): + # --input_file supports both .class specifiers or source files as arguments. + # Only source files need to be wrapped inside a $(location