fix order of args to CanonicalizePath

This commit is contained in:
Scott Graham 2014-11-08 23:01:23 -08:00
parent 559389de08
commit 4ee1cb54d7
9 changed files with 38 additions and 38 deletions

View File

@ -851,8 +851,8 @@ bool Builder::ExtractDeps(CommandRunner::Result* result,
for (vector<StringPiece>::iterator i = deps.ins_.begin();
i != deps.ins_.end(); ++i) {
unsigned int slash_bits;
if (!CanonicalizePath(const_cast<char*>(i->str_), &i->len_, err,
&slash_bits))
if (!CanonicalizePath(const_cast<char*>(i->str_), &i->len_, &slash_bits,
err))
return false;
deps_nodes->push_back(state_->GetNode(*i, slash_bits));
}

View File

@ -35,7 +35,7 @@ int main() {
int64_t start = GetTimeMillis();
unsigned int slash_bits;
for (int i = 0; i < kNumRepetitions; ++i) {
CanonicalizePath(buf, &len, &err, &slash_bits);
CanonicalizePath(buf, &len, &slash_bits, &err);
}
int delta = (int)(GetTimeMillis() - start);
times.push_back(delta);

View File

@ -393,7 +393,7 @@ bool ImplicitDepLoader::LoadDepFile(Edge* edge, const string& path,
unsigned int unused;
if (!CanonicalizePath(const_cast<char*>(depfile.out_.str_),
&depfile.out_.len_, err, &unused))
&depfile.out_.len_, &unused, err))
return false;
// Check that this depfile matches the edge's output.
@ -413,8 +413,8 @@ bool ImplicitDepLoader::LoadDepFile(Edge* edge, const string& path,
for (vector<StringPiece>::iterator i = depfile.ins_.begin();
i != depfile.ins_.end(); ++i, ++implicit_dep) {
unsigned int slash_bits;
if (!CanonicalizePath(const_cast<char*>(i->str_), &i->len_, err,
&slash_bits))
if (!CanonicalizePath(const_cast<char*>(i->str_), &i->len_, &slash_bits,
err))
return false;
Node* node = state_->GetNode(*i, slash_bits);

View File

@ -101,7 +101,7 @@ string IncludesNormalize::Normalize(const string& input,
strncpy(copy, input.c_str(), input.size() + 1);
string err;
unsigned int slash_bits;
if (!CanonicalizePath(copy, &len, &err, &slash_bits))
if (!CanonicalizePath(copy, &len, &slash_bits, &err))
Warning("couldn't canonicalize '%s': %s\n", input.c_str(), err.c_str());
StringPiece partially_fixed(copy, len);

View File

@ -210,7 +210,7 @@ bool ManifestParser::ParseDefault(string* err) {
string path = eval.Evaluate(env_);
string path_err;
unsigned int slash_bits; // Unused because this only does lookup.
if (!CanonicalizePath(&path, &path_err, &slash_bits))
if (!CanonicalizePath(&path, &slash_bits, &path_err))
return lexer_.Error(path_err, err);
if (!state_->AddDefault(path, &path_err))
return lexer_.Error(path_err, err);
@ -325,7 +325,7 @@ bool ManifestParser::ParseEdge(string* err) {
string path = i->Evaluate(env);
string path_err;
unsigned int slash_bits;
if (!CanonicalizePath(&path, &path_err, &slash_bits))
if (!CanonicalizePath(&path, &slash_bits, &path_err))
return lexer_.Error(path_err, err);
state_->AddIn(edge, path, slash_bits);
}
@ -333,7 +333,7 @@ bool ManifestParser::ParseEdge(string* err) {
string path = i->Evaluate(env);
string path_err;
unsigned int slash_bits;
if (!CanonicalizePath(&path, &path_err, &slash_bits))
if (!CanonicalizePath(&path, &slash_bits, &path_err))
return lexer_.Error(path_err, err);
state_->AddOut(edge, path, slash_bits);
}

View File

@ -229,7 +229,7 @@ struct RealFileReader : public ManifestParser::FileReader {
bool NinjaMain::RebuildManifest(const char* input_file, string* err) {
string path = input_file;
unsigned int slash_bits; // Unused because this path is only used for lookup.
if (!CanonicalizePath(&path, err, &slash_bits))
if (!CanonicalizePath(&path, &slash_bits, err))
return false;
Node* node = state_.LookupNode(path);
if (!node)
@ -252,7 +252,7 @@ bool NinjaMain::RebuildManifest(const char* input_file, string* err) {
Node* NinjaMain::CollectTarget(const char* cpath, string* err) {
string path = cpath;
unsigned int slash_bits; // Unused because this path is only used for lookup.
if (!CanonicalizePath(&path, err, &slash_bits))
if (!CanonicalizePath(&path, &slash_bits, err))
return NULL;
// Special syntax: "foo.cc^" means "the first output of foo.cc".

View File

@ -85,13 +85,13 @@ void Error(const char* msg, ...) {
fprintf(stderr, "\n");
}
bool CanonicalizePath(string* path, string* err, unsigned int* slash_bits) {
bool CanonicalizePath(string* path, unsigned int* slash_bits, string* err) {
METRIC_RECORD("canonicalize str");
size_t len = path->size();
char* str = 0;
if (len > 0)
str = &(*path)[0];
if (!CanonicalizePath(str, &len, err, slash_bits))
if (!CanonicalizePath(str, &len, slash_bits, err))
return false;
path->resize(len);
return true;
@ -108,8 +108,8 @@ unsigned int ShiftOverBit(int offset, unsigned int bits) {
return (above >> 1) | below;
}
bool CanonicalizePath(char* path, size_t* len, string* err,
unsigned int* slash_bits) {
bool CanonicalizePath(char* path, size_t* len, unsigned int* slash_bits,
string* err) {
// WARNING: this function is performance-critical; please benchmark
// any changes you make to it.
METRIC_RECORD("canonicalize path");

View File

@ -43,9 +43,9 @@ void Error(const char* msg, ...);
/// Canonicalize a path like "foo/../bar.h" into just "bar.h".
/// |slash_bits| has bits set starting from lowest for a backslash that was
/// normalized to a forward slash. (only used on Windows)
bool CanonicalizePath(string* path, string* err, unsigned int* slash_bits);
bool CanonicalizePath(char* path, size_t* len, string* err,
unsigned int* slash_bits);
bool CanonicalizePath(string* path, unsigned int* slash_bits, string* err);
bool CanonicalizePath(char* path, size_t* len, unsigned int* slash_bits,
string* err);
/// Appends |input| to |*result|, escaping according to the whims of either
/// Bash, or Win32's CommandLineToArgvW().

View File

@ -20,7 +20,7 @@ namespace {
bool CanonicalizePath(string* path, string* err) {
unsigned int unused;
return ::CanonicalizePath(path, err, &unused);
return ::CanonicalizePath(path, &unused, err);
}
} // namespace
@ -164,82 +164,82 @@ TEST(CanonicalizePath, SlashTracking) {
unsigned int slash_bits;
path = "foo.h"; err = "";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("foo.h", path);
EXPECT_EQ(0, slash_bits);
path = "a\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/foo.h", path);
EXPECT_EQ(1, slash_bits);
path = "a/bcd/efh\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/bcd/efh/foo.h", path);
EXPECT_EQ(4, slash_bits);
path = "a\\bcd/efh\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/bcd/efh/foo.h", path);
EXPECT_EQ(5, slash_bits);
path = "a\\bcd\\efh\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/bcd/efh/foo.h", path);
EXPECT_EQ(7, slash_bits);
path = "a/bcd/efh/foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/bcd/efh/foo.h", path);
EXPECT_EQ(0, slash_bits);
path = "a\\./efh\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/efh/foo.h", path);
EXPECT_EQ(3, slash_bits);
path = "a\\../efh\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("efh/foo.h", path);
EXPECT_EQ(1, slash_bits);
path = "a\\b\\c\\d\\e\\f\\g\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/b/c/d/e/f/g/foo.h", path);
EXPECT_EQ(127, slash_bits);
path = "a\\b\\c\\..\\..\\..\\g\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("g/foo.h", path);
EXPECT_EQ(1, slash_bits);
path = "a\\b/c\\../../..\\g\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("g/foo.h", path);
EXPECT_EQ(1, slash_bits);
path = "a\\b/c\\./../..\\g\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/g/foo.h", path);
EXPECT_EQ(3, slash_bits);
path = "a\\b/c\\./../..\\g/foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/g/foo.h", path);
EXPECT_EQ(1, slash_bits);
path = "a\\\\\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/foo.h", path);
EXPECT_EQ(1, slash_bits);
path = "a/\\\\foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/foo.h", path);
EXPECT_EQ(0, slash_bits);
path = "a\\//foo.h";
EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err));
EXPECT_EQ("a/foo.h", path);
EXPECT_EQ(1, slash_bits);
}
@ -288,13 +288,13 @@ TEST(CanonicalizePath, NotNullTerminated) {
path = "foo/. bar/.";
len = strlen("foo/."); // Canonicalize only the part before the space.
EXPECT_TRUE(CanonicalizePath(&path[0], &len, &err, &unused));
EXPECT_TRUE(CanonicalizePath(&path[0], &len, &unused, &err));
EXPECT_EQ(strlen("foo"), len);
EXPECT_EQ("foo/. bar/.", string(path));
path = "foo/../file bar/.";
len = strlen("foo/../file");
EXPECT_TRUE(CanonicalizePath(&path[0], &len, &err, &unused));
EXPECT_TRUE(CanonicalizePath(&path[0], &len, &unused, &err));
EXPECT_EQ(strlen("file"), len);
EXPECT_EQ("file ./file bar/.", string(path));
}