aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Reyna <David.Reyna@windriver.com>2019-01-19 14:29:08 -0800
committerDavid Reyna <David.Reyna@windriver.com>2019-01-19 14:29:08 -0800
commit54384c586752584ddc5d85693e60e87594c8ce6f (patch)
treed48175eb6bb32e287ec550d1e091c267d8090850
parent3f4c288266b812613aa77cc43dfa9ec4068b0b90 (diff)
downloadsrtool-54384c586752584ddc5d85693e60e87594c8ce6f.tar.gz
srtool-54384c586752584ddc5d85693e60e87594c8ce6f.tar.bz2
srtool-54384c586752584ddc5d85693e60e87594c8ce6f.zip
srtool_patcher: add custom exclusion support
Add the ability to exclude sections of the common code. The primary use case is if the common code is executinga function that causes undesired side effects for the customization. Here is example code in "bin/acme/patcher/inplace/bin/srt.patch": ### ACME_EXTENSION_EXCLUDE_BEGIN ### #echo "The system will $CMD." # ### ACME_EXTENSION_EXCLUDE_END ### ### ACME_EXTENSION_BEGIN ### # # NOTE: Exclusions should be used only when necessary # NOTE: The excluded lines are commented so that they are inactive # but restorable # echo "The ACME SRTool system will now $CMD!" ### ACME_EXTENSION_END ### The content in the excluded section are commented, so that when it is cleaned those lines can be restored to the original. Signed-off-by: David Reyna <David.Reyna@windriver.com>
-rwxr-xr-xbin/acme/patcher.json11
-rwxr-xr-xbin/acme/patcher/inplace/bin/srt12
-rwxr-xr-xbin/common/srtool_patcher.py93
3 files changed, 94 insertions, 22 deletions
diff --git a/bin/acme/patcher.json b/bin/acme/patcher.json
index 03332d0e..a0c96733 100755
--- a/bin/acme/patcher.json
+++ b/bin/acme/patcher.json
@@ -17,6 +17,14 @@
"options" : "INPLACE DISABLE"
}
],
+ "custom_directories" : [
+ {
+ "dir" : "bin/acme"
+ },
+ {
+ "dir" : "lib/acme"
+ }
+ ],
"documentation" : [
{
"help_original" : "the location of the original mainline file",
@@ -26,7 +34,8 @@
"help_patch" : "optional location of extracted patch file, default is '$patcher_dir/$filename.patch'",
"help_options" : "When empty, indicates the default workflow of a custom file in custom app directory derived from a mainline template file (e.g. bin/common/srtool_jira_template.py)",
"help_options_INPLACE" : "Add the 'INPLACE' key if the file is patched in place in the mainline code",
- "help_options_DISABLE" : "Add the 'DISABLE' key to make this mapping inactive"
+ "help_options_DISABLE" : "Add the 'DISABLE' key to make this mapping inactive",
+ "help_custom_directories" : "These are the custom directories that are overlaid on the SRTool code, and are ignored for in-place scanning"
}
]
}
diff --git a/bin/acme/patcher/inplace/bin/srt b/bin/acme/patcher/inplace/bin/srt
index eaa7cd31..af8a1fb2 100755
--- a/bin/acme/patcher/inplace/bin/srt
+++ b/bin/acme/patcher/inplace/bin/srt
@@ -266,7 +266,17 @@ elif [ "$CMD" = "" ]; then
exit 1
fi
-echo "The system will $CMD."
+### ACME_EXTENSION_EXCLUDE_BEGIN ###
+#echo "The system will $CMD."
+#
+### ACME_EXTENSION_EXCLUDE_END ###
+### ACME_EXTENSION_BEGIN ###
+#
+# NOTE: Exclusions should be used only when necessary
+# NOTE: The excluded lines are commented so that they are inactive but restorable
+#
+echo "The ACME SRTool system will now $CMD!"
+### ACME_EXTENSION_END ###
# Execute the commands
case $CMD in
diff --git a/bin/common/srtool_patcher.py b/bin/common/srtool_patcher.py
index bda941fc..17032750 100755
--- a/bin/common/srtool_patcher.py
+++ b/bin/common/srtool_patcher.py
@@ -68,10 +68,39 @@ DISABLE_TAG = 'DISABLE'
# Extract a clean version of the file without the the custom sections,
# and generate a patch file of those sections
#
+# States:
+# 'LOOKING' : scan the lines for an extension beginning, otherwise output lines
+# 'FOUND_EXTEND' : scan the lines for an extension ending, otherwise skip lines
+# 'FOUND_EXCLUDE' : scan the lines for an exclude ending, otherwise uncomment the lines
+# 'BLANK' : scan for a trailing blank line after an extension, skip if found
+#
+
+def _uncomment_line(line):
+ def remove_delimiters(line,lead,tail):
+ pos = line.find(lead)
+ if 0 <= pos:
+ line = line[0:pos] + line[pos+len(lead):]
+ if tail:
+ pos = line.rfind(tail)
+ if 0 <= pos:
+ line = line[0:pos] + line[pos+len(tail):]
+ return(line)
+ test_line = line.strip()
+ if test_line.startswith('#'):
+ return remove_delimiters(line,'#','')
+ if test_line.startswith('<!--'):
+ return remove_delimiters(line,'<!--','-->')
+ if test_line.startswith('/*'):
+ return remove_delimiters(line,'/*','*/')
+ if test_line.startswith('"__'):
+ return remove_delimiters(line,'__','')
+ return(line)
def extract_custom_patch(custom_file,clean_file,patch_file,label,patcher_dir,options):
- tag_begin = "%s_EXTENSION_BEGIN" % label
- tag_end = "%s_EXTENSION_END" % label
+ tag_exclude_begin = "%s_EXTENSION_EXCLUDE_BEGIN" % label
+ tag_exclude_end = "%s_EXTENSION_EXCLUDE_END" % label
+ tag_extend_begin = "%s_EXTENSION_BEGIN" % label
+ tag_extend_end = "%s_EXTENSION_END" % label
ret = 0
# Insure patcher working directory is ready
@@ -89,30 +118,54 @@ def extract_custom_patch(custom_file,clean_file,patch_file,label,patcher_dir,opt
with open(custom_file, 'r') as fs:
with open(clean_file, 'w') as fd:
- state = "find"
+ state = "LOOKING"
+ leading_blank_line = False
for line in fs:
#print("LINE(%s):%s" % (state,line.strip()))
- if state == "find":
- if 0 < line.find(tag_begin):
- #print("START:$line")
- state = "found"
+ # Process state
+ if state == "LOOKING":
+ if 0 < line.find(tag_exclude_begin):
+ #print("START_FOUND_EXCLUDE:%s" % line)
+ state = "FOUND_EXCLUDE"
+ continue
+ if 0 < line.find(tag_extend_begin):
+ #print("START_FOUND_EXTEND:%s" % line)
+ state = "FOUND_EXTEND"
+ continue
+ elif state == "FOUND_EXCLUDE":
+ if 0 < line.find(tag_exclude_end):
+ #print("STOP_FOUND_EXCLUDE:%s" % line)
+ state = "LOOKING"
continue
- elif state == "found":
- if 0 < line.find(tag_end):
- #print("STOP:$line")
- state = "blank"
+ elif state == "FOUND_EXTEND":
+ if 0 < line.find(tag_extend_end):
+ #print("STOP_FOUND_EXTEND:%s" % line)
+ if leading_blank_line:
+ # Remove trailing blank line
+ state = "BLANK"
+ else:
+ state = "LOOKING"
continue
- elif state == "blank":
- state = "find"
+ elif state == "BLANK":
+ state = "LOOKING"
# if next line after stop is blank, hide that also
if not line.strip():
continue
- # Normal line?
- if state != "found":
+
+ # Output line?
+ if state == "FOUND_EXCLUDE":
+ # Restore excluded line
+ line = _uncomment_line(line)
+ fd.write('%s' % line)
+ elif state != "FOUND_EXTEND":
+ # Normal line
fd.write('%s' % line)
+ leading_blank_line = not line.strip()
+
# Did we end cleanly?
- if state != "find":
+ if state != "LOOKING":
print("ERROR: START not STOPPED (%s)" % state)
+
if INPLACE_TAG in options:
cmd = "git diff %s > %s" % (custom_file,patch_file)
print(cmd)
@@ -207,15 +260,14 @@ def diff_original(custom_file,original_file,patch_file,label,patcher_dir,options
#
def clean_inplace(custom_file,original_file,patch_file,label,patcher_dir,options):
- print("FOO1:%s,%s" % (INPLACE_TAG,options))
# Skip if not in-place
if not INPLACE_TAG in options:
return 0
- print("FOO2")
# Only continue if 'original' file has custom patches, in case this
# command is run multiple times by accident
- cmd = "grep %s %s" % (label,original_file)
+ print("* Confirm in-place file has customization")
+ cmd = "grep %s %s > /dev/null 2>&1" % (label,original_file)
ret = os.system(cmd)
if 0 != ret:
print("ERROR:SKIP: original file '%s' does not have custom tags '%s'" % (original_file,label))
@@ -352,7 +404,8 @@ def main(argv):
ret = 0
for custom_file,original_file,patch_file,options in file_list:
- #print("PATCH_FILE:%s,%s,%s,%s,%s,%s" % (custom_file,original_file,patch_file,options,patcher_dir,options))
+ if verbose:
+ print("*** PATCHER_FILE:%s,%s,%s,%s,%s" % (custom_file,original_file,patch_file,patcher_dir,options))
if 'merge_original' == args.command:
validate_file(custom_file,'Custom')
validate_file(original_file,'Original')