build.run: only use os.path on the target OS.
authorwhitequark <whitequark@whitequark.org>
Sun, 7 Jul 2019 00:18:56 +0000 (00:18 +0000)
committerwhitequark <whitequark@whitequark.org>
Sun, 7 Jul 2019 00:18:56 +0000 (00:18 +0000)
Before this commit, BuildPlan.add_file would use os.path.normpath,
which would be the wrong thing for cross-builds.

nmigen/build/run.py

index 47de5ddbf2b8d01c77b41b366517924afd933e4a..31d04c8e1e97560d37763165b6470bc99f87d042 100644 (file)
@@ -30,8 +30,6 @@ class BuildPlan:
         forward slashes (``/``).
         """
         assert isinstance(filename, str) and filename not in self.files
-        # Just to make sure we don't accidentally overwrite anything.
-        assert not os.path.normpath(filename).startswith("..")
         self.files[filename] = content
 
     def archive(self, file):
@@ -60,6 +58,9 @@ class BuildPlan:
             os.chdir(root)
 
             for filename, content in self.files.items():
+                filename = os.path.normpath(filename)
+                # Just to make sure we don't accidentally overwrite anything outside of build root.
+                assert not filename.startswith("..")
                 dirname = os.path.dirname(filename)
                 if dirname:
                     os.makedirs(dirname, exist_ok=True)