kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/objc_bazel_support.h (about) 1 /* 2 * Copyright 2016 The Kythe Authors. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef KYTHE_CXX_EXTRACTOR_OBJC_BAZEL_SUPPORT_H_ 18 #define KYTHE_CXX_EXTRACTOR_OBJC_BAZEL_SUPPORT_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include "third_party/bazel/src/main/protobuf/extra_actions_base.pb.h" 24 25 namespace kythe { 26 27 /// \brief Make `s` safe to output to a command line. 28 /// 29 /// If `s` has no single quotes, place `s` in single quotes to make it safe. If 30 /// `s` has at least one single quote, place `s` in double quotes and escape 31 /// backslash, double-quote, dollar sign, and back-tick. 32 /// 33 /// For example: 34 /// FOO -> 'FOO' 35 /// FOO BAR -> 'FOO BAR' 36 /// FOO"B" -> 'FOO"B"' 37 /// FOO'B' -> "FOO'B'" 38 /// "FOO"'B' -> "\"FOO\"'B'" 39 /// See the implementation for full details on all the transformations 40 /// preformed. 41 std::string SanitizeArgument(const std::string& s); 42 43 /// \brief Build a command prefix that specifies the environment variables 44 // that should be set according to bazel. This returns a string like: 45 // "env V1=VAL V2=VAL " 46 std::string BuildEnvVarCommandPrefix( 47 const google::protobuf::RepeatedPtrField<blaze::EnvironmentVariable>& vars); 48 49 /// \brief Run a command and capture its (trimmed) stdout in a string. 50 std::string RunScript(const std::string& cmd); 51 52 // \brief Populate args with the arguments from ci where the magic bazel strings 53 // have been replaced with their actual values. 54 void FillWithFixedArgs(std::vector<std::string>& args, 55 const blaze::CppCompileInfo& ci, 56 const std::string& devdir, const std::string& sdkroot); 57 58 // \brief Populate args with the arguments from si where the magic bazel strings 59 // have been replaced with their actual values. 60 void FillWithFixedArgs(std::vector<std::string>& args, 61 const blaze::SpawnInfo& si, const std::string& devdir, 62 const std::string& sdkroot); 63 64 } // namespace kythe 65 66 #endif // KYTHE_CXX_EXTRACTOR_OBJC_BAZEL_SUPPORT_H_