Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: tools/testing/dart/http_server.dart

Issue 12183022: Change the location of the output directory of generated tests to be inside build directory, but no… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library http_server; 5 library http_server;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 import 'test_suite.dart'; // For TestUtils. 9 import 'test_suite.dart'; // For TestUtils.
10 // TODO(efortuna): Rewrite to not use the args library and simply take an 10 // TODO(efortuna): Rewrite to not use the args library and simply take an
(...skipping 22 matching lines...) Expand all
33 print(parser.getUsage()); 33 print(parser.getUsage());
34 } else { 34 } else {
35 // Pretend we're running test.dart so that TestUtils doesn't get confused 35 // Pretend we're running test.dart so that TestUtils doesn't get confused
36 // about the "current directory." This is only used if we're trying to run 36 // about the "current directory." This is only used if we're trying to run
37 // this file independently for local testing. 37 // this file independently for local testing.
38 TestUtils.testScriptPath = new Path(new Options().script) 38 TestUtils.testScriptPath = new Path(new Options().script)
39 .directoryPath 39 .directoryPath
40 .join(new Path('../../test.dart')) 40 .join(new Path('../../test.dart'))
41 .canonicalize() 41 .canonicalize()
42 .toNativePath(); 42 .toNativePath();
43 // Note: args['package-root'] is always the build directory. We have the
44 // implicit assumption that it contains the 'packages' subdirectory.
45 // TODO: We should probably rename 'package-root' to 'build-directory'.
43 TestingServerRunner._packageRootDir = new Path(args['package-root']); 46 TestingServerRunner._packageRootDir = new Path(args['package-root']);
47 TestingServerRunner._buildDirectory = new Path(args['package-root']);
44 TestingServerRunner.startHttpServer('127.0.0.1', 48 TestingServerRunner.startHttpServer('127.0.0.1',
45 port: int.parse(args['port'])); 49 port: int.parse(args['port']));
46 print('Server listening on port ' 50 print('Server listening on port '
47 '${TestingServerRunner.serverList[0].port}.'); 51 '${TestingServerRunner.serverList[0].port}.');
48 TestingServerRunner.startHttpServer('127.0.0.1', 52 TestingServerRunner.startHttpServer('127.0.0.1',
49 allowedPort: TestingServerRunner.serverList[0].port, port: 53 allowedPort: TestingServerRunner.serverList[0].port, port:
50 int.parse(args['crossOriginPort'])); 54 int.parse(args['crossOriginPort']));
51 print( 55 print(
52 'Server listening on port ${TestingServerRunner.serverList[1].port}.'); 56 'Server listening on port ${TestingServerRunner.serverList[1].port}.');
53 } 57 }
54 } 58 }
55 /** 59 /**
56 * Runs a set of servers that are initialized specifically for the needs of our 60 * Runs a set of servers that are initialized specifically for the needs of our
57 * test framework, such as dealing with package-root. 61 * test framework, such as dealing with package-root.
58 */ 62 */
59 class TestingServerRunner { 63 class TestingServerRunner {
60 static List serverList = []; 64 static List serverList = [];
61 static Path _packageRootDir = null; 65 static Path _packageRootDir = null;
66 static Path _buildDirectory = null;
62 67
63 // Added as a getter so that the function will be called again each time the 68 // Added as a getter so that the function will be called again each time the
64 // default request handler closure is executed. 69 // default request handler closure is executed.
65 static Path get packageRootDir => _packageRootDir; 70 static Path get packageRootDir => _packageRootDir;
71 static Path get buildDirectory => _buildDirectory;
66 72
67 static setPackageRootDir(Map configuration) { 73 static setPackageRootDir(Map configuration) {
68 _packageRootDir = TestUtils.currentWorkingDirectory.join( 74 _packageRootDir = TestUtils.currentWorkingDirectory.join(
69 new Path(TestUtils.buildDir(configuration))); 75 new Path(TestUtils.buildDir(configuration)));
70 } 76 }
71 77
78 static setBuildDir(Map configuration) {
79 _buildDirectory = new Path(TestUtils.buildDir(configuration));
80 }
81
72 static startHttpServer(String host, {int allowedPort:-1, int port: 0}) { 82 static startHttpServer(String host, {int allowedPort:-1, int port: 0}) {
73 var basePath = TestUtils.dartDir(); 83 var basePath = TestUtils.dartDir();
74 var httpServer = new HttpServer(); 84 var httpServer = new HttpServer();
75 var packagesDirName = 'packages'; 85 var packagesDirName = 'packages';
76 httpServer.onError = (e) { 86 httpServer.onError = (e) {
77 // TODO(ricow): Once we have a debug log we should write this out there. 87 // TODO(ricow): Once we have a debug log we should write this out there.
78 print('Test http server error: $e'); 88 print('Test http server error: $e');
79 }; 89 };
80 httpServer.defaultRequestHandler = (request, resp) { 90 httpServer.defaultRequestHandler = (request, resp) {
91 // TODO(kustermann,ricow): We could change this to the following scheme:
92 // http://host:port/root_dart/X -> $DartDir/X
93 // http://host:port/root_build/X -> $BuildDir/X
94 // http://host:port/root_packages/X -> $BuildDir/packages/X
95 // Issue: 8368
96
81 var requestPath = new Path(request.path.substring(1)).canonicalize(); 97 var requestPath = new Path(request.path.substring(1)).canonicalize();
82 var path = basePath.join(requestPath); 98 var path = basePath.join(requestPath);
83 var file = new File(path.toNativePath()); 99 var file = new File(path.toNativePath());
84 100 // Since the build directory may not be located directly beneath the dart
101 // root directory (if we pass it in, e.g., for dartium testing) we serve
102 // files from the build directory explicitly. Please note that if
103 // buildDirectory has the same name as a directory inside the dart repo
104 // we will server files from the buildDirectory.
105 if (requestPath.toString().startsWith(buildDirectory.toString())) {
Emily Fortuna 2013/02/07 23:37:47 This doesn't work because requestPath isn't an abs
kustermann 2013/02/08 01:55:13 It "sort of" works because this code assumes that
106 file = new File(requestPath.toNativePath());
107 }
85 if (requestPath.segments().contains(packagesDirName)) { 108 if (requestPath.segments().contains(packagesDirName)) {
86 // Essentially implement the packages path rewriting, so we don't have 109 // Essentially implement the packages path rewriting, so we don't have
87 // to pass environment variables to the browsers. 110 // to pass environment variables to the browsers.
88 var requestPathStr = requestPath.toNativePath().substring( 111 var requestPathStr = requestPath.toNativePath().substring(
89 requestPath.toNativePath().indexOf(packagesDirName)); 112 requestPath.toNativePath().indexOf(packagesDirName));
90 path = packageRootDir.append(requestPathStr); 113 path = packageRootDir.append(requestPathStr);
91 file = new File(path.toNativePath()); 114 file = new File(path.toNativePath());
92 } 115 }
93 file.exists().then((exists) { 116 file.exists().then((exists) {
94 if (exists) { 117 if (exists) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 }); 156 });
134 157
135 httpServer.listen(host, port); 158 httpServer.listen(host, port);
136 serverList.add(httpServer); 159 serverList.add(httpServer);
137 } 160 }
138 161
139 static terminateHttpServers() { 162 static terminateHttpServers() {
140 for (var server in serverList) server.close(); 163 for (var server in serverList) server.close();
141 } 164 }
142 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698