]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
yocto-bsp: add replace_file()
authorTom Zanussi <tom.zanussi@intel.com>
Thu, 13 Dec 2012 04:56:35 +0000 (22:56 -0600)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 13 Dec 2012 16:53:14 +0000 (16:53 +0000)
Add a function that can be used to replace a template file by a
user-specified file.  The initial use of this capability is to allow
users-specified defconfigs.

Signed-off-by: Tom Zanussi <tom.zanussi@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/bsp/engine.py
scripts/lib/bsp/substrate/target/arch/common/recipes-kernel/linux/{{ if kernel_choice == "custom": }} linux-yocto-custom/defconfig
scripts/lib/bsp/tags.py

index 6309e29a23418ce4d51fc1f89a00081a20c2bb64..8985544811424c0c0eaf76a0e697e688960aecbe 100644 (file)
@@ -38,6 +38,7 @@ from tags import *
 import shlex
 import json
 import subprocess
+import shutil
 
 class Line():
     """
@@ -83,7 +84,7 @@ class NormalLine(Line):
 
     def gen(self, context = None):
         if self.is_filename:
-            line = "of = open(\"" + os.path.join(self.out_filebase, self.escape(self.line)) + "\", \"w\")"
+            line = "current_file = \"" + os.path.join(self.out_filebase, self.escape(self.line)) + "\"; of = open(current_file, \"w\")"
         elif self.is_dirname:
             dirname = os.path.join(self.out_filebase, self.escape(self.line))
             line = "if not os.path.exists(\"" + dirname + "\"): os.mkdir(\"" + dirname + "\")"
@@ -134,7 +135,7 @@ class AssignmentLine(NormalLine):
             idx = line.find(ASSIGN_TAG)
             line = line[:idx] + replacement + line[idx + assignment.end - assignment.start:]
         if self.is_filename:
-            return "of = open(\"" + os.path.join(self.out_filebase, line) + "\", \"w\")"
+            return "current_file = \"" + os.path.join(self.out_filebase, line) + "\"; of = open(current_file, \"w\")"
         elif self.is_dirname:
             dirname = os.path.join(self.out_filebase, line)
             return "if not os.path.exists(\"" + dirname + "\"): os.mkdir(\"" + dirname + "\")"
@@ -564,6 +565,17 @@ def get_verified_file(input_str, name, filename_can_be_null):
         filename = default(raw_input(msg), name)
 
 
+def replace_file(replace_this, with_this):
+    """
+    Replace the given file with the contents of filename, retaining
+    the original filename.
+    """
+    try:
+        shutil.copy(with_this, replace_this)
+    except IOError:
+        pass
+
+
 def boolean(input_str, name):
     """
     Return lowercase version of first char in string, or value in name.
@@ -1197,7 +1209,7 @@ def gen_program_header_lines(program_lines):
     """
     Generate any imports we need.
     """
-    pass
+    program_lines.append("current_file = \"\"")
 
 
 def gen_supplied_property_vals(properties, program_lines):
index c2745c5e1e28f7e0e400aad8320a7f879a20ecee..e544a0a4a52a731966fbcfa321f02c862bad5639 100644 (file)
@@ -2,3 +2,4 @@
 # Placeholder for custom default kernel configuration.  yocto-bsp will
 # replace this file with a user-specified defconfig.
 #
+{{ if custom_kernel_defconfig: replace_file(current_file, custom_kernel_defconfig) }}
index 869b1d065a28f8d6a3965a19b278be8943067a63..256b25cb043750a9cd7c01496dab2b078456405b 100644 (file)
@@ -35,7 +35,7 @@ INDENT_STR =  "    "
 
 BLANKLINE_STR = "of.write(\"\\n\")"
 NORMAL_START =  "of.write"
-OPEN_START =    "of = open"
+OPEN_START =    "current_file ="
 
 INPUT_TYPE_PROPERTY = "type"