1 /* 2 * RProjectFile.hpp 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 16 #ifndef CORE_R_UTIL_R_PROJECT_FILE_HPP 17 #define CORE_R_UTIL_R_PROJECT_FILE_HPP 18 19 #include <string> 20 #include <iosfwd> 21 22 #include <core/r_util/RVersionInfo.hpp> 23 24 namespace rstudio { 25 namespace core { 26 27 class Error; 28 class FilePath; 29 30 namespace r_util { 31 32 enum YesNoAskValue 33 { 34 DefaultValue = 0, 35 YesValue = 1, 36 NoValue = 2, 37 AskValue = 3 38 }; 39 40 extern const int kLineEndingsUseDefault; 41 42 extern const char * const kBuildTypeNone; 43 extern const char * const kBuildTypePackage; 44 extern const char * const kBuildTypeMakefile; 45 extern const char * const kBuildTypeWebsite; 46 extern const char * const kBuildTypeCustom; 47 extern const char * const kBuildTypeQuarto; 48 49 extern const char * const kMarkdownWrapUseDefault; 50 extern const char * const kMarkdownWrapNone; 51 extern const char * const kMarkdownWrapColumn; 52 extern const char * const kMarkdownWrapSentence; 53 54 extern const int kMarkdownWrapAtColumnDefault; 55 56 extern const char * const kMarkdownReferencesUseDefault; 57 extern const char * const kMarkdownReferencesBlock; 58 extern const char * const kMarkdownReferencesSection; 59 extern const char * const kMarkdownReferencesDocument; 60 61 62 std::ostream& operator << (std::ostream& stream, const YesNoAskValue& val); 63 64 struct RProjectBuildDefaults 65 { RProjectBuildDefaultsrstudio::core::r_util::RProjectBuildDefaults66 RProjectBuildDefaults() 67 : useDevtools(true) 68 { 69 } 70 bool useDevtools; 71 }; 72 73 struct RProjectConfig 74 { RProjectConfigrstudio::core::r_util::RProjectConfig75 RProjectConfig() 76 : version(1.0), 77 rVersion(kRVersionDefault), 78 saveWorkspace(DefaultValue), 79 restoreWorkspace(DefaultValue), 80 alwaysSaveHistory(DefaultValue), 81 enableCodeIndexing(true), 82 useSpacesForTab(true), 83 numSpacesForTab(2), 84 autoAppendNewline(false), 85 stripTrailingWhitespace(false), 86 lineEndings(kLineEndingsUseDefault), 87 encoding(), 88 defaultSweaveEngine(), 89 defaultLatexProgram(), 90 rootDocument(), 91 buildType(), 92 packagePath(), 93 packageInstallArgs(), 94 packageBuildArgs(), 95 packageBuildBinaryArgs(), 96 packageCheckArgs(), 97 packageRoxygenize(), 98 packageUseDevtools(false), 99 makefilePath(), 100 websitePath(), 101 customScriptPath(), 102 tutorialPath(), 103 quitChildProcessesOnExit(DefaultValue), 104 disableExecuteRprofile(false), 105 defaultOpenDocs(), 106 defaultTutorial(), 107 markdownWrap(kMarkdownWrapUseDefault), 108 markdownWrapAtColumn(kMarkdownWrapAtColumnDefault), 109 markdownReferences(kMarkdownReferencesUseDefault), 110 markdownCanonical(DefaultValue), 111 zoteroLibraries(), 112 pythonType(), 113 pythonVersion(), 114 pythonPath(), 115 spellingDictionary() 116 { 117 } 118 119 double version; 120 RVersionInfo rVersion; 121 int saveWorkspace; 122 int restoreWorkspace; 123 int alwaysSaveHistory; 124 bool enableCodeIndexing; 125 bool useSpacesForTab; 126 int numSpacesForTab; 127 bool autoAppendNewline; 128 bool stripTrailingWhitespace; 129 int lineEndings; 130 std::string encoding; 131 std::string defaultSweaveEngine; 132 std::string defaultLatexProgram; 133 std::string rootDocument; 134 std::string buildType; 135 std::string packagePath; 136 std::string packageInstallArgs; 137 std::string packageBuildArgs; 138 std::string packageBuildBinaryArgs; 139 std::string packageCheckArgs; 140 std::string packageRoxygenize; 141 bool packageUseDevtools; 142 std::string makefilePath; 143 std::string websitePath; 144 std::string customScriptPath; 145 std::string tutorialPath; 146 int quitChildProcessesOnExit; 147 bool disableExecuteRprofile; 148 std::string defaultOpenDocs; 149 std::string defaultTutorial; 150 std::string markdownWrap; 151 int markdownWrapAtColumn; 152 std::string markdownReferences; 153 int markdownCanonical; 154 boost::optional<std::vector<std::string>> zoteroLibraries; 155 std::string pythonType; 156 std::string pythonVersion; 157 std::string pythonPath; 158 std::string spellingDictionary; 159 }; 160 161 Error findProjectFile(FilePath filePath, 162 FilePath anchorPath, 163 FilePath* pProjPath); 164 165 Error findProjectConfig(FilePath filePath, 166 const FilePath& anchorPath, 167 RProjectConfig* pConfig); 168 169 Error readProjectFile(const FilePath& projectFilePath, 170 RProjectConfig* pConfig, 171 std::string* pUserErrMsg); 172 173 Error readProjectFile(const FilePath& projectFilePath, 174 const RProjectConfig& defaultConfig, 175 const RProjectBuildDefaults& buildDefaults, 176 RProjectConfig* pConfig, 177 bool* pProvidedDefaults, 178 std::string* pUserErrMsg); 179 180 Error writeProjectFile(const FilePath& projectFilePath, 181 const RProjectBuildDefaults& buildDefaults, 182 const RProjectConfig& config); 183 184 FilePath projectFromDirectory(const FilePath& directoryPath); 185 186 // update the package install args default (only if it is set to 187 // the previous default value) 188 bool updateSetPackageInstallArgsDefault(RProjectConfig* pConfig); 189 190 // indicate whether the given directory is an R Markdown website 191 bool isWebsiteDirectory(const FilePath& projectDir); 192 193 // discover website root directory for a filePath 194 FilePath websiteRootDirectory(const FilePath& filePath); 195 196 } // namespace r_util 197 } // namespace core 198 } // namespace rstudio 199 200 201 #endif // CORE_R_UTIL_R_PROJECT_FILE_HPP 202 203