diff --git a/HACKING b/HACKING index 21fcf7a..4e29745 100644 --- a/HACKING +++ b/HACKING @@ -29,6 +29,7 @@ To run all tests, install these packages: * python-nose, python-pep8, and rpm-python * python3-nose, python3-pep8, and rpm-python3 * createrepo +* git-annex Then from the root of the project: diff --git a/src/tito/builder/main.py b/src/tito/builder/main.py index 7623556..5bac2a4 100644 --- a/src/tito/builder/main.py +++ b/src/tito/builder/main.py @@ -433,7 +433,7 @@ class Builder(ConfigObject, BuilderBase): debug("Creating %s from git tag: %s..." % (self.tgz_filename, self.git_commit_id)) create_tgz(self.git_root, self.tgz_dir, self.git_commit_id, - self.relative_project_dir, self.rel_eng_dir, + self.relative_project_dir, os.path.join(self.rpmbuild_sourcedir, self.tgz_filename)) # Extract the source so we can get at the spec file, etc. @@ -596,7 +596,7 @@ class GemBuilder(NoTgzBuilder): debug("Creating %s from git tag: %s..." % (self.tgz_filename, self.git_commit_id)) create_tgz(self.git_root, self.tgz_dir, self.git_commit_id, - self.relative_project_dir, self.rel_eng_dir, + self.relative_project_dir, os.path.join(self.rpmbuild_sourcedir, self.tgz_filename)) # Extract the source so we can get at the spec file, etc. @@ -694,7 +694,7 @@ class UpstreamBuilder(NoTgzBuilder): tgz_fullpath = os.path.join(self.rpmbuild_sourcedir, tgz_filename) print("Creating %s from git tag: %s..." % (tgz_filename, commit)) create_tgz(self.git_root, prefix, commit, relative_dir, - self.rel_eng_dir, tgz_fullpath) + tgz_fullpath) self.ran_tgz = True self.sources.append(tgz_fullpath) @@ -1202,7 +1202,7 @@ class GitAnnexBuilder(NoTgzBuilder): old_cwd = os.getcwd() os.chdir(os.path.join(old_cwd, self.relative_project_dir)) - (status, output) = run_command("which git-annex") + (status, output) = getstatusoutput("which git-annex") if status != 0: msg = "Please run 'yum install git-annex' as root." error_out('%s' % msg) diff --git a/src/tito/common.py b/src/tito/common.py index 83a724c..fefedf6 100644 --- a/src/tito/common.py +++ b/src/tito/common.py @@ -512,7 +512,7 @@ def get_commit_timestamp(sha1_or_tag): return output -def create_tgz(git_root, prefix, commit, relative_dir, rel_eng_dir, +def create_tgz(git_root, prefix, commit, relative_dir, dest_tgz): """ Create a .tar.gz from a projects source in git. @@ -545,7 +545,7 @@ def create_tgz(git_root, prefix, commit, relative_dir, rel_eng_dir, git_archive_cmd, timestamp_script, timestamp, commit, dest_tgz)) debug(archive_cmd) - run_command(archive_cmd) + return run_command(archive_cmd) def get_git_repo_url(): @@ -658,7 +658,6 @@ def find_wrote_in_rpmbuild_output(output): paths = [] look_for = "Wrote: " for line in output.split('\n'): - print("Checking: %s" % line) if line.startswith(look_for): paths.append(line[len(look_for):]) debug("Found wrote line: %s" % paths[-1]) diff --git a/test/functional/build_gitannex_tests.py b/test/functional/build_gitannex_tests.py new file mode 100644 index 0000000..eb410d9 --- /dev/null +++ b/test/functional/build_gitannex_tests.py @@ -0,0 +1,77 @@ +# +# Copyright (c) 2008-2014 Red Hat, Inc. +# +# This software is licensed to you under the GNU General Public License, +# version 2 (GPLv2). There is NO WARRANTY for this software, express or +# implied, including the implied warranties of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +# along with this software; if not, see +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +# +# Red Hat trademarks are not licensed under GPLv2. No permission is +# granted to use or replicate Red Hat trademarks that are incorporated +# in this software or its documentation. +""" +Functional Tests for the GitAnnexBuilder. +""" + +import os +import glob +import tempfile +import shutil +from os.path import join + +from functional.fixture import TitoGitTestFixture, tito + +from tito.compat import * +from tito.common import run_command +from tito.builder import GitAnnexBuilder + +PKG_NAME = "extsrc" + + +class GitAnnexBuilderTests(TitoGitTestFixture): + + def setUp(self): + TitoGitTestFixture.setUp(self) + + # Setup test config: + self.config = RawConfigParser() + self.config.add_section("buildconfig") + self.config.set("buildconfig", "builder", + "tito.builder.GitAnnexBuilder") + self.config.set("buildconfig", "offline", + "true") + + os.chdir(self.repo_dir) + spec = join(os.path.dirname(__file__), "specs/extsrc.spec") + self.create_project_from_spec(PKG_NAME, self.config, + spec=spec) + self.source_filename = 'extsrc-0.0.2.tar.gz' + + # Make a fake source file, do we need something more real? + run_command('touch %s' % self.source_filename) + print(run_command('git-annex init')) + + self.output_dir = tempfile.mkdtemp("-titotestoutput") + + def tearDown(self): + run_command('chmod -R u+rw %s' % self.output_dir) + shutil.rmtree(self.output_dir) + TitoGitTestFixture.tearDown(self) + + def test_simple_build(self): + run_command('git annex add %s' % self.source_filename) + run_command('git commit -a -m "Add source."') + # This will create 0.0.2: + tito('tag --debug --accept-auto-changelog') + builder = GitAnnexBuilder(PKG_NAME, None, self.output_dir, + self.config, {}, {}, **{'offline': True}) + builder.rpm() + self.assertEquals(1, len(builder.sources)) + + self.assertEquals(2, len(builder.artifacts)) + self.assertEquals(1, len(glob.glob(join(self.output_dir, + "extsrc-0.0.2-1.*src.rpm")))) + self.assertEquals(1, len(glob.glob(join(self.output_dir, 'noarch', + "extsrc-0.0.2-1.*.noarch.rpm")))) diff --git a/test/functional/fetch_tests.py b/test/functional/fetch_tests.py index 795c2af..0f44683 100644 --- a/test/functional/fetch_tests.py +++ b/test/functional/fetch_tests.py @@ -65,6 +65,7 @@ class FetchBuilderTests(TitoGitTestFixture): def tearDown(self): TitoGitTestFixture.tearDown(self) + # Git annex restricts permissions, change them before we remove: shutil.rmtree(self.output_dir) def test_simple_build_no_tag(self): diff --git a/test/functional/fixture.py b/test/functional/fixture.py index dfba03b..d9c7917 100644 --- a/test/functional/fixture.py +++ b/test/functional/fixture.py @@ -127,6 +127,7 @@ class TitoGitTestFixture(unittest.TestCase): run_command("git commit -m 'set offline in tito.props'") def tearDown(self): + run_command('chmod -R u+rw %s' % self.repo_dir) shutil.rmtree(self.repo_dir) pass