You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/10/18 21:16:25 UTC

[GitHub] csantanapr commented on a change in pull request #53: Compiler cleanup with examples

csantanapr commented on a change in pull request #53: Compiler cleanup with examples
URL: https://github.com/apache/incubator-openwhisk-runtime-go/pull/53#discussion_r226468666
 
 

 ##########
 File path: common/gobuild.py
 ##########
 @@ -26,40 +26,41 @@
 
 def sources(launcher, source_dir, main):
 
-    # if you choose main, then it must be upper case
-    func = "Main" if main == "main" else main
-
-    # copy the uploaded main code, if it exists
-    src = "%s/%s" % (source_dir, main)
+    func = main.capitalize()
     has_main = None
+
+    # copy the exec to exec.go
+    # also check if it has a main in it
+    src = "%s/exec" % source_dir
+    dst = "%s/exec__.go" % source_dir
     if os.path.isfile(src):
-        dst = "%s/func_%s_.go" % (source_dir, func)
-        with codecs.open(dst, 'w', 'utf-8') as d:
-            with codecs.open(src, 'r', 'utf-8') as s:
+        with codecs.open(src, 'r', 'utf-8') as s:
+            with codecs.open(dst, 'w', 'utf-8') as d:
                 body = s.read()
                 has_main = re.match(r".*package\s+main\W.*func\s+main\s*\(\s*\)", body, flags=re.DOTALL)
                 d.write(body)
 
-
     # copy the launcher fixing the main
     if not has_main:
-        dst = "%s/launch_%s_.go" % (source_dir, func)
+        dst = "%s/main__.go" % source_dir
         with codecs.open(dst, 'w', 'utf-8') as d:
             with codecs.open(launcher, 'r', 'utf-8') as e:
                 code = e.read()
                 code = code.replace("Main", func)
                 d.write(code)
 
-    return os.path.abspath(dst)
-
 def build(parent, source_dir, target):
     # compile...
+    env = {
+      "PATH": os.environ["PATH"],
+      "GOPATH": os.path.abspath(parent)
+    }
     p = subprocess.Popen(
-        ["go", "build", "-i", "-o", target],
+        ["go", "build", "-i", "-ldflags=-s -w",  "-o", target],
 
 Review comment:
   it might worth thinking on providing a way if user wants override flags, maybe file or env variables, just a thought for the future

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services