Skip to content
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

fix for SLE11SP3 #5

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
161 changes: 77 additions & 84 deletions golang-macros.rb → golang.rb
Expand Up @@ -22,34 +22,23 @@
$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"

def goprep(importpath=nil)
puts "Preparation Stage:\n"

# ARGV[1] the import path
if ARGV[1] == nil
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"

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
# like shell scripts
open("/tmp/importpath","w:UTF-8") { |f| f.puts(importpath) }

# 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)

Expand All @@ -62,32 +51,29 @@
puts "Files are moved!\n"

# create target directories
puts "Creating directory for binaries " + $buildroot + "/usr/bin" + "\n"
puts "Creating directory for binaries " + $buildroot + "/usr/bin" + "\n"
FileUtils.mkdir_p($buildroot + "/usr/bin")
puts "Creating directory for contrib " + $buildroot + $go_contribdir + "\n"
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

puts "Preparation Finished!\n"

elsif ARGV[0] == "--build"

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.txt saved by prep()
importpath = open("/tmp/importpath.txt","r:UTF-8").gets.strip!

# 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 = ""
extraflags = String.new
sharedflags = " -buildmode=shared -linkshared "

unless opts.empty?
if opts.include?("--with-buildid")
Expand All @@ -96,19 +82,22 @@
extraflags = extraflags + ' -ldflags "-B ' + buildid + '"'
opts.delete("--with-buildid")
end

if opts.include?("--enable-shared")
extraflags = extraflags + sharedflags
opts.delete("--enable-shared")
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}")
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}...")
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}")
Expand All @@ -117,16 +106,15 @@
end

puts "Build Finished!\n"
end

elsif ARGV[0] == "--install"

def goinstall()
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" }
# check previous exitstatus
abort "Build stage failed! Abort!" if File.exist?("/tmp/failed")

unless Dir["#{$builddir}/go/pkg/*"].empty?
puts "Copying generated stuff to " + $buildroot + $go_contribdir
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)
Expand All @@ -135,32 +123,29 @@
end

unless Dir["#{$builddir}/go/bin/*"].empty?
puts "Copyig binaries to " + $buildroot + "/usr/bin"
puts "Copyig golang binaries to " + $buildroot + "/usr/bin"
Dir.glob($builddir + "/go/bin/*").each do |f|
puts "Copying " + 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

elsif ARGV[0] == "--source"

def gosource()
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" }
# 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),'')
Expand All @@ -171,48 +156,40 @@
end

puts "Source package created!"
end

elsif ARGV[0] == "--fix"

def gofix()
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

# 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

elsif ARGV[0] == "--test"

def gotest()
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
# 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

# generate filelist for go_contribdir go_contribdir_dir
elsif ARGV[0] == "--filelist"

def gofiles()
puts "Processing filelists..."

# check exitstatus
File.open("/tmp/exitstatus.txt","r:UTF-8") {|f| abort "Previous stage failed! Abort!" if f.read != "0\n" }
# check previous exitstatus
abort "Previous stage failed! Abort!" if File.exist?("/tmp/failed")

opts = Opts.get_opts
excludes = Opts.get_mods[0]
Expand All @@ -221,7 +198,7 @@
builddir = builddirs[0]

# find shared build from linux_amd64_dynlink
if opts.include?("--shared")
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")
Expand All @@ -237,12 +214,28 @@
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

15 changes: 15 additions & 0 deletions golang.req
Expand Up @@ -6,6 +6,18 @@ 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|
Expand All @@ -21,6 +33,9 @@ end
requires = []

unless filelist.empty? then

requires << "golang(API) = " + go_get_version()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is still wrong, We don't have any runtime requirement for that, it's always buildtime requirement only.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I do respect you and this is not personal. but actually your style of collaboration...really...I can't fit.

I hate when I replied a lot, you didn't make any correction with strong evidence, and just told me "no it's not". then conversation certainly stopped.

About this commit. it's already been discussed here: https://lists.opensuse.org/opensuse-go/2016-06/msg00000.html. (the last reply came from you too, telling me to talking to someone I don't even know he's actually in the development talk, when I've got support from other objective contributors).

Please remember I'm the author of golang-packaging. If you guys can't make me figure out what you are going to achieve, it'll be really hard to make progress in this project. Because I can switch the Source to https://github.com/marguerite/golang-packaging any time.

Sorry for the inconvenince. But look, you didn't even tell me where I was wrong and I didn't know what you were talking about. How will our collaboration go on?

Marguerite

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I am stupid. but Linus style of collaboration has one fundamental fact that Linus is one of the major authors of the Kernel. this is not the case. I see little code that convince people. so it sounds to me like an outsider who don't have his hands dirty is pointing here and there without solid evidences and codes.

Or maybe, please, you can treat me as an idiot who hold the nuclear suitcase. You have to stop her from pressing the wrong button. That needs a lot. Not just a "No".

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really cool that you are pushing golang packaging forward! Seriously! But as I said, tools built with Golang generally don't have any runtime dependency, it got only build dependencies. That's the big cool thing on Go that you don't depend on any shared stuff. Build a single binary and that's it. But with that change we got the Go compiler as a runtime dependency which is a useless overhead for installing a package that got only a single binary without any dependencies.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't want to discourage your work, maybe we should just take the time to chat more interactively via IRC or even Mumble and write some mail with the outcome to the go mailinglist. I think that should be much more productive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @marguerite , nobody ever meant to offend or disregard your work. We are grateful for all the job you and the community did at packaging Go.

I might be wrong, but it looks like this change would cause all the kind of Go packages to require the Go compiler at runtime. This might be fine for static and shared libraries, but it would be useless for Go programs.

Would it be possible to rework this patch to avoid this issue?

As for the big picture about Go packaging, I'm currently writing a response to #4 but I'm being slowed down by other tasks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tboerger

Yes...I also think effective communication is a must...I can get your idea. "we don't need any runtime dependency for any golang binary". what confuse me is...have you extended the definition of "binary" to "any go compiled codes", that is, ".a"...and many other questions which I may have a different/wrong answer from my side...maybe I should send you an email with lists of my questions which can help us find common views....because, you know, we have different options on the same thing, and it is not Politics, the only reason I can think is I may stand on the non-existent soil. And you just didn't explain me, which push me into anxiety.

Marguerite

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flavio

Yes...it will drag requirement of go itself...I know this commit may be not "fine"...but actually I just want to pull the SLE_11_SP3 fix...I just don't know how to send a single commit separately...and, this commit is meaningful to me because in my branch I was implementing "buildmode=shared" and "buildmode=c-shared" and "linkshared" support. In that case, the dependency of go itself is useful...because the shared standard libraries (those .shlibname) are packaged in go itself. But my work just hang there...because there's a bug happened in our go (I'm not sure whether it's packaging or upstream), about which I sent an email to opensuse-go mailing list some days ago.

I promised on the mailing list that I'll require go itself only for shared built stuff. But since my shared build support is not finished. I certianlly don't know how to set these codes conditional.

And please reply to #4 when you're free...because I really didn't find the "strong evidences" that can prevent me from shipping prebuilt ".a" stuff...everyone is telling me "hey! people just use .go!", I know that. But logically it doesn't explain why I shouldn't use ".a". And I found myself a lot of "evidences" that ".a" could be used. we did that because we could do...and I think most of the people didn't think human-being can live on Mars, but that is what NASA is trying to do...:-D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi all. I just hope I can help a bit here... so the problem is that requiring golang(API) = VERSION is needed when packaging .a files , but it is a problem if we are packaging an executable (meaning it has a main function).

So, what we need is basically a way to distinguish the 2 cases.

Right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jordimassaguerpla It's easy to distinguish the 2 cases...executables locate in $GOBIN. it's easy to detect if there's any binary. but I think people from SUSE were talking about some fundamental changes: from shipping .a to .go. I call it fundamental because golang-packaging actually unpacks those .a to find Provides/Requires.


filelist.each do |f|
# unarchive .a
system("ar -x #{f} __.PKGDEF")
Expand Down
27 changes: 11 additions & 16 deletions 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
Expand All @@ -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

Expand All @@ -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