Files
SDK_RK3288/art/tools/gen_sha.py

152 lines
4.6 KiB
Python
Executable File

#!/usr/bin/python
#
# Copyright (C) 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys, getopt
from os import listdir
from os.path import isfile, join
from hashlib import sha512
def genSha(data):
s = sha512()
s.update("blob %u\0" % len(data))
s.update(data)
return s.hexdigest()
headerFiles = [
"runtime/stack.h",
"runtime/atomic.h",
"compiler/dex/backend.h",
"runtime/base/bit_vector-inl.h",
"runtime/base/casts.h",
"runtime/base/macros.h",
"runtime/base/mutex.h",
"runtime/base/stl_util.h",
"compiler/dex/compiler_internals.h",
"compiler/dex/compiler_ir.h",
"compiler/dex/dataflow_iterator.h",
"compiler/dex/dataflow_iterator-inl.h",
"runtime/dex_file-inl.h",
"runtime/dex_instruction-inl.h",
"compiler/dex/pass_driver.h",
"compiler/dex/pass.h",
"compiler/dex/selectivity.h",
"compiler/dex/global_value_numbering.h",
"compiler/dex/mir_graph.h",
"runtime/mirror/art_method.h",
"runtime/mirror/art_method-inl.h",
"compiler/dex/pass_driver.h",
"compiler/dex/pass_driver_me_opts.h",
"compiler/dex/pass_driver_me_post_opt.h",
"compiler/dex/pass.h",
"compiler/dex/pass_me.h",
"compiler/dex/post_opt_passes.h",
"runtime/safe_map.h",
"compiler/utils/allocation.h",
"compiler/utils/arena_allocator.h",
"runtime/verifier/method_verifier.h",
"runtime/verifier/method_verifier-inl.h",
"compiler/plugin_handler.h"
]
def createHeader(shaHeader, shaData):
topContent ="""
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* This file is automatically generated. DO NOT MODIFY!!"
*/
#ifndef ART_COMPILER_SHA_VERSION_H_
#define ART_COMPILER_SHA_VERSION_H_
"""
bottomContent ="""
#endif // ART_COMPILER_SHA_VERSION_H_
"""
with open(shaHeader, 'w') as header:
header.write(topContent)
header.write(shaData)
header.write(bottomContent)
def main(argv):
shaData = ''
basePath = ''
outFile = ''
try:
opts, args = getopt.getopt(argv, "p:o:h", ["path=", "out=", "help"])
except getopt.GetoptError:
print "usage: gen_sha.py -p <path_to_base_dir> -o <output_file>"
sys.exit(2)
if opts == []:
print "usage: gen_sha.py -p <path_to_base_dir> -o <output_file>"
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print "usage: gen_sha.py -p <path_to_base_dir> -o <output_file>"
sys.exit()
elif opt in ("-p", "--path"):
basePath = arg + "/"
elif opt in ("-o", "--out"):
outFile = arg
else:
print "usage: gen_sha.py -p <path_to_base_dir> -o <output_file>"
sys.exit(2)
for hdr in headerFiles:
with open (basePath + hdr, 'r') as header:
data=header.read().replace('\n', '')
shaData += data
sha = genSha(shaData.replace(' ', ''))
headerData = "#define SHA_ART_VERSION \"" + sha + "\""
shaHeaderFile = outFile
print sha
if isfile(shaHeaderFile):
same = 0
with open(shaHeaderFile, 'r') as shaHeader:
for line in shaHeader:
if line.strip() == headerData:
same = 1
break
if not same:
createHeader(shaHeaderFile, headerData)
else:
createHeader(shaHeaderFile, headerData)
if __name__ == "__main__":
main(sys.argv[1:])