From: Gabe Black Date: Fri, 23 Oct 2020 03:01:02 +0000 (-0700) Subject: util: Rework some checks in the m5 util scons to use Configure(). X-Git-Tag: develop-gem5-snapshot~372 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=97aa8425d640ce5f4f013e8a865e162f14bb0c09;p=gem5.git util: Rework some checks in the m5 util scons to use Configure(). This is the official scons way to check for things on the system. This adds two custom checks, one for java packages and one for pkg-config packages. This change also adds a check for the org.junit java package which is/will be used for a test for the java wrapper. Change-Id: I59ca559f257a4c671e9b72a50b5635b5eb61ee69 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28180 Tested-by: kokoro Reviewed-by: Bobby R. Bruce Maintainer: Gabe Black --- diff --git a/util/m5/SConstruct b/util/m5/SConstruct index 6f1ca9fad..5725f6c87 100644 --- a/util/m5/SConstruct +++ b/util/m5/SConstruct @@ -91,12 +91,47 @@ else: main['ENV']['PATH'] = os.environ['PATH'] # Pass through terminal information to, for instance, enable color output. main['ENV']['TERM'] = os.environ['TERM'] +# Pass through the java CLASSPATH (if it exists) so we can find libraries. +main['ENV']['CLASSPATH'] = os.environ.get('CLASSPATH', '') # Detect some dependencies of some forms of the m5 utility/library. +def CheckForJavaPkg(context, pkg_name): + context.Message('Checking for java package %s...' % pkg_name) + result = main['HAVE_JAVA'] and \ + context.TryAction('${JAVAC} ${JAVACFLAGS} ${SOURCES}', + 'import %s.*;' % pkg_name, '.java')[0] + context.Result(result) + return result + +def CheckForPkgConfigPackage(context, package): + context.Message('Checking for pkg-config package %s...' % package) + result = main['HAVE_PKG_CONFIG'] and \ + os.system('pkg-config --exists %s' % package) == 0 + context.Result(result) + return result; + +conf = Configure(main, conf_dir=build_dir.Dir('.scons_config'), + log_file=build_dir.File('scons_config.log'), custom_tests={ + 'CheckForJavaPkg' : CheckForJavaPkg, + 'CheckForPkgConfigPackage' : CheckForPkgConfigPackage +}) main['HAVE_JAVA'] = all(key in main for key in ('JAVAC', 'JAR')) -main['HAVE_PKG_CONFIG'] = main.Detect('pkg-config') is not None -main['HAVE_LUA51'] = (main['HAVE_PKG_CONFIG'] and - os.system('pkg-config --exists lua51') == 0) +if not main['HAVE_JAVA']: + print('javac and/or jar not detected, not building java wrapper.') + +main['HAVE_JUNIT'] = conf.CheckForJavaPkg('org.junit') +if main['HAVE_JAVA'] and not main['HAVE_JUNIT']: + print('junit test framework not found, not build java wrapper test') + +main['HAVE_PKG_CONFIG'] = conf.CheckProg('pkg-config') +if not main['HAVE_PKG_CONFIG']: + print("pkg-config not detected, can't check for lua51.") + +main['HAVE_LUA51'] = conf.CheckForPkgConfigPackage('lua51') +if not main['HAVE_LUA51']: + print('lua 5.1 not detected, not building lua wrapper.') + +conf.Finish() # Put the sconsign file in the build dir so everything can be deleted at once. main.SConsignFile(os.path.join(abspath(build_dir), 'sconsign'))