Use setLoadingOrWorkspacePhase instead of setLoadingPhase where relevant,

commit 3fedf9e618cbce3dbdd00559b2de0bb8e2d43171 introduced the distinction between the loading phase and the workspace phase.

This check broke the use of native.existing_rule(s) in skylark remote repository, added a regression test for it.

Fixes #1277

--
MOS_MIGRATED_REVID=122988569
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
index e26b257..d9a8b27 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
@@ -399,6 +399,16 @@
   }
 
   /**
+   * Checks that the current Environment is in the loading or the workspace phase.
+   * @param symbol name of the function being only authorized thus.
+   */
+  public void checkLoadingOrWorkspacePhase(String symbol, Location loc) throws EvalException {
+    if (phase == Phase.ANALYSIS) {
+      throw new EvalException(loc, symbol + "() cannot be called during the analysis phase");
+    }
+  }
+
+  /**
    * Checks that the current Environment is in the loading phase.
    * @param symbol name of the function being only authorized thus.
    */