Skip to content

Commit

Permalink
Refactor/rework ruby raketasks part1 (SeleniumHQ#7562)
Browse files Browse the repository at this point in the history
Refactor/rework Ruby raketasks

* Simplify c.rb - dll builder method
* Refactor of c.rb to use non-regex methods where not required
* Syntax tweaks
* Minor syntax tweaks, removal of some monkeypatches which are no longer required / relevant
* Additional minor tweaks
* Minor tweaks to syntax in crazy-fun/main
* Massive tabbing fixes to crazy-fun/build_grammar.rb
* Undo simplification and fix up YodaCondition
* Add backwards compatible 'hack' whilst we're not in full OO mode
  • Loading branch information
luke-hill authored and p0deje committed Sep 17, 2019
1 parent 271ac61 commit aeda13d
Show file tree
Hide file tree
Showing 9 changed files with 713 additions and 742 deletions.
2 changes: 0 additions & 2 deletions rake-tasks/browsers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require 'rake-tasks/checks'

#:available => whether this browser is available on this computer. Defaults to true.

BROWSERS = {
'ff' => {
python: {
Expand Down
93 changes: 51 additions & 42 deletions rake-tasks/c.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
# C related tasks

require 'rake-tasks/files.rb'
require 'rake-tasks/files'

# Because this is created inside a main construct, accessors don't work shorthand
# So we'll define them long-hand and then revert to shorthand once we classify the
# files properly - Luke - Sep 2019
# attr_accessor :bitness

def bitness
@bitness
end

def bitness=(value)
@bitness = value
end


def dll(args)
deps = build_deps_(args[:deps])
result_array = Array(args[:out])

Array(args[:out]).each do |result|
result_array.each do |result|
out = "build/#{result}"

file out => build_deps_(args[:src]) + deps do
if out =~ /\.dll$/
msbuild_legacy(args[:solution], out, args[:prebuilt])
elsif out =~ /\.so$/
is_32_bit = args[:arch] != 'amd64'
gcc(args[:src], out, args[:args], args[:link_args], is_32_bit, args[:prebuilt])
else
puts "Cannot compile #{args[:out]}"
exit -1
end
end
compile_file(out, deps, args)

# TODO(simon): Yuck. Not Good Enough
task args[:name].to_s => out
Expand All @@ -27,65 +32,69 @@ def dll(args)
end
end

def msbuild_legacy(solution, out, prebuilt)
if msbuild_installed?
unless File.exist? out
sh "MSBuild.exe #{solution} /verbosity:q /target:Rebuild /property:Configuration=Release /property:Platform=x64", verbose: false
sh "MSBuild.exe #{solution} /verbosity:q /target:Rebuild /property:Configuration=Release /property:Platform=Win32", verbose: false
copy_to_prebuilt(out, prebuilt)
def compile_file(out, deps, args)
full_build_deps = "#{build_deps_(args[:src])}#{deps}"

file out => full_build_deps do
if out.end_with?('.dll')
msbuild_legacy(args[:solution], out, args[:prebuilt])
elsif out.end_with?('.so')
is_32_bit = args[:arch] != 'amd64'
self.bitness = is_32_bit
gcc(args[:src], out, args[:args], args[:link_args], args[:prebuilt])
else
puts "Cannot compile #{args[:out]}"
exit -1
end
else
copy_prebuilt(prebuilt, out)
end
end

def gcc(srcs, out, args, link_args, is_32_bit, prebuilt)
unless gcc?
copy_prebuilt(prebuilt, out)
return
def msbuild_legacy(solution, out, prebuilt)
return copy_prebuilt(prebuilt, out) unless msbuild_installed?

unless File.exist?(out)
sh "MSBuild.exe #{solution} /verbosity:q /target:Rebuild /property:Configuration=Release /property:Platform=x64", verbose: false
sh "MSBuild.exe #{solution} /verbosity:q /target:Rebuild /property:Configuration=Release /property:Platform=Win32", verbose: false
copy_to_prebuilt(out, prebuilt)
end
end

def gcc(srcs, out, args, link_args, prebuilt)
return copy_prebuilt(prebuilt, out) unless gcc?

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

mkdir_p obj_dir

is_cpp_code = false
srcs.each do |src|
ok = gccbuild_c(src, obj_dir, args, is_32_bit)
unless ok
copy_prebuilt(prebuilt, out)
return
end
is_cpp_code = true if src =~ /\.cpp$/
ok = gccbuild_c(src, obj_dir, args)
return copy_prebuilt(prebuilt, out) unless ok
is_cpp_code = true if src.end_with?('.cpp')
end

flags = '-Wall -shared -fPIC -Os -fshort-wchar '
flags += "-m#{bitness} "
flags = "-Wall -shared -fPIC -Os -fshort-wchar -m#{bitness}"
flags += " #{link_args} " if link_args

# 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
return copy_prebuilt(prebuilt, out)
end
sh linker_cmd do |link_ok|
return copy_prebuilt(prebuilt, out) unless link_ok
end

copy_to_prebuilt(out, prebuilt)

rm_rf "#{out}_temp"
end

def gccbuild_c(src_file, obj_dir, args, is_32_bit)
bitness = is_32_bit ? '32' : '64'
compiler = src_file =~ /\.c$/ ? 'gcc' : 'g++'
def gccbuild_c(src_file, obj_dir, args)
compiler = src_file.end_with?('.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 += " -m#{bitness}"
cmd += args if args
sh cmd do |ok, _res|
sh cmd do |ok|
return puts 'Unable to build. Aborting compilation' unless ok
end
true
Expand Down
6 changes: 2 additions & 4 deletions rake-tasks/crazy_fun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize
end

def add_mapping(type_name, handler)
@mappings[type_name] = [] unless @mappings.key? type_name
@mappings[type_name] = [] unless @mappings.key?(type_name)

@mappings[type_name].push handler
end
Expand Down Expand Up @@ -60,9 +60,7 @@ def create_tasks(files)
puts "Parsing #{f}" if $DEBUG
outputs = BuildFile.new.parse_file(f)
outputs.each do |type|
unless @mappings.key? type.name
raise 'No mapping for type: ' + type.name
end
raise "No mapping for type: #{type.name}" unless @mappings.key?(type.name)

mappings = @mappings[type.name]
mappings.each do |mapping|
Expand Down
Loading

0 comments on commit aeda13d

Please sign in to comment.