Solution.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. //-----------------------------------------------------------------------------
  3. // Copyright (c) 2012 GarageGames, LLC
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. //
  24. // Solution info container
  25. //
  26. class Solution
  27. {
  28. public $name;
  29. public $guid;
  30. public $project_refs = array();
  31. public $project_extRefs = array();
  32. public $outputs = array();
  33. public function Solution( $name, $guid, $outputs = null )
  34. {
  35. $this->name = $name;
  36. $this->guid = $guid;
  37. $this->setOutputs( $outputs );
  38. }
  39. public function addProjectRef( $pname )
  40. {
  41. array_push( $this->project_refs, $pname );
  42. }
  43. public function addSolutionProjectRefExt( $pname, $ppath, $pguid )
  44. {
  45. $v = array();
  46. $v[0] = $ppath;
  47. $v[1] = $pguid;
  48. // This is the project GUID for a C# project
  49. // TODO: Add support for C++ projects if need to add them
  50. // as an external project, to date this hasn't been necessary
  51. $v[2] = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}";
  52. $this->project_extRefs[$pname] = $v;
  53. }
  54. public function setOutputs( $outputs )
  55. {
  56. if( isset( $outputs ) )
  57. $this->outputs = array_merge( $this->outputs, $outputs );
  58. }
  59. public function generate( $tpl, $platform, $root_dir )
  60. {
  61. // Project container for templates
  62. $projects = array();
  63. $refs = array();
  64. // make sure that startup project is the first in the solution
  65. if (getGameProjectName())
  66. array_push( $refs, getGameProjectName() );
  67. foreach( $this->project_refs as $pname )
  68. {
  69. if (getGameProjectName() && $pname == getGameProjectName())
  70. continue;
  71. array_push( $refs, $pname );
  72. }
  73. // Look up each project ref and add its info to the list
  74. foreach( $refs as $pname )
  75. {
  76. $project = T3D_Generator::lookupProjectByName( $pname );
  77. if( isset( $project ) )
  78. {
  79. echo( " - project ref: " . $pname . " = " . $project->guid . "\n" );
  80. array_push( $projects, $project );
  81. // Let the project update any dependencies
  82. $project->validateDependencies();
  83. }
  84. else
  85. trigger_error( "Solution::generate() - project ref not found: " . $pname . "\n", E_USER_ERROR );
  86. }
  87. // No use going forward if there were no projects for this solution is there?
  88. // (Would we ever want to generate an empty solution at all?)
  89. if( count( $projects ) == 0 )
  90. {
  91. echo( "Solution::generate() - no project refs found for solution: " . $this->name . "\n" );
  92. continue;
  93. }
  94. //
  95. //sort( $projects );
  96. // Set smarty params that dont change during loop once here
  97. $tpl->assign_by_ref( "solution_guid", $this->guid );
  98. $tpl->assign_by_ref( "projects", $projects );
  99. $tpl->assign_by_ref( "projectExtRefs", $this->project_extRefs );
  100. // Generate a solution file for all outputs for this solution
  101. foreach( $this->outputs as $output )
  102. {
  103. // Supported platform?
  104. if( !$output->supportsPlatform( $platform ) )
  105. {
  106. //echo( " # Skipping output: '$outputName'.\n" );
  107. continue;
  108. }
  109. // Reset to base dir
  110. chdir( $root_dir );
  111. // Then offset
  112. if( !FileUtil::prepareOutputDir( $output->output_dir ) || !$output->template_sln )
  113. continue;
  114. $outfile = $this->name . $output->solution_ext;
  115. echo( " - Writing solution file: " . $output->output_dir . "/" . $outfile );
  116. // Project filenames are <projectname>.<outputext> where ext is set per output.
  117. // The template builds each project output using the project name and this ext.
  118. $tpl->assign_by_ref( "project_ext", $output->output_ext );
  119. if( $f = fopen( $outfile, 'w' ) )
  120. {
  121. fputs( $f, $tpl->fetch( $output->template_sln ) );
  122. fclose( $f );
  123. echo( " - success " . "\n" );
  124. }
  125. else
  126. trigger_error( "\nCould not write output file: " . $outfile, E_USER_ERROR );
  127. }
  128. }
  129. }
  130. ?>