`make check-spec-files` verifies unstaged local changes in
.spec files for corectness
`make check-spec-files BASE_COMMIT=<commit hash>` verifies .spec files
corectness for all commits between <commit hash> and HEAD
Change-Id: If8b306fc00683f5465e13925da659bc6a2fa6e57
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/5837
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Srivatsa S. Bhat <srivatsab@vmware.com>
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>
... | ... |
@@ -249,7 +249,10 @@ clean-stage-for-incremental-build: |
249 | 249 |
@test -n "$$(git diff --name-only $(BASE_COMMIT) @ | grep SPECS)" && $(PHOTON_SPECDEPS) -s $(PHOTON_SPECS_DIR) -i remove-upward-deps -p $$(echo `git diff --name-only $(BASE_COMMIT) @ | grep .spec | xargs -n1 basename 2>/dev/null` | tr ' ' :) ||: |
250 | 250 |
@test -n "$$(git diff --name-only $(BASE_COMMIT) @ | grep support)" && $(RM) -rf $(PHOTON_RPMS_DIR) ||: |
251 | 251 |
|
252 |
-packages: check-docker-py check-tools $(PHOTON_STAGE) $(PHOTON_PUBLISH_XRPMS) $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES) $(CONTAIN) generate-dep-lists |
|
252 |
+check-spec-files: |
|
253 |
+ @./tools/scripts/check_spec_files.sh $(BASE_COMMIT) |
|
254 |
+ |
|
255 |
+packages: check-docker-py check-tools $(PHOTON_STAGE) $(PHOTON_PUBLISH_XRPMS) $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES) $(CONTAIN) check-spec-files generate-dep-lists |
|
253 | 256 |
@echo "Building all RPMS..." |
254 | 257 |
@cd $(PHOTON_PKG_BUILDER_DIR) && \ |
255 | 258 |
$(PHOTON_PACKAGE_BUILDER) \ |
... | ... |
@@ -613,7 +616,7 @@ check: packages |
613 | 613 |
$(rpmcheck_stop_on_error) \ |
614 | 614 |
-t ${THREADS} |
615 | 615 |
|
616 |
-%: check-tools $(PHOTON_PUBLISH_RPMS) $(PHOTON_PUBLISH_XRPMS) $(PHOTON_SOURCES) $(CONTAIN) $(eval PKG_NAME = $@) |
|
616 |
+%: check-tools $(PHOTON_PUBLISH_RPMS) $(PHOTON_PUBLISH_XRPMS) $(PHOTON_SOURCES) $(CONTAIN) check-spec-files $(eval PKG_NAME = $@) |
|
617 | 617 |
$(eval PKG_NAME = $@) |
618 | 618 |
@echo "Building package $(PKG_NAME) ..." |
619 | 619 |
@cd $(PHOTON_PKG_BUILDER_DIR) && \ |
620 | 620 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,91 @@ |
0 |
+#! /bin/bash |
|
1 |
+ |
|
2 |
+# Dist tag must present in Release: |
|
3 |
+function check-for-dist-tag() |
|
4 |
+{ |
|
5 |
+ cat $1 | grep "Release:" | grep "%{?dist}" > /dev/null |
|
6 |
+ if [ "$?" -ne 0 ];then |
|
7 |
+ echo "ERROR in $1: Release field doesn't contain %{?dist} tag" |
|
8 |
+ cat $1 | grep "Release:" |
|
9 |
+ exit 1 |
|
10 |
+ fi |
|
11 |
+} |
|
12 |
+ |
|
13 |
+# Check for Version-Release matching top entry from the Changelog |
|
14 |
+function check-for-correct-version() |
|
15 |
+{ |
|
16 |
+ versions=`sed -e '1,/%changelog/d' $1 | grep '<' | grep '>' | grep '*' | cut -f 2 -d '>'`; |
|
17 |
+ latest_version_in_changelog=`echo $versions | cut -d ' ' -f 1` |
|
18 |
+ version=`cat $1 | grep Version: | cut -f 2 -d ':' | sed 's/ //g' | sed '1!d'`; |
|
19 |
+ sub_version=`cat $1 | grep Release: | cut -f 2 -d ':' | cut -f 1 -d '%' | sed 's/ //g' | tr -d ' '` |
|
20 |
+ s=`echo ${sub_version//[[:blank:]]/}` |
|
21 |
+ v=`echo ${version//[[:blank:]]/}` |
|
22 |
+ full_version=${v}-${s}; |
|
23 |
+ if [ "${latest_version_in_changelog}" != "${full_version}" ]; then |
|
24 |
+ echo "ERROR in $1: Top changelog entry version ${latest_version_in_changelog} does NOT MATCH package version ${full_version}" |
|
25 |
+ echo "Please update %changelog or Version,Release: in $1 to make them match each other" |
|
26 |
+ exit 1 |
|
27 |
+ fi |
|
28 |
+} |
|
29 |
+ |
|
30 |
+# Changelog should have correct dates |
|
31 |
+function check-for-bogus-dates() |
|
32 |
+{ |
|
33 |
+ local IFS=$'\n' |
|
34 |
+ for entry in `sed -e '1,/%changelog/d' $i | grep '<' | grep '>' | grep '*' | sed 's/^*//g' | sed 's/ \+/ /g'` ; do |
|
35 |
+ IFS=$' ' read D m d y s <<< $entry |
|
36 |
+ day=`date --date "$m $d $y" +%a` |
|
37 |
+ if [ "${D}" != "${day}" ]; then |
|
38 |
+ echo "ERROR in $1: bogus date in $entry" |
|
39 |
+ echo "$m $d $y is $day" |
|
40 |
+ exit 1 |
|
41 |
+ fi |
|
42 |
+ done |
|
43 |
+} |
|
44 |
+ |
|
45 |
+# No trailing spaces |
|
46 |
+function check-for-trailing-spaces() |
|
47 |
+{ |
|
48 |
+ grep -e " $" $1 |
|
49 |
+ if [ $? -eq 0 ] ; then |
|
50 |
+ echo "ERROR in $1: trailing spaces detected" |
|
51 |
+ exit 1 |
|
52 |
+ fi |
|
53 |
+} |
|
54 |
+ |
|
55 |
+# Do not use ./configure |
|
56 |
+function check-for-configure() |
|
57 |
+{ |
|
58 |
+ grep -e "./configure" $1 |
|
59 |
+ if [ $? -eq 0 ] ; then |
|
60 |
+ echo "ERROR in $1: use %configure instead of ./configure" |
|
61 |
+ exit 1 |
|
62 |
+ fi |
|
63 |
+} |
|
64 |
+ |
|
65 |
+# All BuildRequires should on the top |
|
66 |
+function check-for-buildrequires() |
|
67 |
+{ |
|
68 |
+ sed -e '1,/%description/d' $1 | grep -e "^BuildRequires" |
|
69 |
+ if [ $? -eq 0 ] ; then |
|
70 |
+ echo "ERROR in $1: BuildRequires in subpackages detected." |
|
71 |
+ echo "Move all BuildRequires to the top" |
|
72 |
+ exit 1 |
|
73 |
+ fi |
|
74 |
+} |
|
75 |
+ |
|
76 |
+SPECS=`git diff --name-only $1 @ | grep -e "SPECS/.*.spec$"` |
|
77 |
+for i in `echo $SPECS`; |
|
78 |
+do |
|
79 |
+ echo Analyzing $i ... |
|
80 |
+ if [ ! -f $i ]; then |
|
81 |
+ echo "$i is removed by the current changeset." |
|
82 |
+ else |
|
83 |
+ check-for-dist-tag $i |
|
84 |
+ check-for-correct-version $i |
|
85 |
+ check-for-bogus-dates $i |
|
86 |
+ check-for-trailing-spaces $i |
|
87 |
+ check-for-configure $i |
|
88 |
+ check-for-buildrequires $i |
|
89 |
+ fi |
|
90 |
+done |