// Copyright 2014 The Bazel Authors. All rights reserved. // // 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. package com.google.devtools.build.lib.packages; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.annotation.Nullable; /** * Environment for varref variables (formerly called "Makefile * variables"). * *
The most recent binding for a particular variable takes precedence, even if
* a more specific binding came earlier.
*
* @param varname the name of the Makefile variable;
* @param value the string value to assign;
* @param platformSetRegexp a set of platforms for which this variable definition
* should take effect. This is expressed as a regexp over gplatform
* strings.
*/
public void update(String varname, String value, String platformSetRegexp) {
if (varname == null || value == null || platformSetRegexp == null) {
throw new NullPointerException();
}
LinkedListupdate
emulates a very restricted subset of the behaviour of
* GNU Make's environment. In particular, does not attempt to simulate Make's
* complex range of assigment operators.
*/
@Immutable @ThreadSafe
public class MakeEnvironment {
/**
* The platform set regexp that matches all platforms. Canonical.
*/
public static final String MATCH_ANY = ".*";
// A platform-specific binding of a value for a given variable.
static class Binding {
private final String value;
private final String platformSetRegexp;
Binding(String value, String platformSetRegexp) {
this.value = value;
this.platformSetRegexp = platformSetRegexp;
}
@Override
public String toString() {
return value + " (" + platformSetRegexp + ")";
}
String getValue() {
return value;
}
String getPlatformSetRegexp() {
return platformSetRegexp;
}
}
// Maps each variable name to the [short] list of platform-specific bindings
// for it. The first matching binding is definitive.
private final ImmutableMap