bug 1052744 - Add mozbuild.makeutil.write_dep_makefile. r=gps

This commit is contained in:
Ted Mielczarek 2014-08-26 11:55:47 -04:00
Родитель a3d6dd49d1
Коммит 3f93d58a2e
2 изменённых файлов: 18 добавлений и 0 удалений

Просмотреть файл

@ -172,3 +172,13 @@ def read_dep_makefile(fh):
if rule:
raise Exception('Makefile finishes with a backslash. Expected more input.')
def write_dep_makefile(fh, target, deps):
'''
Write a Makefile containing only target's dependencies to the file handle
specified.
'''
mk = Makefile()
rule = mk.create_rule(targets=[target])
rule.add_dependencies(deps)
mk.dump(fh, removal_guard=True)

Просмотреть файл

@ -6,6 +6,7 @@ from mozbuild.makeutil import (
Makefile,
read_dep_makefile,
Rule,
write_dep_makefile,
)
from mozunit import main
import os
@ -153,5 +154,12 @@ class TestMakefile(unittest.TestCase):
self.assertEqual(list(result[1].targets()), ['baz', 'qux'])
self.assertEqual(list(result[1].dependencies()), ['hoge', 'piyo', 'fuga'])
def test_write_dep_makefile(self):
out = StringIO()
write_dep_makefile(out, 'target', ['b', 'c', 'a'])
self.assertEqual(out.getvalue(),
'target: b c a\n' +
'a b c:\n')
if __name__ == '__main__':
main()