From 174ea11b1c83b6ebfcd5ac763a08831b96de7bd4 Mon Sep 17 00:00:00 2001 From: fg2it Date: Sun, 18 Sep 2016 09:03:47 +0000 Subject: [PATCH 1/4] avoid copy of go dep. from vendor/ for release --- tasks/build_task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/build_task.js b/tasks/build_task.js index 3ace8514164..4a6c208c1c6 100644 --- a/tasks/build_task.js +++ b/tasks/build_task.js @@ -59,7 +59,7 @@ module.exports = function(grunt) { }); grunt.config('copy.backend_files', { expand: true, - src: ['conf/defaults.ini', 'conf/sample.ini', 'vendor/**/*', 'scripts/*'], + src: ['conf/defaults.ini', 'conf/sample.ini', 'vendor/phantomjs/*', 'scripts/*'], options: { mode: true}, dest: '<%= tempDir %>' }); From 62a2f80f10ea0e34df210828b4ce87507831b364 Mon Sep 17 00:00:00 2001 From: fg2it Date: Sun, 18 Sep 2016 09:13:00 +0000 Subject: [PATCH 2/4] add option for grunt release --- Gruntfile.js | 5 ++- README.md | 2 +- tasks/options/phantomjs.js | 72 ++++++++++++++++++++------------------ 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9a0c69b96f9..1f96048746b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -9,7 +9,6 @@ module.exports = function (grunt) { genDir: 'public_gen', destDir: 'dist', tempDir: 'tmp', - arch: os.arch(), platform: process.platform.replace('win32', 'windows'), }; @@ -17,6 +16,10 @@ module.exports = function (grunt) { config.arch = process.env.hasOwnProperty('ProgramFiles(x86)') ? 'x64' : 'x86'; } + config.arch = grunt.option('arch') || os.arch(); + + config.phjs = grunt.option('phjsToRelease'); + config.pkg.version = grunt.option('pkgVer') || config.pkg.version; console.log('Version', config.pkg.version); diff --git a/README.md b/README.md index 3a5c7dce6d3..98f4b4d3c9d 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ easily the grafana repository you want to build. ```bash go get github.com/*your_account*/grafana mkdir $GOPATH/src/github.com/grafana -ln -s github.com/*your_account*/grafana $GOPATH/src/github.com/grafana/grafana +ln -s $GOPATH/src/github.com/*your_account*/grafana $GOPATH/src/github.com/grafana/grafana ``` ### Building the backend diff --git a/tasks/options/phantomjs.js b/tasks/options/phantomjs.js index 4339f9880b6..83a7b502f65 100644 --- a/tasks/options/phantomjs.js +++ b/tasks/options/phantomjs.js @@ -1,34 +1,38 @@ -module.exports = function(config,grunt) { - 'use strict'; - - grunt.registerTask('phantomjs', 'Copy phantomjs binary from node', function() { - - var dest = './vendor/phantomjs/phantomjs'; - var confDir = './node_modules/phantomjs-prebuilt/lib/'; - - if (!grunt.file.exists(dest)){ - - var m=grunt.file.read(confDir+"location.js") - var src=/= \"([^\"]*)\"/.exec(m)[1]; - - if (!grunt.file.isPathAbsolute(src)) { - src = confDir+src; - } - - try { - grunt.config('copy.phantom_bin', { - src: src, - dest: dest, - options: { mode: true}, - }); - grunt.task.run('copy:phantom_bin'); - } catch (err) { - grunt.verbose.writeln(err); - grunt.fail.warn('No working Phantomjs binary available') - } - - } else { - grunt.log.writeln('Phantomjs already imported from node'); - } - }); -}; +module.exports = function(config,grunt) { + 'use strict'; + + grunt.registerTask('phantomjs', 'Copy phantomjs binary from node', function() { + + var dest = './vendor/phantomjs/phantomjs'; + var confDir = './node_modules/phantomjs-prebuilt/lib/'; + + if (!grunt.file.exists(dest)){ + + src = config.phjs + + if (!src){ + var m=grunt.file.read(confDir+"location.js") + var src=/= \"([^\"]*)\"/.exec(m)[1]; + + if (!grunt.file.isPathAbsolute(src)) { + src = confDir+src; + } + } + + try { + grunt.config('copy.phantom_bin', { + src: src, + dest: dest, + options: { mode: true}, + }); + grunt.task.run('copy:phantom_bin'); + } catch (err) { + grunt.verbose.writeln(err); + grunt.fail.warn('No working Phantomjs binary available') + } + + } else { + grunt.log.writeln('Phantomjs already imported from node'); + } + }); +}; From c669de116998552594d6c02890cce8a8dfb2f081 Mon Sep 17 00:00:00 2001 From: fg2it Date: Sun, 18 Sep 2016 10:07:12 +0000 Subject: [PATCH 3/4] add options to support cross build --- .github/CONTRIBUTING.md | 2 +- build.go | 42 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 148722e5f73..fe0a1d6c548 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -12,7 +12,7 @@ grunt karma:dev ### Run tests for backend assets before commit ``` -test -z "$(gofmt -s -l . | grep -v vendor/src/ | tee /dev/stderr)" +test -z "$(gofmt -s -l . | grep -v -E 'vendor/(github.com|golang.org|gopkg.in)' | tee /dev/stderr)" ``` ### Run tests for frontend assets before commit diff --git a/build.go b/build.go index b881645b5fb..f9ef09ff5b9 100644 --- a/build.go +++ b/build.go @@ -25,11 +25,16 @@ var ( versionRe = regexp.MustCompile(`-[0-9]{1,3}-g[0-9a-f]{5,10}`) goarch string goos string + gocc string + gocxx string + cgo string + pkgArch string version string = "v1" // deb & rpm does not support semver so have to handle their version a little differently linuxPackageVersion string = "v1" linuxPackageIteration string = "" race bool + phjsToRelease string workingDir string binaries []string = []string{"grafana-server", "grafana-cli"} ) @@ -47,6 +52,11 @@ func main() { flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH") flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS") + flag.StringVar(&gocc, "cc", "", "CC") + flag.StringVar(&gocxx, "cxx", "", "CXX") + flag.StringVar(&cgo, "cgo-enabled", "", "CGO_ENABLED") + flag.StringVar(&pkgArch, "pkg-arch", "", "PKG ARCH") + flag.StringVar(&phjsToRelease, "phjs", "", "PhantomJS binary") flag.BoolVar(&race, "race", race, "Use race detector") flag.Parse() @@ -73,15 +83,15 @@ func main() { grunt("test") case "package": - grunt("release", fmt.Sprintf("--pkgVer=%v-%v", linuxPackageVersion, linuxPackageIteration)) + grunt(gruntBuildArg("release")...) createLinuxPackages() case "pkg-rpm": - grunt("release") + grunt(gruntBuildArg("release")...) createRpmPackages() case "pkg-deb": - grunt("release") + grunt(gruntBuildArg("release")...) createDebPackages() case "latest": @@ -258,6 +268,10 @@ func createPackage(options linuxPackageOptions) { "-p", "./dist", } + if pkgArch != "" { + args = append(args, "-a", pkgArch) + } + if linuxPackageIteration != "" { args = append(args, "--iteration", linuxPackageIteration) } @@ -307,9 +321,20 @@ func grunt(params ...string) { runPrint("./node_modules/.bin/grunt", params...) } +func gruntBuildArg(task string) []string { + args := []string{task, fmt.Sprintf("--pkgVer=%v-%v", linuxPackageVersion, linuxPackageIteration)} + if pkgArch != "" { + args = append(args, fmt.Sprintf("--arch=%v", pkgArch)) + } + if phjsToRelease != "" { + args = append(args, fmt.Sprintf("--phjsToRelease=%v", phjsToRelease)) + } + return args +} + func setup() { runPrint("go", "get", "-v", "github.com/kardianos/govendor") - runPrint("go", "get", "-v", "github.com/blang/semver") + runPrint("go", "get", "-v", "github.com/blang/semver") runPrint("go", "get", "-v", "github.com/mattn/go-sqlite3") runPrint("go", "install", "-v", "github.com/mattn/go-sqlite3") } @@ -382,6 +407,15 @@ func setBuildEnv() { if goarch == "386" { os.Setenv("GO386", "387") } + if cgo != "" { + os.Setenv("CGO_ENABLED", cgo) + } + if gocc != "" { + os.Setenv("CC", gocc) + } + if gocxx != "" { + os.Setenv("CXX", gocxx) + } } func getGitSha() string { From 699c515369ef53bd9fdbcd810a5b573d5e395c28 Mon Sep 17 00:00:00 2001 From: fg2it Date: Sun, 18 Sep 2016 11:45:46 +0000 Subject: [PATCH 4/4] enforce unconditional copy --- tasks/options/phantomjs.js | 45 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/tasks/options/phantomjs.js b/tasks/options/phantomjs.js index 83a7b502f65..ab3bd072652 100644 --- a/tasks/options/phantomjs.js +++ b/tasks/options/phantomjs.js @@ -1,38 +1,33 @@ module.exports = function(config,grunt) { 'use strict'; - grunt.registerTask('phantomjs', 'Copy phantomjs binary from node', function() { + grunt.registerTask('phantomjs', 'Copy phantomjs binary to vendor/', function() { var dest = './vendor/phantomjs/phantomjs'; var confDir = './node_modules/phantomjs-prebuilt/lib/'; - if (!grunt.file.exists(dest)){ + src = config.phjs - src = config.phjs + if (!src){ + var m=grunt.file.read(confDir+"location.js") + var src=/= \"([^\"]*)\"/.exec(m)[1]; - if (!src){ - var m=grunt.file.read(confDir+"location.js") - var src=/= \"([^\"]*)\"/.exec(m)[1]; - - if (!grunt.file.isPathAbsolute(src)) { - src = confDir+src; - } + if (!grunt.file.isPathAbsolute(src)) { + src = confDir+src; } - - try { - grunt.config('copy.phantom_bin', { - src: src, - dest: dest, - options: { mode: true}, - }); - grunt.task.run('copy:phantom_bin'); - } catch (err) { - grunt.verbose.writeln(err); - grunt.fail.warn('No working Phantomjs binary available') - } - - } else { - grunt.log.writeln('Phantomjs already imported from node'); } + + try { + grunt.config('copy.phantom_bin', { + src: src, + dest: dest, + options: { mode: true}, + }); + grunt.task.run('copy:phantom_bin'); + } catch (err) { + grunt.verbose.writeln(err); + grunt.fail.warn('No working Phantomjs binary available') + } + }); };