bindgen icon indicating copy to clipboard operation
bindgen copied to clipboard

Better cxxflags setting in spec/clang/spec_helper.cr

Open docelic opened this issue 5 years ago • 0 comments

spec_helper.cr needs access to the cxxflags variable which is determined when the clang tool (subdir clang/ runs). Currently, the tool dumps variables to Makefile.variables, in Makefile format, and spec_helper reads it in a basic way.

diff --git a/spec/clang/spec_helper.cr b/spec/clang/spec_helper.cr
index 71e0bd0..672c502 100644
--- a/spec/clang/spec_helper.cr
+++ b/spec/clang/spec_helper.cr
@@ -18,8 +18,17 @@ def clang_tool(cpp_code, arguments, **checks)

   tool = ENV["BINDGEN_BIN"]? || Bindgen::Parser::Runner::BINARY_PATH

+  cxx_flags = "-std=c++11 -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS"
+  makefile_vars = File.join(__DIR__, "../../clang/Makefile.variables")
+  if File.exists?(makefile_vars)
+    File.read_lines(makefile_vars).each do |line|
+      if line =~ /^LLVM_CXX_FLAGS/
+        cxx_flags = line.split(" := ").last.chomp
+      end
+    end
+  end
   command = "#{tool} #{file.path} #{arguments} -- " \
-            "-x c++ -std=c++11 -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS " \
+            "-x c++ #{cxx_flags} " \
             "-Wno-implicitly-unsigned-literal"

We should change this to pass this data in a more formal way. One possible way to do it would be for the clang tool to read some (existing or new) file in YAML or Crystal format.

docelic avatar May 12 '20 19:05 docelic