Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions golang1.17/bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,44 @@ def build(source_dir, target_dir):
}

gomod = "%s/go.mod" % source_dir
vendor = "%s/vendor" % source_dir

has_gomod = exists(gomod)
deps_vendored = exists(vendor)

if has_gomod:
print("detected go.mod file")
Comment thread
mattwelke marked this conversation as resolved.
Outdated
if deps_vendored:
print("Detected vendor directory. Will skip downloading modules.")

if os.environ.get("__NIM_REMOTE_BUILD"):
if exists(gomod):
print("downloading modules")
ret = subprocess.call(["go", "mod", "download"], cwd=source_dir, env=env)
if ret != 0:
sys.exit(ret)
if has_gomod:
if not deps_vendored:
Comment thread
mattwelke marked this conversation as resolved.
print("downloading modules")
ret = subprocess.call(["go", "mod", "download"], cwd=source_dir, env=env)
if ret != 0:
sys.exit(ret)
Comment thread
mattwelke marked this conversation as resolved.
else:
print("initializing modules")
ret = subprocess.call(["go", "mod", "init", "exec"], cwd=source_dir, env=env)
if ret != 0:
sys.exit(ret)
else:
with open(os.devnull, "w") as dn:
if exists(gomod):
ret = subprocess.call(["go", "mod", "download"], cwd=source_dir, env=env, stderr=dn, stdout=dn)
if ret != 0:
print("cannot download modules")
return
if has_gomod:
if not deps_vendored:
ret = subprocess.call(["go", "mod", "download"], cwd=source_dir, env=env, stderr=dn, stdout=dn)
if ret != 0:
print("cannot download modules")
return
else:
ret = subprocess.call(["go", "mod", "init", "exec"], cwd=source_dir, env=env, stdout=dn, stderr=dn)
if ret != 0:
print("cannot init modules")
return

ldflags = "-s -w"
gobuild = ["go", "build", "-o", target, "-ldflags", ldflags]
gobuild = ["go", "build"] + (["-mod=vendor"] if deps_vendored else []) + ["-o", target, "-ldflags", ldflags]
if os.environ.get("__OW_EXECUTION_ENV"):
ldflags += " -X main.OwExecutionEnv=%s" % os.environ["__OW_EXECUTION_ENV"]
if os.environ.get("__NIM_REMOTE_BUILD"):
Expand Down