1#!/usr/bin/env ruby 2# Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15require "ostruct" 16require 'optparse' 17 18options = OpenStruct.new 19 20optparser = OptionParser.new do |opts| 21 opts.banner = 'Usage: gen.rb [options]' 22 23 opts.on('-d', '--data FILE', 'Source data (required)') 24 opts.on('-o', '--output FILE', 'Output file') 25 opts.on('-s', '--suffix STRING', 'Suffix for generated variable') 26 27 opts.on('-h', '--help', 'Prints this help') do 28 puts opts 29 exit 30 end 31end 32optparser.parse!(into: options) 33 34lines = File.readlines(options.data) 35lines.map! {|line| line.gsub(/#.*/, '').strip } 36lines = lines.join("") 37lines = "constexpr std::string_view PIPELINE#{options.suffix} = R\"__MAGIC__(#{lines})__MAGIC__\";" 38 39output = options.output ? File.open(File.expand_path(options.output), 'w') : $stdout 40output.write(lines) 41output.close 42