Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
8.2 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: VPC
  4. //
  5. //=====================================================================================//
  6. #include "vpc.h"
  7. static KeywordName_t s_KeywordNameTable[] =
  8. {
  9. {"$General", KEYWORD_GENERAL},
  10. {"$Debugging", KEYWORD_DEBUGGING},
  11. {"$Compiler", KEYWORD_COMPILER},
  12. {"$SNCCompiler", KEYWORD_PS3_SNCCOMPILER},
  13. {"$GCCCompiler", KEYWORD_PS3_GCCCOMPILER},
  14. {"$Librarian", KEYWORD_LIBRARIAN},
  15. {"$Linker", KEYWORD_LINKER},
  16. {"$SNCLinker", KEYWORD_PS3_SNCLINKER},
  17. {"$GCCLinker", KEYWORD_PS3_GCCLINKER},
  18. {"$ManifestTool", KEYWORD_MANIFEST},
  19. {"$XMLDocumentGenerator", KEYWORD_XMLDOCGEN},
  20. {"$BrowseInformation", KEYWORD_BROWSEINFO},
  21. {"$Resources", KEYWORD_RESOURCES},
  22. {"$PreBuildEvent", KEYWORD_PREBUILDEVENT},
  23. {"$PreLinkEvent", KEYWORD_PRELINKEVENT},
  24. {"$PostBuildEvent", KEYWORD_POSTBUILDEVENT},
  25. {"$CustomBuildStep", KEYWORD_CUSTOMBUILDSTEP},
  26. {"$Xbox360ImageConversion", KEYWORD_XBOXIMAGE},
  27. {"$ConsoleDeployment", KEYWORD_XBOXDEPLOYMENT},
  28. };
  29. const char *CVPC::KeywordToName( configKeyword_e keyword )
  30. {
  31. COMPILE_TIME_ASSERT( ARRAYSIZE( s_KeywordNameTable ) == KEYWORD_MAX );
  32. if ( keyword == KEYWORD_UNKNOWN )
  33. {
  34. return "???";
  35. }
  36. return s_KeywordNameTable[keyword].m_pName;
  37. }
  38. configKeyword_e CVPC::NameToKeyword( const char *pKeywordName )
  39. {
  40. COMPILE_TIME_ASSERT( ARRAYSIZE( s_KeywordNameTable ) == KEYWORD_MAX );
  41. for ( int i = 0; i < ARRAYSIZE( s_KeywordNameTable ); i++ )
  42. {
  43. if ( !V_stricmp( pKeywordName, s_KeywordNameTable[i].m_pName ) )
  44. {
  45. return s_KeywordNameTable[i].m_Keyword;
  46. }
  47. }
  48. return KEYWORD_UNKNOWN;
  49. }
  50. //-----------------------------------------------------------------------------
  51. // VPC_Config_Keyword
  52. //
  53. //-----------------------------------------------------------------------------
  54. void VPC_Config_Keyword( configKeyword_e keyword, const char *pkeywordToken )
  55. {
  56. const char *pToken;
  57. bool bShouldSkip = false;
  58. if ( !g_pVPC->GetProjectGenerator()->StartPropertySection( keyword, &bShouldSkip ) )
  59. {
  60. g_pVPC->VPCSyntaxError( "Unsupported Keyword: %s for target platform", pkeywordToken );
  61. }
  62. if ( bShouldSkip )
  63. {
  64. pToken = g_pVPC->GetScript().PeekNextToken( true );
  65. if ( !pToken || !pToken[0] || V_stricmp( pToken, "{" ) )
  66. g_pVPC->VPCSyntaxError();
  67. g_pVPC->GetScript().SkipBracedSection();
  68. }
  69. else
  70. {
  71. pToken = g_pVPC->GetScript().GetToken( true );
  72. if ( !pToken || !pToken[0] || V_stricmp( pToken, "{" ) )
  73. g_pVPC->VPCSyntaxError();
  74. while ( 1 )
  75. {
  76. pToken = g_pVPC->GetScript().GetToken( true );
  77. if ( !pToken || !pToken[0] )
  78. break;
  79. if ( !V_stricmp( pToken, "}" ) )
  80. {
  81. // end of section
  82. break;
  83. }
  84. // Copy off the token name so HandleProperty() doesn't have to (or else the parser will overwrite it on the next token).
  85. char tempTokenName[MAX_PATH];
  86. V_strncpy( tempTokenName, pToken, sizeof( tempTokenName ) );
  87. g_pVPC->GetProjectGenerator()->HandleProperty( tempTokenName );
  88. }
  89. }
  90. g_pVPC->GetProjectGenerator()->EndPropertySection( keyword );
  91. }
  92. //-----------------------------------------------------------------------------
  93. // VPC_Keyword_Configuration
  94. //
  95. //-----------------------------------------------------------------------------
  96. void VPC_Keyword_Configuration()
  97. {
  98. const char *pToken;
  99. char szConfigName[MAX_PATH];
  100. bool bAllowNextLine = false;
  101. int i;
  102. CUtlVector<CUtlString> configs;
  103. char buff[MAX_SYSTOKENCHARS];
  104. while ( 1 )
  105. {
  106. pToken = g_pVPC->GetScript().GetToken( bAllowNextLine );
  107. if ( !pToken || !pToken[0] )
  108. break;
  109. if ( !V_stricmp( pToken, "\\" ) )
  110. {
  111. bAllowNextLine = true;
  112. continue;
  113. }
  114. else
  115. {
  116. bAllowNextLine = false;
  117. }
  118. int index = configs.AddToTail();
  119. configs[index] = pToken;
  120. // check for another optional config
  121. pToken = g_pVPC->GetScript().PeekNextToken( bAllowNextLine );
  122. if ( !pToken || !pToken[0] || !V_stricmp( pToken, "{" ) || !V_stricmp( pToken, "}" ) || (pToken[0] == '$') )
  123. break;
  124. }
  125. // no configuration specified, use all known
  126. if ( !configs.Count() )
  127. {
  128. g_pVPC->GetProjectGenerator()->GetAllConfigurationNames( configs );
  129. if ( !configs.Count() )
  130. {
  131. g_pVPC->VPCError( "Trying to parse a configuration block and no configs have been defined yet.\n[%s line:%d]", g_pVPC->GetScript().GetName(), g_pVPC->GetScript().GetLine() );
  132. }
  133. }
  134. // save parser state
  135. CScriptSource scriptSource = g_pVPC->GetScript().GetCurrentScript();
  136. for ( i=0; i<configs.Count(); i++ )
  137. {
  138. // restore parser state
  139. g_pVPC->GetScript().RestoreScript( scriptSource );
  140. V_strncpy( szConfigName, configs[i].String(), sizeof( szConfigName ) );
  141. // get access objects
  142. g_pVPC->GetProjectGenerator()->StartConfigurationBlock( szConfigName, false );
  143. pToken = g_pVPC->GetScript().GetToken( true );
  144. if ( !pToken || !pToken[0] || V_stricmp( pToken, "{" ) )
  145. {
  146. g_pVPC->VPCSyntaxError();
  147. }
  148. while ( 1 )
  149. {
  150. g_pVPC->GetScript().SkipToValidToken();
  151. if ( !g_pVPC->GetScript().ParsePropertyValue( NULL, buff, sizeof( buff ) ) )
  152. {
  153. g_pVPC->GetScript().SkipBracedSection();
  154. continue;
  155. }
  156. if ( !V_stricmp( buff, "}" ) )
  157. {
  158. // end of section
  159. break;
  160. }
  161. configKeyword_e keyword = g_pVPC->NameToKeyword( buff );
  162. if ( keyword == KEYWORD_UNKNOWN )
  163. {
  164. g_pVPC->VPCSyntaxError();
  165. }
  166. else
  167. {
  168. VPC_Config_Keyword( keyword, buff );
  169. }
  170. }
  171. g_pVPC->GetProjectGenerator()->EndConfigurationBlock();
  172. }
  173. }
  174. //-----------------------------------------------------------------------------
  175. // VPC_Keyword_FileConfiguration
  176. //
  177. //-----------------------------------------------------------------------------
  178. void VPC_Keyword_FileConfiguration()
  179. {
  180. const char *pToken;
  181. char szConfigName[MAX_PATH];
  182. bool bAllowNextLine = false;
  183. char buff[MAX_SYSTOKENCHARS];
  184. CUtlVector< CUtlString > configurationNames;
  185. while ( 1 )
  186. {
  187. pToken = g_pVPC->GetScript().GetToken( bAllowNextLine );
  188. if ( !pToken || !pToken[0] )
  189. break;
  190. if ( !V_stricmp( pToken, "\\" ) )
  191. {
  192. bAllowNextLine = true;
  193. continue;
  194. }
  195. else
  196. {
  197. bAllowNextLine = false;
  198. }
  199. strcpy( szConfigName, pToken );
  200. configurationNames.AddToTail( pToken );
  201. // check for another optional config
  202. pToken = g_pVPC->GetScript().PeekNextToken( bAllowNextLine );
  203. if ( !pToken || !pToken[0] || !V_stricmp( pToken, "{" ) || !V_stricmp( pToken, "}" ) || (pToken[0] == '$') )
  204. break;
  205. }
  206. // no configuration specified, use all known
  207. if ( configurationNames.Count() == 0 )
  208. {
  209. g_pVPC->GetProjectGenerator()->GetAllConfigurationNames( configurationNames );
  210. }
  211. // save parser state
  212. CScriptSource scriptSource = g_pVPC->GetScript().GetCurrentScript();
  213. for ( int i=0; i < configurationNames.Count(); i++ )
  214. {
  215. // restore parser state
  216. g_pVPC->GetScript().RestoreScript( scriptSource );
  217. // Tell the generator we're about to feed it configuration data for this file.
  218. g_pVPC->GetProjectGenerator()->StartConfigurationBlock( configurationNames[i].String(), true );
  219. pToken = g_pVPC->GetScript().GetToken( true );
  220. if ( !pToken || !pToken[0] || V_stricmp( pToken, "{" ) )
  221. {
  222. g_pVPC->VPCSyntaxError();
  223. }
  224. while ( 1 )
  225. {
  226. g_pVPC->GetScript().SkipToValidToken();
  227. pToken = g_pVPC->GetScript().PeekNextToken( true );
  228. if ( pToken && pToken[0] && !V_stricmp( pToken, "$ExcludedFromBuild" ) )
  229. {
  230. pToken = g_pVPC->GetScript().GetToken( true );
  231. if ( !pToken || !pToken[0] )
  232. g_pVPC->VPCSyntaxError();
  233. char buff[MAX_SYSTOKENCHARS];
  234. if ( g_pVPC->GetScript().ParsePropertyValue( NULL, buff, sizeof( buff ) ) )
  235. {
  236. g_pVPC->GetProjectGenerator()->FileExcludedFromBuild( Sys_StringToBool( buff ) );
  237. }
  238. continue;
  239. }
  240. if ( !g_pVPC->GetScript().ParsePropertyValue( NULL, buff, sizeof( buff ) ) )
  241. {
  242. g_pVPC->GetScript().SkipBracedSection();
  243. continue;
  244. }
  245. if ( !V_stricmp( buff, "}" ) )
  246. {
  247. // end of section
  248. break;
  249. }
  250. configKeyword_e keyword = g_pVPC->NameToKeyword( buff );
  251. switch ( keyword )
  252. {
  253. case KEYWORD_COMPILER:
  254. case KEYWORD_PS3_SNCCOMPILER:
  255. case KEYWORD_PS3_GCCCOMPILER:
  256. case KEYWORD_RESOURCES:
  257. case KEYWORD_CUSTOMBUILDSTEP:
  258. VPC_Config_Keyword( keyword, buff );
  259. break;
  260. default:
  261. g_pVPC->VPCSyntaxError();
  262. }
  263. }
  264. g_pVPC->GetProjectGenerator()->EndConfigurationBlock();
  265. }
  266. }