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 sys
import os import os
import re import re
import shutil
from migen.fhdl.structure import Signal, Cat from migen.fhdl.structure import Signal, Cat
from migen.genlib.record import Record from migen.genlib.record import Record
@ -313,7 +312,6 @@ class GenericPlatform:
self.sources = [] self.sources = []
self.verilog_include_paths = [] self.verilog_include_paths = []
self.output_dir = None self.output_dir = None
self.gateware_dir = None
self.finalized = False self.finalized = False
self.use_default_clk = False self.use_default_clk = False
@ -375,20 +373,13 @@ class GenericPlatform:
language = tools.language_by_filename(filename) language = tools.language_by_filename(filename)
if library is None: if library is None:
library = "work" library = "work"
for f, *r in self.sources: for f, *_ in self.sources:
if f == filename: if f == filename:
return return
# If the gateware_dir is already defined, we can copy the file
if self.gateware_dir:
dst = filename
if copy: if copy:
dst = os.path.join(self.gateware_dir, os.path.basename(s[0])) self.sources.append((filename, language, library, True))
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
else: 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): def add_sources(self, path, *filenames, language=None, library=None, copy=False):
for f in filenames: for f in filenames:

View File

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