def _setup_test_specfile(self): if self.test and not self.ran_setup_test_specfile: # If making a test rpm we need to get a little crazy with the spec # file we're building off. (note that this is a temp copy of the # spec) Swap out the actual release for one that includes the git # SHA1 we're building for our test package: sha = self.git_commit_id[:7] fullname = "%s-%s" % (self.project_name, self.display_version) munge_specfile( self.spec_file, sha, self.commit_count, fullname, self.tgz_filename, ) # Custom Openshift v3 stuff follows, everything above is the standard # builder cmd = '. ./hack/common.sh ; echo $(os::build::ldflags)' ldflags = run_command('bash -c \'%s\'' % (cmd) ) update_ldflags = "sed -i 's|^%%global ldflags .*$|%%global ldflags %s|' %s" % \ (ldflags, self.spec_file) output = run_command(update_ldflags) self.build_version += ".git." + str(self.commit_count) + "." + str(self.git_commit_id[:7]) self.ran_setup_test_specfile = True
def test_simple_transform(self): simple_spec = dedent(""" Name: Hello Version: 1.0.0 Release: 1%{?dist} Source: hello-1.0.0.tar.gz %prep %setup -q """) with open(self.spec_file, 'w') as f: f.write(simple_spec) sha = "acecafe" commit_count = 5 display_version = "git-%s.%s" % (commit_count, sha) fullname = "hello-%s" % display_version munge_specfile(self.spec_file, sha, commit_count, fullname, "%s.tar.gz" % fullname) output = open(self.spec_file, 'r').readlines() self.assertEquals(8, len(output)) self.assertEquals( "Release: 1.git.%s.%s%%{?dist}\n" % (commit_count, sha), output[3]) self.assertEquals("Source: %s.tar.gz\n" % fullname, output[4]) self.assertEquals("%%setup -q -n %s\n" % fullname, output[7]) # Spot check some things that should not change self.assertEquals("Name: Hello\n", output[1]) self.assertEqual("%prep\n", output[6])
def _setup_test_specfile(self): if self.test and not self.ran_setup_test_specfile: # If making a test rpm we need to get a little crazy with the spec # file we're building off. (note that this is a temp copy of the # spec) Swap out the actual release for one that includes the git # SHA1 we're building for our test package: sha = self.git_commit_id[:7] fullname = "{0}-{1}".format(self.project_name, self.display_version) munge_specfile( self.spec_file, sha, self.commit_count, fullname, self.tgz_filename, ) # Custom Openshift v3 stuff follows, everything above is the standard # builder cmd = '. ./hack/common.sh ; echo $(os::build::ldflags)' ldflags = run_command("bash -c '{0}'".format(cmd)) print("LDFLAGS::{0}".format(ldflags)) update_ldflags = \ "sed -i 's|^%%global ldflags .*$|%%global ldflags {0}|' {1}".format( ' '.join([ldflag.strip() for ldflag in ldflags.split()]), self.spec_file ) # FIXME - output is never used output = run_command(update_ldflags) self.build_version += ".git." + \ str(self.commit_count) + \ "." + \ str(self.git_commit_id[:7]) self.ran_setup_test_specfile = True
def test_simple_transform(self): simple_spec = dedent(""" Name: Hello Version: 1.0.0 Release: 1%{?dist} Source: hello-1.0.0.tar.gz %prep %setup -q """) with open(self.spec_file, 'w') as f: f.write(simple_spec) sha = "acecafe" commit_count = 5 display_version = "git-%s.%s" % (commit_count, sha) fullname = "hello-%s" % display_version munge_specfile(self.spec_file, sha, commit_count, fullname, "%s.tar.gz" % fullname) output = open(self.spec_file, 'r').readlines() self.assertEquals(8, len(output)) self.assertEquals("Release: 1.git.%s.%s%%{?dist}\n" % (commit_count, sha), output[3]) self.assertEquals("Source: %s.tar.gz\n" % fullname, output[4]) self.assertEquals("%%setup -q -n %s\n" % fullname, output[7]) # Spot check some things that should not change self.assertEquals("Name: Hello\n", output[1]) self.assertEqual("%prep\n", output[6])
def _setup_test_specfile(self): if self.test and not self.ran_setup_test_specfile: # If making a test rpm we need to get a little crazy with the spec # file we're building off. (note that this is a temp copy of the # spec) Swap out the actual release for one that includes the git # SHA1 we're building for our test package: sha = self.git_commit_id[:7] fullname = "%s-%s" % (self.project_name, self.display_version) munge_specfile( self.spec_file, sha, self.commit_count, fullname, self.tgz_filename, ) # Custom Openshift v3 stuff follows, everything above is the standard # builder cmd = '. ./hack/common.sh ; echo $(os::build::ldflags)' ldflags = run_command('bash -c \'%s\'' % (cmd)) update_ldflags = "sed -i 's|^%%global ldflags .*$|%%global ldflags %s|' %s" % \ (ldflags, self.spec_file) output = run_command(update_ldflags) self.build_version += ".git." + str(self.commit_count) + "." + str( self.git_commit_id[:7]) self.ran_setup_test_specfile = True
def _setup_test_specfile(self): if self.test and not self.ran_setup_test_specfile: # If making a test rpm we need to get a little crazy with the spec # file we're building off. (note that this is a temp copy of the # spec) Swap out the actual release for one that includes the git # SHA1 we're building for our test package: sha = self.git_commit_id[:7] fullname = "{0}-{1}".format(self.project_name, self.display_version) munge_specfile(self.spec_file, sha, self.commit_count, fullname, self.tgz_filename) # Custom Openshift v3 stuff follows, everything above is the standard # builder cmd = ". ./hack/common.sh ; echo $(os::build::ldflags)" ldflags = run_command("bash -c '{0}'".format(cmd)) print("LDFLAGS::{0}".format(ldflags)) update_ldflags = "sed -i 's|^%global ldflags .*$|%global ldflags {0}|' {1}".format( " ".join([ldflag.strip() for ldflag in ldflags.split()]), self.spec_file ) # FIXME - output is never used output = run_command(update_ldflags) # Add bundled deps for Fedora Guidelines as per: # https://fedoraproject.org/wiki/Packaging:Guidelines#Bundling_and_Duplication_of_system_libraries provides_list = [] with open("./Godeps/Godeps.json") as godeps: depdict = json.load(godeps) for bdep in [(dep[u"ImportPath"], dep[u"Rev"]) for dep in depdict[u"Deps"]]: provides_list.append("Provides: bundled(golang({0})) = {1}".format(bdep[0], bdep[1])) update_provides_list = "sed -i 's|^### AUTO-BUNDLED-GEN-ENTRY-POINT|{0}|' {1}".format( "\\n".join(provides_list), self.spec_file ) print(run_command(update_provides_list)) self.build_version += ".git." + str(self.commit_count) + "." + str(self.git_commit_id[:7]) self.ran_setup_test_specfile = True
def _setup_test_specfile(self): """ Override parent behavior. """ if self.test: # If making a test rpm we need to get a little crazy with the spec # file we're building off. (note that this is a temp copy of the # spec) Swap out the actual release for one that includes the git # SHA1 we're building for our test package: debug("setup_test_specfile:commit_count = %s" % str(self.commit_count)) munge_specfile( self.spec_file, self.git_commit_id[:7], self.commit_count )
def _setup_test_specfile(self): if self.test and not self.ran_setup_test_specfile: # If making a test rpm we need to get a little crazy with the spec # file we're building off. (note that this is a temp copy of the # spec) Swap out the actual release for one that includes the git # SHA1 we're building for our test package: sha = self.git_commit_id[:7] fullname = "{0}-{1}".format(self.project_name, self.display_version) munge_specfile( self.spec_file, sha, self.commit_count, fullname, self.tgz_filename, ) # Custom Openshift v3 stuff follows, everything above is the standard # builder cmd = '. ./hack/common.sh ; echo $(os::build::ldflags)' ldflags = run_command("bash -c '{0}'".format(cmd)) print("LDFLAGS::{0}".format(ldflags)) update_ldflags = \ "sed -i 's|^%global ldflags .*$|%global ldflags {0}|' {1}".format( ' '.join([ldflag.strip() for ldflag in ldflags.split()]), self.spec_file ) # FIXME - output is never used output = run_command(update_ldflags) # Add bundled deps for Fedora Guidelines as per: # https://fedoraproject.org/wiki/Packaging:Guidelines#Bundling_and_Duplication_of_system_libraries provides_list = [] with open("./Godeps/Godeps.json") as godeps: depdict = json.load(godeps) for bdep in [(dep[u'ImportPath'], dep[u'Rev']) for dep in depdict[u'Deps']]: provides_list.append( "Provides: bundled(golang({0})) = {1}".format( bdep[0], bdep[1])) update_provides_list = \ "sed -i 's|^### AUTO-BUNDLED-GEN-ENTRY-POINT|{0}|' {1}".format( '\\n'.join(provides_list), self.spec_file ) print(run_command(update_provides_list)) self.build_version += ".git." + \ str(self.commit_count) + \ "." + \ str(self.git_commit_id[:7]) self.ran_setup_test_specfile = True
def test_complex_setup_transform(self): simple_spec = dedent(""" %setup -q -n hello-1 """) with open(self.spec_file, 'w') as f: f.write(simple_spec) sha = "acecafe" commit_count = 5 display_version = "git-%s.%s" % (commit_count, sha) fullname = "hello-%s" % display_version munge_specfile(self.spec_file, sha, commit_count, fullname, "%s.tar.gz" % fullname) output = open(self.spec_file, 'r').readlines() self.assertEquals("%%setup -q -n %s\n" % fullname, output[1])
def test_transform_no_whitespace_modifications(self): simple_spec = dedent(""" Release: 1%{?dist} Source: hello-1.0.0.tar.gz """) with open(self.spec_file, 'w') as f: f.write(simple_spec) sha = "acecafe" commit_count = 5 munge_specfile(self.spec_file, sha, commit_count) output = open(self.spec_file, 'r').readlines() self.assertEquals(3, len(output)) self.assertEquals("Release: 1.git.%s.%s%%{?dist}\n" % (commit_count, sha), output[1]) self.assertEquals("Source: hello-1.0.0.tar.gz\n", output[2])
def test_transform_no_dist_tag(self): simple_spec = dedent(""" Release: 1 Source: hello-1.0.0.tar.gz """) with open(self.spec_file, 'w') as f: f.write(simple_spec) sha = "acecafe" commit_count = 5 munge_specfile(self.spec_file, sha, commit_count) output = open(self.spec_file, 'r').readlines() self.assertEquals(3, len(output)) self.assertEquals("Release: 1.git.%s.%s\n" % (commit_count, sha), output[1]) self.assertEquals("Source: hello-1.0.0.tar.gz\n", output[2])
def _setup_test_specfile(self): if self.test and not self.ran_setup_test_specfile: # If making a test rpm we need to get a little crazy with the spec # file we're building off. (note that this is a temp copy of the # spec) Swap out the actual release for one that includes the git # SHA1 we're building for our test package: sha = self.git_commit_id[:7] fullname = "%s-%s" % (self.project_name, self.display_version) munge_specfile( self.spec_file, sha, self.commit_count, fullname, self.tgz_filename, ) self.build_version += ".git." + str(self.commit_count) + "." + str(sha) self.ran_setup_test_specfile = True
def test_transform_release_only(self): simple_spec = dedent(""" Release: 1%{?dist} Source: hello-1.0.0.tar.gz %setup -q """) with open(self.spec_file, 'w') as f: f.write(simple_spec) sha = "acecafe" commit_count = 5 munge_specfile(self.spec_file, sha, commit_count) output = open(self.spec_file, 'r').readlines() self.assertEquals(4, len(output)) self.assertEquals("Release: 1.git.%s.%s%%{?dist}\n" % (commit_count, sha), output[1]) self.assertEquals("Source: hello-1.0.0.tar.gz\n", output[2]) self.assertEquals("%setup -q\n", output[3])
def _setup_test_specfile(self): if self.test and not self.ran_setup_test_specfile: # If making a test rpm we need to get a little crazy with the spec # file we're building off. (note that this is a temp copy of the # spec) Swap out the actual release for one that includes the git # SHA1 we're building for our test package: sha = self.git_commit_id[:7] fullname = "{0}-{1}".format(self.project_name, self.display_version) munge_specfile( self.spec_file, sha, self.commit_count, fullname, self.tgz_filename, ) # Custom Openshift v3 stuff follows, everything above is the standard # builder ## Fixup os_git_vars cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_COMMIT}' os_git_commit = run_command("bash -c '{0}'".format(cmd)) cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_VERSION}' os_git_version = run_command("bash -c '{0}'".format(cmd)) os_git_version = os_git_version.replace('-dirty', '') cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_MAJOR}' os_git_major = run_command("bash -c '{0}'".format(cmd)) cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_MINOR}' os_git_minor = run_command("bash -c '{0}'".format(cmd)) print("OS_GIT_COMMIT::{0}".format(os_git_commit)) print("OS_GIT_VERSION::{0}".format(os_git_version)) print("OS_GIT_MAJOR::{0}".format(os_git_major)) print("OS_GIT_MINOR::{0}".format(os_git_minor)) update_os_git_vars = \ "sed -i 's|^%global os_git_vars .*$|%global os_git_vars OS_GIT_TREE_STATE='clean' OS_GIT_VERSION={0} OS_GIT_COMMIT={1} OS_GIT_MAJOR={2} OS_GIT_MINOR={3}|' {4}".format( os_git_version, os_git_commit, os_git_major, os_git_minor, self.spec_file ) output = run_command(update_os_git_vars) # Add bundled deps for Fedora Guidelines as per: # https://fedoraproject.org/wiki/Packaging:Guidelines#Bundling_and_Duplication_of_system_libraries provides_list = [] with open("./Godeps/Godeps.json") as godeps: depdict = json.load(godeps) for bdep in [ (dep[u'ImportPath'], dep[u'Rev']) for dep in depdict[u'Deps'] ]: provides_list.append( "Provides: bundled(golang({0})) = {1}".format( bdep[0], bdep[1] ) ) # Handle this in python because we have hit the upper bounds of line # count for what we can pass into sed via subprocess because there # are so many bundled libraries. with open(self.spec_file, 'r') as spec_file_f: spec_file_lines = spec_file_f.readlines() with open(self.spec_file, 'w') as spec_file_f: for line in spec_file_lines: if '### AUTO-BUNDLED-GEN-ENTRY-POINT' in line: spec_file_f.write( '\n'.join( [provides.replace('"', '').replace("'", '') for provides in provides_list] ) ) else: spec_file_f.write(line) self.build_version += ".git." + \ str(self.commit_count) + \ "." + \ str(self.git_commit_id[:7]) self.ran_setup_test_specfile = True
def _setup_test_specfile(self): if self.test and not self.ran_setup_test_specfile: # If making a test rpm we need to get a little crazy with the spec # file we're building off. (note that this is a temp copy of the # spec) Swap out the actual release for one that includes the git # SHA1 we're building for our test package: sha = self.git_commit_id[:7] fullname = "{0}-{1}".format(self.project_name, self.display_version) munge_specfile( self.spec_file, sha, self.commit_count, fullname, self.tgz_filename, ) # Custom Openshift v3 stuff follows, everything above is the standard # builder ## Fixup os_git_vars cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_COMMIT}' os_git_commit = run_command("bash -c '{0}'".format(cmd)) cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_VERSION}' os_git_version = run_command("bash -c '{0}'".format(cmd)) cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_MAJOR}' os_git_major = run_command("bash -c '{0}'".format(cmd)) cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_MINOR}' os_git_minor = run_command("bash -c '{0}'".format(cmd)) print("OS_GIT_COMMIT::{0}".format(os_git_commit)) print("OS_GIT_VERSION::{0}".format(os_git_version)) print("OS_GIT_MAJOR::{0}".format(os_git_major)) print("OS_GIT_MINOR::{0}".format(os_git_minor)) update_os_git_vars = \ "sed -i 's|^%global os_git_vars .*$|%global os_git_vars OS_GIT_TREE_STATE='clean' OS_GIT_VERSION={0} OS_GIT_COMMIT={1} OS_GIT_MAJOR={2} OS_GIT_MINOR={3}|' {4}".format( os_git_version, os_git_commit, os_git_major, os_git_minor, self.spec_file ) output = run_command(update_os_git_vars) ## Fixup ldflags cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; echo $(os::build::ldflags)' ldflags = run_command("bash -c '{0}'".format(cmd)) print("LDFLAGS::{0}".format(ldflags)) update_ldflags = \ "sed -i 's|^%global ldflags .*$|%global ldflags {0}|' {1}".format( ' '.join([ldflag.strip() for ldflag in ldflags.split()]), self.spec_file ) output = run_command(update_ldflags) # Add bundled deps for Fedora Guidelines as per: # https://fedoraproject.org/wiki/Packaging:Guidelines#Bundling_and_Duplication_of_system_libraries provides_list = [] with open("./Godeps/Godeps.json") as godeps: depdict = json.load(godeps) for bdep in [ (dep[u'ImportPath'], dep[u'Rev']) for dep in depdict[u'Deps'] ]: provides_list.append( "Provides: bundled(golang({0})) = {1}".format( bdep[0], bdep[1] ) ) update_provides_list = \ "sed -i 's|^### AUTO-BUNDLED-GEN-ENTRY-POINT|{0}|' {1}".format( '\\n'.join(provides_list), self.spec_file ) print(run_command(update_provides_list)) self.build_version += ".git." + \ str(self.commit_count) + \ "." + \ str(self.git_commit_id[:7]) self.ran_setup_test_specfile = True