Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for "else if" in gyp conditions
Right now, a gyp condition consists of exactly two or three parts: [cond_expr, true_dict] [cond_expr, true_dict, false_dict] This means if we want to have an "else if" condition, it needs to be inside a nested 'conditions' list inside the false_dict. This leads to unnecessarily deep levels of nesting in gyp files. This commit makes it so that if the 'false_dict' is not a dict, then we will treat it as another cond_expr. We keep looping like this until we find a false_dict, or until we reach the end of the list. This means we can now have conditions that look like this: [cond_expr1, true_dict1, cond_expr2, true_dict2, false_dict] or: [cond_expr1, true_dict1, cond_expr2, true_dict2, cond_expr3, true_dict3] BUG= R=scottmg@chromium.org Review URL: https://codereview.chromium.org/601353002 git-svn-id: http://gyp.googlecode.com/svn/trunk@2004 78cadc50-ecff-11dd-a971-7dbc132099af
- Loading branch information
Showing
8 changed files
with
197 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
{ | ||
'targets': [ | ||
{ | ||
'variables': { 'test_var': 0 }, | ||
'target_name': 'program0', | ||
'type': 'executable', | ||
'sources': [ 'program.cc' ], | ||
'includes': [ 'elseif_conditions.gypi' ], | ||
}, | ||
{ | ||
'variables': { 'test_var': 1 }, | ||
'target_name': 'program1', | ||
'type': 'executable', | ||
'sources': [ 'program.cc' ], | ||
'includes': [ 'elseif_conditions.gypi' ], | ||
}, | ||
{ | ||
'variables': { 'test_var': 2 }, | ||
'target_name': 'program2', | ||
'type': 'executable', | ||
'sources': [ 'program.cc' ], | ||
'includes': [ 'elseif_conditions.gypi' ], | ||
}, | ||
{ | ||
'variables': { 'test_var': 3 }, | ||
'target_name': 'program3', | ||
'type': 'executable', | ||
'sources': [ 'program.cc' ], | ||
'includes': [ 'elseif_conditions.gypi' ], | ||
}, | ||
{ | ||
'variables': { 'test_var': 4 }, | ||
'target_name': 'program4', | ||
'type': 'executable', | ||
'sources': [ 'program.cc' ], | ||
'includes': [ 'elseif_conditions.gypi' ], | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
# Trigger an error because of two consecutive string conditions. | ||
|
||
{ | ||
'targets': [ | ||
{ | ||
'variables': { 'test_var': 0 }, | ||
'target_name': 'program', | ||
'type': 'executable', | ||
'sources': [ 'program.cc' ], | ||
'conditions': [ | ||
['test_var==0', 'test_var==1', { | ||
}], | ||
], | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
# Trigger an error because of two consecutive string conditions, even if the | ||
# conditions are not actually evaluated. | ||
|
||
{ | ||
'targets': [ | ||
{ | ||
'variables': { 'test_var': 0 }, | ||
'target_name': 'program', | ||
'type': 'executable', | ||
'sources': [ 'program.cc' ], | ||
'conditions': [ | ||
['test_var==0', { | ||
}, 'test_var==1', 'test_var==2', { | ||
}], | ||
], | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
# Trigger an error because there are unexpected trailing items in a condition. | ||
|
||
{ | ||
'targets': [ | ||
{ | ||
'variables': { 'test_var': 0 }, | ||
'target_name': 'program', | ||
'type': 'executable', | ||
'sources': [ 'program.cc' ], | ||
'conditions': [ | ||
['test_var==0' { | ||
}, 'test_var==1', { | ||
}, { | ||
}, 'test_var==2', { | ||
}], | ||
], | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
'conditions': [ | ||
['test_var==0', { | ||
'defines': ['FOO="first_if"'], | ||
}, 'test_var==1', { | ||
'defines': ['FOO="first_else_if"'], | ||
}, 'test_var==2', { | ||
'defines': ['FOO="second_else_if"'], | ||
}, 'test_var==3', { | ||
'defines': ['FOO="third_else_if"'], | ||
}, { | ||
'defines': ['FOO="last_else"'], | ||
}], | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright (c) 2014 Google Inc. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
""" | ||
Verify that "else-if" conditions work. | ||
""" | ||
|
||
import TestGyp | ||
|
||
test = TestGyp.TestGyp() | ||
|
||
test.run_gyp('elseif.gyp') | ||
test.build('elseif.gyp', test.ALL) | ||
test.run_built_executable( | ||
'program0', stdout='first_if\n') | ||
test.run_built_executable( | ||
'program1', stdout='first_else_if\n') | ||
test.run_built_executable( | ||
'program2', stdout='second_else_if\n') | ||
test.run_built_executable( | ||
'program3', stdout='third_else_if\n') | ||
test.run_built_executable( | ||
'program4', stdout='last_else\n') | ||
|
||
# Verify that bad condition blocks fail at gyp time. | ||
test.run_gyp('elseif_bad1.gyp', status=1, stderr=None) | ||
test.run_gyp('elseif_bad2.gyp', status=1, stderr=None) | ||
test.run_gyp('elseif_bad3.gyp', status=1, stderr=None) | ||
|
||
test.pass_test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) 2014 Google Inc. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <stdio.h> | ||
|
||
int main() { | ||
printf("%s\n", FOO); | ||
return 0; | ||
} |