build: handle exceptional case when litex/migen not deployed as git repo
authorGabriel L. Somlo <gsomlo@gmail.com>
Wed, 24 Apr 2019 16:50:47 +0000 (12:50 -0400)
committerGabriel L. Somlo <gsomlo@gmail.com>
Wed, 24 Apr 2019 16:50:47 +0000 (12:50 -0400)
litex/build/tools.py

index aa67b9d82711892bd7d7a77b7a12293e183182e0..50fce4609b0392b0e69dfcf7041d6bb5302b9ec9 100644 (file)
@@ -95,7 +95,10 @@ def get_migen_git_revision():
     import migen
     d = os.getcwd()
     os.chdir(os.path.dirname(migen.__file__))
-    r = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])[:-1].decode("utf-8")
+    try:
+        r = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])[:-1].decode("utf-8")
+    except:
+        r = "--------"
     os.chdir(d)
     return r
 
@@ -103,7 +106,10 @@ def get_litex_git_revision():
     import litex
     d = os.getcwd()
     os.chdir(os.path.dirname(litex.__file__))
-    r = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])[:-1].decode("utf-8")
+    try:
+        r = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])[:-1].decode("utf-8")
+    except:
+        r = "--------"
     os.chdir(d)
     return r
 
@@ -114,4 +120,4 @@ def generated_banner(line_comment="//"):
         get_litex_git_revision())
     r += "{}\n".format(datetime.datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S"))
     r += line_comment + "-"*80 + "\n"
-    return r
\ No newline at end of file
+    return r