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.

197 lines
7.7 KiB

  1. //====== Copyright 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DEPENDENCIES_H
  7. #define DEPENDENCIES_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. enum EDependencyType
  12. {
  13. k_eDependencyType_SourceFile, // .cpp, .cxx, .h, .hxx
  14. k_eDependencyType_Project, // this is a project file WITHOUT the target-specific extension (.mak, .vpj, .vcproj).
  15. k_eDependencyType_Library, // this is a library file
  16. k_eDependencyType_Unknown // Unrecognized file extension (probably .ico or .rc2 or somesuch).
  17. };
  18. class CProjectDependencyGraph;
  19. enum k_EDependsOnFlags
  20. {
  21. k_EDependsOnFlagCheckNormalDependencies = 0x01,
  22. k_EDependsOnFlagCheckAdditionalDependencies = 0x02,
  23. k_EDependsOnFlagRecurse = 0x04,
  24. k_EDependsOnFlagTraversePastLibs = 0x08
  25. };
  26. // Flags to CProjectDependencyGraph::BuildProjectDependencies.
  27. #define BUILDPROJDEPS_FULL_DEPENDENCY_SET 0x01 // This tells it to build a graph of all projects in the source tree _including_ all games.
  28. #define BUILDPROJDEPS_CHECK_ALL_PROJECTS 0x02 // If this is set, then it reads all .vpc files.
  29. // If this is not set, then it only includes the files from the command line with the "vpc +tier0 *bitmap +client /tf" syntax
  30. class CDependency
  31. {
  32. friend class CProjectDependencyGraph;
  33. friend class CSingleProjectScanner;
  34. public:
  35. CDependency( CProjectDependencyGraph *pDependencyGraph );
  36. virtual ~CDependency();
  37. // Flags are a combination of k_EDependsOnFlags.
  38. bool DependsOn( CDependency *pTest, int flags=k_EDependsOnFlagCheckNormalDependencies | k_EDependsOnFlagRecurse );
  39. const char* GetName() const;
  40. // Returns true if the absolute filename of this thing (CDependency::m_Filename) matches the absolute path specified.
  41. bool CompareAbsoluteFilename( const char *pAbsPath ) const;
  42. private:
  43. bool FindDependency_Internal( CUtlVector<CUtlBuffer> &callTreeOutputStack, CDependency *pTest, int flags, int depth );
  44. void Mark();
  45. bool HasBeenMarked();
  46. public:
  47. CUtlString m_Filename; // Full paths (slashes are platform dependent).
  48. // This is the VPC filename for a project (use CDependency_Project::m_ProjectFilename for the VCPROJ/VPJ filename).
  49. EDependencyType m_Type;
  50. // Files that this guy depends on.
  51. CUtlVector<CDependency*> m_Dependencies;
  52. // Files added by $AdditionalProjectDependencies. This is in a separate list because we don't
  53. // always want DependsOn() to check this.
  54. CUtlVector<CDependency*> m_AdditionalDependencies;
  55. private:
  56. CProjectDependencyGraph *m_pDependencyGraph;
  57. unsigned int m_iDependencyMark;
  58. bool m_bCheckedIncludes; // Set to true when we have checked all the includes for this.
  59. // Cache info.
  60. int64 m_nCacheFileSize;
  61. int64 m_nCacheModificationTime;
  62. // Used by the cache.
  63. bool m_bCacheDirty; // File size or modification time don't match.
  64. };
  65. // This represents a project (.vcproj) file, NOT a project like a projectIndex_t.
  66. // There can be separate .vcproj files (and thus separate CDependency_Project) for each game and platform of a projectIndex_t.
  67. // If m_Type == k_eDependencyType_Project, then you can cast to this.
  68. class CDependency_Project : public CDependency
  69. {
  70. public:
  71. typedef CDependency BaseClass;
  72. CDependency_Project( CProjectDependencyGraph *pDependencyGraph );
  73. // These functions read/write g_pVPC->GetOutputFilename() and such (all the m_xxStoredXXXX vars below).
  74. void StoreProjectParameters( const char *szScriptName );
  75. void ExportProjectParameters();
  76. // Does a case-insensitive string compare against m_ProjectName.
  77. // Returns -1 if not found or the index into projects.
  78. static int FindByProjectName( CUtlVector<CDependency_Project*> &projects, const char *pTestName );
  79. public:
  80. // Include directories for the project.
  81. CUtlVector<CUtlString> m_IncludeDirectories;
  82. // Straight out of the $AdditionalProjectDependencies key (split on semicolons).
  83. CUtlVector<CUtlString> m_AdditionalProjectDependencies;
  84. // Straight out of the $AdditionalOutputFiles key (split on semicolons).
  85. CUtlVector<CUtlString> m_AdditionalOutputFiles;
  86. CUtlString m_ProjectName; // This comes from the $Project key in the .vpc file.
  87. CUtlString m_ProjectFilename; // Absolute path to the VCPROJ file (g_pVPC->GetOutputFilename() - see CDependency::m_Filename for the VPC filename).
  88. CUtlString m_ImportLibrary;
  89. // Note that there can be multiple CDependency_Projects with the same m_iProjectIndex.
  90. projectIndex_t m_iProjectIndex;
  91. // This is used by /p4sln. It uses this to call into VPC_ParseProjectScript. These are the values of g_pVPC->GetOutputFilename(), szScriptName,
  92. // and the defines at the time of building this project.
  93. CUtlString m_StoredOutputFilename;
  94. char m_szStoredScriptName[MAX_PATH];
  95. char m_szStoredCurrentDirectory[MAX_PATH];
  96. CUtlVector<bool> m_StoredConditionalsActive;
  97. };
  98. // This class builds a graph of all dependencies, starting at the projects.
  99. class CProjectDependencyGraph : public IProjectIterator
  100. {
  101. friend class CDependency;
  102. public:
  103. CProjectDependencyGraph();
  104. // This is the main function to generate dependencies.
  105. // nBuildProjectDepsFlags is a combination of BUILDPROJDEPS_ flags.
  106. void BuildProjectDependencies( int nBuildProjectDepsFlags );
  107. bool HasGeneratedDependencies() const;
  108. CDependency* FindDependency( const char *pFilename );
  109. CDependency* FindOrCreateDependency( const char *pFilename );
  110. // Look for all projects (that we've scanned during BuildProjectDependencies) that depend on the specified project.
  111. // If bDownwards is true, then it adds iProject and all projects that _it depends on_.
  112. // If bDownwards is false, then it adds iProject and all projects that _depend on it_.
  113. void GetProjectDependencyTree( projectIndex_t iProject, CUtlVector<projectIndex_t> &dependentProjects, bool bDownwards );
  114. // This solves the central mismatch between the way VPC references projects and the way the CDependency stuff does.
  115. //
  116. // - VPC uses projectIndex_t, but a single projectIndex_t can turn into multiple games (server_tf, server_episodic, etc) in VPC_IterateTargetProjects.
  117. // - The dependency code has a separate CDependency_Project for each game.
  118. //
  119. // This takes a bunch of project indices (usually m_targetProjects, which comes from the command line's "+this -that *theother" syntax),
  120. // which are game-agnostic, and based on what games were specified on the command line, it builds the list of CDependency_Project*s.
  121. void TranslateProjectIndicesToDependencyProjects( CUtlVector<projectIndex_t> &projectList, CUtlVector<CDependency_Project*> &out );
  122. // IProjectIterator overrides.
  123. protected:
  124. virtual bool VisitProject( projectIndex_t iProject, const char *szProjectName );
  125. private:
  126. void ClearAllDependencyMarks();
  127. // Functions for the vpc.cache file management.
  128. bool LoadCache( const char *pFilename );
  129. bool SaveCache( const char *pFilename );
  130. void WriteString( FILE *fp, CUtlString &utlString );
  131. CUtlString ReadString( FILE *fp );
  132. void CheckCacheEntries();
  133. void RemoveDirtyCacheEntries();
  134. void MarkAllCacheEntriesValid();
  135. void ResolveAdditionalProjectDependencies();
  136. public:
  137. // Projects and everything they depend on.
  138. CUtlVector<CDependency_Project*> m_Projects;
  139. CUtlDict<CDependency*,int> m_AllFiles; // All files go in here. They should never be duplicated. These are indexed by the full filename (except .lib files, which have that stripped off).
  140. bool m_bFullDependencySet; // See bFullDepedencySet passed into BuildProjectDependencies.
  141. int m_nFilesParsedForIncludes;
  142. private:
  143. // Used when sweeping the dependency graph to prevent looping around forever.
  144. unsigned int m_iDependencyMark;
  145. bool m_bHasGeneratedDependencies; // Set to true after finishing BuildProjectDependencies.
  146. };
  147. bool IsLibraryFile( const char *pFilename );
  148. bool IsSharedLibraryFile( const char *pFilename );
  149. #endif // DEPENDENCIES_H