diff --git a/build.py b/build.py
index 4b233b895568..c6fe7e808924 100644
--- a/build.py
+++ b/build.py
@@ -17,7 +17,7 @@
 import dependencies
 import mlog
 import copy, os
-from mesonlib import File
+from mesonlib import File, flatten
 
 known_basic_kwargs = {'install' : True,
                       'c_pch' : True,
@@ -476,8 +476,9 @@ def add_include_dirs(self, args):
         self.include_dirs += ids
 
     def add_compiler_args(self, language, args):
+        args = flatten(args)
         for a in args:
-            if not isinstance(a, str):
+            if not isinstance(a, (str, File)):
                 raise InvalidArguments('A non-string passed to compiler args.')
         if language in self.extra_args:
             self.extra_args[language] += args
diff --git a/mesonlib.py b/mesonlib.py
index c04e7afc4914..fc51380c9dd7 100644
--- a/mesonlib.py
+++ b/mesonlib.py
@@ -58,6 +58,17 @@ def __eq__(self, other):
     def __hash__(self):
         return hash((self.fname, self.subdir, self.is_built))
 
+def flatten(item):
+    if not isinstance(item, list):
+        return item
+    result = []
+    for i in item:
+        if isinstance(i, list):
+            result += flatten(i)
+        else:
+            result.append(i)
+    return result
+
 def is_osx():
     return platform.system().lower() == 'darwin'
 
diff --git a/ninjabackend.py b/ninjabackend.py
index c929238f066c..04ee778beec5 100644
--- a/ninjabackend.py
+++ b/ninjabackend.py
@@ -689,6 +689,7 @@ def generate_vala_compile(self, target, outfile):
         generated_c = []
         (src, vapi_src) = self.split_vala_sources(target.get_sources())
         vapi_src = [x.rel_to_builddir(self.build_to_src) for x in vapi_src]
+        extra_dep_files = []
         for s in src:
             if not s.endswith('.vala'):
                 continue
@@ -714,11 +715,22 @@ def generate_vala_compile(self, target, outfile):
                             args += ['--target-glib', d.version_requirement[2:]]
                     args += ['--pkg', d.name]
             args += vapi_src
-            args += target.extra_args.get('vala', [])
+            extra_args = []
+
+            for a in target.extra_args.get('vala', []):
+                if isinstance(a, File):
+                    relname = a.rel_to_builddir(self.build_to_src)
+                    extra_dep_files.append(relname)
+                    extra_args.append(relname)
+                else:
+                    extra_args.append(a)
+            print(extra_args)
+            args += extra_args
             generated_c += [relsc]
             element = NinjaBuildElement(relsc, valac.get_language() + '_COMPILER', rel_s)
             element.add_item('ARGS', args)
             element.add_orderdep(vapi_order_deps)
+            element.add_dep(extra_dep_files)
             element.write(outfile)
         return generated_c