From 74a27f1c199d0c4e914cf87963ddedcfeb0942b7 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sat, 18 Nov 2017 15:43:49 +0100 Subject: [PATCH] Add conf/profile Signed-off-by: Jan Lindemann --- conf/Makefile | 4 ++++ conf/profile/Makefile | 4 ++++ scripts/trim-src.py | 21 ++++++++++++++------- test/trim-src/Makefile | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 conf/Makefile create mode 100644 conf/profile/Makefile diff --git a/conf/Makefile b/conf/Makefile new file mode 100644 index 0000000..2f00ade --- /dev/null +++ b/conf/Makefile @@ -0,0 +1,4 @@ +TOPDIR = .. + +include $(TOPDIR)/make/proj.mk +include $(MODDIR)/make/dirs.mk diff --git a/conf/profile/Makefile b/conf/profile/Makefile new file mode 100644 index 0000000..6a9f784 --- /dev/null +++ b/conf/profile/Makefile @@ -0,0 +1,4 @@ +TOPDIR = ../.. + +include $(TOPDIR)/make/proj.mk +include $(MODDIR)/make/profile.mk diff --git a/scripts/trim-src.py b/scripts/trim-src.py index 8508e08..4c54039 100644 --- a/scripts/trim-src.py +++ b/scripts/trim-src.py @@ -29,16 +29,15 @@ class TrimSourceCmd(jwutils.Cmd): for path in args.input: with open(path, 'r+') as infile: contents = infile.read() + name = os.path.basename(path) + ext = os.path.splitext(path)[1] # TODO: support other types in this block mime = magic.detect_from_content(contents).mime_type - if mime != 'text/plain': - raise Exception("unsupported file type", mime, "of", path) - name = os.path.basename(path) - ext = os.path.splitext(path)[1] - if name != 'Makefile' and ext != '.mk': - raise Exception("unsupported file type of", path) - mime = 'text/x-makefile' + if mime in [ 'text/plain', 'application/x-empty' ]: + if name != 'Makefile' and ext != '.mk': + raise Exception("unsupported file type of", path) + mime = 'text/x-makefile' out = self._run(args, mime, path, contents) infile.seek(0) @@ -55,6 +54,8 @@ class CmdBeautify(TrimSourceCmd): return p def _processTextXMakefile(self, args, mime, path, contents): + + # -- assignments r = '' indent = args.indent_assignments for line in contents.splitlines(True): @@ -63,6 +64,12 @@ class CmdBeautify(TrimSourceCmd): r += line continue r += misc.pad(m.group(1), indent - len(m.group(2))) + m.group(2) + m.group(3) + ' ' + m.group(4) + '\n' + + # -- trailing white space + contents = r + r = '' + for line in contents.splitlines(False): + r += line.rstrip() + '\n' return r def _run(self, args, mime, path, contents): diff --git a/test/trim-src/Makefile b/test/trim-src/Makefile index 2ea8bf2..0ed9934 100644 --- a/test/trim-src/Makefile +++ b/test/trim-src/Makefile @@ -2,7 +2,7 @@ TOPDIR = ../.. MAKEFLAGS += --no-builtin-rules -INPUT = test.mk +INPUT = test.mk EXE = $(TOPDIR)/scripts/trim-src.py EXE_ARGS = beautify $(INPUT)