-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathpreprocess.rb
28 lines (22 loc) · 1.02 KB
/
preprocess.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true
# Copyright (c) 2017, 2025 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 2.0, or
# GNU General Public License version 2, or
# GNU Lesser General Public License version 2.1.
require_relative '../truffle/truffle/cext_preprocessor'
require 'stringio'
file_name = ARGV.first
original_content = File.read(file_name)
output = Truffle::CExt::Preprocessor.patch(file_name, original_content, Dir.pwd)
if ENV['PREPROCESS_DEBUG'] && original_content != output
patched_file_name = "#{File.dirname file_name}/.#{File.basename file_name, '.*'}.patched#{File.extname file_name}"
File.write patched_file_name, output
$stderr.print `git diff --no-index --color -- #{file_name} #{patched_file_name}`
file_name = patched_file_name
end
expanded_path = File.expand_path(file_name)
$stdout.puts "#line 1 \"#{expanded_path}\""
$stdout.puts output