[U-Boot] [PATCH 1/4] tools: moveconfig: trim garbage lines after header cleanups

Masahiro Yamada yamada.masahiro at socionext.com
Mon Jul 25 12:20:26 CEST 2016


Hi Tom,


2016-07-25 0:19 GMT+09:00 Tom Rini <trini at konsulko.com>:
> On Sun, Jul 24, 2016 at 11:17:36PM +0900, Masahiro Yamada wrote:
>
>> The tools/moveconfig.py has a feature to cleanup #define/#undef's
>> of moved config options, but I want this tool to do a better job.
>>
>> For example, when we are moving CONFIG_FOO and its define is
>> surrounded by #ifdef ... #endif, like follows:
>>
>>   #ifdef CONFIG_BAR
>>   #  define CONFIG_FOO
>>   #endif
>>
>> The header cleanup will leave empty #ifdef ... #endif:
>>
>>   #ifdef CONFIG_BAR
>>   #endif
>>
>> Likewise, if a define line between two blank lines
>>
>>   <blank line>
>>   #define CONFIG_FOO
>>   <blank lines.
>>
>> ... is deleted, the result of the clean-up will be successive empty
>> lines, which is a coding-style violation.
>
> Thanks!  This is mildly annoying to find/fixup with regex, which is how
> I usually do it.  A few comments / questions:
>
> [snip]
>> +    # remove empty #ifdef ... #endif, successive blank lines
>> +    pattern_ifdef = re.compile(r'#\s*if(def|ndef)?\s')
>
> It starts to get complex to catch if defined/elif defined cases, so
> we should just leave that to manual review, yes?

It was missing from my thought.

It is difficult to invert the logic, like changing ifdef to ifndef,
but just removing can be done easily.

In v2,

"tools/moveconfig -H -c FOO" can clean more!


ex1)

   #if CONFIG_BAR
     /* ... */
  -#elif CONFIG_BAZ
  -# define CONFIG_FOO
   #endif


ex2)
   #if CONFIG_BAR
     /* ... */
  -#elif CONFIG_BAZ
  -# define CONFIG_FOO
   #elif CONFIG_BAZ2
     /* ... */
   #endif





>> +    pattern_endif = re.compile(r'#\s*endif\s')
>> +    pattern_blank = re.compile(r'^\s*$')
>
> The last pattern will catch multiple blank lines, right?

Yes.


-- 
Best Regards
Masahiro Yamada


More information about the U-Boot mailing list