@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow specifying custom celerity resource map

Summary:
We have custom static resources.
We currently include them in Phabricator's celerity resource map which is causing some pain - we need to regenerate the file without our custom resources before pushing upstream, we need to discard our changes before pulling from upstream and we need to rebuild with our changes to run Phabricator.

This diff allows writing and reading the map in other location.
The plan is this - I will run `celerity_mapper.php` twice - once to build Phabricator-only resources (to push to upstream) and once to build Phabricator + ours resoruces to put in our directory.

Better solution would be to create a map just with our resources and read and combine it with Phabricator resources.
But it is complicated because we have dependencies on Phabricator resources.

Test Plan:
`celerity_mapper.php webroot`
`celerity_mapper.php webroot ../facebook/src/__celerity_resource_map__.php`
Delete Phabricator's celerity map, set 'celerity.resource-path' and successfully load Phabricator.

Reviewers: epriestley, edward

Reviewed By: epriestley

CC: aran, Koolvin

Maniphest Tasks: T721

Differential Revision: https://secure.phabricator.com/D2630

vrana 8883c949 06b0f0d8

+52 -15
+1
.gitignore
··· 3 3 /docs/ 4 4 /src/.phutil_module_cache 5 5 /conf/custom/* 6 + /webroot/rsrc/custom 6 7 /.divinercache 7 8 .#* 8 9 *#
+5
conf/default.conf.php
··· 973 973 // "phd launch <N> taskmaster". 974 974 'phd.start-taskmasters' => 4, 975 975 976 + // Path to custom celerity resource map. Absolute or relative to 977 + // 'phabricator/src'. Defaults to '__celerity_resource_map__.php'. 978 + // See also `scripts/celerity_mapper.php`. 979 + 'celerity.resource-path' => null, 980 + 976 981 // This value is an input to the hash function when building resource hashes. 977 982 // It has no security value, but if you accidentally poison user caches (by 978 983 // pushing a bad patch or having something go wrong with a CDN, e.g.) you can
+42 -14
scripts/celerity_mapper.php
··· 149 149 150 150 require_once dirname(__FILE__).'/__init_script__.php'; 151 151 152 - if ($argc != 2) { 153 - $self = basename($argv[0]); 154 - echo "usage: {$self} <webroot>\n"; 155 - exit(1); 152 + $args = new PhutilArgumentParser($argv); 153 + $args->setTagline('map static resources'); 154 + $args->setSynopsis( 155 + "**celerity_mapper.php** [--output __path__] [--with-custom] <webroot>"); 156 + $args->parse( 157 + array( 158 + array( 159 + 'name' => 'output', 160 + 'param' => 'path', 161 + 'default' => '../src/__celerity_resource_map__.php', 162 + 'help' => "Set the path for resource map. It is usually useful for ". 163 + "'celerity.resource-path' configuration.", 164 + ), 165 + array( 166 + 'name' => 'with-custom', 167 + 'help' => 'Include resources in <webroot>/rsrc/custom/.', 168 + ), 169 + array( 170 + 'name' => 'webroot', 171 + 'wildcard' => true, 172 + ), 173 + )); 174 + 175 + $root = $args->getArg('webroot'); 176 + if (count($root) != 1 || !is_dir(reset($root))) { 177 + $args->printHelpAndExit(); 156 178 } 179 + $root = Filesystem::resolvePath(reset($root)); 157 180 158 - $root = Filesystem::resolvePath($argv[1]); 181 + $celerity_path = Filesystem::resolvePath($args->getArg('output'), $root); 182 + $with_custom = $args->getArg('with-custom'); 159 183 160 184 $resource_hash = PhabricatorEnv::getEnvConfig('celerity.resource-hash'); 161 185 $runtime_map = array(); 162 186 163 187 echo "Finding raw static resources...\n"; 164 - $raw_files = id(new FileFinder($root)) 188 + $finder = id(new FileFinder($root)) 165 189 ->withType('f') 166 190 ->withSuffix('png') 167 191 ->withSuffix('jpg') 168 192 ->withSuffix('gif') 169 193 ->withSuffix('swf') 170 194 ->withFollowSymlinks(true) 171 - ->setGenerateChecksums(true) 172 - ->find(); 195 + ->setGenerateChecksums(true); 196 + if (!$with_custom) { 197 + $finder->excludePath('./rsrc/custom'); 198 + } 199 + $raw_files = $finder->find(); 173 200 174 201 echo "Processing ".count($raw_files)." files"; 175 202 foreach ($raw_files as $path => $hash) { ··· 194 221 ->setRawResourceMap($runtime_map); 195 222 196 223 echo "Finding transformable static resources...\n"; 197 - $files = id(new FileFinder($root)) 224 + $finder = id(new FileFinder($root)) 198 225 ->withType('f') 199 226 ->withSuffix('js') 200 227 ->withSuffix('css') 201 228 ->withFollowSymlinks(true) 202 - ->setGenerateChecksums(true) 203 - ->find(); 229 + ->setGenerateChecksums(true); 230 + if (!$with_custom) { 231 + $finder->excludePath('./rsrc/custom'); 232 + } 233 + $files = $finder->find(); 204 234 205 235 echo "Processing ".count($files)." files"; 206 236 ··· 345 375 EOFILE; 346 376 347 377 echo "Writing map...\n"; 348 - Filesystem::writeFile( 349 - $root.'/../src/__celerity_resource_map__.php', 350 - $resource_map); 378 + Filesystem::writeFile($celerity_path, $resource_map); 351 379 echo "Done.\n";
+4 -1
src/infrastructure/celerity/CelerityResourceMap.php
··· 35 35 if (empty(self::$instance)) { 36 36 self::$instance = new CelerityResourceMap(); 37 37 $root = phutil_get_library_root('phabricator'); 38 - $ok = include_once $root.'/__celerity_resource_map__.php'; 38 + $path = PhabricatorEnv::getEnvConfig( 39 + 'celerity.resource-map', 40 + '__celerity_resource_map__.php'); 41 + $ok = include_once Filesystem::resolvePath($path, $root); 39 42 if (!$ok) { 40 43 throw new Exception("Failed to load Celerity resource map!"); 41 44 }