Parse SET_HHVM_THIRD_PARTY_SOURCE_ARGS

This commit is contained in:
Eugen Wissner 2023-06-22 14:24:19 +02:00
parent d63e657948
commit 47e6c49ae2
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0

View File

@ -4,7 +4,48 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'pathname'
namespace :hhvm do namespace :hhvm do
def filter_set_hhvm_third_party_source_args(tokens)
args = tokens[0]
allowed_arguments = tokens[1..].each_slice(2)
.filter do |key, _value|
!key.end_with?('_URL') && !key.end_with?('_HASH')
end
allowed_arguments
.flatten
.prepend(" #{args}")
.join("\n ")
end
def split_set_hhvm_third_party_source_args(section_content)
section_content
.split("\n")
.map do |line|
hash_index = line.index '#'
line = line[...hash_index] unless hash_index.nil?
line.strip
end
end
def rewrite_set_hhvm_third_party_source_args(contents)
set_hhvm_start = contents.index 'SET_HHVM_THIRD_PARTY_SOURCE_ARGS('
return nil if set_hhvm_start.nil?
section_contents = contents[set_hhvm_start + 'SET_HHVM_THIRD_PARTY_SOURCE_ARGS('.length..]
set_hhvm_end = section_contents.index ')'
lines = split_set_hhvm_third_party_source_args section_contents[...set_hhvm_end]
new_cmake_section = filter_set_hhvm_third_party_source_args lines.reject(&:blank?).join(' ').split
contents[...set_hhvm_start] +
"SET_HHVM_THIRD_PARTY_SOURCE_ARGS(\n#{new_cmake_section}\n)\n" +
section_contents[set_hhvm_end..]
end
desc 'Generates diffs with removed download URLs' desc 'Generates diffs with removed download URLs'
task :bundled_dependencies, [:version] do |_, arguments| task :bundled_dependencies, [:version] do |_, arguments|
run_on_source arguments[:version] do |third_party| run_on_source arguments[:version] do |third_party|
@ -12,14 +53,10 @@ namespace :hhvm do
next unless c_make_lists.exist? next unless c_make_lists.exist?
contents = c_make_lists.read contents = c_make_lists.read
set_hhvm_start = contents.index 'SET_HHVM_THIRD_PARTY_SOURCE_ARGS(' rewritten_cmake = rewrite_set_hhvm_third_party_source_args contents
next if set_hhvm_start.nil? next if rewritten_cmake.nil?
line = contents[..set_hhvm_start].count "\n" puts Open3.capture2('diff', '-Nur', c_make_lists.to_path, '-', stdin_data: rewritten_cmake).first
in_lines = contents.lines
4.times { in_lines.delete_at(line + 2) }
puts Open3.capture2('diff', '-Nur', c_make_lists.to_path, '-', stdin_data: in_lines.join).first
end end
end end