Skip to content

Commit

Permalink
Add Ionut's --include-dir and -C option support
Browse files Browse the repository at this point in the history
  • Loading branch information
kati-cisco committed Nov 3, 2018
1 parent 3173dc0 commit bb68d15
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
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 @@ -159,6 +162,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 @@ -68,6 +68,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

0 comments on commit bb68d15

Please sign in to comment.