Brian Silverman | 4e662aa | 2022-05-11 23:10:19 -0700 | [diff] [blame^] | 1 | // Copyright 2021 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your |
| 6 | // option. This file may not be copied, modified, or distributed |
| 7 | // except according to those terms. |
| 8 | |
| 9 | use autocxx_engine::Builder; |
| 10 | |
| 11 | use autocxx_integration_tests::{BuilderModifier, BuilderModifierFns, TestBuilderContext}; |
| 12 | |
| 13 | pub(crate) fn make_cpp17_adder() -> Option<BuilderModifier> { |
| 14 | make_clang_arg_adder(&["-std=c++17"]) |
| 15 | } |
| 16 | |
| 17 | struct ClangArgAdder(Vec<String>); |
| 18 | |
| 19 | pub(crate) fn make_clang_arg_adder(args: &[&str]) -> Option<BuilderModifier> { |
| 20 | let args: Vec<_> = args.iter().map(|a| a.to_string()).collect(); |
| 21 | Some(Box::new(ClangArgAdder(args))) |
| 22 | } |
| 23 | |
| 24 | impl BuilderModifierFns for ClangArgAdder { |
| 25 | fn modify_autocxx_builder<'a>( |
| 26 | &self, |
| 27 | builder: Builder<'a, TestBuilderContext>, |
| 28 | ) -> Builder<'a, TestBuilderContext> { |
| 29 | let refs: Vec<_> = self.0.iter().map(|s| s.as_str()).collect(); |
| 30 | builder.extra_clang_args(&refs) |
| 31 | } |
| 32 | |
| 33 | fn modify_cc_builder<'a>(&self, mut builder: &'a mut cc::Build) -> &'a mut cc::Build { |
| 34 | for f in &self.0 { |
| 35 | builder = builder.flag(f); |
| 36 | } |
| 37 | builder |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | pub(crate) struct SetSuppressSystemHeaders; |
| 42 | |
| 43 | impl BuilderModifierFns for SetSuppressSystemHeaders { |
| 44 | fn modify_autocxx_builder<'a>( |
| 45 | &self, |
| 46 | builder: Builder<'a, TestBuilderContext>, |
| 47 | ) -> Builder<'a, TestBuilderContext> { |
| 48 | builder.suppress_system_headers(true) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | pub(crate) struct EnableAutodiscover; |
| 53 | |
| 54 | impl BuilderModifierFns for EnableAutodiscover { |
| 55 | fn modify_autocxx_builder<'a>( |
| 56 | &self, |
| 57 | builder: Builder<'a, TestBuilderContext>, |
| 58 | ) -> Builder<'a, TestBuilderContext> { |
| 59 | builder.auto_allowlist(true) |
| 60 | } |
| 61 | } |