FAQ
Hello,

I would like to be able to distribute my go library without its source.

Before go1.5 we used a trick where we package up all the .a files in
GOPATH/pkg and all the source files in GOPATH/src except for the files we
didn't want to distribute. Those we would replace with a fake.go file that
only contained the package declaration. We would make sure the modification
time on the fake.go files was earlier than the corresponding .a. This would
make sure the go compiler didn't look at the source file.

In go1.5 this trick doesn't seem to work anymore. The go compiler now
complains about missing struct and function definitions in our fake.go.

I thought the shared library support in go1.5 would provide another
solution here, but I haven't figured out a way to compile code that imports
the code we don't want to distribute without providing that code.

Any suggestions would be appreciated.

Thanks,
Aaron

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Aaronb at Aug 19, 2015 at 11:11 pm
    Turns out the go tool in 1.5 is slightly more strict about the files that
    have their source code stripped. To get it to work you need to keep the
    same file name and leave all the imports.
    See https://github.com/golang/go/issues/12186

    Here is an awk script for creating the stripping the source:

    awk '/^import "/ { done = 1; $1 = $1 " _" }
          block && $1~/^[a-zA-Z]/ { $1 = "\t _" }
          block && $1~/^"/ { $1 = "\t_ " $1 }
          /^import \(/ { block = 1 }
          block && /^\)$/ { done = 1 }
          done && /^$/ || /^(func|var|const|type) / {
              print "\n// Contents removed."
              exit
          }
          { print }' INFILE > OUTFILE

    On Thursday, August 13, 2015 at 11:51:15 AM UTC-7, aar...@arista.com wrote:

    Hello,

    I would like to be able to distribute my go library without its source.

    Before go1.5 we used a trick where we package up all the .a files in
    GOPATH/pkg and all the source files in GOPATH/src except for the files we
    didn't want to distribute. Those we would replace with a fake.go file that
    only contained the package declaration. We would make sure the modification
    time on the fake.go files was earlier than the corresponding .a. This would
    make sure the go compiler didn't look at the source file.

    In go1.5 this trick doesn't seem to work anymore. The go compiler now
    complains about missing struct and function definitions in our fake.go.

    I thought the shared library support in go1.5 would provide another
    solution here, but I haven't figured out a way to compile code that imports
    the code we don't want to distribute without providing that code.

    Any suggestions would be appreciated.

    Thanks,
    Aaron
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Tsuna at Aug 19, 2015 at 11:39 pm

    On Wed, Aug 19, 2015 at 4:11 PM, wrote:
    Turns out the go tool in 1.5 is slightly more strict about the files that
    have their source code stripped. To get it to work you need to keep the same
    file name and leave all the imports. See
    https://github.com/golang/go/issues/12186

    Here is an awk script for creating the stripping the source:

    awk '/^import "/ { done = 1; $1 = $1 " _" }
    block && $1~/^[a-zA-Z]/ { $1 = "\t _" }
    block && $1~/^"/ { $1 = "\t_ " $1 }
    /^import \(/ { block = 1 }
    block && /^\)$/ { done = 1 }
    done && /^$/ || /^(func|var|const|type) / {
    print "\n// Contents removed."
    exit
    }
    { print }' INFILE > OUTFILE
    Bear in mind that you want to preserve the timestamp on the files so
    you want to do something like:
        touch -r INFILE OUTFILE
    After running the awk script.

    --
    Benoit "tsuna” Sigoure

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 13, '15 at 6:51p
activeAug 19, '15 at 11:39p
posts3
users2
websitegolang.org

2 users in discussion

Aaronb: 2 posts Tsuna: 1 post

People

Translate

site design / logo © 2022 Grokbase