Esempio n. 1
0
 def test_honor_build_dir_parameter(self):
     source = os.path.join(samurai_sys.top_dir, "b", "c")
     mkdir_p(source)
     build_dir = os.path.join(samurai_sys.top_dir, "custom_build")
     answer = os.path.join(build_dir, "b", "c")
     self.assertEqual(samurai_sys.get_default_build_dir_for(source, a_build_dir=build_dir), answer)
     self.assertEqual(samurai_sys.get_default_build_dir_for(PathLib(source), a_build_dir=build_dir), PathLib(answer))
Esempio n. 2
0
 def test_intermediary_isnot_adir(self):
     afile = os.path.join(self.tmpdir, "afile")
     with open(afile, "w"):
         pass
     adir = os.path.join(afile, "adir")
     with self.assertRaises(NotADirectoryError):
         mkdir_p(adir)
Esempio n. 3
0
 def test_first_not_empty(self):
     d1 = os.path.join(self.tmpdir, "a")
     d2 = os.path.join(d1, "b")
     mkdir_p(d2)
     self.assertTrue(os.path.isdir(d2))
     rmdir_p(d1)
     self.assertTrue(os.path.isdir(d2))
Esempio n. 4
0
 def test_accept_pathlib(self):
     a = os.path.join(self.tmpdir, "a")
     os.mkdir(os.path.join(self.tmpdir, "sentinel"))
     abc = PathLib(os.path.join(a, "b", "c"))
     mkdir_p(abc)
     self.assertTrue(os.path.exists(a))
     rmdir_p(abc)
     self.assertFalse(os.path.exists(a))
 def test_default_build_dir(self):
     subdir = os.path.join(self.tmpdir, "sub")
     mkdir_p(subdir)
     manifest = os.path.join(subdir, "build.samurai")
     write_file(manifest, "")
     build_dir = os.path.join(samurai_sys.build_dir, "sub")
     s = SubSamurai(manifest)
     self.assertEqual(s.build_dir, build_dir)
     s = SubSamurai(PathLib(manifest))
     self.assertEqual(s.build_dir, PathLib(build_dir))
Esempio n. 6
0
 def generate(self):
     mkdir_p(self.build_dir)
     p = subprocess.Popen(
         ("cmake", "-G", "Ninja", str(self.source_dir)),
         cwd=str(self.build_dir),
         stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
         universal_newlines=True)
     for line in p.stdout.readlines():
         sys.stdout.write(line)
     p.wait()
     if p.returncode != 0:
         raise RuntimeError("failed to generate cmake project '{}' to '{}'"
                            .format(self.source_dir, self.build_dir))
Esempio n. 7
0
def create_fs_tree(root_dir, spec):
    fs = {}
    for k, v in spec.items():
        if os.path.isabs(k):
            path = k
        else:
            path = os.path.join(root_dir, k)
        if isinstance(v, dict):
            fs[k] = create_fs_tree(path, v)
        else:
            if v is None:
                mkdir_p(path)
            else:
                create_file(path, v)
            fs[k] = path
    return fs
Esempio n. 8
0
 def test_rm_empty_dir(self):
     a = os.path.join(self.tmpdir, "a")
     ab = os.path.join(a, "b")
     abc = os.path.join(ab, "c")
     ad = os.path.join(a, "d")
     mkdir_p(abc)
     mkdir_p(ad)
     self.assertTrue(os.path.exists(abc))
     self.assertTrue(os.path.exists(ab))
     self.assertTrue(os.path.exists(a))
     self.assertTrue(os.path.exists(ad))
     rmdir_p(abc)
     self.assertFalse(os.path.exists(abc))
     self.assertFalse(os.path.exists(ab))
     self.assertTrue(os.path.exists(a))
     self.assertTrue(os.path.exists(ad))
Esempio n. 9
0
def main(argv):
    cli = build_cli()
    options = cli.parse_args(argv[1:])
    init_logger(options.verbose)
    if options.change_dir:
        LOGGER.info("changing current working directory to: %r",
                    options.change_dir)
        os.chdir(options.change_dir)
    if options.clean:
        LOGGER.info("removing build directory: %r", options.build_dir)
        if os.path.exists(options.build_dir):
            shutil.rmtree(options.build_dir)
    if options.make_dirs or options.clean:
        LOGGER.info("making build directory: %r", options.build_dir)
        mkdir_p(options.build_dir)
    generator = Generator(options.manifest, options.build_dir)
    generator.maybe_generate(force=(not options.execute or options.force))
    if options.execute:
        _run_ninja(options.build_dir, get_ninja(),
                   get_ninja(), *options.ninja_args)
    return 0
Esempio n. 10
0
 def test_basic(self):
     manifest = os.path.join(self.tmpdir, "sub", "manifest")
     mkdir_p(os.path.dirname(manifest))
     write_file(manifest, "")
     build_dir = os.path.join(self.build_dir(), "sub")
     s = SubSamurai(manifest, build_dir)
     s.generate = MagicMock()
     self.dump(s)
     s.generate.assert_called_once_with()
     build_content = read_file(self.dumper.build_pathname())
     self.assertRegex(build_content,
                      re.compile(r"^# SubSamurai sub-project from",
                                 re.MULTILINE))
     self.assertRegex(build_content,
                      re.compile(r"^#.*'{manifest}'$"
                                 .format(manifest=manifest),
                                 re.MULTILINE))
     self.assertRegex(build_content,
                      re.compile(r"^subninja {build_dir}/build.ninja\n"
                                 .format(build_dir=build_dir),
                                 re.MULTILINE))
     self.assertEqual(self.dumper.rule_count, 0)
     self.assertEqual(self.dumper.build_count, 0)
     self.assertEqual(self.dumper.subgenerator_count, 1)
Esempio n. 11
0
 def generate(self, manifest):
     self.generator = Generator(manifest, self.build_dir())
     mkdir_p(self.build_dir())
     return self.generator.generate()
Esempio n. 12
0
def create_file(path, content):
    mkdir_p(os.path.dirname(path))
    with open(path, "w") as stream:
        stream.write(content)
Esempio n. 13
0
 def test_final_exist(self):
     d = os.path.join(self.tmpdir, "a_dir")
     os.mkdir(d)
     mkdir_p(d) # No exception raised
     self.assertTrue(os.path.isdir(d))
Esempio n. 14
0
 def setUp(self):
     super().setUp()
     mkdir_p(self.build_dir())
     self.dumper = NinjaDumper(self.build_dir())
Esempio n. 15
0
 def test_final_doesnotexist(self):
     d = os.path.join(self.tmpdir, "a_dir")
     mkdir_p(d)
     self.assertTrue(os.path.isdir(d))
Esempio n. 16
0
 def test_source_is_dir(self):
     source = os.path.join(samurai_sys.top_dir, "b", "c")
     mkdir_p(source)
     answer = os.path.join(samurai_sys.build_dir, "b", "c")
     self.assertEqual(samurai_sys.get_default_build_dir_for(source), answer)
     self.assertEqual(samurai_sys.get_default_build_dir_for(PathLib(source)), PathLib(answer))
Esempio n. 17
0
 def test_all_doesnotexist(self):
     d = os.path.join(self.tmpdir, "d1", "d2", "d3")
     mkdir_p(d)
     self.assertTrue(os.path.isdir(d))
Esempio n. 18
0
 def test_accept_pathlib(self):
     d = PathLib(self.tmpdir) / "a_dir"
     mkdir_p(d)