• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright 2016 The Android Open Source Project
8#
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20#
21#-------------------------------------------------------------------------
22
23import os
24import re
25import sys
26import argparse
27
28def readFile (filename):
29	f = open(filename, 'rb')
30	d = f.read()
31	f.close()
32	return d
33
34def writeFile (filename, data):
35	f = open(filename, 'wb')
36	f.write(data)
37	f.close()
38
39COMMIT	= 0
40REF		= 1
41
42def getCommitOrRef (filename):
43	src = readFile(filename)
44	m = re.search(r'^[a-zA-Z0-9]{40}', src)
45	if m:
46		return (COMMIT, m.group(0))
47	m = re.search(r'^ref:\s+([^\s]+)', src)
48	if m:
49		return (REF, m.group(1))
50	raise Exception("Coulnd't parse %s" % filename)
51
52def getHead (gitDir):
53	curFile = os.path.join(gitDir, "HEAD")
54	while True:
55		type, ptr = getCommitOrRef(curFile)
56		if type == COMMIT:
57			return ptr
58		else:
59			assert type == REF
60			curFile = os.path.join(gitDir, ptr)
61
62def makeReleaseInfo (name, id):
63	return """
64/* WARNING: auto-generated file, use {genFileName} to modify */
65
66#define DEQP_RELEASE_NAME	"{releaseName}"
67#define DEQP_RELEASE_ID		{releaseId}
68"""[1:].format(
69		genFileName	= os.path.basename(__file__),
70		releaseName	= name,
71		releaseId	= id)
72
73def parseArgs ():
74	parser = argparse.ArgumentParser(description="Generate release info for build")
75	parser.add_argument('--name', dest='releaseName', default=None, help="Release name")
76	parser.add_argument('--id', dest='releaseId', default=None, help="Release ID (must be C integer literal)")
77	parser.add_argument('--git', dest='git', action='store_true', default=False, help="Development build, use git HEAD to identify")
78	parser.add_argument('--git-dir', dest='gitDir', default=None, help="Use specific git dir for extracting info")
79	parser.add_argument('--out', dest='out', default=None, help="Output file")
80
81	args = parser.parse_args()
82
83	if (args.releaseName == None) != (args.releaseId == None):
84		print "Both --name and --id must be specified"
85		parser.print_help()
86		sys.exit(-1)
87
88	if (args.releaseName != None) == args.git:
89		print "Either --name and --id, or --git must be specified"
90		parser.print_help()
91		sys.exit(-1)
92
93	return args
94
95if __name__ == "__main__":
96	curDir			= os.path.dirname(__file__)
97	defaultGitDir	= os.path.normpath(os.path.join(curDir, "..", "..", ".git"))
98	defaultDstFile	= os.path.join(curDir, "qpReleaseInfo.inl")
99
100	args = parseArgs()
101
102	if args.git:
103		gitDir		= args.gitDir if args.gitDir != None else defaultGitDir
104		head		= getHead(gitDir)
105		releaseName	= "git-%s" % head
106		releaseId	= "0x%s" % head[0:8]
107	else:
108		releaseName	= args.releaseName
109		releaseId	= args.releaseId
110
111	releaseInfo	= makeReleaseInfo(releaseName, releaseId)
112	dstFile		= args.out if args.out != None else defaultDstFile
113
114	writeFile(dstFile, releaseInfo)
115