From f7f277548e9f004fcdddafd6f835d156faf4626c Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 24 Mar 2021 13:24:05 +0100 Subject: [PATCH] Compat: Add litex.compat to handle retro-compatibility on API changes and move integration/soc_sdram to it. Compat Notice is not yet enabled for soc_sdram since targets first need to be updated. --- litex/build/tools.py | 5 --- litex/compat/__init__.py | 35 +++++++++++++++++++ .../{soc/integration => compat}/soc_sdram.py | 10 +++--- litex/soc/integration/__init__.py | 3 ++ 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 litex/compat/__init__.py rename litex/{soc/integration => compat}/soc_sdram.py (93%) diff --git a/litex/build/tools.py b/litex/build/tools.py index 8635100c7..d82abc450 100644 --- a/litex/build/tools.py +++ b/litex/build/tools.py @@ -134,8 +134,3 @@ def generated_banner(line_comment="//"): r += "{}\n".format(datetime.datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")) r += line_comment + "-"*80 + "\n" return r - - -def deprecated_warning(msg): - print("[WARNING] Deprecated, please update " + msg) - time.sleep(2) # annoy user to force update :) diff --git a/litex/compat/__init__.py b/litex/compat/__init__.py new file mode 100644 index 000000000..cdb97d75a --- /dev/null +++ b/litex/compat/__init__.py @@ -0,0 +1,35 @@ +import sys +import time + +def colorer(s, color="bright"): # FIXME: Move colorer to litex.common? + header = { + "bright": "\x1b[1m", + "green": "\x1b[32m", + "cyan": "\x1b[36m", + "red": "\x1b[31m", + "yellow": "\x1b[33m", + "underline": "\x1b[4m"}[color] + trailer = "\x1b[0m" + return header + str(s) + trailer + +def compat_notice(name, date, info=""): + print("Compat: {name} is {deprecated} since {date} and will soon no longer work, please {update}. {info}".format( + name = colorer(name), + deprecated = colorer("deprecated", color="red"), + date = colorer(date), + update = colorer("update", color="red"), + info = info, + ), end="") + # Annoy user to force update :) + for i in range(10): + time.sleep(0.2) + print(".", end="") + sys.stdout.flush() + print("thanks :)") + time.sleep(1) + +def add_compat(location): + if location == "litex.soc.integration": + #compat_notice("SoCSDRAM", date="2020-03-24", info="Switch to SoCCore/add_sdram/soc_core_args instead.") + from litex.compat import soc_sdram + sys.modules["litex.soc.integration.soc_sdram"] = soc_sdram diff --git a/litex/soc/integration/soc_sdram.py b/litex/compat/soc_sdram.py similarity index 93% rename from litex/soc/integration/soc_sdram.py rename to litex/compat/soc_sdram.py index 31cb0380b..1f9373150 100644 --- a/litex/soc/integration/soc_sdram.py +++ b/litex/compat/soc_sdram.py @@ -1,3 +1,8 @@ +#################################################################################################### +# DISCLAIMER: Provides retro-compatibility layer for SoCSDRAM based designs. +# Will soon no longer work, please don't use in new designs. +#################################################################################################### + # # This file is part of LiteX. # @@ -6,11 +11,6 @@ # This file is Copyright (c) 2019 Gabriel L. Somlo # SPDX-License-Identifier: BSD-2-Clause -#################################################################################################### -# DISCLAIMER: Provides retro-compatibility layer for existing SoCSDRAM based designs. -# Most of the SoC code has been refactored/improved and is now located in integration/soc.py -#################################################################################################### - import inspect from migen import * diff --git a/litex/soc/integration/__init__.py b/litex/soc/integration/__init__.py index e69de29bb..1660b4cf5 100644 --- a/litex/soc/integration/__init__.py +++ b/litex/soc/integration/__init__.py @@ -0,0 +1,3 @@ +import sys +from litex.compat import add_compat +add_compat(__name__)