build/builder: Simplify/Review #1190.

- Only do copy in Builder.
- Use relative path for copied files (will be useful to create self-contained gateware archive).
This commit is contained in:
Florent Kermarrec 2022-01-28 19:10:40 +01:00
parent 3dcc6180f3
commit bfad61cd2a
2 changed files with 11 additions and 24 deletions

View File

@ -9,7 +9,6 @@
import sys
import os
import re
import shutil
from migen.fhdl.structure import Signal, Cat
from migen.genlib.record import Record
@ -313,7 +312,6 @@ class GenericPlatform:
self.sources = []
self.verilog_include_paths = []
self.output_dir = None
self.gateware_dir = None
self.finalized = False
self.use_default_clk = False
@ -375,20 +373,13 @@ class GenericPlatform:
language = tools.language_by_filename(filename)
if library is None:
library = "work"
for f, *r in self.sources:
for f, *_ in self.sources:
if f == filename:
return
# If the gateware_dir is already defined, we can copy the file
if self.gateware_dir:
dst = filename
if copy:
dst = os.path.join(self.gateware_dir, os.path.basename(s[0]))
shutil.copyfile(filename, dst)
self.sources.append((dst, language, library))
# If it's too early and the gateware_dir is not known and if it's
# necessary, the file will be copied by the Builder class
self.sources.append((filename, language, library, True))
else:
self.sources.append((filename, language, library, copy))
self.sources.append((filename, language, library))
def add_sources(self, path, *filenames, language=None, library=None, copy=False):
for f in filenames:

View File

@ -279,7 +279,6 @@ class Builder:
def build(self, **kwargs):
# Pass Output Directory to Platform.
self.soc.platform.output_dir = self.output_dir
self.soc.platform.gateware_dir = self.gateware_dir
# Check if BIOS is used and add software package if so.
with_bios = self.soc.cpu_type is not None
@ -289,15 +288,12 @@ class Builder:
# Create Gateware directory.
_create_dir(self.gateware_dir)
# If asked, copy files to the gateware directory and change the source file location.
# Drop the 'copy' element from the tupple.
# 'copy' may or may not be present in the tupple.
for i, (f, language, library, *r) in enumerate(self.soc.platform.sources):
dst = f
if r[0] is True:
dst = os.path.join(self.gateware_dir, os.path.basename(f))
shutil.copyfile(f, dst)
self.soc.platform.sources[i] = (dst, language, library)
# Copy Sources to Gateware directory (Optional).
for i, (f, language, library, *copy) in enumerate(self.soc.platform.sources):
if len(copy) and copy[0]:
shutil.copy(f, self.gateware_dir)
f = os.path.basename(f)
self.soc.platform.sources[i] = (f, language, library)
# Create Software directory.
# First check if software needs a full re-build and remove software dir if so.