Skip to content

Commit

Permalink
[lbuild] Warn if submodules are not up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Aug 7, 2019
1 parent 9fffd5d commit 72d5ae9
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,37 @@ from distutils.version import StrictVersion
from git import Repo
from os.path import normpath

sys.path.append(repopath("ext/modm-devices/tools/device"))
try:
import modm_devices.parser
except Exception as e:
print(e, "\n")
print("You might be missing the git submodules in `ext/`.\n"
"Try:\n"
" cd modm\n"
" git submodule update --init\n"
"then build again.")
exit(1)

# Check for miminum required lbuild version
import lbuild
min_lbuild_version = "1.12.1"
if StrictVersion(getattr(lbuild, "__version__", "0.1.0")) < StrictVersion(min_lbuild_version):
print("modm requires at least lbuild v{}, please upgrade!\n"
" pip3 install -U lbuild".format(min_lbuild_version))
exit(1)

# Check for submodule existance and their version
def check_submodules():
repo = Repo(localpath("."))
has_error = True
if any(not sm.module_exists() for sm in repo.submodules):
print("\n>> modm: One or more git submodules in `modm/ext/` is missing!\n"
">> modm: Please checkout the submodules:\n\n"
" cd modm\n"
" git submodule update --init\n")
exit(1)
elif any(sm.hexsha != sm.module().commit().hexsha for sm in repo.submodules):
print("\n>> modm: One or more git submodules in `modm/ext/` is not up-to-date!\n"
">> modm: Please update the submodules:\n\n"
" cd modm\n"
" git submodule sync\n"
" git submodule update --init\n")

# Import modm-device tools
sys.path.append(repopath("ext/modm-devices/tools/device"))
try:
import modm_devices.parser
except ModuleNotFoundError:
check_submodules()

# =============================================================================
class DevicesCache(dict):
Expand Down Expand Up @@ -123,7 +135,8 @@ class DevicesCache(dict):
recompute_required = True

if recompute_required:
print("Recomputing device cache...")
check_submodules()
print(">> modm: Recomputing device cache...")
content = self.parse_all()
# prefix the files with a / so we can distinguish them from partnames
files = ["/{} {}".format(Path(f).relative_to(repopath(".")),
Expand Down

0 comments on commit 72d5ae9

Please sign in to comment.