Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/fixlecode.py: initial commit #3904

Merged
merged 2 commits into from Oct 25, 2019
Merged

tools/fixlecode.py: initial commit #3904

merged 2 commits into from Oct 25, 2019

Conversation

MilhouseVH
Copy link
Contributor

Hopefully this tool will be useful in helping automate the cleanup of build system code (scripts/*, config/*, and package.mk's) so that it is more consistent, initially addressing the following common issues:

  1. Updating variable concatenation (appends) to use the += operator, from:
PKG_XYZ="${PKG_XYZ} blah"

to

PKG_XYZ+=" blah"`
  1. Adding braces {} around variables, from:
echo "$PKG_XYZ"

to

echo "${PKG_XYZ}"
  1. Replacing backticks (``) with dollar parens ($()), from:
lines=`cat file | wc -l`

to

lines=$(cat file | wc -l)
  1. Remove whitespace before semicolon in if statements, and for/while loops, from
if [ test ] ; then

to

if [ test ]; then

All fixes are enabled by default, but can be optionally disabled (see below).

It's certainly not perfect, but should do most of the work required and help cut down on the manual labour. I haven't run this on the entire code base, so if anyone finds problematic code then please let me know.

Example command line (outputs summary only, input file is not modified):

LibreELEC.tv$ tools/fixlecode.py -f packages/mediacenter/kodi/package.mk

Summary of changes [packages/mediacenter/kodi/package.mk]
==================
Appends   :   25
Braces    :  188
Backticks :    0
Semicolons:    0

Options:
-q to disable summary, with -Q to only output summary when a change occurs
-d to output a diff -Naur of the differences.
-w to overwrite the input file (then use git diff to review changes).
-f filename to specify the file(s) to be processed - read stdin if not specified
-o filename write output to filename (or stdout if filename is -)
-xa disable append processing
-xb disable brace processing
-xs disable semicolon processing
-xt disable backtick processing

@chewitt chewitt merged commit cf22269 into LibreELEC:master Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants