1#!/usr/bin/env python 2# 3# Copyright (C) 2024 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17"""A tool for constructing UFFD GC flag.""" 18 19import argparse 20import os 21 22from uffd_gc_utils import should_enable_uffd_gc 23 24 25def parse_args(): 26 parser = argparse.ArgumentParser() 27 parser.add_argument('kernel_version_file') 28 parser.add_argument('output') 29 return parser.parse_args() 30 31def main(): 32 args = parse_args() 33 enable_uffd_gc = should_enable_uffd_gc(args.kernel_version_file) 34 flag = '--runtime-arg -Xgc:CMC' if enable_uffd_gc else '' 35 # Prevent the file's mtime from being changed if the contents don't change. 36 # This avoids unnecessary dexpreopt reruns. 37 if os.path.isfile(args.output): 38 with open(args.output, 'r') as f: 39 if f.read() == flag: 40 return 41 with open(args.output, 'w') as f: 42 f.write(flag) 43 44 45if __name__ == '__main__': 46 main() 47