<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 29 Mar 2021, at 9:40 pm, Joshua Root <<a href="mailto:jmr@macports.org" class="">jmr@macports.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On 2021-3-30 06:35 , Christopher Jones wrote:<br class=""><blockquote type="cite" class="">Hi All,<br class="">Working on fixing a build issue and hitting a limit in my current understanding of Tcl… I am trying to set some new env vars in the build.env<br class="">         set ldflags ${configure.ldflags}<br class="">         build.env-append   GO_EXTLINK_ENABLED=1<br class="">         build.env-append   GO_LDFLAGS='-extldflags\=$ldflags’<br class="">however, when the port in question using ${build.env} I get<br class="">DEBUG: system -W /opt/local/var/macports/build/_Users_chris_Projects_MacPorts_ports_devel_codesearch/codesearch/work/gopath/src/<a href="http://github.com/google/codesearch:" class="">github.com/google/codesearch:</a> <<a href="http://github.com/google/codesearch:" class="">http://github.com/google/codesearch:</a>> GOPATH=/opt/local/var/macports/build/_Users_chris_Projects_MacPorts_ports_devel_codesearch/codesearch/work/gopath GOARCH=amd64 GOOS=darwin CC=/usr/bin/clang CXX=/usr/bin/clang++ GOPROXY=off GO111MODULE=off C_INCLUDE_PATH=/opt/local/include/LegacySupport OBJC_INCLUDE_PATH=/opt/local/include/LegacySupport CPLUS_INCLUDE_PATH=/opt/local/include/LegacySupport OBJCPLUS_INCLUDE_PATH=/opt/local/include/LegacySupport GO_EXTLINK_ENABLED=1 {GO_LDFLAGS='-extldflags=-L/opt/local/lib -Wl,-headerpad_max_install_names -lMacportsLegacySupport'} /opt/local/bin/go build cmd/cgrep/cgrep.go<br class="">sh: {GO_LDFLAGS=-extldflags=-L/opt/local/lib -Wl,-headerpad_max_install_names -lMacportsLegacySupport}:<br class=""></blockquote><br class="">That isn't a result of setting build.env. You must have added this to build.args or similar.<br class=""></div></div></blockquote><div><br class=""></div><div><br class=""></div>I haven’t, but I think some ports do, see below.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">See how the second env var I define above is shown inside {} braces, which of course sh cannot parse.<br class="">I have tried numerous forms of how to set<br class="">build.env-append   GO_LDFLAGS='-extldflags\=$ldflags’<br class="">but they all have the same issue.<br class="">I suspect this is just my lack of really undertanding quoting in tcl, so I am hoping someone can tell me what I am doing wrong ?<br class=""></blockquote><br class="">Do you want literal single quotes in the value of the environment variable? If so:<br class=""><br class="">build.env-append   GO_LDFLAGS='-extldflags=${configure.ldflags}’<br class=""><br class="">if not:<br class=""><br class="">build.env-append   GO_LDFLAGS=-extldflags=${configure.ldflags}<br class=""><br class="">The value of the *.env options never gets passed to a shell; the environment variables are set directly by our code. The parsing is very simple, perhaps deceptively so if you expect it to work like a shell. Each list element is expected to contain a single assignment, with everything before the first '=' used as the variable name, and everything after it used as the value to set it to.<br class=""></div></div></blockquote><div><br class=""></div><div>This is probably the problem, as there are a few ports that do pass it to a shell. see e.g.</div><div><br class=""></div><div><a href="https://github.com/macports/macports-ports/blob/749ad2787c30497020bdc4cca116eff9f09c800b/devel/codesearch/Portfile#L33" class="">https://github.com/macports/macports-ports/blob/749ad2787c30497020bdc4cca116eff9f09c800b/devel/codesearch/Portfile#L33</a></div><div><br class=""></div><div>All I have been trying to do is fix a few issues with go based builds, by adding some additional build env vars, on older systems, and I ran into the port above having problems. It appears to take build.env and directly pass it to a sell command, which from what you say should probably never be done. If thats the case I won’t worry about this one corner case port.</div><div><br class=""></div><div>There are a handful of other ports that do something similar.</div><div><br class=""></div><div>Chris</div><div><br class=""></div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div class=""><br class="">A corollary is that something like this won't (in general) work:<br class=""><br class="">build.args-append ${build.env}<br class=""><br class="">because build.args has to deal with shell quoting. There's also a second bug in that line because it appends the entirety of build.env, which is a list, as a single element. The {*} operator is essential when doing something like this:<br class=""><br class="">build.args foo bar<br class="">destroot.args-append {*}${build.args}<br class=""><br class="">- Josh<br class=""></div></div></blockquote></div><br class=""></body></html>