from utils import *;

def force_dbo_and_dnm_versions(defs):
   # Use this version info if nothing is specified by the IDE.
   # These versions are understood by MULTI 6.
   ideMaxDloVersion = 33
   ideMaxDnmVersion = 37

   # Default toolchain version info
   toolsDloVersion = 36
   toolsDnmVersion = 40


   # Check for version info supplied by the IDE.
   # MULTI 7 and older do not supply this information, but MULTI 7 supports
   # newer versions than MULTI 6.  If the max supported versions are not
   # supplied, check for __GHS_NPW_PROVIDES_BATCH_CUSTOMIZATION_CHANGE as a
   # means of distinguishing between MULTI 7 and older versions of the IDE.
   if ("__GHS_IDE_MAX_DLO_VERSION" in defs):
       ideMaxDloVersion = int(defs["__GHS_IDE_MAX_DLO_VERSION"])
   elif ("__GHS_NPW_PROVIDES_BATCH_CUSTOMIZATION_CHANGE" in defs):
       ideMaxDloVersion = 36
   if ("__GHS_IDE_MAX_DNM_VERSION" in defs):
       ideMaxDnmVersion = int(defs["__GHS_IDE_MAX_DNM_VERSION"])
   elif ("__GHS_NPW_PROVIDES_BATCH_CUSTOMIZATION_CHANGE" in defs):
       ideMaxDnmVersion = 40

   # If the toolchain default version is higher than the IDE max, force
   # them lower.
   if (toolsDloVersion > ideMaxDloVersion):
       set_in_top_project(defs, "-dblink.args=-dloVersion=" + str(ideMaxDloVersion))
   if (toolsDnmVersion > ideMaxDnmVersion):
       set_in_top_project(defs, "-dblink.args=-dnmVersion=" + str(ideMaxDnmVersion))

