Add support for "[file <filename>]" .sby sections
authorClifford Wolf <clifford@clifford.at>
Wed, 8 Feb 2017 20:33:40 +0000 (21:33 +0100)
committerClifford Wolf <clifford@clifford.at>
Wed, 8 Feb 2017 20:33:47 +0000 (21:33 +0100)
sbysrc/sby_core.py

index 9a7da46d9adc3e64b0fed8b6e77c8c8a950745c2..705d4e078cacb53f446ccaf6409326d8a5916c1b 100644 (file)
@@ -127,6 +127,7 @@ class SbyJob:
         self.engines = list()
         self.script = list()
         self.files = dict()
+        self.verbatim_files = dict()
         self.models = dict()
         self.workdir = workdir
         self.status = "UNKNOWN"
@@ -154,6 +155,7 @@ class SbyJob:
 
         with open(filename, "r") as f:
             for line in f:
+                raw_line = line
                 line = line.strip()
                 # print(line)
 
@@ -183,6 +185,14 @@ class SbyJob:
                         assert len(entries) == 1
                         continue
 
+                    if entries[0] == "file":
+                        mode = "file"
+                        assert len(entries) == 2
+                        current_verbatim_file = entries[1]
+                        assert current_verbatim_file not in self.verbatim_files
+                        self.verbatim_files[current_verbatim_file] = list()
+                        continue
+
                     if entries[0] == "files":
                         mode = "files"
                         assert len(entries) == 1
@@ -215,6 +225,10 @@ class SbyJob:
                         assert False
                     continue
 
+                if mode == "file":
+                    self.verbatim_files[current_verbatim_file].append(raw_line)
+                    continue
+
                 assert False
 
     def taskloop(self):
@@ -251,6 +265,14 @@ class SbyJob:
     def copy_src(self):
         os.makedirs(self.workdir + "/src")
 
+        for dstfile, lines in self.verbatim_files.items():
+            dstfile = self.workdir + "/src/" + dstfile
+            self.log("Writing '%s'." % dstfile)
+
+            with open(dstfile, "w") as f:
+                for line in lines:
+                    f.write(line)
+
         for dstfile, srcfile in self.files.items():
             dstfile = self.workdir + "/src/" + dstfile