Skip to content

Commit

Permalink
windows: add dirname term to build, fix some paths
Browse files Browse the repository at this point in the history
Fixes up some windows path issues.  I believe that the only
test failures now are just path expectations in the php tests,
and because we don't currently have pcre support in the
windows build.

Ref: facebook#19
  • Loading branch information
wez committed Jul 29, 2015
1 parent 2a67af3 commit 5ef973b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 9 deletions.
3 changes: 3 additions & 0 deletions arcanist/lib/WatchmanTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Licensed under the Apache License, Version 2.0 */

function w_normalize_filename($a) {
if ($a === null) {
return null;
}
return str_replace('/', DIRECTORY_SEPARATOR, $a);
}

Expand Down
22 changes: 18 additions & 4 deletions cmds/watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ static bool find_file_in_dir_tree(const char *root_file, char *candidate_dir,
char *proj_path;
int rv;

ignore_result(asprintf(&proj_path, "%s/%s", candidate_dir, root_file));
ignore_result(asprintf(&proj_path, "%s%c%s", candidate_dir,
WATCHMAN_DIR_SEP, root_file));
rv = w_path_exists(proj_path);
free(proj_path);

Expand All @@ -144,14 +145,27 @@ static bool find_file_in_dir_tree(const char *root_file, char *candidate_dir,
}

// Walk up to the next level
#ifdef _WIN32
if (strlen(candidate_dir) == 3 &&
candidate_dir[1] == ':' && candidate_dir[2] == '\\') {
// Drive letter; is a root
break;
}
if (strlen(candidate_dir) <= 2) {
// Effectively a root
break;
}
#else
if (!strcmp(candidate_dir, "/")) {
// Can't go any higher than this
break;
}
#endif


slash = strrchr(candidate_dir, '/');
slash = strrchr(candidate_dir, WATCHMAN_DIR_SEP);
if (restore_slash) {
*restore_slash = '/';
*restore_slash = WATCHMAN_DIR_SEP;
}
if (!slash) {
break;
Expand All @@ -161,7 +175,7 @@ static bool find_file_in_dir_tree(const char *root_file, char *candidate_dir,
}

if (restore_slash) {
*restore_slash = '/';
*restore_slash = WATCHMAN_DIR_SEP;
}
*relpath = NULL;
return false;
Expand Down
9 changes: 7 additions & 2 deletions query/dirname.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ static void dispose_dirname(void *ptr) {
free(data);
}

static inline bool is_dir_sep(int c) {
return c == '/' || c == '\\';
}

static bool eval_dirname(struct w_query_ctx *ctx,
struct watchman_file *file, void *ptr) {
struct dirname_data *data = ptr;
Expand All @@ -39,7 +43,8 @@ static bool eval_dirname(struct w_query_ctx *ctx,
// Want to make sure that wholename is a child of dirname, so
// check for a dir separator. Special case for dirname == '' (the root),
// which won't have a slash in position 0.
if (data->dirname->len > 0 && str->buf[data->dirname->len] != '/') {
if (data->dirname->len > 0 &&
!is_dir_sep(str->buf[data->dirname->len])) {
// may have a common prefix with, but is not a child of dirname
return false;
}
Expand All @@ -51,7 +56,7 @@ static bool eval_dirname(struct w_query_ctx *ctx,
// Now compute the depth of file from dirname. We do this by
// counting dir separators, not including the one we saw above.
for (i = data->dirname->len + 1; i < str->len; i++) {
if (str->buf[i] == '/') {
if (is_dir_sep(str->buf[i])) {
depth++;
}
}
Expand Down
1 change: 1 addition & 0 deletions root.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ static w_string_t *w_resolve_filesystem_canonical_name(const char *path)
if (long_len == 0 && err == ERROR_FILE_NOT_FOUND) {
// signal to caller that the file has disappeared -- the caller will read
// errno and do error handling
errno = map_win32_err(err);
return NULL;
}

Expand Down
1 change: 1 addition & 0 deletions tests/integration/trigger-chdir.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function testChdirRelativeRoot() {
$this->waitFor(
function () use ($env, $root) {
$envdata = @file_get_contents($env);
$root = preg_quote($root);
return preg_match(",PWD=$root/sub,", $envdata) == 1;
},
10,
Expand Down
8 changes: 5 additions & 3 deletions tests/integration/watchproject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class watchProjectTestCaseHelper extends WatchmanTestCase {
function runProjectTests($tests, $touch_watchmanconfig = false) {
foreach ($tests as $info) {
list($touch, $expected_watch, $expect_rel, $expected_pass) = $info;
$dir = PhutilDirectoryFixture::newEmptyFixture();
$dir = new WatchmanDirectoryFixture();
$root = realpath($dir->getPath());

mkdir("$root/a/b/c", 0777, true);
Expand All @@ -30,8 +30,10 @@ function runProjectTests($tests, $touch_watchmanconfig = false) {
if ($err) {
$this->assertFailure("failed to watch-project: $err");
}
$this->assertEqual($full_watch, idx($res, 'watch'), $label);
$this->assertEqual($expect_rel, idx($res, 'relative_path'), $label);
$this->assertEqual(w_normalize_filename($full_watch),
idx($res, 'watch'), $label);
$this->assertEqual(w_normalize_filename($expect_rel),
idx($res, 'relative_path'), $label);
} else {
if ($err) {
$this->assertEqual(
Expand Down
4 changes: 4 additions & 0 deletions winbuild/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ JSON_SRCS=\

SRCS=\
$(JSON_SRCS) \
winbuild\abort.c \
winbuild\errmap.c \
winbuild\pathmap.c \
winbuild\stat.c \
Expand Down Expand Up @@ -58,13 +59,15 @@ SRCS=\
cmds\debug.c \
query\base.c \
query\parse.c \
query\dirname.c \
query\eval.c \
query\type.c \
query\suffix.c \
query\match.c \
query\pcre.c \
query\name.c \
query\fieldlist.c \
query\intcompare.c \
query\since.c \
query\empty.c \
watcher\win32.c \
Expand All @@ -82,6 +85,7 @@ TEST_SRCS=\
winbuild\time.c \
winbuild\pthread.c \
winbuild\backtrace.c \
winbuild\abort.c \
argv.c \
$(JSON_SRCS)

Expand Down
13 changes: 13 additions & 0 deletions winbuild/abort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Copyright 2015-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */

#include "watchman.h"

// We do our own abort because the standard implementation invokes
// troubleshooting UI that the user won't care about, and because
// this actually doesn't work properly in our test harness
void w_abort(void) {
ignore_result(write(STDERR_FILENO, "aborting\n",
(int)strlen("aborting\n")));
exit(1);
}
4 changes: 4 additions & 0 deletions winbuild/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include <io.h>
#include <sys/types.h>

// Use our own abort implementation
#define abort() w_abort()
extern void w_abort(void);

typedef ptrdiff_t ssize_t;

#define WATCHMAN_DIR_SEP '\\'
Expand Down

0 comments on commit 5ef973b

Please sign in to comment.