def test_svn(self): """Test component checkouts from SVN.""" subprocess.run(['svnadmin', 'create', self.svndir], check=True) svn_uri = 'file://%s' % self.svndir subprocess.run(['svn', '-q', 'co', svn_uri, self.codir], check=True) self.co_file_write('svnfile', 'svnfile contents') subprocess.run(['svn', '-q', 'add', 'svnfile'], cwd=self.codir, check=True) subprocess.run(['svn', '-q', 'commit', '-m', 'commit message'], cwd=self.codir, check=True) relcfg_text = ('cfg.add_component("generic")\n' 'cfg.generic.vc.set(SvnVC("%s"))\n' 'cfg.generic.version.set("1.23")\n' 'cfg.build.set("x86_64-linux-gnu")\n' 'cfg.target.set("aarch64-linux-gnu")\n' % svn_uri) relcfg = ReleaseConfig(self.context, relcfg_text, ReleaseConfigTextLoader(), self.args) component = relcfg.get_component('generic') component.vars.vc.get().checkout_component(component) self.assertEqual(self.src_file_read('generic-1.23/svnfile'), 'svnfile contents') self.co_file_write('svnfile', 'modified contents') subprocess.run(['svn', '-q', 'commit', '-m', 'commit 2'], cwd=self.codir, check=True) component.vars.vc.get().checkout_component(component) self.assertEqual(self.src_file_read('generic-1.23/svnfile'), 'modified contents')
def test_git(self): """Test component checkouts from git.""" os.mkdir(self.codir) subprocess.run(['git', 'init', '-q'], cwd=self.codir, check=True) self.co_file_write('gitfile', 'gitfile contents') subprocess.run(['git', 'add', '.'], cwd=self.codir, check=True) subprocess.run(['git', 'commit', '-q', '-m', 'commit message'], cwd=self.codir, check=True) relcfg_text = ('cfg.add_component("generic")\n' 'cfg.generic.vc.set(GitVC("%s"))\n' 'cfg.generic.version.set("1.23")\n' 'cfg.build.set("x86_64-linux-gnu")\n' 'cfg.target.set("aarch64-linux-gnu")\n' % self.codir) relcfg = ReleaseConfig(self.context, relcfg_text, ReleaseConfigTextLoader(), self.args) component = relcfg.get_component('generic') component.vars.vc.get().checkout_component(component) self.assertEqual(self.src_file_read('generic-1.23/gitfile'), 'gitfile contents') self.co_file_write('gitfile', 'modified contents') subprocess.run(['git', 'commit', '-q', '-a', '-m', 'commit 2'], cwd=self.codir, check=True) component.vars.vc.get().checkout_component(component) self.assertEqual(self.src_file_read('generic-1.23/gitfile'), 'modified contents')
def test_touch(self): """Test component checkouts touching files.""" self.create_test_tar(['f2', 'f4', 'f1', 'f3']) relcfg_text = ('cfg.add_component("files_to_touch")\n' 'cfg.files_to_touch.vc.set(TarVC("%s"))\n' 'cfg.files_to_touch.version.set("1.23")\n' 'cfg.build.set("x86_64-linux-gnu")\n' 'cfg.target.set("aarch64-linux-gnu")\n' % os.path.join(self.tempdir, 'test.tar')) relcfg = ReleaseConfig(self.context, relcfg_text, ReleaseConfigTextLoader(), self.args) component = relcfg.get_component('files_to_touch') component.vars.vc.get().checkout_component(component) self.check_file_order(os.path.join(self.srcdir, 'files_to_touch-1.23'), ['f1', 'f3', 'f2', 'f4']) # Test variant with glob patterns used. shutil.rmtree(self.codir) shutil.rmtree(self.srcdir) self.create_test_tar( ['g3', 'g2', 'g1', 'f', 'x', 'd/x', 'dd/ee/x', 'd/y']) relcfg_text = ('cfg.add_component("files_to_touch_glob")\n' 'cfg.files_to_touch_glob.vc.set(TarVC("%s"))\n' 'cfg.files_to_touch_glob.version.set("1.23")\n' 'cfg.build.set("x86_64-linux-gnu")\n' 'cfg.target.set("aarch64-linux-gnu")\n' % os.path.join(self.tempdir, 'test.tar')) relcfg = ReleaseConfig(self.context, relcfg_text, ReleaseConfigTextLoader(), self.args) component = relcfg.get_component('files_to_touch_glob') component.vars.vc.get().checkout_component(component) self.check_file_order( os.path.join(self.srcdir, 'files_to_touch_glob-1.23'), ['f', 'd/y', 'd/x', 'dd/ee/x', 'x', 'g1', 'g2', 'g3']) contents = sorted( os.listdir(os.path.join(self.srcdir, 'files_to_touch_glob-1.23'))) self.assertEqual(contents, ['d', 'dd', 'f', 'g1', 'g2', 'g3', 'x'])
def test_postcheckout(self): """Test component checkout calls postcheckout hook.""" os.mkdir(self.codir) self.co_file_write('tarfile', 'tarfile contents') subprocess.run(['tar', '-c', '-z', '-f', 'test.tar.gz', 'co'], cwd=self.tempdir, check=True) relcfg_text = ('cfg.add_component("postcheckout")\n' 'cfg.postcheckout.vc.set(TarVC("%s"))\n' 'cfg.postcheckout.version.set("1.23")\n' 'cfg.build.set("x86_64-linux-gnu")\n' 'cfg.target.set("aarch64-linux-gnu")\n' % os.path.join(self.tempdir, 'test.tar.gz')) relcfg = ReleaseConfig(self.context, relcfg_text, ReleaseConfigTextLoader(), self.args) component = relcfg.get_component('postcheckout') component.postcheckout_hook_called = False component.vars.vc.get().checkout_component(component) self.assertTrue(component.postcheckout_hook_called)
def test_tar(self): """Test component checkouts from tarballs.""" os.mkdir(self.codir) self.co_file_write('tarfile', 'tarfile contents') subprocess.run(['tar', '-c', '-z', '-f', 'test.tar.gz', 'co'], cwd=self.tempdir, check=True) relcfg_text = ('cfg.add_component("generic")\n' 'cfg.generic.vc.set(TarVC("%s"))\n' 'cfg.generic.version.set("1.23")\n' 'cfg.build.set("x86_64-linux-gnu")\n' 'cfg.target.set("aarch64-linux-gnu")\n' % os.path.join(self.tempdir, 'test.tar.gz')) relcfg = ReleaseConfig(self.context, relcfg_text, ReleaseConfigTextLoader(), self.args) component = relcfg.get_component('generic') component.vars.vc.get().checkout_component(component) contents = sorted(os.listdir(os.path.join(self.srcdir, 'generic-1.23'))) self.assertEqual(contents, ['tarfile']) self.assertEqual(self.src_file_read('generic-1.23/tarfile'), 'tarfile contents')
def test_finalize(self): """Test finalize.""" loader = ReleaseConfigTextLoader() relcfg_text = ('cfg.build.set("x86_64-linux-gnu")\n' 'cfg.target.set("aarch64-linux-gnu")\n' 'cfg.add_component("generic")\n' 'cfg.generic.vc.set(GitVC("dummy"))\n' 'cfg.generic.version.set("1.23")\n' 'cfg.add_component("sysrooted_libc")\n' 'cfg.sysrooted_libc.vc.set(GitVC("dummy"))\n' 'cfg.sysrooted_libc.version.set("1.23")\n') relcfg = ReleaseConfig(self.context, relcfg_text, loader, self.args) # Test sysrooted libc case, non-default settings for everything. multilib = Multilib(self.context, 'generic', 'sysrooted_libc', ('-mx', '-my'), tool_opts={'as': ['--opt']}, sysroot_suffix='foo', headers_suffix='foo2', sysroot_osdir='os', osdir='os2', target='other') multilib.finalize(relcfg) self.assertIs(multilib.compiler, relcfg.get_component('generic')) self.assertIs(multilib.libc, relcfg.get_component('sysrooted_libc')) self.assertEqual(multilib.sysroot_suffix, 'foo') self.assertEqual(multilib.headers_suffix, 'foo2') self.assertEqual(multilib.sysroot_osdir, 'os') self.assertEqual(multilib.sysroot_rel, 'opt/toolchain/aarch64-linux-gnu/libc/foo') self.assertEqual(multilib.headers_rel, 'opt/toolchain/aarch64-linux-gnu/libc/foo2') self.assertEqual(multilib.osdir, 'os2') self.assertEqual(multilib.target, 'other') self.assertIsInstance(multilib.build_cfg, BuildCfg) self.assertEqual( repr(multilib.build_cfg), "BuildCfg('other', tool_prefix='aarch64-linux-gnu-', " "ccopts=('-mx', '-my'), " "tool_opts={'as': ('--opt',)})") # Test sysrooted libc case, default settings. multilib = Multilib(self.context, 'generic', 'sysrooted_libc', ()) multilib.finalize(relcfg) self.assertIs(multilib.compiler, relcfg.get_component('generic')) self.assertIs(multilib.libc, relcfg.get_component('sysrooted_libc')) self.assertEqual(multilib.sysroot_suffix, '.') self.assertEqual(multilib.headers_suffix, '.') self.assertEqual(multilib.sysroot_osdir, '.') self.assertEqual(multilib.sysroot_rel, 'opt/toolchain/aarch64-linux-gnu/libc') self.assertEqual(multilib.headers_rel, 'opt/toolchain/aarch64-linux-gnu/libc') self.assertEqual(multilib.osdir, '.') self.assertEqual(multilib.target, 'aarch64-linux-gnu') self.assertIsInstance(multilib.build_cfg, BuildCfg) self.assertEqual(repr(multilib.build_cfg), "BuildCfg('aarch64-linux-gnu')") # Test non-sysrooted libc case, non-default settings. multilib = Multilib(self.context, 'generic', 'generic', ('-mx', '-my'), osdir='os2', target='other') multilib.finalize(relcfg) self.assertIs(multilib.compiler, relcfg.get_component('generic')) self.assertIs(multilib.libc, relcfg.get_component('generic')) self.assertIsNone(multilib.sysroot_suffix) self.assertIsNone(multilib.headers_suffix) self.assertIsNone(multilib.sysroot_osdir) self.assertIsNone(multilib.sysroot_rel) self.assertIsNone(multilib.headers_rel) self.assertEqual(multilib.osdir, 'os2') self.assertEqual(multilib.target, 'other') self.assertIsInstance(multilib.build_cfg, BuildCfg) self.assertEqual( repr(multilib.build_cfg), "BuildCfg('other', tool_prefix='aarch64-linux-gnu-', " "ccopts=('-mx', '-my'))") # Test non-sysrooted libc case, default settings. multilib = Multilib(self.context, 'generic', 'generic', ()) multilib.finalize(relcfg) self.assertIs(multilib.compiler, relcfg.get_component('generic')) self.assertIs(multilib.libc, relcfg.get_component('generic')) self.assertIsNone(multilib.sysroot_suffix) self.assertIsNone(multilib.headers_suffix) self.assertIsNone(multilib.sysroot_osdir) self.assertIsNone(multilib.sysroot_rel) self.assertIsNone(multilib.headers_rel) self.assertEqual(multilib.osdir, '.') self.assertEqual(multilib.target, 'aarch64-linux-gnu') self.assertIsInstance(multilib.build_cfg, BuildCfg) self.assertEqual(repr(multilib.build_cfg), "BuildCfg('aarch64-linux-gnu')") # Test no libc component, sysrooted, non-default settings. multilib = Multilib(self.context, 'generic', None, ('-mx', '-my'), sysroot_suffix='foo', headers_suffix='foo2', sysroot_osdir='os', osdir='os2', target='other') multilib.finalize(relcfg) self.assertIs(multilib.compiler, relcfg.get_component('generic')) self.assertIsNone(multilib.libc) self.assertEqual(multilib.sysroot_suffix, 'foo') self.assertEqual(multilib.headers_suffix, 'foo2') self.assertEqual(multilib.sysroot_osdir, 'os') self.assertEqual(multilib.sysroot_rel, 'opt/toolchain/aarch64-linux-gnu/libc/foo') self.assertEqual(multilib.headers_rel, 'opt/toolchain/aarch64-linux-gnu/libc/foo2') self.assertEqual(multilib.osdir, 'os2') self.assertEqual(multilib.target, 'other') self.assertIsInstance(multilib.build_cfg, BuildCfg) self.assertEqual( repr(multilib.build_cfg), "BuildCfg('other', tool_prefix='aarch64-linux-gnu-', " "ccopts=('-mx', '-my'))") # Test no libc component, sysrooted, default settings. multilib = Multilib(self.context, 'generic', None, (), sysroot_suffix='.') multilib.finalize(relcfg) self.assertIs(multilib.compiler, relcfg.get_component('generic')) self.assertIsNone(multilib.libc) self.assertEqual(multilib.sysroot_suffix, '.') self.assertEqual(multilib.headers_suffix, '.') self.assertEqual(multilib.sysroot_osdir, '.') self.assertEqual(multilib.sysroot_rel, 'opt/toolchain/aarch64-linux-gnu/libc') self.assertEqual(multilib.headers_rel, 'opt/toolchain/aarch64-linux-gnu/libc') self.assertEqual(multilib.osdir, '.') self.assertEqual(multilib.target, 'aarch64-linux-gnu') self.assertIsInstance(multilib.build_cfg, BuildCfg) self.assertEqual(repr(multilib.build_cfg), "BuildCfg('aarch64-linux-gnu')") # Test no libc component, non-sysrooted, non-default settings. multilib = Multilib(self.context, 'generic', None, ('-mx', '-my'), osdir='os2', target='other') multilib.finalize(relcfg) self.assertIs(multilib.compiler, relcfg.get_component('generic')) self.assertIsNone(multilib.libc) self.assertIsNone(multilib.sysroot_suffix) self.assertIsNone(multilib.headers_suffix) self.assertIsNone(multilib.sysroot_osdir) self.assertIsNone(multilib.sysroot_rel) self.assertIsNone(multilib.headers_rel) self.assertEqual(multilib.osdir, 'os2') self.assertEqual(multilib.target, 'other') self.assertIsInstance(multilib.build_cfg, BuildCfg) self.assertEqual( repr(multilib.build_cfg), "BuildCfg('other', tool_prefix='aarch64-linux-gnu-', " "ccopts=('-mx', '-my'))") # Test no libc component, non-sysrooted, default settings. multilib = Multilib(self.context, 'generic', None, ()) multilib.finalize(relcfg) self.assertIs(multilib.compiler, relcfg.get_component('generic')) self.assertIsNone(multilib.libc) self.assertIsNone(multilib.sysroot_suffix) self.assertIsNone(multilib.headers_suffix) self.assertIsNone(multilib.sysroot_osdir) self.assertIsNone(multilib.sysroot_rel) self.assertIsNone(multilib.headers_rel) self.assertEqual(multilib.osdir, '.') self.assertEqual(multilib.target, 'aarch64-linux-gnu') self.assertIsInstance(multilib.build_cfg, BuildCfg) self.assertEqual(repr(multilib.build_cfg), "BuildCfg('aarch64-linux-gnu')") # Test default for osdir derived from non-default # sysroot_suffix and sysroot_osdir settings. multilib = Multilib(self.context, 'generic', 'sysrooted_libc', (), sysroot_suffix='foo', sysroot_osdir='os') multilib.finalize(relcfg) self.assertEqual(multilib.osdir, 'os/foo') multilib = Multilib(self.context, 'generic', 'sysrooted_libc', (), sysroot_suffix='foo', sysroot_osdir='../lib64') multilib.finalize(relcfg) self.assertEqual(multilib.osdir, '../lib64/foo') multilib = Multilib(self.context, 'generic', 'sysrooted_libc', (), sysroot_suffix='.', sysroot_osdir='../lib64') multilib.finalize(relcfg) self.assertEqual(multilib.osdir, '../lib64') multilib = Multilib(self.context, 'generic', 'sysrooted_libc', (), sysroot_suffix='foo', sysroot_osdir='.') multilib.finalize(relcfg) self.assertEqual(multilib.osdir, 'foo')