mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1045617 - move services's run_server.py Makefile rules into mach; r=gps
This commit is contained in:
parent
cd91df4210
commit
a9ceaeb4dd
@ -74,6 +74,7 @@ MACH_MODULES = [
|
||||
'python/mozboot/mozboot/mach_commands.py',
|
||||
'python/mozbuild/mozbuild/mach_commands.py',
|
||||
'python/mozbuild/mozbuild/frontend/mach_commands.py',
|
||||
'services/common/tests/mach_commands.py',
|
||||
'testing/mach_commands.py',
|
||||
'testing/marionette/mach_commands.py',
|
||||
'testing/mochitest/mach_commands.py',
|
||||
|
@ -3,20 +3,3 @@
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
PREF_JS_EXPORTS := $(srcdir)/services-common.js
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
# What follows is a helper to launch a standalone storage server instance.
|
||||
# Most of the code lives in a Python script in the tests directory. If we
|
||||
# ever consolidate our Python code, and/or have a supplemental driver for the
|
||||
# build system, this can go away.
|
||||
|
||||
server_port := 8080
|
||||
|
||||
storage-server:
|
||||
$(PYTHON) $(srcdir)/tests/run_server.py $(topsrcdir) \
|
||||
$(MOZ_BUILD_ROOT) run_storage_server.js --port $(server_port)
|
||||
|
||||
bagheera-server:
|
||||
$(PYTHON) $(srcdir)/tests/run_server.py $(topsrcdir) \
|
||||
$(MOZ_BUILD_ROOT) run_bagheera_server.js --port $(server_port)
|
||||
|
127
services/common/tests/mach_commands.py
Normal file
127
services/common/tests/mach_commands.py
Normal file
@ -0,0 +1,127 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import mozpack.path
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
import which
|
||||
|
||||
from mozbuild.base import (
|
||||
MachCommandBase,
|
||||
)
|
||||
|
||||
from mach.decorators import (
|
||||
CommandArgument,
|
||||
CommandProvider,
|
||||
Command,
|
||||
)
|
||||
|
||||
from mach.registrar import (
|
||||
Registrar
|
||||
)
|
||||
|
||||
from shutil import rmtree
|
||||
from subprocess import Popen
|
||||
from sys import argv
|
||||
from sys import exit
|
||||
from tempfile import mkdtemp
|
||||
|
||||
import mozpack.path as mozpath
|
||||
|
||||
|
||||
DEFAULT_PORT = 8080
|
||||
DEFAULT_HOSTNAME = 'localhost'
|
||||
|
||||
SRCDIR = mozpath.abspath(mozpath.dirname(__file__))
|
||||
|
||||
STORAGE_SERVER_SCRIPT = mozpath.join(SRCDIR, 'run_storage_server.js')
|
||||
BAGHEERA_SERVER_SCRIPT = mozpath.join(SRCDIR, 'run_bagheera_server.js')
|
||||
|
||||
def SyncStorageCommand(func):
|
||||
"""Decorator that adds shared command arguments to services commands."""
|
||||
|
||||
port = CommandArgument('--port', metavar='PORT', type=int,
|
||||
default=DEFAULT_PORT, help='Port to run server on.')
|
||||
func = port(func)
|
||||
|
||||
address = CommandArgument('--address', metavar='ADDRESS',
|
||||
default=DEFAULT_HOSTNAME,
|
||||
help='Hostname to bind server to.')
|
||||
func = address(func)
|
||||
|
||||
return func
|
||||
|
||||
Registrar.register_category(name='services',
|
||||
title='Services utilities',
|
||||
description='Commands for services development.')
|
||||
|
||||
@CommandProvider
|
||||
class SyncTestCommands(MachCommandBase):
|
||||
def __init__(self, context):
|
||||
MachCommandBase.__init__(self, context)
|
||||
|
||||
def run_server(self, js_file, hostname, port):
|
||||
topsrcdir = self.topsrcdir
|
||||
topobjdir = self.topobjdir
|
||||
|
||||
unit_test_dir = mozpath.join(SRCDIR, 'unit')
|
||||
|
||||
head_paths = [
|
||||
'head_global.js',
|
||||
'head_helpers.js',
|
||||
'head_http.js',
|
||||
]
|
||||
|
||||
head_paths = ['"%s"' % mozpath.join(unit_test_dir, path) for path in head_paths]
|
||||
|
||||
args = [
|
||||
'%s/run-mozilla.sh' % self.bindir,
|
||||
'%s/xpcshell' % self.bindir,
|
||||
'-g', self.bindir,
|
||||
'-a', self.bindir,
|
||||
'-r', '%s/components/httpd.manifest' % self.bindir,
|
||||
'-m',
|
||||
'-s',
|
||||
'-f', '%s/testing/xpcshell/head.js' % topsrcdir,
|
||||
'-e', 'const _SERVER_ADDR = "%s";' % hostname,
|
||||
'-e', 'const _TESTING_MODULES_DIR = "%s/_tests/modules";' % topobjdir,
|
||||
'-e', 'const SERVER_PORT = "%s";' % port,
|
||||
'-e', 'const INCLUDE_FILES = [%s];' % ', '.join(head_paths),
|
||||
'-e', '_register_protocol_handlers();',
|
||||
'-e', 'for each (let name in INCLUDE_FILES) load(name);',
|
||||
'-e', '_fakeIdleService.activate();',
|
||||
'-f', js_file
|
||||
]
|
||||
|
||||
profile_dir = mkdtemp()
|
||||
print 'Created profile directory: %s' % profile_dir
|
||||
|
||||
try:
|
||||
env = {'XPCSHELL_TEST_PROFILE_DIR': profile_dir}
|
||||
proc = Popen(args, env=env)
|
||||
|
||||
return proc.wait()
|
||||
|
||||
finally:
|
||||
print 'Removing profile directory %s' % profile_dir
|
||||
rmtree(profile_dir)
|
||||
|
||||
@Command('doesthiswork', category='testing', description='Example command')
|
||||
def doesthiswork(self):
|
||||
print 'hi!'
|
||||
|
||||
@Command('storage-server', category='services',
|
||||
description='Run a storage server.')
|
||||
@SyncStorageCommand
|
||||
def run_storage_server(self, port=DEFAULT_PORT, address=DEFAULT_HOSTNAME):
|
||||
exit(self.run_server(STORAGE_SERVER_SCRIPT, address, port))
|
||||
|
||||
@Command('bagheera-server', category='services',
|
||||
description='Run a bagheera server.')
|
||||
def run_bagheera_server(self, port=DEFAULT_PORT, address=DEFAULT_HOSTNAME):
|
||||
exit(self.run_server(BAGHEERA_SERVER_SCRIPT, address, port))
|
@ -1,79 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from shutil import rmtree
|
||||
from subprocess import Popen
|
||||
from sys import argv
|
||||
from sys import exit
|
||||
from tempfile import mkdtemp
|
||||
|
||||
DEFAULT_PORT = 8080
|
||||
DEFAULT_HOSTNAME = 'localhost'
|
||||
|
||||
def run_server(srcdir, objdir, js_file, hostname=DEFAULT_HOSTNAME,
|
||||
port=DEFAULT_PORT):
|
||||
|
||||
dist_dir = '%s/dist' % objdir
|
||||
head_dir = '%s/services/common/tests/unit' % srcdir
|
||||
|
||||
head_paths = [
|
||||
'head_global.js',
|
||||
'head_helpers.js',
|
||||
'head_http.js',
|
||||
]
|
||||
|
||||
head_paths = ['"%s/%s"' % (head_dir, path) for path in head_paths]
|
||||
|
||||
args = [
|
||||
'%s/bin/xpcshell' % dist_dir,
|
||||
'-g', '%s/bin' % dist_dir,
|
||||
'-a', '%s/bin' % dist_dir,
|
||||
'-r', '%s/bin/components/httpd.manifest' % dist_dir,
|
||||
'-m',
|
||||
'-n',
|
||||
'-s',
|
||||
'-f', '%s/testing/xpcshell/head.js' % srcdir,
|
||||
'-e', 'const _SERVER_ADDR = "%s";' % hostname,
|
||||
'-e', 'const _TESTING_MODULES_DIR = "%s/_tests/modules";' % objdir,
|
||||
'-e', 'const SERVER_PORT = "%s";' % port,
|
||||
'-e', 'const INCLUDE_FILES = [%s];' % ', '.join(head_paths),
|
||||
'-e', '_register_protocol_handlers();',
|
||||
'-e', 'for each (let name in INCLUDE_FILES) load(name);',
|
||||
'-e', '_fakeIdleService.activate();',
|
||||
'-f', '%s/services/common/tests/%s' % (srcdir, js_file)
|
||||
]
|
||||
|
||||
profile_dir = mkdtemp()
|
||||
print 'Created profile directory: %s' % profile_dir
|
||||
|
||||
try:
|
||||
env = {'XPCSHELL_TEST_PROFILE_DIR': profile_dir}
|
||||
proc = Popen(args, env=env)
|
||||
|
||||
return proc.wait()
|
||||
|
||||
finally:
|
||||
print 'Removing profile directory %s' % profile_dir
|
||||
rmtree(profile_dir)
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = ArgumentParser(description="Run a standalone JS server.")
|
||||
parser.add_argument('srcdir',
|
||||
help="Root directory of Firefox source code.")
|
||||
parser.add_argument('objdir',
|
||||
help="Root directory object directory created during build.")
|
||||
parser.add_argument('js_file',
|
||||
help="JS file (in this directory) to execute.")
|
||||
parser.add_argument('--port', default=DEFAULT_PORT, type=int,
|
||||
help="Port to run server on.")
|
||||
parser.add_argument('--address', default=DEFAULT_HOSTNAME,
|
||||
help="Hostname to bind server to.")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
exit(run_server(args.srcdir, args.objdir, args.js_file, args.address,
|
||||
args.port))
|
Loading…
Reference in New Issue
Block a user