Create ValidationEnvironment from Environment

Allow ValidationEnvironment to be created from initial Environment so that
there is no need to manually keep two different sets of constructors in synch.

--
MOS_MIGRATED_REVID=101588695
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java
index 7aedca2..9b71f96 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java
@@ -47,13 +47,21 @@
 
   // Whether this validation environment is not modified therefore clonable or not.
   private boolean clonable;
-  
+
   /**
    * Tracks the number of nested for loops that contain the statement that is currently being
    * validated
    */
   private int loopCount = 0;
 
+  /**
+   * Create a ValidationEnvironment for a given global Environment
+   */
+  public ValidationEnvironment(Environment env) {
+    this(env.getVariableNames());
+    Preconditions.checkArgument(env.isGlobal());
+  }
+
   public ValidationEnvironment(Set<String> builtinVariables) {
     parent = null;
     variables.addAll(builtinVariables);
@@ -135,7 +143,7 @@
   /**
    * Starts a session with temporarily disabled readonly checking for variables between branches.
    * This is useful to validate control flows like if-else when we know that certain parts of the
-   * code cannot both be executed. 
+   * code cannot both be executed.
    */
   public void startTemporarilyDisableReadonlyCheckSession() {
     futureReadOnlyVariables.add(new HashSet<String>());
@@ -190,14 +198,14 @@
   public boolean isInsideLoop() {
     return (loopCount > 0);
   }
-  
+
   /**
    * Signals that the block of a for loop was entered
    */
   public void enterLoop()   {
     ++loopCount;
   }
-  
+
   /**
    * Signals that the block of a for loop was left
    *