def test_workspace(self): tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, "foo")) workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) self.assertEqual(workspace.source_root, tmpdir1) self.assertEqual(workspace.build_root, tmpdir2) # source_dir self.assertEqual(workspace.source_dir("foo"), os.path.join(tmpdir1, "foo")) # build_dir self.assertEqual(workspace.build_dir("target", "product"), os.path.join(tmpdir2, "product-target")) shutil.rmtree(tmpdir1) shutil.rmtree(tmpdir2)
def test_workspace(self): tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'foo')) workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) self.assertEqual(workspace.source_root, tmpdir1) self.assertEqual(workspace.build_root, tmpdir2) # source_dir self.assertEqual(workspace.source_dir('foo'), os.path.join(tmpdir1, 'foo')) # build_dir self.assertEqual(workspace.build_dir('target', 'product'), os.path.join(tmpdir2, 'product-target')) shutil.rmtree(tmpdir1) shutil.rmtree(tmpdir2)
class NinjaTestCase(unittest.TestCase): def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'ninja')) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = '/path/to/cc' self.toolchain.cxx = '/path/to/cxx' # Setup args self.args = argparse.Namespace(build_ninja=True, darwin_deployment_version_osx="10.9") # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr def tearDown(self): shutil.rmtree(self.workspace.build_root) shutil.rmtree(self.workspace.source_root) sys.stdout = self._orig_stdout sys.stderr = self._orig_stderr shell.dry_run = False self.workspace = None self.toolchain = None self.args = None def test_ninja_bin_path(self): ninja_build = Ninja(args=self.args, toolchain=self.toolchain, source_dir='/path/to/src', build_dir='/path/to/build') self.assertEqual(ninja_build.ninja_bin_path, '/path/to/build/ninja') def test_do_build(self): ninja_build = Ninja(args=self.args, toolchain=self.toolchain, source_dir=self.workspace.source_dir('ninja'), build_dir=self.workspace.build_dir( 'build', 'ninja')) ninja_build.do_build() expect_env = "" if platform.system() == "Darwin": expect_env = ( "env " "'CFLAGS=-isysroot {sysroot} -mmacosx-version-min=10.9' " "CXX={cxx} " "LDFLAGS=-mmacosx-version-min=10.9 ").format( cxx=self.toolchain.cxx, sysroot=xcrun.sdk_path('macosx')) self.assertEqual( self.stdout.getvalue(), """\ + rm -rf {build_dir} + cp -r {source_dir} {build_dir} + pushd {build_dir} + {expect_env}{python} configure.py --bootstrap + popd """.format(source_dir=os.path.join(self.workspace.source_root, 'ninja'), build_dir=os.path.join(self.workspace.build_root, 'ninja-build'), expect_env=expect_env, python=sys.executable))
class NinjaTestCase(unittest.TestCase): def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'ninja')) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = '/path/to/cc' self.toolchain.cxx = '/path/to/cxx' # Setup args self.args = argparse.Namespace( build_ninja=True, darwin_deployment_version_osx="10.9") # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr def tearDown(self): shutil.rmtree(self.workspace.build_root) shutil.rmtree(self.workspace.source_root) sys.stdout = self._orig_stdout sys.stderr = self._orig_stderr shell.dry_run = False self.workspace = None self.toolchain = None self.args = None def test_ninja_bin_path(self): ninja_build = Ninja( args=self.args, toolchain=self.toolchain, source_dir='/path/to/src', build_dir='/path/to/build') self.assertEqual(ninja_build.ninja_bin_path, '/path/to/build/ninja') def test_do_build(self): ninja_build = Ninja( args=self.args, toolchain=self.toolchain, source_dir=self.workspace.source_dir('ninja'), build_dir=self.workspace.build_dir('build', 'ninja')) ninja_build.do_build() expect_env = "" if platform.system() == "Darwin": expect_env = ( "env " "'CFLAGS=-isysroot {sysroot} -mmacosx-version-min=10.9' " "CXX={cxx} " "LDFLAGS=-mmacosx-version-min=10.9 " ).format( cxx=self.toolchain.cxx, sysroot=xcrun.sdk_path('macosx') ) self.assertEqual(self.stdout.getvalue(), """\ + rm -rf {build_dir} + cp -r {source_dir} {build_dir} + pushd {build_dir} + {expect_env}{python} configure.py --bootstrap + popd """.format( source_dir=os.path.join(self.workspace.source_root, 'ninja'), build_dir=os.path.join(self.workspace.build_root, 'ninja-build'), expect_env=expect_env, python=sys.executable))