Skip to content

Commit bb68d15

Browse files
committed
Add Ionut's --include-dir and -C option support
1 parent 3173dc0 commit bb68d15

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

fileutil.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "log.h"
3535
#include "strutil.h"
36+
#include "flags.h"
3637

3738
bool Exists(StringPiece filename) {
3839
CHECK(filename.size() < PATH_MAX);
@@ -174,6 +175,17 @@ class GlobCache {
174175
} else {
175176
if (Exists(pat))
176177
files->push_back(pat);
178+
else {
179+
for (auto inc_path : g_flags.include_dirs) {
180+
auto to_check = (inc_path + '/' + pat);
181+
LOG("searching for %s in : %s", pat, inc_path.c_str());
182+
LOG("checking for Exists(|%s|)", to_check.c_str());
183+
if (Exists(to_check.c_str())) {
184+
LOG("found %s in : %s", pat, inc_path.c_str());
185+
files->push_back(to_check);
186+
}
187+
}
188+
}
177189
}
178190
}
179191
*files = p.first->second;

flags.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ void Flags::Parse(int argc, char** argv) {
7070
should_propagate = false;
7171
} else if (!strcmp(arg, "-c")) {
7272
is_syntax_check_only = true;
73+
} else if (!strcmp(arg, "-C")) {
74+
if (chdir(argv[++i]) != 0)
75+
PERROR("chdir failed");
7376
} else if (!strcmp(arg, "-i")) {
7477
is_dry_run = true;
7578
} else if (!strcmp(arg, "-s")) {
@@ -159,6 +162,8 @@ void Flags::Parse(int argc, char** argv) {
159162
} else if (ParseCommandLineOptionWithArg("--writable", argv, &i,
160163
&writable_str)) {
161164
writable.push_back(writable_str);
165+
} else if (!strncmp(arg, "--include-dir=", 14)) {
166+
include_dirs.push_back(string(&arg[14]));
162167
} else if (arg[0] == '-') {
163168
ERROR("Unknown flag: %s", arg);
164169
} else {

flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct Flags {
6868
vector<Symbol> targets;
6969
vector<StringPiece> cl_vars;
7070
vector<string> writable;
71+
vector<string> include_dirs;
7172

7273
void Parse(int argc, char** argv);
7374
};

testcase/include_dir.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set -e
2+
3+
mk="$@"
4+
5+
cat <<EOF > Makefile
6+
test: test2
7+
echo PASS
8+
include myfile.mk
9+
EOF
10+
11+
mkdir -p test_dir
12+
echo -e "test2:\n\techo \$@" > test_dir/myfile.mk
13+
${mk} --include-dir test_dir 2> /dev/null

0 commit comments

Comments
 (0)