douao3636 2014-12-29 19:27
浏览 84
已采纳

生成后删除.a文件-GoLang

I'm currently using fresh to rebuild and restart the webserver on every change of any of the source files in my project.

It works ok. However, after some time files are created at pkg directory. This causes the refresh does not happens anymore, and the reason is instead of getting the source files (.go files) to build the binary, it gets the .a files. How can I avoid this feature?

Adding information:

File: runner.conf at the same level of main.go

root: .
tmp_path: ./tmp
build_name: bin/app.bin
build_log: runner-build-errors.log
valid_ext: .go, .tpl, .tmpl, .html
build_delay: 600
colors: 1
log_color_main: cyan
log_color_build: yellow
log_color_runner: green
log_color_watcher: magenta
log_color_app:
ignore_dirs: ./pkg

Is not working at all:

13:39:48 watcher     | Watching .
13:39:48 watcher     | Watching bin
13:39:48 watcher     | Watching pkg
13:39:48 watcher     | Watching pkg/darwin_amd64
13:39:48 watcher     | Watching public
13:39:48 watcher     | Watching src
13:39:48 watcher     | Watching src/site.org
13:39:48 watcher     | Watching src/site.org/application
13:39:48 watcher     | Watching src/site.org/application/controllers
13:39:48 watcher     | Watching src/site.org/application/controllers/web
13:39:48 watcher     | Watching src/site.org/system

FIXING

In the end, I was not able to make it work. However, I create a solution using this plugin:

https://github.com/alexnj/SublimeOnSaveBuild

That tries to build on save, and I've created this build system (called GoLang):

{
    "shell_cmd": "sh /Users/acruz/go_projects/build_go.sh \"$project_path\"",
    "working_dir": "${project_path}"
}

And the file build_go.sh is:

#!/bin/sh
echo "Removing PKG folder if exists"
rm -Rf pkg

echo "Building application"
go build -o bin/app.bin main.go

echo "Killing application"
killall app.bin

echo "Running application ./bin/app.bin"
echo ""
echo "Debug information:"
echo ""

./bin/app.bin

One @TODO will be defining in the project configuration the name of the binary... but for me this works ok. One of the benefits of doing this is you don't have to add the -a flag, which will make slow the compilation process, and the debug information will be showed just there in the build window...

Debug information

  • 写回答

2条回答 默认 最新

  • douya5194 2014-12-29 20:45
    关注

    You can change $GOPATH/src/github.com/pilu/fresh/runner/build.go#L13

    cmd := exec.Command("go", "build", "-o", buildPath(), root())
    

    to be

    cmd := exec.Command("go", "build", "-a", "-o", buildPath(), root())
    

    and then

    go install -a github.com/pilu/fresh
    

    flag -a force recompiling of .a files

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看