Skip to content

Commit ac76284

Browse files
author
OpenShift Bot
authored
Merge pull request #12824 from openshift/revert-12727-revert-12684-skuznets/refactor-tito
Merged by openshift-bot
2 parents 98ad752 + 81032f6 commit ac76284

File tree

4 files changed

+80
-298
lines changed

4 files changed

+80
-298
lines changed

.tito/lib/origin/builder/__init__.py

+11-82
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
"""
22
Code for building Origin
33
"""
4-
5-
import sys
64
import json
75

8-
from tito.common import (
9-
get_latest_commit,
10-
get_latest_tagged_version,
11-
check_tag_exists,
12-
run_command,
13-
find_spec_file,
14-
get_spec_version_and_release,
15-
munge_specfile
16-
)
17-
6+
from tito.common import get_latest_commit, run_command
187
from tito.builder import Builder
198

9+
from ..common import inject_os_git_vars
10+
2011
class OriginBuilder(Builder):
2112
"""
2213
builder which defines 'commit' as the git hash prior to building
2314
2415
Used For:
2516
- Packages that want to know the commit in all situations
2617
"""
18+
def _get_tag_for_version(self, version):
19+
return "v{}".format(version)
2720

2821
def _get_rpmbuild_dir_options(self):
2922
git_hash = get_latest_commit()
30-
cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; echo $(os::build::ldflags)'
23+
cmd = 'source ./hack/lib/init.sh; os::build::ldflags'
3124
ldflags = run_command("bash -c '{0}'".format(cmd))
3225

3326
return ('--define "_topdir %s" --define "_sourcedir %s" --define "_builddir %s" '
@@ -40,46 +33,12 @@ def _get_rpmbuild_dir_options(self):
4033

4134
def _setup_test_specfile(self):
4235
if self.test and not self.ran_setup_test_specfile:
43-
# If making a test rpm we need to get a little crazy with the spec
44-
# file we're building off. (note that this is a temp copy of the
45-
# spec) Swap out the actual release for one that includes the git
46-
# SHA1 we're building for our test package:
47-
sha = self.git_commit_id[:7]
48-
fullname = "{0}-{1}".format(self.project_name, self.display_version)
49-
munge_specfile(
50-
self.spec_file,
51-
sha,
52-
self.commit_count,
53-
fullname,
54-
self.tgz_filename,
55-
)
56-
# Custom Openshift v3 stuff follows, everything above is the standard
57-
# builder
36+
super(OriginBuilder, self)._setup_test_specfile()
5837

59-
## Fixup os_git_vars
60-
cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_COMMIT}'
61-
os_git_commit = run_command("bash -c '{0}'".format(cmd))
62-
cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_VERSION}'
63-
os_git_version = run_command("bash -c '{0}'".format(cmd))
64-
os_git_version = os_git_version.replace('-dirty', '')
65-
cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_MAJOR}'
66-
os_git_major = run_command("bash -c '{0}'".format(cmd))
67-
cmd = '. ./hack/common.sh ; OS_ROOT=$(pwd) ; os::build::os_version_vars ; echo ${OS_GIT_MINOR}'
68-
os_git_minor = run_command("bash -c '{0}'".format(cmd))
69-
print("OS_GIT_COMMIT::{0}".format(os_git_commit))
70-
print("OS_GIT_VERSION::{0}".format(os_git_version))
71-
print("OS_GIT_MAJOR::{0}".format(os_git_major))
72-
print("OS_GIT_MINOR::{0}".format(os_git_minor))
73-
update_os_git_vars = \
74-
"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(
75-
os_git_version,
76-
os_git_commit,
77-
os_git_major,
78-
os_git_minor,
79-
self.spec_file
80-
)
81-
output = run_command(update_os_git_vars)
38+
inject_os_git_vars(self.spec_file)
39+
self._inject_bundled_deps()
8240

41+
def _inject_bundled_deps(self):
8342
# Add bundled deps for Fedora Guidelines as per:
8443
# https://fedoraproject.org/wiki/Packaging:Guidelines#Bundling_and_Duplication_of_system_libraries
8544
provides_list = []
@@ -113,34 +72,4 @@ def _setup_test_specfile(self):
11372
else:
11473
spec_file_f.write(line)
11574

116-
self.build_version += ".git." + \
117-
str(self.commit_count) + \
118-
"." + \
119-
str(self.git_commit_id[:7])
120-
self.ran_setup_test_specfile = True
121-
122-
def _get_build_version(self):
123-
"""
124-
Figure out the git tag and version-release we're building.
125-
"""
126-
# Determine which package version we should build:
127-
build_version = None
128-
if self.build_tag:
129-
build_version = self.build_tag[len(self.project_name + "-"):]
130-
else:
131-
build_version = get_latest_tagged_version(self.project_name)
132-
if build_version is None:
133-
if not self.test:
134-
error_out(["Unable to lookup latest package info.",
135-
"Perhaps you need to tag first?"])
136-
sys.stderr.write("WARNING: unable to lookup latest package "
137-
"tag, building untagged test project\n")
138-
build_version = get_spec_version_and_release(self.start_dir,
139-
find_spec_file(in_dir=self.start_dir))
140-
self.build_tag = "v{0}".format(build_version)
141-
142-
if not self.test:
143-
check_tag_exists(self.build_tag, offline=self.offline)
144-
return build_version
145-
146-
# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0:
75+
# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0:

.tito/lib/origin/common.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from tito.common import run_command, get_latest_commit
2+
3+
def inject_os_git_vars(spec_file):
4+
"""
5+
Determine the OpenShift version variables as dictated by the Origin
6+
shell utilities and overwrite the specfile to reflect them. A line
7+
with the following syntax is expected in the specfile:
8+
9+
%global os_git_vars
10+
11+
This line will be overwritten to add the git tree state, the full
12+
"git version", the last source commit in the release, and the major
13+
and minor versions of the current product release.
14+
"""
15+
os_git_vars = get_os_git_vars()
16+
for var_name in os_git_vars:
17+
print("{}::{}".format(var_name, os_git_vars[var_name]))
18+
19+
update_os_git_vars = \
20+
"sed -i 's|^%global os_git_vars .*$|%global os_git_vars {}|' {}".format(
21+
" ".join(["{}={}".format(key, value) for key, value in os_git_vars.items()]),
22+
spec_file
23+
)
24+
output = run_command(update_os_git_vars)
25+
26+
def get_os_git_vars():
27+
"""
28+
Determine the OpenShift version variables as dictated by the Origin
29+
shell utilities. The git tree state is spoofed.
30+
"""
31+
git_vars = {}
32+
for var in ["COMMIT", "VERSION", "MAJOR", "MINOR"]:
33+
var_name = "OS_GIT_{}".format(var)
34+
git_vars[var_name] = run_command(
35+
"bash -c 'source ./hack/lib/init.sh; os::build::os_version_vars; echo ${}'".format(var_name)
36+
)
37+
38+
# we hard-code this to a clean state as tito will have dirtied up the tree
39+
# but that will not have changed any of the source used for the product
40+
# release and we therefore don't want that reflected in the release version
41+
git_vars["OS_GIT_TREE_STATE"] = "clean"
42+
git_vars["OS_GIT_VERSION"] = git_vars["OS_GIT_VERSION"].replace("-dirty", "")
43+
return git_vars
44+
45+
def update_global_hash(spec_file):
46+
"""
47+
Update the specfile to reflect the latest commit. A line
48+
with the following syntax is expected in the specfile:
49+
50+
%global commit
51+
52+
This line will be overwritten to add the git commit.
53+
"""
54+
git_hash = get_latest_commit()
55+
update_commit = \
56+
"sed -i 's/^%global commit .*$/%global commit {0}/' {1}".format(
57+
git_hash,
58+
spec_file
59+
)
60+
output = run_command(update_commit)

0 commit comments

Comments
 (0)