From a1c1f3f7c583267ef9ccc9b24c84568ed0cb47f6 Mon Sep 17 00:00:00 2001 From: Mark Hatle Date: Fri, 17 May 2019 04:54:50 -0400 Subject: bitbake: svn.py: Stop SVN from directly pulling from an external layer w/o fetcher Add a new option to the svn fetcher url "externals=allowed". This will allow a user to enable svn co w/ externals. However, this does avoid the fetcher, network access and mirror systems. By default we no longer allow externals in the checkout. This ensures a deterministic download. The system does attempt to identify SVN repos that have externals enabled, and will warn the user. It is up to the user to determine if these are necessary for the recipe. They may disable the warning by adding "externals=nowarn" to the url. In the future we would like to parse this list and see if the items are already in the SRC_URI for that recipe, but with SVN being in limited use these days that extra work is likely not worth the trouble. Add test cases that generated a local SVN tree, with an external source set to github bitbake in svn format. One test case checks that externals are ignored, and one checks that they in downloaded. (Bitbake rev: bf53f07c3647e57d8452a7743a2b04bcb72c80d6) Signed-off-by: Mark Hatle Signed-off-by: Richard Purdie --- bitbake/lib/bb/tests/fetch.py | 80 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'bitbake/lib/bb/tests') diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 6bdf0416d7..16f975b137 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py @@ -991,6 +991,86 @@ class FetcherNetworkTest(FetcherTest): self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/deps/ctest/README.md')), msg='Missing submodule checkout') self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/deps/testrunner/readme.md')), msg='Missing submodule checkout') +class SVNTest(FetcherTest): + def skipIfNoSvn(): + import shutil + if not shutil.which("svn"): + return unittest.skip("svn not installed, tests being skipped") + + if not shutil.which("svnadmin"): + return unittest.skip("svnadmin not installed, tests being skipped") + + return lambda f: f + + @skipIfNoSvn() + def setUp(self): + """ Create a local repository """ + + super(SVNTest, self).setUp() + + # Create something we can fetch + src_dir = tempfile.mkdtemp(dir=self.tempdir, + prefix='svnfetch_srcdir_') + src_dir = os.path.abspath(src_dir) + bb.process.run("echo readme > README.md", cwd=src_dir) + + # Store it in a local SVN repository + repo_dir = tempfile.mkdtemp(dir=self.tempdir, + prefix='svnfetch_localrepo_') + repo_dir = os.path.abspath(repo_dir) + bb.process.run("svnadmin create project", cwd=repo_dir) + + self.repo_url = "file://%s/project" % repo_dir + bb.process.run("svn import --non-interactive -m 'Initial import' %s %s/trunk" % (src_dir, self.repo_url), + cwd=repo_dir) + + bb.process.run("svn co %s svnfetch_co" % self.repo_url, cwd=self.tempdir) + # Github will emulate SVN. Use this to check if we're downloding... + bb.process.run("svn propset svn:externals 'bitbake http://github.com/openembedded/bitbake' .", + cwd=os.path.join(self.tempdir, 'svnfetch_co', 'trunk')) + bb.process.run("svn commit --non-interactive -m 'Add external'", + cwd=os.path.join(self.tempdir, 'svnfetch_co', 'trunk')) + + self.src_dir = src_dir + self.repo_dir = repo_dir + + @skipIfNoSvn() + def tearDown(self): + os.chdir(self.origdir) + if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes": + print("Not cleaning up %s. Please remove manually." % self.tempdir) + else: + bb.utils.prunedir(self.tempdir) + + @skipIfNoSvn() + @skipIfNoNetwork() + def test_noexternal_svn(self): + # Always match the rev count from setUp (currently rev 2) + url = "svn://%s;module=trunk;protocol=file;rev=2" % self.repo_url.replace('file://', '') + fetcher = bb.fetch.Fetch([url], self.d) + fetcher.download() + os.chdir(os.path.dirname(self.unpackdir)) + fetcher.unpack(self.unpackdir) + + self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk')), msg="Missing trunk") + self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk', 'README.md')), msg="Missing contents") + self.assertFalse(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk')), msg="External dir should NOT exist") + self.assertFalse(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk', 'README')), msg="External README should NOT exit") + + @skipIfNoSvn() + def test_external_svn(self): + # Always match the rev count from setUp (currently rev 2) + url = "svn://%s;module=trunk;protocol=file;externals=allowed;rev=2" % self.repo_url.replace('file://', '') + fetcher = bb.fetch.Fetch([url], self.d) + fetcher.download() + os.chdir(os.path.dirname(self.unpackdir)) + fetcher.unpack(self.unpackdir) + + self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk')), msg="Missing trunk") + self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk', 'README.md')), msg="Missing contents") + self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk')), msg="External dir should exist") + self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk', 'README')), msg="External README should exit") + class TrustedNetworksTest(FetcherTest): def test_trusted_network(self): # Ensure trusted_network returns False when the host IS in the list. -- cgit v1.2.3-54-g00ecf