lib/makit/protoc.rb in makit-0.0.27 vs lib/makit/protoc.rb in makit-0.0.28

- old
+ new

@@ -1,6 +1,7 @@ # frozen_string_literal: true +require "pathname" # This module provides classes for the Makit gem. module Makit # This class provide methods for working with the system Environment. # @@ -72,16 +73,32 @@ FileUtils.mkdir_p(csharp_output_dir) unless Dir.exist?(csharp_output_dir) "protoc --#{language}_out=#{csharp_output_dir} #{proto_filename}".run end # language: charp, ruby, go, etc. - def self.generate_source_files(proto_source_dir, language, csharp_output_dir) - proto_files = get_proto_files_from_path(proto_source_dir) - proto_files.each { |proto| - namespace_dir = File.dirname(proto) - puts "Generating #{proto} in #{namespace_dir}" - FileUtils.mkdir_p("#{csharp_output_dir}/#{namespace_dir}") unless Dir.exist?("#{csharp_output_dir}/#{namespace_dir}") - "protoc --#{language}_out=#{csharp_output_dir}/#{namespace_dir} protos/#{proto}".run - } + def self.generate_source_files(proto_source_dir, language, output_dir) + debug = false + puts "Generating source files for #{language} in #{proto_source_dir} to #{output_dir}" if debug + FileUtils.mkdir_p(output_dir) unless Dir.exist?(output_dir) + + path_a = Pathname.new(proto_source_dir) + path_b = Pathname.new(output_dir) + output_relative_path = path_b.relative_path_from(path_a) + puts "output_relative_path: #{output_relative_path}" if debug + + Dir.chdir(proto_source_dir) do + Dir.glob("**/*.proto").each do |proto| + puts "Generating #{proto}" if debug + if (language == "csharp") + namespace_dir = File.dirname(proto) + output_dir = "#{output_relative_path}/#{namespace_dir}" + puts "Generating #{proto} in #{output_dir}" if debug + FileUtils.mkdir_p("#{output_dir}") unless Dir.exist?("#{output_dir}") + "protoc --csharp_out=#{output_dir} #{proto}".run + else + "protoc --#{language}_out=#{output_relative_path} #{proto}".run + end + end + end end end end