Skip to content

Commit

Permalink
Release version 14.10
Browse files Browse the repository at this point in the history
* don't find runtime requires for static builds
* distribute plain source code for static builds
  only binaries in /usr/bin will be distributed in
  compiled format.
  • Loading branch information
marguerite committed Aug 15, 2016
1 parent e4666c0 commit d9c5a8b
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 49 deletions.
28 changes: 16 additions & 12 deletions golang.prov
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,44 @@ 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

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

140 changes: 103 additions & 37 deletions golang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ def goprep(importpath=nil)

puts "IMPORTPATH set to: " + importpath + "\n"
# export IMPORTPATH to a temp file, as ruby can't export system environment variables
# like shell scripts
# 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"
Expand All @@ -66,14 +68,15 @@ def goprep(importpath=nil)
def gobuild()
puts "Build stage:\n"
gopath = $builddir + "/go:" + $libdir + "/go/contrib"
gobin = $builddir + "/go/bin"
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")
Expand All @@ -85,44 +88,93 @@ def gobuild()
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 install #{extraflags} #{buildflags} #{importpath}")
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 install #{extraflags} #{buildflags} #{importpath}/...")
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 install #{extraflags} #{buildflags} #{importpath}/#{mod}")
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")
abort "Build stage failed! Abort!" if File.exist?("/tmp/failed")

unless Dir["#{$builddir}/go/pkg/*"].empty?
puts "Copying golang modules 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)
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?
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
Expand All @@ -138,21 +190,27 @@ def goinstall()
def gosource()
puts "Source package creation:"
# check previous exitstatus
abort "Install stage failed! Abort!" if File.exist?("/tmp/failed")

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)
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!"
Expand All @@ -161,21 +219,21 @@ def gosource()
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
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
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")
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"
Expand All @@ -189,7 +247,7 @@ def gotest()
def gofiles()
puts "Processing filelists..."
# check previous exitstatus
abort "Previous stage failed! Abort!" if File.exist?("/tmp/failed")
abort "Previous stage failed! Abort!" if File.exist?("/tmp/failed")

opts = Opts.get_opts
excludes = Opts.get_mods[0]
Expand All @@ -205,11 +263,19 @@ def gofiles()
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)
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
Filelists.new($buildroot + $go_contribdir,builddir + "/file.lst")
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)
Expand All @@ -222,7 +288,7 @@ def gofiles()
puts $go_arch
elsif ARGV[0] == "--prep"
# ARGV[1] the import path or nil
goprep(ARGV[1])
goprep(ARGV[1])
elsif ARGV[0] == "--build"
gobuild()
elsif ARGV[0] == "--install"
Expand Down
4 changes: 4 additions & 0 deletions golang.req
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env ruby

if File.exist? "/tmp/shared"

require '/usr/lib/rpm/golang/rpmsysinfo.rb'
include RpmSysinfo
buildroot = RpmSysinfo.get_buildroot
Expand Down Expand Up @@ -65,3 +67,5 @@ unless filelist.empty? then
end

end

end

0 comments on commit d9c5a8b

Please sign in to comment.