Bug 672938: Make pythonpath.py work as a pymake native command. r=ted
authorKyle Huey <khuey@kylehuey.com>
Thu, 21 Jul 2011 15:07:33 -0700
changeset 73953 a751aa806dbfe26b5bbce3bf5d9468656f945d6c
parent 73952 bf397db9ccfcf608831e50f944e13c08fd397e88
child 73954 a8d3614c62e2cdae6250cf38e68b02a67b952efc
push id235
push userbzbarsky@mozilla.com
push dateTue, 27 Sep 2011 17:13:04 +0000
treeherdermozilla-beta@2d1e082d176a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs672938
milestone8.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 672938: Make pythonpath.py work as a pymake native command. r=ted
config/pythonpath.py
js/src/config/pythonpath.py
--- a/config/pythonpath.py
+++ b/config/pythonpath.py
@@ -1,42 +1,52 @@
 """
 Run a python script, adding extra directories to the python path.
 """
 
-import sys, os
 
-def usage():
-    print >>sys.stderr, "pythonpath.py -I directory script.py [args...]"
-    sys.exit(150)
-
-paths = []
+def main(args):
+    def usage():
+        print >>sys.stderr, "pythonpath.py -I directory script.py [args...]"
+        sys.exit(150)
 
-while True:
-    try:
-        arg = sys.argv[1]
-    except IndexError:
-        usage()
+    paths = []
 
-    if arg == '-I':
-        del sys.argv[1]
+    while True:
         try:
-            path = sys.argv.pop(1)
+            arg = args[0]
         except IndexError:
             usage()
 
-        paths.append(path)
-        continue
+        if arg == '-I':
+            args.pop(0)
+            try:
+                path = args.pop(0)
+            except IndexError:
+                usage()
 
-    if arg.startswith('-I'):
-        path = sys.argv.pop(1)[2:]
-        paths.append(path)
-        continue
+            paths.append(path)
+            continue
+
+        if arg.startswith('-I'):
+            paths.append(args.pop(0)[2:])
+            continue
+
+        break
 
-    break
+    script = args[0]
 
-sys.argv.pop(0)
-script = sys.argv[0]
+    sys.path[0:0] = [os.path.dirname(script)] + paths
+    sys.argv = args
+    sys.argc = len(args)
+
+    frozenglobals['__name__'] = '__main__'
+    frozenglobals['__file__'] = script
 
-sys.path[0:0] = [os.path.dirname(script)] + paths
-__name__ = '__main__'
-__file__ = script
-execfile(script)
+    execfile(script, frozenglobals)
+
+# Freeze scope here ... why this makes things work I have no idea ...
+frozenglobals = globals()
+
+import sys, os
+
+if __name__ == '__main__':
+    main(sys.argv[1:])
--- a/js/src/config/pythonpath.py
+++ b/js/src/config/pythonpath.py
@@ -1,42 +1,52 @@
 """
 Run a python script, adding extra directories to the python path.
 """
 
-import sys, os
 
-def usage():
-    print >>sys.stderr, "pythonpath.py -I directory script.py [args...]"
-    sys.exit(150)
-
-paths = []
+def main(args):
+    def usage():
+        print >>sys.stderr, "pythonpath.py -I directory script.py [args...]"
+        sys.exit(150)
 
-while True:
-    try:
-        arg = sys.argv[1]
-    except IndexError:
-        usage()
+    paths = []
 
-    if arg == '-I':
-        del sys.argv[1]
+    while True:
         try:
-            path = sys.argv.pop(1)
+            arg = args[0]
         except IndexError:
             usage()
 
-        paths.append(path)
-        continue
+        if arg == '-I':
+            args.pop(0)
+            try:
+                path = args.pop(0)
+            except IndexError:
+                usage()
 
-    if arg.startswith('-I'):
-        path = sys.argv.pop(1)[2:]
-        paths.append(path)
-        continue
+            paths.append(path)
+            continue
+
+        if arg.startswith('-I'):
+            paths.append(args.pop(0)[2:])
+            continue
+
+        break
 
-    break
+    script = args[0]
 
-sys.argv.pop(0)
-script = sys.argv[0]
+    sys.path[0:0] = [os.path.dirname(script)] + paths
+    sys.argv = args
+    sys.argc = len(args)
+
+    frozenglobals['__name__'] = '__main__'
+    frozenglobals['__file__'] = script
 
-sys.path[0:0] = [os.path.dirname(script)] + paths
-__name__ = '__main__'
-__file__ = script
-execfile(script)
+    execfile(script, frozenglobals)
+
+# Freeze scope here ... why this makes things work I have no idea ...
+frozenglobals = globals()
+
+import sys, os
+
+if __name__ == '__main__':
+    main(sys.argv[1:])