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

Refactor/ruby rake tasks tidy #7551

Merged
merged 7 commits into from
Sep 11, 2019
Merged
Prev Previous commit
Next Next commit
Fix up some string interpolation improvements and compress some lines…
… down where appropriate
  • Loading branch information
luke-hill committed Sep 10, 2019
commit 310b44284950502258b1356fdf8be6d399e873b8
23 changes: 10 additions & 13 deletions rake-tasks/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def dll(args)
end

# TODO(simon): Yuck. Not Good Enough
task (args[:name]).to_s => out
task args[:name].to_s => out
task args[:out] => out
Rake::Task[args[:name]].out = out.to_s
end
Expand All @@ -45,7 +45,8 @@ def gcc(srcs, out, args, link_args, is_32_bit, prebuilt)
return
end

obj_dir = "#{out}_temp/obj" + (is_32_bit ? '32' : '64')
bitness = is_32_bit ? '32' : '64'
obj_dir = "#{out}_temp/obj#{bitness}"

mkdir_p obj_dir

Expand All @@ -60,17 +61,15 @@ def gcc(srcs, out, args, link_args, is_32_bit, prebuilt)
end

flags = '-Wall -shared -fPIC -Os -fshort-wchar '
flags += (is_32_bit ? '-m32 ' : '-m64 ')
flags += ' ' + link_args + ' ' if link_args
flags += "-m#{bitness} "
flags += " #{link_args} " if link_args

# if we've made it this far, try to link. If link fails,
# copy from prebuilt.
# if we've made it this far, try to link. If link fails, copy from prebuilt.
linker = is_cpp_code ? 'g++' : 'gcc'
linker_cmd = "#{linker} -o #{out} #{obj_dir}/*.o #{flags}"
sh linker_cmd do |link_ok, _res|
unless link_ok
copy_prebuilt(prebuilt, out)
return
return copy_prebuilt(prebuilt, out)
end
end

Expand All @@ -80,16 +79,14 @@ def gcc(srcs, out, args, link_args, is_32_bit, prebuilt)
end

def gccbuild_c(src_file, obj_dir, args, is_32_bit)
bitness = is_32_bit ? '32' : '64'
compiler = src_file =~ /\.c$/ ? 'gcc' : 'g++'
objname = src_file.split('/')[-1].sub(/\.c[p{2}]*?$/, '.o')
cmd = "#{compiler} #{src_file} -Wall -c -fshort-wchar -fPIC -o #{obj_dir}/#{objname} "
cmd += (is_32_bit ? ' -m32' : ' -m64')
cmd += " -m#{bitness}"
cmd += args if args
sh cmd do |ok, _res|
unless ok
puts 'Unable to build. Aborting compilation'
return false
end
return puts 'Unable to build. Aborting compilation' unless ok
end
true
end