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

Cannot pass more than one -D option to idf.py (IDFGH-1275) #3570

Closed
bpietsch opened this issue Jun 1, 2019 · 9 comments
Closed

Cannot pass more than one -D option to idf.py (IDFGH-1275) #3570

bpietsch opened this issue Jun 1, 2019 · 9 comments

Comments

@bpietsch
Copy link

bpietsch commented Jun 1, 2019

I want to declare multiple cache entries via the -D option to idf.py, but each successive one overwrites the previous when they are being parsed. Ironically, the -T option in unit-test-app maps to -D, but explicitly overrides the action behavior to append rather than overwrite. I think the -D action just needs to do the same.

@github-actions github-actions bot changed the title Cannot pass more than one -D option to idf.py Cannot pass more than one -D option to idf.py (IDFGH-1275) Jun 1, 2019
@bpietsch
Copy link
Author

bpietsch commented Jun 1, 2019

I figured out I had some slightly incorrect syntax. As defined, it needs to be "-D Foo=bar BAZ=zed", but that results in a sub-list under the define_cache_entry list. Then, when adding the -T option you end up with a mixture of the sub-list plus a separate individual string. With the change below, the syntax changes to specifying individual -D options for each cache entry you want to add, but each one ends up as a top-level string in the define_cache_entry list, which is what is needed for the options to actually take effect as expected.

diff --git a/tools/idf.py b/tools/idf.py
index c9a3e464e..fd765658f 100755
--- a/tools/idf.py
+++ b/tools/idf.py
@@ -557,7 +557,7 @@ def main():
     parser.add_argument('-G', '--generator', help="Cmake generator", choices=GENERATOR_CMDS.keys())
     parser.add_argument('-n', '--no-warnings', help="Disable Cmake warnings", action="store_true")
     parser.add_argument('-v', '--verbose', help="Verbose build output", action="store_true")
-    parser.add_argument('-D', '--define-cache-entry', help="Create a cmake cache entry", nargs='+')
+    parser.add_argument('-D', '--define-cache-entry', help="Create a cmake cache entry", action="append")
     parser.add_argument('--no-ccache', help="Disable ccache. Otherwise, if ccache is available on the PATH then it will be used for faster builds.",
                         action="store_true")
     parser.add_argument('actions', help="Actions (build targets or other operations)", nargs='+',

@bpietsch
Copy link
Author

bpietsch commented Jun 1, 2019

Additional recommended change... with -T having nargs=+, you can't put the "action" (i.e. build) immediately after -T (or -D, for that matter without the change in my previous comment), yet the usage output of idf.py implies you should put the action at the end, resulting in very cryptic errors (that I had to debug the python code in a debugger to figure out).

diff --git a/tools/unit-test-app/idf_ext.py b/tools/unit-test-app/idf_ext.py
index 06b843f01..8de2df569 100644
--- a/tools/unit-test-app/idf_ext.py
+++ b/tools/unit-test-app/idf_ext.py
@@ -45,6 +45,8 @@ class TestComponentAction(argparse.Action):
 
         # Brute force add reconfigure at the very beginning
         existing_actions = getattr(namespace, "actions", [])
+        if existing_actions is None:
+            existing_actions = []
         if "reconfigure" not in existing_actions:
             existing_actions = ["reconfigure"] + existing_actions
         setattr(namespace, "actions", existing_actions)
@@ -66,6 +68,8 @@ class TestExcludeComponentAction(argparse.Action):
 
         # Brute force add reconfigure at the very beginning
         existing_actions = getattr(namespace, "actions", [])
+        if existing_actions is None:
+            existing_actions = []
         if "reconfigure" not in existing_actions:
             existing_actions = ["reconfigure"] + existing_actions
         setattr(namespace, "actions", existing_actions)
@@ -73,9 +77,9 @@ class TestExcludeComponentAction(argparse.Action):
 
 def add_argument_extensions(parser):
     # For convenience, define a -T argument that gets converted to -D arguments
-    parser.add_argument('-T', '--test-component', help="Specify the components to test", nargs='+', action=TestComponentAction)
+    parser.add_argument('-T', '--test-component', help="Specify the components to test", action=TestComponentAction)
     # For convenience, define a -T argument that gets converted to -D arguments
-    parser.add_argument('-E', '--test-exclude-components', help="Specify the components to exclude from testing", nargs='+', action=TestExcludeComponentAction)
+    parser.add_argument('-E', '--test-exclude-components', help="Specify the components to exclude from testing", action=TestExcludeComponentAction)

@bpietsch
Copy link
Author

bpietsch commented Jun 1, 2019

Hmmm... OK, scratch the previous idf_ext.py patch... that introduced a new problem (it needs to translate to a single -D TEST_COMPONENTS='...' For now, I just moved the "build" positional arg to the beginning of my argument list, but that isn't obvious (per my previous comment)

@renzbagaporo
Copy link
Contributor

Hi @bpietsch, like #3571, this is also in the scope of the changes under review.

@bpietsch
Copy link
Author

bpietsch commented Jun 3, 2019

Thanks. I also am struggling with how quote -D options that have spaces in them... e.g. if I want to pass multiple paths to EXTRA_COMPONENT_DIRS (i.e. -D EXTRA_COMPONENT_DIRS="/foo /bar"). I get a cmake error: "define_property command is not scriptable"

@renzbagaporo
Copy link
Contributor

renzbagaporo commented Jun 3, 2019

Is a component in your EXTRA_COMPONENT_DIRS calling define_property before register_component call? We do an early expansion of components, that is, there is a step where component CMakeLists.txt is processed in script mode up until register_component. And script mode forbids certain commands, define_property being one of them.

@bpietsch
Copy link
Author

bpietsch commented Jun 3, 2019

Nope, only a few "set" calls, but just to be sure I moved register_component to the very top and am still getting the error.

@bpietsch
Copy link
Author

bpietsch commented Jun 3, 2019

Ugh... user error... the call stack from the make error clued me in that I was specifying my project directory and not the components sub-directory for EXTRA_COMPONENTS_DIR. Sorry for the noise, but appreciate your help.

@renzbagaporo
Copy link
Contributor

Glad to see it work out @bpietsch. Regarding MR, this issue (and your other one) should be closed once those changes I mentioned are synced to this repo.

@igrr igrr closed this as completed in 20156f9 Jun 10, 2019
trombik pushed a commit to trombik/esp-idf that referenced this issue Aug 9, 2019
Changes argument parsing mechanism from argparse to a new one, that provides better support for extensions and options that are only applicable to specific subcommands,

Breaking changes:

1. All global options should go before subcommands, i.e. `idf.py build -C ~/some/project` will not work anymore, only `idf.py -C ~/some/project build` is acceptable
2. To provide multiple values to an option like `--define-cache-entry` it's necessary to repeat option many times, i.e. `idf.py -D entry1 entry2 entry3` will not work, right way is: `idf.py -D entry1 -D entry2 -D entry3`
At the moment there are 3 options like this:  `--define-cache-entry` in base list and `--test-components` and `--test-exclude-components` in the unit test extensions
3. Drops `defconfig` and `bootloader-clean` subcommands

Closes espressif#3570
Closes espressif#3571
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants