make webserver build on windows

Change-Id: Ib580d8a39607a28ce6670a2a11cfc3ca42dcc866
This commit is contained in:
Brad Fitzpatrick 2011-07-17 15:27:20 -07:00
parent eb288d95f1
commit 114404d4a7
4 changed files with 81 additions and 14 deletions

View File

@ -359,6 +359,19 @@ sub build {
v("Built '$target'");
}
sub filter_go_os {
my @good;
my $is_windows = $^O eq "msys" || $^O eq "MSWin32";
foreach my $f (@_) {
my $for_unix = $f =~ /_unix\.go$/;
my $for_windows = $f =~ /_windows\.go$/;
next if $for_unix && $is_windows;
next if $for_windows && !$is_windows;
push @good, $f;
}
return @good;
}
sub find_go_camli_deps {
my $target = shift;
if ($target =~ /\bthird_party\b/) {
@ -375,6 +388,7 @@ sub find_go_camli_deps {
my $target_dir = dir($target);
opendir(my $dh, $target_dir) or die "Failed to open directory: $target\n";
my @go_files = grep { !m!^\.\#! } grep { !/_testmain\.go$/ } grep { /\.go$/ } readdir($dh);
@go_files = filter_go_os(@go_files);
closedir($dh);
# TODO: just stat the files first and keep a cache file of the
@ -439,6 +453,7 @@ sub gen_target_makefile {
opendir(my $dh, $target_dir) or die;
my @dir_files = readdir($dh);
my @go_files = grep { !m!^\.\#! } grep { !/_testmain\.go$/ } grep { /\.go$/ } @dir_files;
@go_files = filter_go_os(@go_files);
closedir($dh);
if ($t->{tags}{fileembed}) {

View File

@ -0,0 +1,36 @@
/*
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package webserver
import (
"fmt"
"log"
"os"
"strconv"
)
func pipeFromEnvFd(env string) (*os.File, os.Error) {
fdStr := os.Getenv(env)
if fdStr == "" {
return nil, fmt.Errorf("Environment variable %q was blank", env)
}
fd, err := strconv.Atoi(fdStr)
if err != nil {
log.Fatalf("Bogus test harness fd '%s': %v", fdStr, err)
}
return os.NewFile(fd, "testingpipe-"+env), nil
}

View File

@ -0,0 +1,25 @@
/*
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package webserver
import (
"os"
)
func pipeFromEnvFd(env string) (*os.File, os.Error) {
return nil, os.NewError("not implemented")
}

View File

@ -25,7 +25,6 @@ import (
"log"
"net"
"os"
"strconv"
"strings"
"time"
)
@ -135,24 +134,16 @@ func (s *Server) Serve() {
}
func pipeFromEnvFd(env string) *os.File {
fdStr := os.Getenv(env)
if fdStr == "" {
return nil
}
fd, err := strconv.Atoi(fdStr)
if err != nil {
log.Fatalf("Bogus test harness fd '%s': %v", fdStr, err)
}
return os.NewFile(fd, "testingpipe-"+env)
}
// Signals the test harness that we've started listening.
// TODO: write back the port number that we randomly selected?
// For now just writes back a single byte.
func runTestHarnessIntegration(listener net.Listener) {
writePipe := pipeFromEnvFd("TESTING_PORT_WRITE_FD")
readPipe := pipeFromEnvFd("TESTING_CONTROL_READ_FD")
writePipe, err := pipeFromEnvFd("TESTING_PORT_WRITE_FD")
if err != nil {
return
}
readPipe, _ := pipeFromEnvFd("TESTING_CONTROL_READ_FD")
if writePipe != nil {
writePipe.Write([]byte(listener.Addr().String() + "\n"))