diff --git a/golang-macros.rb b/golang-macros.rb deleted file mode 100755 index 57841ed..0000000 --- a/golang-macros.rb +++ /dev/null @@ -1,248 +0,0 @@ -#!/usr/bin/env ruby - -require 'fileutils' -require 'securerandom' -require 'find' -require File.join(File.dirname(__FILE__),'golang/rpmsysinfo.rb') -require File.join(File.dirname(__FILE__),'golang/opts.rb') -require File.join(File.dirname(__FILE__),'golang/filelists.rb') -require File.join(File.dirname(__FILE__),'golang/cli.rb') -include RpmSysinfo -include Opts -include Filelists -include CLI - -# GLOBAL RPM MACROS - -$builddir = RpmSysinfo.get_builddir -$buildroot = RpmSysinfo.get_buildroot -$libdir = RpmSysinfo.get_libdir -$go_arch = RpmSysinfo.get_go_arch -$go_contribdir = RpmSysinfo.get_go_contribdir -$go_contribsrcdir = RpmSysinfo.get_go_contribsrcdir -$go_tooldir = RpmSysinfo.get_go_tooldir - -# ARGV[0], the called method itself -if ARGV[0] == "--arch" - - puts $go_arch - -elsif ARGV[0] == "--prep" - - puts "Preparation Stage:\n" - - # ARGV[1] the import path - if ARGV[1] == nil - puts "[ERROR]Empty IMPORTPATH! Please specify a valid one.\n" - else - gopath = $builddir + "/go" - puts "GOPATH set to: " + gopath + "\n" - - importpath = ARGV[1] - puts "IMPORTPATH set to: " + importpath + "\n" - - # export IMPORTPATH to a temp file, as ruby can't export system environment variables - # like shell scripts - File.open("/tmp/importpath.txt","w:UTF-8") do |f| - f.puts(importpath) - end - - # return current directory name, eg: ruby-2.2.4 - dir = File.basename(Dir.pwd) - destination = gopath + "/src/" + importpath - puts "Creating " + destination + "\n" - FileUtils.mkdir_p(destination) - - # copy everything to destination - puts "Copying everything under " + $builddir + "/" + dir + " to " + destination + " :\n" - Dir.glob($builddir + "/" + dir + "/*").each do |f| - puts "Copying " + f + "\n" - FileUtils.cp_r(f, File.join(destination, File.basename(f))) - end - puts "Files are moved!\n" - - # create target directories - puts "Creating directory for binaries " + $buildroot + "/usr/bin" + "\n" - FileUtils.mkdir_p($buildroot + "/usr/bin") - puts "Creating directory for contrib " + $buildroot + $go_contribdir + "\n" - FileUtils.mkdir_p($buildroot + $go_contribdir) - puts "Creating directory for source " + $buildroot + $go_contribsrcdir + "\n" - FileUtils.mkdir_p($buildroot + $go_contribsrcdir) - puts "Creating directory for tool " + $buildroot + $go_tooldir + "\n" - FileUtils.mkdir_p($buildroot + $go_tooldir) - end - - puts "Preparation Finished!\n" - -elsif ARGV[0] == "--build" - - puts "Build stage:\n" - - gopath = $builddir + "/go:" + $libdir + "/go/contrib" - gobin = $builddir + "/go/bin" - buildflags = "-s -v -p 4 -x" - - # get importpath from /tmp/importpath.txt saved by prep() - importpath = open("/tmp/importpath.txt","r:UTF-8").gets.strip! - - opts = Opts.get_opts - mods = Opts.get_mods - extraflags = "" - - unless opts.empty? - if opts.include?("--with-buildid") - buildid = "0x" + SecureRandom.hex(20) - # whitespace is important! - extraflags = extraflags + ' -ldflags "-B ' + buildid + '"' - opts.delete("--with-buildid") - end - - opts.each do |o| - extraflags = extraflags + " #{o}" - end - end - - # MODs: nil, "...", "/...", "foo...", "foo/...", "foo bar", "foo bar... baz" and etc - if mods.empty? - CLI.run({"GOPATH"=>gopath,"GOBIN"=>gobin}, "go install #{extraflags} #{buildflags} #{importpath}") - else - for mod in mods do - if mod == "..." - CLI.run({"GOPATH"=>gopath,"GOBIN"=>gobin}, "go install #{extraflags} #{buildflags} #{importpath}...") - break - else - CLI.run({"GOPATH"=>gopath,"GOBIN"=>gobin}, "go install #{extraflags} #{buildflags} #{importpath}/#{mod}") - end - end - end - - puts "Build Finished!\n" - -elsif ARGV[0] == "--install" - - puts "Installation stage:\n" - - # check exitstatus - File.open("/tmp/exitstatus.txt","r:UTF-8") {|f| abort "Previous stage failed! Abort!" if f.read != "0\n" } - - unless Dir["#{$builddir}/go/pkg/*"].empty? - puts "Copying generated stuff to " + $buildroot + $go_contribdir - Dir.glob($builddir + "/go/pkg/linux_" + $go_arch + "/*").each do |f| - puts "Copying " + f - FileUtils.cp_r(f, $buildroot + $go_contribdir) - end - puts "Done!" - end - - unless Dir["#{$builddir}/go/bin/*"].empty? - puts "Copyig binaries to " + $buildroot + "/usr/bin" - Dir.glob($builddir + "/go/bin/*").each do |f| - puts "Copying " + f - FileUtils.chmod_R(0755,f) - FileUtils.cp_r(f,$buildroot + "/usr/bin") - end - puts "Done!" - end - - puts "Install finished!\n" - -elsif ARGV[0] == "--source" - - puts "Source package creation:" - - # check exitstatus - File.open("/tmp/exitstatus.txt","r:UTF-8") {|f| abort "Previous stage failed! Abort!" if f.read != "0\n" } - - puts "This will copy all *.go files in #{$builddir}/go/src, but resource files needed are still not copyed" - - Find.find($builddir + "/go/src") do |f| - unless FileTest.directory?(f) - if f.index(/\.go$/) - puts "Copying " + f - FileUtils.chmod_R(0644,f) - - # create the same hierarchy - dir = $buildroot + $go_contribsrcdir + f.gsub($builddir + "/go/src",'') - dir1 = dir.gsub(File.basename(dir),'') - FileUtils.mkdir_p(dir1) - FileUtils.install(f,dir1) - end - end - end - - puts "Source package created!" - -elsif ARGV[0] == "--fix" - - puts "Fixing stuff..." - - # check exitstatus - File.open("/tmp/exitstatus.txt","r:UTF-8") {|f| abort "Previous stage failed! Abort!" if f.read != "0\n" } - - # only "--fix" is given, no other parameters - if ARGV.length == 1 - puts "[ERROR]gofix: please specify a valid importpath, see: go help fix" - else - gopath = $builddir + "/go" - CLI.run({"GOPATH"=>gopath},"go fix #{ARGV[1]}...") - end - - puts "Fixed!" - -elsif ARGV[0] == "--test" - - puts "Testing codes..." - - # check exitstatus - File.open("/tmp/exitstatus.txt","r:UTF-8") {|f| abort "Previous stage failed! Abort!" if f.read != "0\n" } - - # only "--test" is given, no other parameters - if ARGV.length == 1 - puts "[ERROR]gotest: please specify a valid importpath, see: go help test" - else - gopath = $builddir + "/go:" + $libdir + "/go/contrib" - CLI.run({"GOPATH"=>gopath}, "go test -x #{ARGV[1]}...") - end - - puts "Test passed!" - -# generate filelist for go_contribdir go_contribdir_dir -elsif ARGV[0] == "--filelist" - - puts "Processing filelists..." - - # check exitstatus - File.open("/tmp/exitstatus.txt","r:UTF-8") {|f| abort "Previous stage failed! Abort!" if f.read != "0\n" } - - opts = Opts.get_opts - excludes = Opts.get_mods[0] - # two directories, one is /BUILD/go. reject it, returns array with 1 element. - builddirs = Dir.glob($builddir + "/*").reject! { |f| f == $builddir + "/go" } - builddir = builddirs[0] - - # find shared build from linux_amd64_dynlink - if opts.include?("--shared") - Filelists.new($buildroot + $go_contribdir + "_dynlink", builddir + "/shared.lst") - Filelists.new($buildroot + "/usr/bin", builddir + "/shared.lst") - Filelists.new($buildroot + $go_tooldir,builddir + "/shared.lst") - Filelists.exclude(builddir + "/shared.lst",excludes) - # process for -source sub-package - elsif opts.include?("--source") - Filelists.new($buildroot + $go_contribsrcdir, builddir + "/source.lst") - Filelists.exclude(builddir + "/source.lst",excludes) - # default for main package, static build - else - Filelists.new($buildroot + $go_contribdir,builddir + "/file.lst") - Filelists.new($buildroot + "/usr/bin", builddir + "/file.lst") - Filelists.new($buildroot + $go_tooldir,builddir + "/file.lst") - Filelists.exclude(builddir + "/file.lst",excludes) - end - - puts "Filelists created!" - -else - - puts "Please specify a valid method: --prep, --build, --install, --fix, --test, --source, --filelist" - -end - diff --git a/golang.prov b/golang.prov index d46db76..978c420 100755 --- a/golang.prov +++ b/golang.prov @@ -5,20 +5,22 @@ include RpmSysinfo buildroot = RpmSysinfo.get_buildroot contribdir = RpmSysinfo.get_go_contribdir +contribsrcdir = RpmSysinfo.get_go_contribsrcdir importpath = RpmSysinfo.get_go_importpath # read stdin for filelist rpm feeds us for a (sub) package filelist = [] -prefix = buildroot + contribdir + "/" + ARGF.each do |l| - # if line has "*.a" - # buildroot + contribdir + golang.org/x/text/collate/colltab.a - filelist << l.gsub(prefix,'').strip! if ( l.index(".a\n") && ! l.gsub(prefix + importpath,'').index(/example|test/) ) + if File.exist?("/tmp/shared") + prefix = buildroot + contribdir + "/" + filelist << l.gsub(prefix,'').strip! if ( l.index(".a\n") && ! l.gsub(prefix + importpath,'').index(/example|test/) ) + else + prefix = buildroot + contribsrcdir + "/" + filelist << l.gsub(prefix,'').strip! if ( l.index(".go\n") && ! l.gsub(prefix + importpath, '').index(/example|test/) ) + end end -# filelist: -# golang.org/x/text/collate/colltab.a - provides = [] unless filelist.empty? then @@ -26,19 +28,21 @@ unless filelist.empty? then provides << "golang(" + importpath + ")" filelist.each do |f| - provides << "golang(" + f.gsub(".a","") + ")" + if File.exist?("/tmp/shared") + provides << "golang(" + f.gsub(".a","") + ")" + else + # match the last "/" and following bits, will return the direcctory + provides << "golang(" + f.gsub(/\/(?:.(?!\/))+$/,'') + ")" + end end uni = provides.uniq! unless uni == nil - uni.each {|p| puts p} - else - provides.each {|p| puts p} - end end + diff --git a/golang.rb b/golang.rb new file mode 100755 index 0000000..5c96cea --- /dev/null +++ b/golang.rb @@ -0,0 +1,307 @@ +#!/usr/bin/env ruby + +require 'fileutils' +require 'securerandom' +require 'find' +require File.join(File.dirname(__FILE__),'golang/rpmsysinfo.rb') +require File.join(File.dirname(__FILE__),'golang/opts.rb') +require File.join(File.dirname(__FILE__),'golang/filelists.rb') +require File.join(File.dirname(__FILE__),'golang/cli.rb') +include RpmSysinfo +include Opts +include Filelists +include CLI + +# GLOBAL RPM MACROS + +$builddir = RpmSysinfo.get_builddir +$buildroot = RpmSysinfo.get_buildroot +$libdir = RpmSysinfo.get_libdir +$go_arch = RpmSysinfo.get_go_arch +$go_contribdir = RpmSysinfo.get_go_contribdir +$go_contribsrcdir = RpmSysinfo.get_go_contribsrcdir +$go_tooldir = RpmSysinfo.get_go_tooldir + +def goprep(importpath=nil) + puts "Preparation Stage:\n" + if importpath.nil? + puts "[ERROR]Empty IMPORTPATH! Please specify a valid one.\n" + else + gopath = $builddir + "/go" + # return current directory name, eg: ruby-2.2.4 + dir = File.basename(Dir.pwd) + destination = gopath + "/src/" + importpath + + puts "GOPATH set to: " + gopath + "\n" + + puts "IMPORTPATH set to: " + importpath + "\n" + # export IMPORTPATH to a temp file, as ruby can't export system environment variables + # like shell scripts + open("/tmp/importpath","w:UTF-8") { |f| f.puts(importpath) } + + puts "Creating " + destination + "\n" + FileUtils.mkdir_p(destination) + puts "Creating GOBIN directory\n" + FileUtils.mkdir_p(gopath + "/bin") + + # copy everything to destination + puts "Copying everything under " + $builddir + "/" + dir + " to " + destination + " :\n" + Dir.glob($builddir + "/" + dir + "/*").each do |f| + puts "Copying " + f + "\n" + FileUtils.cp_r(f, File.join(destination, File.basename(f))) + end + puts "Files are moved!\n" + + # create target directories + puts "Creating directory for binaries " + $buildroot + "/usr/bin" + "\n" + FileUtils.mkdir_p($buildroot + "/usr/bin") + puts "Creating directory for contrib " + $buildroot + $go_contribdir + "\n" + FileUtils.mkdir_p($buildroot + $go_contribdir) + puts "Creating directory for source " + $buildroot + $go_contribsrcdir + "\n" + FileUtils.mkdir_p($buildroot + $go_contribsrcdir) + puts "Creating directory for tool " + $buildroot + $go_tooldir + "\n" + FileUtils.mkdir_p($buildroot + $go_tooldir) + puts "Preparation Finished!\n" + end +end + +def gobuild() + puts "Build stage:\n" + gopath = $builddir + "/go:" + $libdir + "/go/contrib" + gobin = $builddir + "/go/bin" + buildflags = "-s -v -p 4 -x" + # get importpath from /tmp/importpath saved by prep() + importpath = open("/tmp/importpath","r:UTF-8").gets.strip! + opts = Opts.get_opts + mods = Opts.get_mods + extraflags = String.new + sharedflags = " -buildmode=shared -linkshared " + cmd = "build" + + unless opts.empty? + if opts.include?("--with-buildid") + buildid = "0x" + SecureRandom.hex(20) + # whitespace is important! + extraflags = extraflags + ' -ldflags "-B ' + buildid + '"' + opts.delete("--with-buildid") + end + if opts.include?("--enable-shared") + extraflags = extraflags + sharedflags + opts.delete("--enable-shared") + # touch /tmp/shared for indentification of shared build later + FileUtils.touch "/tmp/shared" + # change build command to 'go install' + cmd = "install" + end + opts.each do |o| + extraflags = extraflags + " #{o}" + end + end + + # go build will leave binaries in currently directory, save the contents of current directory. + current = Array.new + Dir.glob(Dir.pwd + "/*") {|f| current << f} + + # MODs: nil, "...", "/...", "foo...", "foo/...", "foo bar", "foo bar... baz" and etc + if mods.empty? + CLI.run({"GOPATH"=>gopath,"GOBIN"=>gobin}, "go #{cmd} #{extraflags} #{buildflags} #{importpath}") + else + for mod in mods do + if mod == "..." + CLI.run({"GOPATH"=>gopath,"GOBIN"=>gobin}, "go #{cmd} #{extraflags} #{buildflags} #{importpath}") + Dir.glob($builddir + "/go/src/" + importpath + "/**/*") do |d| + if File.directory?(d) + buildable = false + Dir.glob(d + "/*") do |f| + if f.index(/\.go$/) + buildable = true + break + end + end + CLI.run({"GOPATH"=>gopath,"GOBIN"=>gobin}, "go #{cmd} #{extraflags} #{buildflags} " + d.gsub($builddir + "/go/src/",'')) if buildable + end + end + break + else + CLI.run({"GOPATH"=>gopath,"GOBIN"=>gobin}, "go #{cmd} #{extraflags} #{buildflags} #{importpath}/#{mod}") + end + end + end + + # go build will leave binaries in current directory, copy them to $GOBIN + currentnew = Array.new + Dir.glob(Dir.pwd + "/*") {|f| currentnew << f} + diff = currentnew - current + diff.each do |f| + p f + FileUtils.install(f,gobin + "/") + end + + puts "Build Finished!\n" +end + +def goinstall() + puts "Installation stage:\n" + # check previous exitstatus + abort "Build stage failed! Abort!" if File.exist?("/tmp/failed") + + importpath = open("/tmp/importpath","r:UTF-8").gets.strip! + + # static: if there's any binary inside $GOBIN, which indicates there's a main function somewhere inside the source code, + # then it is a Go program that we don't need to distribute its source codes to work as a build dependency. + # then we make it optional through gosource() + # shared: we'll distribute its built codes (libraries) + if File.exist? "/tmp/shared" + unless Dir[$builddir + "/go/pkg/*"].empty? + # TODO: shared stuff + end + elsif Dir[$builddir + "/go/bin/*"].empty? + puts "This will copy all *.go files in #{$builddir}/go/src, but resource files needed are still not copyed" + Find.find($builddir + "/go/src") do |f| + unless FileTest.directory?(f) + # don't install test files + if f.index(/\.go$/) && ! f.gsub(importpath,'').index(/(example|test)/) + puts "Copying " + f + FileUtils.chmod_R(0644,f) + # create the same hierarchy + dir = $buildroot + $go_contribsrcdir + f.gsub($builddir + "/go/src",'') + dir1 = dir.gsub(File.basename(dir),'') + FileUtils.mkdir_p(dir1) + FileUtils.install(f,dir1) + end + end + end + puts "Done!" + end + + unless Dir[$builddir + "/go/bin/*"].empty? + puts "Copyig golang binaries to " + $buildroot + "/usr/bin" + Dir.glob($builddir + "/go/bin/*").each do |f| + puts "Copying binary" + f + FileUtils.chmod_R(0755,f) + FileUtils.cp_r(f,$buildroot + "/usr/bin") + end + puts "Done!" + end + + puts "Install finished!\n" +end + +def gosource() + puts "Source package creation:" + # check previous exitstatus + abort "Install stage failed! Abort!" if File.exist?("/tmp/failed") + + if ! Dir[$builddir + "/go/bin/*"].empty? || File.exist?("/tmp/shared") + puts "This will copy all *.go files in #{$builddir}/go/src, but resource files needed are still not copyed" + Find.find($builddir + "/go/src") do |f| + unless FileTest.directory?(f) + if f.index(/\.go$/) + puts "Copying " + f + FileUtils.chmod_R(0644,f) + # create the same hierarchy + dir = $buildroot + $go_contribsrcdir + f.gsub($builddir + "/go/src",'') + dir1 = dir.gsub(File.basename(dir),'') + FileUtils.mkdir_p(dir1) + FileUtils.install(f,dir1) + end + end + end + else + puts "gosource is only meaningful for Go programs that have binaries inside /usr/bin," + puts "or shared builds that have .shlibname suffix. because currently go source codes" + puts "are distributed by default for static builds. consider remove it from specfile." + end + + puts "Source package created!" +end + +def gofix() + puts "Fixing stuff..." + # check previous exitstatus + abort "Previous stage failed! Abort!" if File.exist?("/tmp/failed") + # "--fix" should be given without other parameters + if ARGV.length <= 1 + puts "[ERROR]gofix: please specify a valid importpath, see: go help fix" + else + gopath = $builddir + "/go" + CLI.run({"GOPATH"=>gopath},"go fix #{ARGV[1]}...") + end + puts "Fixed!" +end + +def gotest() + puts "Testing codes..." + # check previous exitstatus + abort "Previous stage failed! Abort!" if File.exist?("/tmp/failed") + # "--test" should be given without other parameters + if ARGV.length <= 1 + puts "[ERROR]gotest: please specify a valid importpath, see: go help test" + else + gopath = $builddir + "/go:" + $libdir + "/go/contrib" + CLI.run({"GOPATH"=>gopath}, "go test -x #{ARGV[1]}...") + end + puts "Test passed!" +end + +def gofiles() + puts "Processing filelists..." + # check previous exitstatus + abort "Previous stage failed! Abort!" if File.exist?("/tmp/failed") + + opts = Opts.get_opts + excludes = Opts.get_mods[0] + # two directories, one is /BUILD/go. reject it, returns array with 1 element. + builddirs = Dir.glob($builddir + "/*").reject! { |f| f == $builddir + "/go" } + builddir = builddirs[0] + + # find shared build from linux_amd64_dynlink + if opts.include?("--enable-shared") + Filelists.new($buildroot + $go_contribdir + "_dynlink", builddir + "/shared.lst") + Filelists.new($buildroot + "/usr/bin", builddir + "/shared.lst") + Filelists.new($buildroot + $go_tooldir,builddir + "/shared.lst") + Filelists.exclude(builddir + "/shared.lst",excludes) + # process for -source sub-package + elsif opts.include?("--source") + if ! Dir[$builddir + "/go/bin/*"].empty? || File.exist?("/tmp/shared") + Filelists.new($buildroot + $go_contribsrcdir, builddir + "/source.lst") + Filelists.exclude(builddir + "/source.lst",excludes) + else + puts "'go_filelist --source' is only meaningful for Go programs that have binaries inside /usr/bin," + puts "or shared builds that have .shlibname suffix. because currently go source codes" + puts "are distributed by default for static builds. consider remove it from specfile." + end + # default for main package, static build + else + if Dir[$builddir + "/go/bin/*"].empty? + Filelists.new($buildroot + $go_contribsrcdir,builddir + "/file.lst") + end + Filelists.new($buildroot + "/usr/bin", builddir + "/file.lst") + Filelists.new($buildroot + $go_tooldir,builddir + "/file.lst") + Filelists.exclude(builddir + "/file.lst",excludes) + end + puts "Filelists created!" +end + +# ARGV[0], the called method itself +if ARGV[0] == "--arch" + puts $go_arch +elsif ARGV[0] == "--prep" + # ARGV[1] the import path or nil + goprep(ARGV[1]) +elsif ARGV[0] == "--build" + gobuild() +elsif ARGV[0] == "--install" + goinstall() +elsif ARGV[0] == "--source" + gosource() +elsif ARGV[0] == "--fix" + gofix() +elsif ARGV[0] == "--test" + gotest() +# generate filelist for go_contribdir go_contribdir_dir +elsif ARGV[0] == "--filelist" + gofiles() +else + puts "Please specify a valid method: --prep, --build, --install, --fix, --test, --source, --filelist" +end diff --git a/golang.req b/golang.req index bb71d03..fa26bd2 100755 --- a/golang.req +++ b/golang.req @@ -1,11 +1,25 @@ #!/usr/bin/env ruby +if File.exist? "/tmp/shared" + require '/usr/lib/rpm/golang/rpmsysinfo.rb' include RpmSysinfo buildroot = RpmSysinfo.get_buildroot contribdir = RpmSysinfo.get_go_contribdir importpath = RpmSysinfo.get_go_importpath +def go_get_version() + IO.popen("go version") do |process| + process.each_line do |l| + # "go version go1.6.1 linux/amd64" + version_re = /^go version go([0-9]\.[0-9])(\.[0-9])?\s+([^\/]+)\/(.*)$/ + md = version_re.match(l.chomp) + # 1:"1.6" 2:".1" or nil 3:"linux" 4:"amd64" + return md[1] if md + end + end +end + # read stdin for filelist rpm feeds us for a (sub) package filelist = [] ARGF.each do |l| @@ -21,6 +35,9 @@ end requires = [] unless filelist.empty? then + + requires << "golang(API) = " + go_get_version() + filelist.each do |f| # unarchive .a system("ar -x #{f} __.PKGDEF") @@ -50,3 +67,5 @@ unless filelist.empty? then end end + +end diff --git a/golang/cli.rb b/golang/cli.rb index 65081d8..4161767 100644 --- a/golang/cli.rb +++ b/golang/cli.rb @@ -1,18 +1,8 @@ module CLI + require 'fileutils' require 'timeout' - def write_status(status) - file = "/tmp/exitstatus.txt" - mode = "w:UTF-8" - if status == 0 - File.open(file,mode) {|f| f.puts(0)} - else - File.open(file,mode) {|f| f.puts(1)} - abort "[ERROR]Go command failed! Please check." - end - end - # popen in 1.8 doesn't support env hash def popen_env(hash, cmd) # set ENV separately @@ -24,17 +14,20 @@ def popen_env(hash, cmd) # set timeout 300s, because go install takes # lots of time sometimes begin - Timeout.timeout(300) do + Timeout.timeout(300) do @pipe = IO.popen(cmd) Process.wait(@pipe.pid) end rescue Timeout::Error Process.kill(9,@pipe.pid) # collect status - Process.wait(@pipe.pid) + Process.wait(@pipe.pid) end - write_status($?) + if $? == 1 + FileUtils.touch "/tmp/failed" + abort '[ERROR]Go command failed! Please check.' + end end @@ -46,10 +39,12 @@ def self.run(env={},cmd="") popen_env(env,cmd) {|f| f.each_line {|l| puts l}} else IO.popen(env,cmd) {|f| f.each_line {|l| puts l}} - write_status($?) + if $? != 0 + FileUtils.touch "/tmp/failed" + abort "[ERROR]Go command faild! Please check." + end end end end - diff --git a/golang/rpmsysinfo.rb b/golang/rpmsysinfo.rb index 3933287..9d5fcec 100644 --- a/golang/rpmsysinfo.rb +++ b/golang/rpmsysinfo.rb @@ -2,6 +2,18 @@ module RpmSysinfo require 'rbconfig' + if File.directory?("/usr/src/packages") & File.writable?("/usr/src/packages") + @@topdir = "/usr/src/packages" + else + @@topdir = ENV["HOME"] + "/rpmbuild" + end + + @@buildroot = Dir.glob(@@topdir + "/BUILDROOT/*")[0] + + # sometimes buildroot locates in tmppath/name-version-build + + @@buildroot = Dir.glob("/var/tmp/*-build")[0] if @@buildroot == nil + # x86_64-(gnu|linux|blabla...) @@rbarch = RUBY_PLATFORM.gsub(/-.*$/,"") # architectures are defined in /usr/lib/rpm/macros @@ -31,13 +43,13 @@ module RpmSysinfo def self.get_builddir - return ENV["RPM_BUILD_DIR"] + return @@topdir + "/BUILD" end def self.get_buildroot - return ENV["RPM_BUILD_ROOT"] + return @@buildroot end @@ -75,8 +87,8 @@ def self.get_go_importpath # this funtion is used in golang.prov/req only # called after %go_prep - # so the simplest method is to read /tmp/importpath.txt - return open("/tmp/importpath.txt","r:UTF-8").gets.strip! + # so the simplest method is to read /tmp/importpath + return open("/tmp/importpath","r:UTF-8").gets.strip! end diff --git a/macros.go b/macros.go index e5b9948..7ec4bb5 100644 --- a/macros.go +++ b/macros.go @@ -38,7 +38,7 @@ Provides: %{name}-devel-static = %{version} # Prepare the expected Go package build environement. # We need a $GOPATH: go help gopath # We need a valid importpath: go help packages -%goprep %{_prefix}/lib/rpm/golang-macros.rb --prep +%goprep %{_prefix}/lib/rpm/golang.rb --prep # %%gobuild macro actually performs the command "go install", but the go # toolchain will install to the $GOPATH which allows us then customise the final @@ -88,18 +88,18 @@ Provides: %{name}-devel-static = %{version} # go install importpath/baz # # See: go help install, go help packages -%gobuild %{_prefix}/lib/rpm/golang-macros.rb --build +%gobuild %{_prefix}/lib/rpm/golang.rb --build # Install all compiled packages and binaries to the buildroot -%goinstall %{_prefix}/lib/rpm/golang-macros.rb --install +%goinstall %{_prefix}/lib/rpm/golang.rb --install -%gofix %{_prefix}/lib/rpm/golang-macros.rb --fix +%gofix %{_prefix}/lib/rpm/golang.rb --fix -%gotest %{_prefix}/lib/rpm/golang-macros.rb --test +%gotest %{_prefix}/lib/rpm/golang.rb --test -%gosrc %{_prefix}/lib/rpm/golang-macros.rb --source +%gosrc %{_prefix}/lib/rpm/golang.rb --source -%go_filelist %{_prefix}/lib/rpm/golang-macros.rb --filelist +%go_filelist %{_prefix}/lib/rpm/golang.rb --filelist # Template for source sub-package %gosrc_package(n:r:) \