Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This fixes issue #157 #158

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions fileutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "log.h"
#include "strutil.h"
#include "flags.h"

bool Exists(StringPiece filename) {
CHECK(filename.size() < PATH_MAX);
Expand Down Expand Up @@ -174,6 +175,17 @@ class GlobCache {
} else {
if (Exists(pat))
files->push_back(pat);
else {
for (auto inc_path : g_flags.include_dirs) {
auto to_check = (inc_path + '/' + pat);
LOG("searching for %s in : %s", pat, inc_path.c_str());
LOG("checking for Exists(|%s|)", to_check.c_str());
if (Exists(to_check.c_str())) {
LOG("found %s in : %s", pat, inc_path.c_str());
files->push_back(to_check);
}
}
}
}
}
*files = p.first->second;
Expand Down
5 changes: 5 additions & 0 deletions flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ void Flags::Parse(int argc, char** argv) {
should_propagate = false;
} else if (!strcmp(arg, "-c")) {
is_syntax_check_only = true;
} else if (!strcmp(arg, "-C")) {
if (chdir(argv[++i]) != 0)
PERROR("chdir failed");
} else if (!strcmp(arg, "-i")) {
is_dry_run = true;
} else if (!strcmp(arg, "-s")) {
Expand Down Expand Up @@ -155,6 +158,8 @@ void Flags::Parse(int argc, char** argv) {
} else if (ParseCommandLineOptionWithArg("--writable", argv, &i,
&writable_str)) {
writable.push_back(writable_str);
} else if (!strncmp(arg, "--include-dir=", 14)) {
include_dirs.push_back(string(&arg[14]));
} else if (arg[0] == '-') {
ERROR("Unknown flag: %s", arg);
} else {
Expand Down
1 change: 1 addition & 0 deletions flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct Flags {
vector<Symbol> targets;
vector<StringPiece> cl_vars;
vector<string> writable;
vector<string> include_dirs;

void Parse(int argc, char** argv);
};
Expand Down
13 changes: 13 additions & 0 deletions testcase/include_dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set -e

mk="$@"

cat <<EOF > Makefile
test: test2
echo PASS
include myfile.mk
EOF

mkdir -p test_dir
echo -e "test2:\n\techo \$@" > test_dir/myfile.mk
${mk} --include-dir test_dir 2> /dev/null