diff options
author | Tom Zanussi <tom.zanussi@intel.com> | 2012-12-12 22:56:35 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-12-13 16:54:33 +0000 |
commit | 125eb6f390b4882778f1a5179dca5f78675e19e5 (patch) | |
tree | c54bc65ece16bf5f3eb51237463034b3e7ed9ca0 /scripts/lib/bsp | |
parent | 205872b7b88f64dcb5a725e53811aedacac21da1 (diff) | |
download | poky-125eb6f390b4882778f1a5179dca5f78675e19e5.tar.gz |
yocto-bsp: add replace_file()
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.
(From meta-yocto rev: b52a22d40d4701a9515490bdd31c8d0341fb12bc)
Signed-off-by: Tom Zanussi <tom.zanussi@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/bsp')
3 files changed, 17 insertions, 4 deletions
diff --git a/scripts/lib/bsp/engine.py b/scripts/lib/bsp/engine.py index 6309e29a23..8985544811 100644 --- a/scripts/lib/bsp/engine.py +++ b/scripts/lib/bsp/engine.py | |||
@@ -38,6 +38,7 @@ from tags import * | |||
38 | import shlex | 38 | import shlex |
39 | import json | 39 | import json |
40 | import subprocess | 40 | import subprocess |
41 | import shutil | ||
41 | 42 | ||
42 | class Line(): | 43 | class Line(): |
43 | """ | 44 | """ |
@@ -83,7 +84,7 @@ class NormalLine(Line): | |||
83 | 84 | ||
84 | def gen(self, context = None): | 85 | def gen(self, context = None): |
85 | if self.is_filename: | 86 | if self.is_filename: |
86 | line = "of = open(\"" + os.path.join(self.out_filebase, self.escape(self.line)) + "\", \"w\")" | 87 | line = "current_file = \"" + os.path.join(self.out_filebase, self.escape(self.line)) + "\"; of = open(current_file, \"w\")" |
87 | elif self.is_dirname: | 88 | elif self.is_dirname: |
88 | dirname = os.path.join(self.out_filebase, self.escape(self.line)) | 89 | dirname = os.path.join(self.out_filebase, self.escape(self.line)) |
89 | line = "if not os.path.exists(\"" + dirname + "\"): os.mkdir(\"" + dirname + "\")" | 90 | line = "if not os.path.exists(\"" + dirname + "\"): os.mkdir(\"" + dirname + "\")" |
@@ -134,7 +135,7 @@ class AssignmentLine(NormalLine): | |||
134 | idx = line.find(ASSIGN_TAG) | 135 | idx = line.find(ASSIGN_TAG) |
135 | line = line[:idx] + replacement + line[idx + assignment.end - assignment.start:] | 136 | line = line[:idx] + replacement + line[idx + assignment.end - assignment.start:] |
136 | if self.is_filename: | 137 | if self.is_filename: |
137 | return "of = open(\"" + os.path.join(self.out_filebase, line) + "\", \"w\")" | 138 | return "current_file = \"" + os.path.join(self.out_filebase, line) + "\"; of = open(current_file, \"w\")" |
138 | elif self.is_dirname: | 139 | elif self.is_dirname: |
139 | dirname = os.path.join(self.out_filebase, line) | 140 | dirname = os.path.join(self.out_filebase, line) |
140 | return "if not os.path.exists(\"" + dirname + "\"): os.mkdir(\"" + dirname + "\")" | 141 | 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): | |||
564 | filename = default(raw_input(msg), name) | 565 | filename = default(raw_input(msg), name) |
565 | 566 | ||
566 | 567 | ||
568 | def replace_file(replace_this, with_this): | ||
569 | """ | ||
570 | Replace the given file with the contents of filename, retaining | ||
571 | the original filename. | ||
572 | """ | ||
573 | try: | ||
574 | shutil.copy(with_this, replace_this) | ||
575 | except IOError: | ||
576 | pass | ||
577 | |||
578 | |||
567 | def boolean(input_str, name): | 579 | def boolean(input_str, name): |
568 | """ | 580 | """ |
569 | Return lowercase version of first char in string, or value in name. | 581 | Return lowercase version of first char in string, or value in name. |
@@ -1197,7 +1209,7 @@ def gen_program_header_lines(program_lines): | |||
1197 | """ | 1209 | """ |
1198 | Generate any imports we need. | 1210 | Generate any imports we need. |
1199 | """ | 1211 | """ |
1200 | pass | 1212 | program_lines.append("current_file = \"\"") |
1201 | 1213 | ||
1202 | 1214 | ||
1203 | def gen_supplied_property_vals(properties, program_lines): | 1215 | def gen_supplied_property_vals(properties, program_lines): |
diff --git a/scripts/lib/bsp/substrate/target/arch/common/recipes-kernel/linux/{{ if kernel_choice == "custom": }} linux-yocto-custom/defconfig b/scripts/lib/bsp/substrate/target/arch/common/recipes-kernel/linux/{{ if kernel_choice == "custom": }} linux-yocto-custom/defconfig index c2745c5e1e..e544a0a4a5 100644 --- a/scripts/lib/bsp/substrate/target/arch/common/recipes-kernel/linux/{{ if kernel_choice == "custom": }} linux-yocto-custom/defconfig +++ b/scripts/lib/bsp/substrate/target/arch/common/recipes-kernel/linux/{{ if kernel_choice == "custom": }} linux-yocto-custom/defconfig | |||
@@ -2,3 +2,4 @@ | |||
2 | # Placeholder for custom default kernel configuration. yocto-bsp will | 2 | # Placeholder for custom default kernel configuration. yocto-bsp will |
3 | # replace this file with a user-specified defconfig. | 3 | # replace this file with a user-specified defconfig. |
4 | # | 4 | # |
5 | {{ if custom_kernel_defconfig: replace_file(current_file, custom_kernel_defconfig) }} | ||
diff --git a/scripts/lib/bsp/tags.py b/scripts/lib/bsp/tags.py index 869b1d065a..256b25cb04 100644 --- a/scripts/lib/bsp/tags.py +++ b/scripts/lib/bsp/tags.py | |||
@@ -35,7 +35,7 @@ INDENT_STR = " " | |||
35 | 35 | ||
36 | BLANKLINE_STR = "of.write(\"\\n\")" | 36 | BLANKLINE_STR = "of.write(\"\\n\")" |
37 | NORMAL_START = "of.write" | 37 | NORMAL_START = "of.write" |
38 | OPEN_START = "of = open" | 38 | OPEN_START = "current_file =" |
39 | 39 | ||
40 | INPUT_TYPE_PROPERTY = "type" | 40 | INPUT_TYPE_PROPERTY = "type" |
41 | 41 | ||