Skip to content

Commit 87c453f

Browse files
committed
makepanda: refactor code to emit errors/warnings
1 parent 61dbe47 commit 87c453f

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

makepanda/makepanda.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,9 +2573,9 @@ def WriteConfigSettings():
25732573

25742574
WarnConflictingFiles()
25752575
if SystemLibraryExists("dtoolbase"):
2576-
print("%sWARNING:%s Found conflicting Panda3D libraries from other ppremake build!" % (GetColor("red"), GetColor()))
2576+
Warn("Found conflicting Panda3D libraries from other ppremake build!")
25772577
if SystemLibraryExists("p3dtoolconfig"):
2578-
print("%sWARNING:%s Found conflicting Panda3D libraries from other makepanda build!" % (GetColor("red"), GetColor()))
2578+
Warn("Found conflicting Panda3D libraries from other makepanda build!")
25792579

25802580
##########################################################################################
25812581
#
@@ -3061,7 +3061,7 @@ def get_config_express():
30613061
pattern = os.path.join('C:' + os.sep, 'Windows', 'WinSxS', 'Manifests', sxs_name + '_*.manifest')
30623062
manifests = glob.glob(pattern)
30633063
if not manifests:
3064-
print("%sWARNING:%s Could not locate manifest %s. You may need to reinstall the Visual C++ Redistributable." % (GetColor("red"), GetColor(), pattern))
3064+
Warn("Could not locate manifest %s. You may need to reinstall the Visual C++ Redistributable." % (pattern))
30653065
continue
30663066

30673067
CopyFile(GetOutputDir() + "/python/" + ident.get('name') + ".manifest", manifests[0])
@@ -7008,7 +7008,7 @@ def MakeInstallerLinux():
70087008
rpmbuild_present = True
70097009

70107010
if dpkg_present and rpmbuild_present:
7011-
print("Warning: both dpkg and rpmbuild present.")
7011+
Warn("both dpkg and rpmbuild present.")
70127012

70137013
if dpkg_present:
70147014
# Invoke installpanda.py to install it into a temporary dir

makepanda/makepandacore.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
def WarnConflictingFiles(delete = False):
151151
for cfile in CONFLICTING_FILES:
152152
if os.path.exists(cfile):
153-
print("%sWARNING:%s file may conflict with build: %s%s%s" % (GetColor("red"), GetColor(), GetColor("green"), cfile, GetColor()))
153+
Warn("file may conflict with build:", cfile)
154154
if delete:
155155
os.unlink(cfile)
156156
print("Deleted.")
@@ -284,6 +284,20 @@ def exit(msg = ""):
284284
print(msg)
285285
raise "initiate-exit"
286286

287+
def Warn(msg, extra=None):
288+
if extra is not None:
289+
print("%sWARNING:%s %s %s%s%s" % (GetColor("red"), GetColor(), msg, GetColor("green"), extra, GetColor()))
290+
else:
291+
print("%sWARNING:%s %s" % (GetColor("red"), GetColor(), msg))
292+
sys.stdout.flush()
293+
294+
def Error(msg, extra=None):
295+
if extra is not None:
296+
print("%sERROR:%s %s %s%s%s" % (GetColor("red"), GetColor(), msg, GetColor("green"), extra, GetColor()))
297+
else:
298+
print("%sERROR:%s %s" % (GetColor("red"), GetColor(), msg))
299+
exit()
300+
287301
########################################################################
288302
##
289303
## SetTarget, GetTarget, GetHost
@@ -723,7 +737,7 @@ def NeedsBuild(files, others):
723737
print(" dependency changed: %s" % (key))
724738

725739
if VERBOSE and frozenset(cached) != frozenset(dates):
726-
print("%sWARNING:%s file dependencies changed: %s%s%s" % (GetColor("red"), GetColor(), GetColor("green"), files, GetColor()))
740+
Warn("file dependencies changed:", files)
727741

728742
return True
729743

@@ -1298,7 +1312,7 @@ def GetThirdpartyDir():
12981312
THIRDPARTYDIR = GetThirdpartyBase()+"/android-libs-%s/" % (GetTargetArch())
12991313

13001314
else:
1301-
print("%s Unsupported platform: %s" % (ColorText("red", "WARNING:"), target))
1315+
Warn("Unsupported platform:", target)
13021316
return
13031317

13041318
if (GetVerbose()):
@@ -1744,11 +1758,10 @@ def SmartPkgEnable(pkg, pkgconfig = None, libs = None, incs = None, defs = None,
17441758
if not custom_loc and pkgconfig is not None and not libs:
17451759
# pkg-config is all we can do, abort if it wasn't found.
17461760
if pkg in PkgListGet():
1747-
print("%sWARNING:%s Could not locate pkg-config package %s, excluding from build" % (GetColor("red"), GetColor(), pkgconfig))
1761+
Warn("Could not locate pkg-config package %s, excluding from build" % (pkgconfig))
17481762
PkgDisable(pkg)
17491763
else:
1750-
print("%sERROR:%s Could not locate pkg-config package %s, aborting build" % (GetColor("red"), GetColor(), pkgconfig))
1751-
exit()
1764+
Error("Could not locate pkg-config package %s, aborting build" % (pkgconfig))
17521765

17531766
else:
17541767
# Okay, our pkg-config attempts failed. Let's try locating the libs by ourselves.
@@ -1812,14 +1825,12 @@ def SmartPkgEnable(pkg, pkgconfig = None, libs = None, incs = None, defs = None,
18121825

18131826
if not have_pkg:
18141827
if custom_loc:
1815-
print("%sERROR:%s Could not locate thirdparty package %s in specified directory, aborting build" % (GetColor("red"), GetColor(), pkg.lower()))
1816-
exit()
1828+
Error("Could not locate thirdparty package %s in specified directory, aborting build" % (pkg.lower()))
18171829
elif pkg in PkgListGet():
1818-
print("%sWARNING:%s Could not locate thirdparty package %s, excluding from build" % (GetColor("red"), GetColor(), pkg.lower()))
1830+
Warn("Could not locate thirdparty package %s, excluding from build" % (pkg.lower()))
18191831
PkgDisable(pkg)
18201832
else:
1821-
print("%sERROR:%s Could not locate thirdparty package %s, aborting build" % (GetColor("red"), GetColor(), pkg.lower()))
1822-
exit()
1833+
Error("Could not locate thirdparty package %s, aborting build" % (pkg.lower()))
18231834

18241835
########################################################################
18251836
##
@@ -2100,7 +2111,7 @@ def SdkLocatePython(prefer_thirdparty_python=False):
21002111
os.environ["PYTHONHOME"] = SDK["PYTHON"]
21012112

21022113
if sys.version[:3] != ver:
2103-
print("Warning: running makepanda with Python %s, but building Panda3D with Python %s." % (sys.version[:3], ver))
2114+
Warn("running makepanda with Python %s, but building Panda3D with Python %s." % (sys.version[:3], ver))
21042115

21052116
elif CrossCompiling() or (prefer_thirdparty_python and os.path.isdir(os.path.join(GetThirdpartyDir(), "python"))):
21062117
tp_python = os.path.join(GetThirdpartyDir(), "python")
@@ -2743,12 +2754,11 @@ def LibName(opt, name):
27432754
WARNINGS.append(name + " not found. Skipping Package " + opt)
27442755
if (opt in PkgListGet()):
27452756
if not PkgSkip(opt):
2746-
print("%sWARNING:%s Could not locate thirdparty package %s, excluding from build" % (GetColor("red"), GetColor(), opt.lower()))
2757+
Warn("Could not locate thirdparty package %s, excluding from build" % (opt.lower()))
27472758
PkgDisable(opt)
27482759
return
27492760
else:
2750-
print("%sERROR:%s Could not locate thirdparty package %s, aborting build" % (GetColor("red"), GetColor(), opt.lower()))
2751-
exit()
2761+
Error("Could not locate thirdparty package %s, aborting build" % (opt.lower()))
27522762
LIBNAMES.append((opt, name))
27532763

27542764
def DefSymbol(opt, sym, val=""):
@@ -2831,7 +2841,7 @@ def SetupBuildEnvironment(compiler):
28312841

28322842
returnval = handle.close()
28332843
if returnval != None and returnval != 0:
2834-
print("%sWARNING:%s %s failed" % (GetColor("red"), GetColor(), cmd))
2844+
Warn("%s failed" % (cmd))
28352845
SYS_LIB_DIRS += [SDK.get("SYSROOT", "") + "/usr/lib"]
28362846

28372847
# Now extract the preprocessor's include directories.
@@ -2860,7 +2870,7 @@ def SetupBuildEnvironment(compiler):
28602870
print("Ignoring non-existent include directory %s" % (line))
28612871

28622872
if handle.returncode != 0 or not SYS_INC_DIRS:
2863-
print("%sWARNING:%s %s failed or did not produce the expected result" % (GetColor("red"), GetColor(), cmd))
2873+
Warn("%s failed or did not produce the expected result" % (cmd))
28642874
sysroot = SDK.get("SYSROOT", "")
28652875
# Add some sensible directories as a fallback.
28662876
SYS_INC_DIRS = [
@@ -3374,7 +3384,7 @@ def FindLocation(fn, ipath, pyabi=None):
33743384

33753385
elif ext != ".pyd" and loc not in WARNED_FILES:
33763386
WARNED_FILES.add(loc)
3377-
print("%sWARNING:%s file depends on Python but is not in an ABI-specific directory: %s%s%s" % (GetColor("red"), GetColor(), GetColor("green"), loc, GetColor()))
3387+
Warn("file depends on Python but is not in an ABI-specific directory:", loc)
33783388

33793389
ORIG_EXT[loc] = ext
33803390
return loc

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy