]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Let `arc liberate` throw on unsupported PHP features
authorRichard van Velzen <rvanvelzen1@gmail.com>
Tue, 17 Jun 2014 12:13:05 +0000 (05:13 -0700)
committerepriestley <git@epriestley.com>
Tue, 17 Jun 2014 12:13:05 +0000 (05:13 -0700)
Summary: Ref T4725.

Test Plan: add some files that have unsupported constructs all over the place and run `arc liberate`

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T4725

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

scripts/phutil_symbols.php

index 4de03121405da09b91cf6808d625b00790757ce2..9349ab875db065646058e1646b4f305b5b58048c 100755 (executable)
@@ -77,6 +77,32 @@ $root = $tree->getRootNode();
 
 $root->buildSelectCache();
 
+// -(  Unsupported Constructs  )------------------------------------------------
+
+$namespaces = $root->selectDescendantsOfType('n_NAMESPACE');
+foreach ($namespaces as $namespace) {
+  phutil_fail_on_unsupported_feature(
+    $namespace, $path, pht('namespaces'));
+}
+
+$uses = $root->selectDescendantsOfType('n_USE');
+foreach ($namespaces as $namespace) {
+  phutil_fail_on_unsupported_feature(
+    $namespace, $path, pht('namespace `use` statements'));
+}
+
+$possible_traits = $root->selectDescendantsOfType('n_CLASS_DECLARATION');
+foreach ($possible_traits as $possible_trait) {
+  $attributes = $possible_trait->getChildByIndex(0);
+  // can't use getChildByIndex here because not all classes have attributes
+  foreach ($attributes->getChildren() as $attribute) {
+    if (strtolower($attribute->getConcreteString()) == 'trait') {
+      phutil_fail_on_unsupported_feature(
+        $possible_trait, $path, pht('traits'));
+    }
+  }
+}
+
 
 // -(  Marked Externals  )------------------------------------------------------
 
@@ -459,6 +485,24 @@ if ($args->getArg('ugly')) {
 
 // -(  Library  )---------------------------------------------------------------
 
+function phutil_fail_on_unsupported_feature(XHPASTNode $node, $file, $what) {
+  $line = $node->getLineNumber();
+  $message = phutil_console_wrap(pht(
+      "`arc liberate` has limited support for features introduced after PHP ".
+      "5.2.3. This library uses an unsupported feature (%s) on line %d of %s",
+    $what,
+    $line,
+    Filesystem::readablePath($file)));
+
+  $result = array(
+    'error' => $message,
+    'line'  => $line,
+    'file'  => $file,
+  );
+  $json = new PhutilJSON();
+  echo $json->encodeFormatted($result);
+  exit(0);
+}
 
 function phutil_symbols_get_builtins() {
   $builtin = array();