aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2016-06-25 11:24:59 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2016-06-25 11:24:59 +0900
commit8e77fa71e9365a8a6cc1b13a6fb41a3827146053 (patch)
treee41d38d6ac5b2b924a750624428c2d7403db163a
parent52fe6fcb7e0143e48b8f82f92283dea89e5c3741 (diff)
parent5e6b2e4c094eb2b034e524884c72aab060af9999 (diff)
Merge branch 'jzhupo-master'
-rw-r--r--flags.cc8
-rw-r--r--symtab.cc4
-rwxr-xr-xtestcase/cmdline_var.sh27
-rwxr-xr-xtestcase/cmdline_var_makeflags.sh36
-rwxr-xr-xtestcase/cmdline_var_modify.sh27
-rwxr-xr-xtestcase/cmdline_var_override.sh27
6 files changed, 129 insertions, 0 deletions
diff --git a/flags.cc b/flags.cc
index 876e855..1ed9afd 100644
--- a/flags.cc
+++ b/flags.cc
@@ -16,6 +16,7 @@
#include "flags.h"
+#include <stdlib.h>
#include <unistd.h>
#include "log.h"
@@ -52,6 +53,13 @@ void Flags::Parse(int argc, char** argv) {
num_jobs = num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
const char* num_jobs_str;
+ if (const char* makeflags = getenv("MAKEFLAGS")) {
+ for (StringPiece tok : WordScanner(makeflags)) {
+ if (!HasPrefix(tok, "-") && tok.find('=') != string::npos)
+ cl_vars.push_back(tok);
+ }
+ }
+
for (int i = 1; i < argc; i++) {
const char* arg = argv[i];
bool should_propagate = true;
diff --git a/symtab.cc b/symtab.cc
index b47522b..cbaa4b4 100644
--- a/symtab.cc
+++ b/symtab.cc
@@ -69,6 +69,10 @@ void Symbol::SetGlobalVar(Var* v, bool is_override) const {
orig->Origin() == VarOrigin::ENVIRONMENT_OVERRIDE)) {
return;
}
+ if (orig->Origin() == VarOrigin::COMMAND_LINE &&
+ v->Origin() == VarOrigin::FILE) {
+ return;
+ }
if (orig->Origin() == VarOrigin::AUTOMATIC) {
ERROR("overriding automatic variable is not implemented yet");
}
diff --git a/testcase/cmdline_var.sh b/testcase/cmdline_var.sh
new file mode 100755
index 0000000..b892736
--- /dev/null
+++ b/testcase/cmdline_var.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# Copyright 2016 Google Inc. All rights reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+mk="$@"
+
+cat <<EOF > Makefile
+CLVAR := FAIL
+all:
+ @echo \$(CLVAR)
+EOF
+
+${mk} CLVAR:=PASS 2> /dev/null
diff --git a/testcase/cmdline_var_makeflags.sh b/testcase/cmdline_var_makeflags.sh
new file mode 100755
index 0000000..6e38a2d
--- /dev/null
+++ b/testcase/cmdline_var_makeflags.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# Copyright 2016 Google Inc. All rights reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+mk="$@"
+
+cat <<EOF > Makefile
+CLVAR := FAIL
+MFVAR := FAIL
+FILEVAR := PASS
+all:
+ @echo \$(ENVVAR) \$(origin ENVVAR)
+ @echo \$(MFVAR) \$(origin MFVAR)
+ @echo \$(CLVAR) \$(origin CLVAR)
+ @echo \$(FILEVAR) \$(origin FILEVAR)
+EOF
+
+export ENVVAR=PASS
+export FILEVAR=FAIL
+export MAKEFLAGS="MFVAR=PASS CLVAR=FAIL"
+
+${mk} CLVAR=PASS 2> /dev/null
diff --git a/testcase/cmdline_var_modify.sh b/testcase/cmdline_var_modify.sh
new file mode 100755
index 0000000..9616a2b
--- /dev/null
+++ b/testcase/cmdline_var_modify.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# Copyright 2016 Google Inc. All rights reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+mk="$@"
+
+cat <<EOF > Makefile
+CLVAR := FAIL
+all:
+ @echo \$(CLVAR)
+EOF
+
+${mk} CLVAR:=P CLVAR+=A CLVAR+=SS CLVAR?=FAIL 2> /dev/null
diff --git a/testcase/cmdline_var_override.sh b/testcase/cmdline_var_override.sh
new file mode 100755
index 0000000..0a5b3c1
--- /dev/null
+++ b/testcase/cmdline_var_override.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# Copyright 2016 Google Inc. All rights reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+mk="$@"
+
+cat <<EOF > Makefile
+override CLVAR := PASS
+all:
+ @echo \$(CLVAR)
+EOF
+
+${mk} CLVAR:=FAIL 2> /dev/null