From ec9a3ddb23e17ed43cbe16f5fa3be591461c2e5e Mon Sep 17 00:00:00 2001
From: epriestley <git@epriestley.com>
Date: Tue, 13 Mar 2012 11:17:28 -0700
Subject: [PATCH] Add a check to 'arc liberate' for loose .php files in the
 library root

Summary: @koolvin ran into this and was justifiably confused.

Test Plan: Put some random .php file in src/, ran arc liberate src/, got warned.

Reviewers: btrahan, Koolvin

Reviewed By: btrahan

CC: aran, epriestley

Differential Revision: https://secure.phabricator.com/D1878
---
 .../liberate/ArcanistLiberateWorkflow.php     | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/workflow/liberate/ArcanistLiberateWorkflow.php b/src/workflow/liberate/ArcanistLiberateWorkflow.php
index 934b073a..03bf4601 100644
--- a/src/workflow/liberate/ArcanistLiberateWorkflow.php
+++ b/src/workflow/liberate/ArcanistLiberateWorkflow.php
@@ -131,6 +131,8 @@ EOTEXT
     $readable = Filesystem::readablePath($path);
     echo "Using library root at '{$readable}'...\n";
 
+    $this->checkForLooseFiles($path);
+
     if ($this->getArgument('all')) {
       echo "Dropping module cache...\n";
       Filesystem::remove($path.'/.phutil_module_cache');
@@ -339,4 +341,25 @@ EOTEXT
     return (int)$unresolved;
   }
 
+  /**
+   * Sanity check to catch people putting class files in the root of a libphutil
+   * library.
+   */
+  private function checkForLooseFiles($path) {
+    foreach (Filesystem::listDirectory($path) as $item) {
+      if (!preg_match('/\.php$/', $item)) {
+        // Not a ".php" file.
+        continue;
+      }
+      if (preg_match('/^__/', $item)) {
+        // Has magic '__' prefix.
+        continue;
+      }
+
+      echo phutil_console_wrap(
+        "WARNING: File '{$item}' is not in a module and won't be loaded. ".
+        "Put source files in subdirectories, not the top level directory.\n");
+    }
+  }
+
 }