Skip to content

Building tags not work as thought for gopherjs build #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
oskca opened this issue Feb 26, 2017 · 12 comments
Open

Building tags not work as thought for gopherjs build #598

oskca opened this issue Feb 26, 2017 · 12 comments
Labels
bug gopherjs-tool Related to the gopherjs tool or its build system (but not the compiler itself). NeedsFix NeedsInvestigation

Comments

@oskca
Copy link

oskca commented Feb 26, 2017

In my VueJS binding project Vuejs, I tried
to include different version of Vue Javascript Code using go building tags,
but the generated js code does not change with or without building tags.

I hava tow files to switch tags: inc_debug.go

//+build debug

package vue

//using vue-2.1.10.inc.js 219K
import _ "github.com/oskca/gopherjs-vue/jscode/debug" 

and inc_minified.go

//+build !debug

package vue

//using vue-2.1.10.min.inc.js 71K
import _ "github.com/oskca/gopherjs-vue/jscode/debug" 

Steps to show the problem

  1. RM to clean the build
$ rm -rf $GOPATH/pkg/linux_js/github.com/oskca
  1. A refresh build works with expected package building sequence
$ gopherjs build -v --tags debug $GOPATH/src/github.com/oskca/gopherjs-vue/examples/basic/basic.go
github.com/oskca/gopherjs-dom
github.com/oskca/gopherjs-json
github.com/oskca/gopherjs-vue/jscode/debug
github.com/oskca/gopherjs-vue
main
  1. And outputs a debug version
$ lh $GOPATH/src/github.com/oskca/gopherjs-vue/examples/basic/basic.js
-rw-rw-r-- 1 oskca oskca 340K 22:56 basic.js ## bigger file size
  1. The second build without the building flags
$ gopherjs build -v $GOPATH/src/github.com/oskca/gopherjs-vue/examples/basic/basic.go
github.com/oskca/gopherjs-vue/jscode/minified ## expected
main
  1. Outputs not change, still the debug version
$ lh $GOPATH/src/github.com/oskca/gopherjs-vue/examples/basic/basic.js
-rw-rw-r-- 1 oskca oskca 340K 22:57 basic.js ## size not change

If you swap setp 3 and step 2

the generated js code would only include the vue-2.1.10.min.inc.js

$ lh $GOPATH/src/github.com/oskca/gopherjs-vue/examples/basic/basic.js
-rw-rw-r-- 1 oskca oskca 192K 23:10 basic.js ## smaller one

I also tried building tags in *.inc.js, but it not work as #468

@flimzy
Copy link
Member

flimzy commented Feb 26, 2017

This is likely related to #559 . GopherJS's caching is broken in several ways. A work-around is to always clear the cache when building--perhaps manually, or as part of a build process (such as a Makefile).

rm -rf ${GOPATH}/pkg/*_js

is what I use to accomplish this.

@oskca
Copy link
Author

oskca commented Feb 26, 2017

@flimzy Thanks for your suggestions.

rm -rf ${GOPATH}/pkg/*_js surely works, but It will cause some users like me be confused when first confronting this problem.

As in oskca/gopherjs-vue#6, is there a good way to switch different versions of *.inc.js files by just go or gopherjs itself?

@oskca oskca changed the title Building tags not work as expected for gopherjs build Building tags not work as thought for gopherjs build Feb 26, 2017
@flimzy
Copy link
Member

flimzy commented Feb 26, 2017

See my comment on #468 on a potential work-around for that issue.

@oskca
Copy link
Author

oskca commented Mar 4, 2017

#468 (comment) does not work for my situation, in my case I just want the following 2 CMDs produce different output, but in fact the output will not change:

gopherjs build -v $GOPATH/src/github.com/oskca/gopherjs-vue/examples/basic/basic.go
gopherjs build -v --tags debug $GOPATH/src/github.com/oskca/gopherjs-vue/examples/basic/basic.go

unless you change the code in github.com/oskca/gopherjs-vue and then gopherjs will rebuild package github.com/oskca/gopherjs-vue, the output changes.

@dmitshur
Copy link
Member

dmitshur commented Mar 4, 2017

That sounds like the caching bug(s) are less harmless than previously thought, since it affects valid code that's compiled with different builds tags. Fixing this would be desirable.

@fiatjaf
Copy link

fiatjaf commented Apr 10, 2017

Also related: #620

@dmitshur
Copy link
Member

I've fixed #559 just now. That may or may not be sufficient to resolve this issue too.

Is it possible for you to check if this issue still occurs with latest GopherJS?

@oskca
Copy link
Author

oskca commented Apr 28, 2017

Well, this issue still exists

@dmitshur
Copy link
Member

Thanks for confirming. Is it possible for you to make a more minimal (ideally, without too many outside packages) reproduce sample that demonstrates the problem? For a good example, see #559 (comment).

@flimzy
Copy link
Member

flimzy commented Sep 10, 2017

This continues to bite me, despite my best efforts to work around it.

Would it be reasonable to disable caching unless/until this bug can be fixed?

@dmitshur
Copy link
Member

dmitshur commented Sep 25, 2017

I think (but haven't confirmed) that disabling caching may be a large and invasive change, which might be no less work and risk than investigating and fixing the bug in the first place.

Is it possible for you to create a way to reproduce this issue @flimzy?

(FWIW, I have not seen any issues with build caching.)

@terinjokes
Copy link

In my tests, it seems build tags are ignored if the minify flag is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug gopherjs-tool Related to the gopherjs tool or its build system (but not the compiler itself). NeedsFix NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

5 participants