Ejemplo 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))
Ejemplo 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)
Ejemplo 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))
Ejemplo 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))
Ejemplo n.º 5
0
 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))
Ejemplo 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))
Ejemplo 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
Ejemplo 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))
Ejemplo 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
Ejemplo 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)
Ejemplo n.º 11
0
 def generate(self, manifest):
     self.generator = Generator(manifest, self.build_dir())
     mkdir_p(self.build_dir())
     return self.generator.generate()
Ejemplo n.º 12
0
def create_file(path, content):
    mkdir_p(os.path.dirname(path))
    with open(path, "w") as stream:
        stream.write(content)
Ejemplo 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))
Ejemplo n.º 14
0
 def setUp(self):
     super().setUp()
     mkdir_p(self.build_dir())
     self.dumper = NinjaDumper(self.build_dir())
Ejemplo 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))
Ejemplo 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))
Ejemplo 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))
Ejemplo n.º 18
0
 def test_accept_pathlib(self):
     d = PathLib(self.tmpdir) / "a_dir"
     mkdir_p(d)