BUILD.gn file for submodules

.git file will be in a new location when submodules are enabled.

b/253329946

Change-Id: Icec9b9ac2b60fca830423af59ad2817f711d2d7a
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/glslang/+/822069
Reviewed-by: Nathan Mulcahey <nmulcahey@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 928fad6..f2d20dc 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -31,6 +31,7 @@
 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
+import("//build/checkout.gni")
 import("//build_overrides/glslang.gni")
 
 # Both Chromium and Fuchsia use by default a set of warning errors
@@ -46,6 +47,18 @@
   _configs_to_add = [ "//build/config/compiler:no_chromium_code" ]
 }
 
+if (submodules) {
+  git_link_path_list =
+    read_file(".git", "list lines")
+  git_link_path = git_link_path_list[0]
+  relative_git_dir_split = string_split(git_link_path)
+  relative_git_dir = relative_git_dir_split[1]
+  git_head =
+    "${relative_git_dir}/HEAD"
+} else {
+  git_head = ".git/HEAD"
+}
+
 action("glslang_build_info") {
   script = "build_info.py"
 
@@ -58,7 +71,7 @@
     changes_file,
     script,
     template_file,
-    ".git/HEAD",
+    git_head,
   ]
   outputs = [ out_file ]
   args = [