@@ -204,6 +204,7 @@ python do_ar_original() {
fetch = bb.fetch.Fetch(urls, ld)
tarball_suffix = {}
for url in fetch.urls:
+ ud = fetch.ud[url]
local = fetch.localpath(url).rstrip("/");
if os.path.isfile(local):
shutil.copy(local, ar_outdir)
@@ -214,6 +215,18 @@ python do_ar_original() {
fetch.unpack(tmpdir, (url,))
if not os.listdir(tmpdir):
bb.fatal("Cannot archive original source %s: nothing was unpacked" % url)
+ if isinstance(ud.method, bb.fetch.git.Git) and not ud.nocheckout:
+ # The .git of a clone has no objects (clone -s only references
+ # them via objects/info/alternates), and the one of a shallow
+ # tarball duplicates the sources, so it is of no use in the
+ # archive. This includes the .git files of submodules. Keep it
+ # with nocheckout (and bareclone), where it is the source.
+ for root, dirs, files in os.walk(ud.destdir):
+ if '.git' in dirs:
+ dirs.remove('.git')
+ bb.utils.remove(os.path.join(root, '.git'), recurse=True)
+ if '.git' in files:
+ os.remove(os.path.join(root, '.git'))
# To handle recipes with more than one source, we add the "name"
# URL parameter as suffix. We treat it as an error when
# there's more than one URL without a name, or a name gets reused.
@@ -212,6 +212,69 @@ class Archiver(OESelftestTestCase):
names = self._get_original_git_archive_names(target)
self.assertTrue([n for n in names if n.endswith('/COPYING')], 'Archive has no source files: %s' % names[:20])
+ self._assert_no_git(names)
+
+ def test_archiver_mode_original_git(self):
+ """
+ Test that the archive of a git source with
+ `ARCHIVER_MODE[src] = "original"` has no .git directory.
+ """
+ target = 'gitrepotest'
+
+ features = 'INHERIT += "archiver"\n'
+ features += 'ARCHIVER_MODE[src] = "original"\n'
+ self.write_config(features)
+
+ bitbake('-c cleansstate %s' % target)
+ bitbake('-c deploy_archives %s' % target)
+
+ names = self._get_original_git_archive_names(target)
+ self.assertTrue([n for n in names if n.endswith('/COPYING')], 'Archive has no source files: %s' % names[:20])
+ self._assert_no_git(names)
+
+ def test_archiver_mode_original_gitsm(self):
+ """
+ Test that the archive of a git source with submodules with
+ `ARCHIVER_MODE[src] = "original"` contains the submodules, but neither
+ the .git directory nor the .git files of the submodules.
+ """
+ target = 'git-submodule-test'
+
+ features = 'INHERIT += "archiver"\n'
+ features += 'ARCHIVER_MODE[src] = "original"\n'
+ features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n'
+ self.write_config(features)
+
+ bitbake('-c cleansstate %s' % target)
+ bitbake('-c deploy_archives %s' % target)
+
+ names = self._get_original_git_archive_names(target)
+ self.assertTrue([n for n in names if n.endswith('/.gitmodules')], 'Archive has no .gitmodules: %s' % names[:20])
+ # .gitmodules is part of the superproject, check a file of a submodule
+ self.assertTrue([n for n in names if n.endswith('/bitbake/lib/bb/__init__.py')], 'Archive has no submodule content: %s' % names[:20])
+ self._assert_no_git(names)
+
+ def test_archiver_mode_original_git_nocheckout(self):
+ """
+ Test that the archive of a git source with nocheckout=1 keeps the .git
+ directory, since the repository is the source in this case.
+ """
+ target = 'gitrepotest'
+
+ features = 'INHERIT += "archiver"\n'
+ features += 'ARCHIVER_MODE[src] = "original"\n'
+ features += 'SRC_URI:pn-%s = "git://git.yoctoproject.org/matchbox-panel-2;branch=master;protocol=https;nocheckout=1 file://0001-testpatch.patch"\n' % target
+ self.write_config(features)
+
+ bitbake('-c cleansstate %s' % target)
+ bitbake('-c deploy_archives %s' % target)
+
+ names = self._get_original_git_archive_names(target)
+ self.assertTrue([n for n in names if '.git' in n.split('/')], 'Archive has no .git: %s' % names[:20])
+
+ def _assert_no_git(self, names):
+ git = [n for n in names if '.git' in n.split('/')]
+ self.assertFalse(git, 'Archive contains .git: %s' % git[:20])
def _get_original_git_archive_names(self, target):
"""