Sort expansions of aggregating middlemen by exec file path. These commonly
contain a large set of files required for a particular toolchain that are added
to every single compile action. Some exeutors in turn sort all action inputs in
order to properly cache, deduplicate and serialize them.

Sorting the expansion of these middlemen needs to be done only once and a later
sorting together with a bunch of other action input files is much faster (as
Java's TimSort algorithm is effectively linear with mostly sorted inputs).

RELNOTES: None.
PiperOrigin-RevId: 204285426
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
index a084c3d..3587f08 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
@@ -43,6 +43,7 @@
 import com.google.devtools.build.skyframe.SkyValue;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Nullable;
@@ -298,7 +299,10 @@
       }
     }
     return (action.getActionType() == MiddlemanType.AGGREGATING_MIDDLEMAN)
-        ? new AggregatingArtifactValue(inputs.build(), value)
+        ? new AggregatingArtifactValue(
+            ImmutableList.sortedCopyOf(
+                Comparator.comparing(pair -> pair.first.getExecPathString()), inputs.build()),
+            value)
         : new RunfilesArtifactValue(inputs.build(), value);
   }