add doit.sh
[openwrt/staging/blogic.git] / gentree.py
index 186a41477b18829db044d872fdb66ec968bbf523..816674b3193f4fb0f9a668c1d045668bcd11aa4a 100755 (executable)
@@ -549,7 +549,7 @@ def apply_patches(args, desc, source_dir, patch_src, target_dir, logwrite=lambda
                 logwrite("Failed to apply changes from %s" % print_name)
                 for line in output:
                     logwrite('> %s' % line)
-            raise Exception('Patch failed')
+            return 2
 
         if args.refresh:
             pfilef = open(pfile + '.tmp', 'a')
@@ -569,7 +569,7 @@ def apply_patches(args, desc, source_dir, patch_src, target_dir, logwrite=lambda
                     logwrite("Failed to diff to refresh %s" % print_name)
                     pfilef.close()
                     os.unlink(pfile + '.tmp')
-                    raise Exception('Refresh failed')
+                    return 2
             pfilef.close()
             os.rename(pfile + '.tmp', pfile)
 
@@ -594,6 +594,7 @@ def apply_patches(args, desc, source_dir, patch_src, target_dir, logwrite=lambda
         print_name = cocci_file[prefix_len:]
         if args.verbose:
             logwrite("Applying SmPL patch %s" % print_name)
+            logwrite(" %s" % cmd)
         sprocess = subprocess.Popen(cmd,
                                     stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                                     close_fds=True, universal_newlines=True,
@@ -602,7 +603,7 @@ def apply_patches(args, desc, source_dir, patch_src, target_dir, logwrite=lambda
         sprocess.wait()
         if sprocess.returncode != 0:
             logwrite("Failed to process SmPL patch %s with %i" % (print_name, sprocess.returncode))
-            raise Exception('SmPL patch failed')
+            return 2
         output = output.split('\n')
         if output[-1] == '':
             output = output[:-1]
@@ -625,7 +626,7 @@ def _main():
     # Our binary requirements go here
     req = reqs.Req()
     req.require('git')
-    req.coccinelle('1.0.0-rc24')
+    req.coccinelle('1.0.6')
     if not req.reqs_match():
         sys.exit(1)
 
@@ -651,7 +652,7 @@ def _main():
                         help='Refresh patches as they are applied, the source dir will be modified!')
     parser.add_argument('--base-name', metavar='<name>', type=str, default='Linux',
                         help='name of base tree, default just "Linux"')
-    parser.add_argument('--gitdebug', const=True, default=False, action="store_const",
+    parser.add_argument('--gitdebug', '--git-debug', const=True, default=False, action="store_const",
                         help='Use git, in the output tree, to debug the various transformation steps ' +
                              'that the tree generation makes (apply patches, ...)')
     parser.add_argument('--verbose', const=True, default=False, action="store_const",
@@ -903,7 +904,9 @@ def process(kerneldir, copy_list_file, git_revision=None,
         bpcfg.disable_symbols(disable_list)
     git_debug_snapshot(args, 'Add automatic backports')
 
-    apply_patches(args, "backport", source_dir, 'patches', bpid.target_dir, logwrite)
+    failure = apply_patches(args, "backport", source_dir, 'patches', bpid.target_dir, logwrite)
+    if failure:
+        return failure
 
     # Kernel integration requires Kconfig.versions already generated for you,
     # we cannot do this for a package as we have no idea what kernel folks
@@ -922,7 +925,7 @@ def process(kerneldir, copy_list_file, git_revision=None,
 
     # some post-processing is required
     configtree = kconfig.ConfigTree(os.path.join(bpid.target_dir, 'Kconfig'), bpid)
-    ignore=['Kconfig.kernel', 'Kconfig.versions']
+    ignore=['Kconfig.kernel', 'Kconfig.versions', 'Kconfig.local']
 
     configtree.verify_sources(ignore=ignore)
     git_debug_snapshot(args, "verify sources on top level backports Kconfig")
@@ -940,6 +943,7 @@ def process(kerneldir, copy_list_file, git_revision=None,
     ignore = [os.path.join(bpid.target_dir, x) for x in [
                 'Kconfig.package.hacks',
                 'Kconfig.versions',
+                'Kconfig.local',
                 'Kconfig',
                 ]
             ]
@@ -958,6 +962,15 @@ def process(kerneldir, copy_list_file, git_revision=None,
             f.write('%s=\n' % sym)
         f.close()
         git_debug_snapshot(args, "add symbols files")
+    # also write Kconfig.local, representing all local symbols
+    # with a BACKPORTED_ prefix
+    f = open(os.path.join(bpid.target_dir, 'Kconfig.local'), 'w')
+    for sym in symbols:
+        f.write('config BACKPORTED_%s\n' % sym)
+        f.write('\ttristate\n')
+        f.write('\tdefault %s\n' % sym)
+    f.close()
+    git_debug_snapshot(args, "add Kconfig.local")
 
     # add defconfigs that we want
     defconfigs_dir = os.path.join(source_dir, 'backport', 'defconfigs')
@@ -1004,6 +1017,8 @@ def process(kerneldir, copy_list_file, git_revision=None,
             data = open(os.path.join(root, f), 'r').read()
             for r in regexes:
                 data = r.sub(r'' + bpid.full_prefix + '\\1', data)
+            # we have an absolue path in $(src) since we compile out of tree
+            data = re.sub(r'\$\(srctree\)/\$\(src\)', '$(src)', data)
             data = re.sub(r'\$\(srctree\)', '$(backport_srctree)', data)
             data = re.sub(r'-Idrivers', '-I$(backport_srctree)/drivers', data)
             if bpid.integrate:
@@ -1074,8 +1089,10 @@ def process(kerneldir, copy_list_file, git_revision=None,
         f.close()
         git_debug_snapshot(args, "hooked backport to top level Kconfig")
 
-        apply_patches(args, "integration", source_dir, 'integration-patches/',
-                      bpid.project_dir, logwrite)
+        failure = apply_patches(args, "integration", source_dir, 'integration-patches/',
+                                bpid.project_dir, logwrite)
+        if failure:
+            return failure
 
     if (args.kup or args.kup_test):
         req = reqs.Req()