Path: blob/master/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/CmakeFlagInfo.java
6004 views
/*******************************************************************************1* Copyright (c) 2017, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package com.ibm.oti.VMCPTool;2223import java.io.BufferedReader;24import java.io.FileReader;25import java.util.HashSet;26import java.util.Set;27import java.util.regex.Matcher;28import java.util.regex.Pattern;2930class CmakeFlagInfo implements IFlagInfo {3132private Set<String> seenFlags = new HashSet<>();33private Set<String> setFlags = new HashSet<>();3435// Convert string to bool using same rules as cmake36private static boolean strToBool(String str) {37str = str.trim().toUpperCase();38if (str.isEmpty() || str.equals("NO") || str.equals("FALSE") || str.equals("OFF") || str.endsWith("-NOTFOUND")) {39return false;40}41return true;42}4344public CmakeFlagInfo(String cacheInfo) throws Throwable {45// CMake cache file lines look like this:46// <VariableName>:<Type>=<Value>4748// Pick out any lines Where <Type> == BOOL49Pattern cacheVarPattern = Pattern.compile("([a-zA-Z0-9_]+):BOOL=(.*)$");50try (BufferedReader reader = new BufferedReader(new FileReader(cacheInfo))) {51String line;5253while (null != (line = reader.readLine())) {54Matcher matcher = cacheVarPattern.matcher(line);55if (matcher.matches()) {56String flagName = matcher.group(1);57boolean flagValue = strToBool(matcher.group(2));5859if (flagName.startsWith("J9VM_")) {60flagName = Util.transformFlag(flagName);61if (flagValue) {62setFlags.add(flagName);63}64seenFlags.add(flagName);65}66}67}68}69}7071@Override72public Set<String> getAllSetFlags() {73return setFlags;74}7576@Override77public boolean isFlagValid(String flagName) {78// TODO We need to properly define all the flags from cmake before we turn this on79// return seenFlags.contains(Util.transformFlag(flagName));80return true;81}8283}848586