From 47e6c49ae26bad4bfae9374bb0747f03b7bb6171 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 22 Jun 2023 14:24:19 +0200 Subject: [PATCH] Parse SET_HHVM_THIRD_PARTY_SOURCE_ARGS --- rakelib/hhvm.rake | 51 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/rakelib/hhvm.rake b/rakelib/hhvm.rake index cb6fc16..b7660b3 100644 --- a/rakelib/hhvm.rake +++ b/rakelib/hhvm.rake @@ -4,7 +4,48 @@ # frozen_string_literal: true +require 'pathname' + 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' task :bundled_dependencies, [:version] do |_, arguments| run_on_source arguments[:version] do |third_party| @@ -12,14 +53,10 @@ namespace :hhvm do next unless c_make_lists.exist? contents = c_make_lists.read - set_hhvm_start = contents.index 'SET_HHVM_THIRD_PARTY_SOURCE_ARGS(' - next if set_hhvm_start.nil? + rewritten_cmake = rewrite_set_hhvm_third_party_source_args contents + next if rewritten_cmake.nil? - line = contents[..set_hhvm_start].count "\n" - 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 + puts Open3.capture2('diff', '-Nur', c_make_lists.to_path, '-', stdin_data: rewritten_cmake).first end end