From e4265d31352ce6f6c23a732829c47bc768a1c79a Mon Sep 17 00:00:00 2001
From: Dr Owain Kenway <o.kenway@ucl.ac.uk>
Date: Sat, 11 Jul 2020 15:02:53 +0100
Subject: [PATCH] llvm-flang: Only build offload code if cuda enabled (#17466)

* llvm-flang Only build offload code if cuda enabled

The current version executes `cmake(*args)` always as part of the post install.  If device offload is not part of the build, this results in referencing `args` without it being set and the error:

```
==> Error: UnboundLocalError: local variable 'args' referenced before assignment

```

Looking at prevoous version of `llvm-package.py` this whole routine appears to be only required for offload, some indent `cmake/make/install` to be under the `if`.

* Update package.py

Add comment
---
 var/spack/repos/builtin/packages/llvm-flang/package.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/var/spack/repos/builtin/packages/llvm-flang/package.py b/var/spack/repos/builtin/packages/llvm-flang/package.py
index 10001e2340..99948fd76f 100644
--- a/var/spack/repos/builtin/packages/llvm-flang/package.py
+++ b/var/spack/repos/builtin/packages/llvm-flang/package.py
@@ -238,6 +238,7 @@ def post_install(self):
                         spec['libelf'].prefix.include,
                         spec['hwloc'].prefix.include))
 
-        cmake(*args)
-        make()
-        make('install')
+            # Only build if offload target.
+            cmake(*args)
+            make()
+            make('install')
-- 
GitLab