All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Lehtonen <markus.lehtonen@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 5/5] devtool: update-recipe: create kernel config fragment
Date: Fri, 18 Dec 2015 10:39:45 +0200	[thread overview]
Message-ID: <1450427985-12504-6-git-send-email-markus.lehtonen@linux.intel.com> (raw)
In-Reply-To: <1450427985-12504-1-git-send-email-markus.lehtonen@linux.intel.com>

Create kernel config fragment if the user makes modifications to
.config. User may change .config e.g. by directly editing it or by
running the 'do_menuconfig' bitbake task which will copy the modified
.config back to the source tree. Devtool generates one monolithic
fragment by simply doing a diff between .config and .config.orig files
in the source directory. If either of these files is missing, the config
fragment is not gerenrated or updated. The output is a file,
'devtool-fragment.cfg' that gets added to SRC_URI in the recipe (as well
as copied into the 'oe-local-files' directory if that is present in the
source tree).

This patch also changes the devtool 'extract' command to create the
.config.orig file at the source tree creation time.

[YOCTO #6658]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 scripts/lib/devtool/standard.py | 50 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py
index f817671..aa9414b 100644
--- a/scripts/lib/devtool/standard.py
+++ b/scripts/lib/devtool/standard.py
@@ -20,6 +20,7 @@ import os
 import sys
 import re
 import shutil
+import subprocess
 import tempfile
 import logging
 import argparse
@@ -474,6 +475,7 @@ def _extract_source(srctree, keep_temp, devbranch, sync, d):
         if kconfig:
             # Store kernel config in srctree
             shutil.copy2(kconfig, srcsubdir)
+            shutil.copy2(kconfig, os.path.join(srcsubdir, '.config.orig'))
 
 
         tempdir_localdir = os.path.join(tempdir, 'oe-local-files')
@@ -804,6 +806,30 @@ def _export_patches(srctree, rd, start_rev, destdir):
     return (updated, added, existing_patches)
 
 
+def _create_kconfig_diff(srctree, rd, outfile):
+    """Create a kernel config fragment"""
+    # Only update config fragment if both config files exist
+    orig_config = os.path.join(srctree, '.config.orig')
+    new_config = os.path.join(srctree, '.config')
+    if os.path.exists(orig_config) and os.path.exists(new_config):
+        cmd = ['diff', '--new-line-format=%L', '--old-line-format=',
+               '--unchanged-line-format=', orig_config, new_config]
+        pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                                stderr=subprocess.PIPE)
+        stdout, stderr = pipe.communicate()
+        if pipe.returncode == 1:
+            with open(outfile, 'w') as fobj:
+                fobj.write(stdout)
+        elif pipe.returncode == 0:
+            if os.path.exists(outfile):
+                # Remove fragment file in case of empty diff
+                os.unlink(outfile)
+        else:
+            raise bb.process.ExecutionError(cmd, pipe.returncode, stdout, stderr)
+        return True
+    return False
+
+
 def _export_local_files(srctree, rd, destdir):
     """Copy local files from srctree to given location.
        Returns three-tuple of dicts:
@@ -824,6 +850,7 @@ def _export_local_files(srctree, rd, destdir):
     updated = OrderedDict()
     added = OrderedDict()
     removed = OrderedDict()
+    local_files_dir = os.path.join(srctree, 'oe-local-files')
     git_files = _git_ls_tree(srctree)
     if 'oe-local-files' in git_files:
         # If tracked by Git, take the files from srctree HEAD. First get
@@ -834,11 +861,32 @@ def _export_local_files(srctree, rd, destdir):
                         env=dict(os.environ, GIT_WORK_TREE=destdir,
                                  GIT_INDEX_FILE=tmp_index))
         new_set = _git_ls_tree(srctree, tree, True).keys()
-    elif os.path.isdir(os.path.join(srctree, 'oe-local-files')):
+    elif os.path.isdir(local_files_dir):
         # If not tracked by Git, just copy from working copy
         new_set = _ls_tree(os.path.join(srctree, 'oe-local-files'))
         bb.process.run(['cp', '-ax',
                         os.path.join(srctree, 'oe-local-files', '.'), destdir])
+    else:
+        new_set = []
+
+    # Special handling for kernel config
+    if bb.data.inherits_class('kernel-yocto', rd):
+        fragment_fn = 'devtool-fragment.cfg'
+        fragment_path = os.path.join(destdir, fragment_fn)
+        if _create_kconfig_diff(srctree, rd, fragment_path):
+            if os.path.exists(fragment_path):
+                if fragment_fn not in new_set:
+                    new_set.append(fragment_fn)
+                # Copy fragment to local-files
+                if os.path.isdir(local_files_dir):
+                    shutil.copy2(fragment_path, local_files_dir)
+            else:
+                if fragment_fn in new_set:
+                    new_set.remove(fragment_fn)
+                # Remove fragment from local-files
+                if os.path.exists(os.path.join(local_files_dir, fragment_fn)):
+                    os.unlink(os.path.join(local_files_dir, fragment_fn))
+
     if new_set is not None:
         for fname in new_set:
             if fname in existing_files:
-- 
2.1.4



      parent reply	other threads:[~2015-12-18  8:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-18  8:39 [PATCH 0/5] devtool: " Markus Lehtonen
2015-12-18  8:39 ` [PATCH 1/5] devtool: extract: use the correct datastore for builddir Markus Lehtonen
2015-12-18  8:39 ` [PATCH 2/5] kernel.bbclass: copy .config instead of moving Markus Lehtonen
2015-12-18 12:22   ` Richard Purdie
2015-12-18 12:39     ` Markus Lehtonen
2015-12-18 14:18       ` Richard Purdie
2015-12-18 15:48         ` Markus Lehtonen
2015-12-18  8:39 ` [PATCH 3/5] devtool: extract: cleanup srctree Markus Lehtonen
2015-12-18  8:39 ` [PATCH 4/5] cml1.bbclass: copy .config to S if externalsr is in use Markus Lehtonen
2015-12-18  8:39 ` Markus Lehtonen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1450427985-12504-6-git-send-email-markus.lehtonen@linux.intel.com \
    --to=markus.lehtonen@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    --subject='Re: [PATCH 5/5] devtool: update-recipe: create kernel config fragment' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.