aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2016-12-15 13:42:28 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2016-12-16 00:04:38 +0530
commit5e5b3f00d8485949634b4411d8304cc467ad8fc7 (patch)
tree9479277d86a4188034327ad9a9e1870923e6b255
parentd5f7ba862bb37ad75b68e007b8b55f40b6f6fd19 (diff)
downloadmeson-5e5b3f00d8485949634b4411d8304cc467ad8fc7.zip
meson-5e5b3f00d8485949634b4411d8304cc467ad8fc7.tar.gz
meson-5e5b3f00d8485949634b4411d8304cc467ad8fc7.tar.bz2
modules: Cache programs found by find_program
This avoids printing several 'Found:' messages during configure, and also avoids doing several searches for the same binary. This is already done by the interpreter for `find_program` calls from build files. Also move it to the module-wide __init__.py file so it can be used by other modules as-needed. Also use it for g-ir-scanner where it was missed in one place, also fix exception name in the same place.
-rw-r--r--mesonbuild/modules/__init__.py13
-rw-r--r--mesonbuild/modules/gnome.py16
-rw-r--r--mesonbuild/modules/qt4.py2
3 files changed, 19 insertions, 12 deletions
diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py
index 493a7b9..8986d7a 100644
--- a/mesonbuild/modules/__init__.py
+++ b/mesonbuild/modules/__init__.py
@@ -1,4 +1,17 @@
from .. import build
+from .. import dependencies
+
+_found_programs = {}
+
+def find_program(program_name, target_name):
+ if program_name in _found_programs:
+ return _found_programs[program_name]
+ program = dependencies.ExternalProgram(program_name)
+ if not program.found():
+ m = "Target {!r} can't be generated as {!r} could not be found"
+ raise MesonException(m.format(target_name, program_name))
+ _found_programs[program_name] = program
+ return program
class GResourceTarget(build.CustomTarget):
def __init__(self, name, subdir, kwargs):
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index eca894a..e291c98 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -25,7 +25,7 @@ from .. import dependencies
from .. import mlog
from .. import mesonlib
from .. import interpreter
-from . import GResourceTarget, GResourceHeaderTarget, GirTarget, TypelibTarget, VapiTarget
+from . import find_program, GResourceTarget, GResourceHeaderTarget, GirTarget, TypelibTarget, VapiTarget
# gresource compilation is broken due to the way
# the resource compiler and Ninja clash about it
@@ -46,19 +46,13 @@ def gir_has_extra_lib_arg():
_gir_has_extra_lib_arg = False
try:
- scanner_options = subprocess.check_output(['g-ir-scanner', '--help']).decode()
- _gir_has_extra_lib_arg = '--extra-library' in scanner_options
- except (FileNotFound, subprocess.CalledProcessError):
+ g_ir_scanner = find_program('g-ir-scanner', '').get_command()
+ opts = Popen_safe(g_ir_scanner + ['--help'], stderr=subprocess.STDOUT)[1]
+ _gir_has_extra_lib_arg = '--extra-library' in opts
+ except (MesonException, FileNotFoundError, subprocess.CalledProcessError):
pass
return _gir_has_extra_lib_arg
-def find_program(program_name, target_name):
- program = dependencies.ExternalProgram(program_name)
- if not program.found():
- raise MesonException('%s can\'t be generated as %s could not be found' % (
- target_name, program_name))
- return program
-
class GnomeModule:
@staticmethod
diff --git a/mesonbuild/modules/qt4.py b/mesonbuild/modules/qt4.py
index ab285fb..63dfef8 100644
--- a/mesonbuild/modules/qt4.py
+++ b/mesonbuild/modules/qt4.py
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os, subprocess
+import os
from .. import mlog
from .. import build
from ..mesonlib import MesonException, Popen_safe