1*7594170eSAndroid Build Coastguard Worker# Copyright (C) 2021 The Android Open Source Project 2*7594170eSAndroid Build Coastguard Worker# 3*7594170eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 4*7594170eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 5*7594170eSAndroid Build Coastguard Worker# You may obtain a copy of the License at 6*7594170eSAndroid Build Coastguard Worker# 7*7594170eSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 8*7594170eSAndroid Build Coastguard Worker# 9*7594170eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*7594170eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 11*7594170eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*7594170eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 13*7594170eSAndroid Build Coastguard Worker# limitations under the License. 14*7594170eSAndroid Build Coastguard Worker 15*7594170eSAndroid Build Coastguard Worker"""A function to generate table of contents files of symbols from a shared library.""" 16*7594170eSAndroid Build Coastguard Worker 17*7594170eSAndroid Build Coastguard WorkerCcTocInfo = provider( 18*7594170eSAndroid Build Coastguard Worker "Information about the table of contents of a shared library", 19*7594170eSAndroid Build Coastguard Worker fields = { 20*7594170eSAndroid Build Coastguard Worker "toc": "The single file for the table of contents", 21*7594170eSAndroid Build Coastguard Worker }, 22*7594170eSAndroid Build Coastguard Worker) 23*7594170eSAndroid Build Coastguard Worker 24*7594170eSAndroid Build Coastguard Workerdef generate_toc(ctx, name, input_file): 25*7594170eSAndroid Build Coastguard Worker so_name = "lib" + name + ".so" 26*7594170eSAndroid Build Coastguard Worker toc_name = so_name + ".toc" 27*7594170eSAndroid Build Coastguard Worker out_file = ctx.actions.declare_file(toc_name) 28*7594170eSAndroid Build Coastguard Worker d_file = ctx.actions.declare_file(toc_name + ".d") 29*7594170eSAndroid Build Coastguard Worker ctx.actions.run( 30*7594170eSAndroid Build Coastguard Worker env = { 31*7594170eSAndroid Build Coastguard Worker "CLANG_BIN": ctx.executable._readelf.dirname, 32*7594170eSAndroid Build Coastguard Worker }, 33*7594170eSAndroid Build Coastguard Worker inputs = [input_file], 34*7594170eSAndroid Build Coastguard Worker tools = [ 35*7594170eSAndroid Build Coastguard Worker ctx.executable._readelf, 36*7594170eSAndroid Build Coastguard Worker ], 37*7594170eSAndroid Build Coastguard Worker outputs = [out_file, d_file], 38*7594170eSAndroid Build Coastguard Worker executable = ctx.executable._toc_script, 39*7594170eSAndroid Build Coastguard Worker arguments = [ 40*7594170eSAndroid Build Coastguard Worker # Only Linux shared libraries for now. 41*7594170eSAndroid Build Coastguard Worker "--elf", 42*7594170eSAndroid Build Coastguard Worker "-i", 43*7594170eSAndroid Build Coastguard Worker input_file.path, 44*7594170eSAndroid Build Coastguard Worker "-o", 45*7594170eSAndroid Build Coastguard Worker out_file.path, 46*7594170eSAndroid Build Coastguard Worker "-d", 47*7594170eSAndroid Build Coastguard Worker d_file.path, 48*7594170eSAndroid Build Coastguard Worker ], 49*7594170eSAndroid Build Coastguard Worker mnemonic = "GenerateToc", 50*7594170eSAndroid Build Coastguard Worker ) 51*7594170eSAndroid Build Coastguard Worker return CcTocInfo(toc = out_file) 52