def test_rule_stmt(self): input_path = os.path.join(TEST_DATA_DIR, 'rule.ninja') parser = ninja.Parser() manifest = parser.parse(input_path, ENCODING) self.assertEqual(2, len(manifest.rules)) rule_cc = manifest.rules[0] self.assertEqual('cc', rule_cc.name) self.assertEqual(1, len(rule_cc.bindings)) sb = ninja.EvalStringBuilder() sb.append_raw('gcc -c -o ') sb.append_var('outs') sb.append_raw(' ') sb.append_var('ins') self.assertEqual(sb.getvalue(), rule_cc.bindings['command']) rule_ld = manifest.rules[1] self.assertEqual('ld', rule_ld.name) self.assertEqual(1, len(rule_ld.bindings)) sb = ninja.EvalStringBuilder() sb.append_raw('gcc -o ') sb.append_var('outs') sb.append_raw(' ') sb.append_var('ins') self.assertEqual(sb.getvalue(), rule_ld.bindings['command'])
def load_build_dep_ninja(ninja_path, work_dir, ninja_deps=None): manifest = ninja.Parser().parse(ninja_path, 'utf-8', ninja_deps) graph = collections.defaultdict(set) for build in manifest.builds: for path in itertools.chain(build.explicit_outs, build.implicit_outs): ins = graph[path] ins.update(build.explicit_ins) ins.update(build.implicit_ins) ins.update(build.depfile_implicit_ins) return load_build_dep_graph(graph)
def test_pool_stmt(self): input_path = os.path.join(TEST_DATA_DIR, 'pool.ninja') parser = ninja.Parser() manifest = parser.parse(input_path, ENCODING) self.assertEqual(1, len(manifest.pools)) pool = manifest.pools[0] self.assertEqual('example', pool.name) self.assertEqual(('t', '5',), pool.bindings['depth'])
def test_default_stmt(self): input_path = os.path.join(TEST_DATA_DIR, 'default.ninja') parser = ninja.Parser() manifest = parser.parse(input_path, ENCODING) self.assertEqual(1, len(manifest.defaults)) default = manifest.defaults[0] self.assertEqual('foo.o', default.outs[0]) self.assertEqual('bar.o', default.outs[1])
def test_build_stmt(self): input_path = os.path.join(TEST_DATA_DIR, 'build.ninja') parser = ninja.Parser() manifest = parser.parse(input_path, ENCODING) self.assertEqual(1, len(manifest.builds)) build = manifest.builds[0] self.assertEqual('explicit_out1', build.explicit_outs[0]) self.assertEqual('explicit_out2', build.explicit_outs[1]) self.assertEqual('implicit_out1', build.implicit_outs[0]) self.assertEqual('implicit_out2', build.implicit_outs[1]) self.assertEqual('phony', build.rule) self.assertEqual('explicit_in1', build.explicit_ins[0]) self.assertEqual('explicit_in2', build.explicit_ins[1]) self.assertEqual('implicit_in1', build.implicit_ins[0]) self.assertEqual('implicit_in2', build.implicit_ins[1]) self.assertEqual('order_only1', build.prerequisites[0]) self.assertEqual('order_only2', build.prerequisites[1]) self.assertEqual(('t', '1',), build.bindings['a']) self.assertEqual(('t', '2',), build.bindings['b'])
def test_init_base_dir(self): parser = ninja.Parser() self.assertEqual(os.getcwd(), parser._base_dir) parser = ninja.Parser('/path/to/a/dir') self.assertEqual('/path/to/a/dir', parser._base_dir)