1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.build.config; 18 19 import java.io.PrintStream; 20 import java.util.ArrayList; 21 import java.util.List; 22 import java.util.Map; 23 import java.util.TreeMap; 24 25 /** 26 * Language-agnostic representation of a configuration statement. 27 */ 28 public class GenericConfig extends ConfigBase { 29 /** 30 * The config files that were imported in this config pass. 31 */ 32 protected final TreeMap<String, ConfigFile> mConfigFiles = new TreeMap(); 33 34 /** 35 * A configuration file. 36 */ 37 public static class ConfigFile { 38 /** 39 * The name of the file, relative to the tree root. 40 */ 41 private final String mFilename; 42 43 /** 44 * Sections of variable definitions and import statements. Product config 45 * files will always have at least one block. 46 */ 47 private final ArrayList<Statement> mStatements = new ArrayList(); 48 ConfigFile(String filename)49 public ConfigFile(String filename) { 50 mFilename = filename; 51 } 52 getFilename()53 public String getFilename() { 54 return mFilename; 55 } 56 addStatement(Statement statement)57 public void addStatement(Statement statement) { 58 mStatements.add(statement); 59 } 60 getStatements()61 public ArrayList<Statement> getStatements() { 62 return mStatements; 63 } 64 } 65 66 /** 67 * Base class for statements that appear in config files. 68 */ 69 public static class Statement { 70 } 71 72 /** 73 * A variable assignment. 74 */ 75 public static class Assign extends Statement { 76 private final String mVarName; 77 private final List<Str> mValue; 78 79 /** 80 * Assignment of a single value 81 */ Assign(String varName, Str value)82 public Assign(String varName, Str value) { 83 mVarName = varName; 84 mValue = new ArrayList(); 85 mValue.add(value); 86 } 87 88 /** 89 * Assignment referencing a previous value. 90 * VAR := $(1) $(VAR) $(2) $(VAR) $(3) 91 */ Assign(String varName, List<Str> value)92 public Assign(String varName, List<Str> value) { 93 mVarName = varName; 94 mValue = value; 95 } 96 getName()97 public String getName() { 98 return mVarName; 99 } 100 getValue()101 public List<Str> getValue() { 102 return mValue; 103 } 104 } 105 106 /** 107 * An $(inherit-product FILENAME) statement 108 */ 109 public static class Inherit extends Statement { 110 private final Str mFilename; 111 Inherit(Str filename)112 public Inherit(Str filename) { 113 mFilename = filename; 114 } 115 getFilename()116 public Str getFilename() { 117 return mFilename; 118 } 119 } 120 121 /** 122 * Adds the given config file. Returns any one previously added, or null. 123 */ addConfigFile(ConfigFile file)124 public ConfigFile addConfigFile(ConfigFile file) { 125 return mConfigFiles.put(file.getFilename(), file); 126 } 127 getFiles()128 public TreeMap<String, ConfigFile> getFiles() { 129 return mConfigFiles; 130 } 131 } 132