mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Pass extra arguments to the native program with a new "pio run --program-arg" option // Resolve #4246
This commit is contained in:
@ -95,6 +95,7 @@ Please check `Migration guide from 5.x to 6.0 <https://docs.platformio.org/en/la
|
|||||||
|
|
||||||
* **Miscellaneous**
|
* **Miscellaneous**
|
||||||
|
|
||||||
|
- Pass extra arguments to the `native <https://docs.platformio.org/en/latest/platforms/native.html>`__ program with a new `pio run --program-arg <https://docs.platformio.org/en/latest/core/userguide/cmd_run.html#cmdoption-pio-run-a>`__ option (`issue #4246 <https://github.com/platformio/platformio-core/issues/4246>`_)
|
||||||
- Improved PIO Remote setup on credit-card sized computers (Raspberry Pi, BeagleBon, etc) (`issue #3865 <https://github.com/platformio/platformio-core/issues/3865>`_)
|
- Improved PIO Remote setup on credit-card sized computers (Raspberry Pi, BeagleBon, etc) (`issue #3865 <https://github.com/platformio/platformio-core/issues/3865>`_)
|
||||||
- Finally removed all tracks to the Python 2.7, the Python 3.6 is the minimum supported version.
|
- Finally removed all tracks to the Python 2.7, the Python 3.6 is the minimum supported version.
|
||||||
|
|
||||||
|
2
docs
2
docs
Submodule docs updated: 7ea8af9265...a035ea48bb
@ -44,6 +44,7 @@ clivars.AddVariables(
|
|||||||
("PIOENV",),
|
("PIOENV",),
|
||||||
("PIOTEST_RUNNING_NAME",),
|
("PIOTEST_RUNNING_NAME",),
|
||||||
("UPLOAD_PORT",),
|
("UPLOAD_PORT",),
|
||||||
|
("PROGRAM_ARGS",),
|
||||||
)
|
)
|
||||||
|
|
||||||
DEFAULT_ENV_OPTIONS = dict(
|
DEFAULT_ENV_OPTIONS = dict(
|
||||||
|
@ -66,10 +66,17 @@ except NotImplementedError:
|
|||||||
"Default is a number of CPUs in a system (N=%d)" % DEFAULT_JOB_NUMS
|
"Default is a number of CPUs in a system (N=%d)" % DEFAULT_JOB_NUMS
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@click.option("-s", "--silent", is_flag=True)
|
@click.option(
|
||||||
@click.option("-v", "--verbose", is_flag=True)
|
"-a",
|
||||||
|
"--program-arg",
|
||||||
|
"program_args",
|
||||||
|
multiple=True,
|
||||||
|
help="A program argument (multiple are allowed)",
|
||||||
|
)
|
||||||
@click.option("--disable-auto-clean", is_flag=True)
|
@click.option("--disable-auto-clean", is_flag=True)
|
||||||
@click.option("--list-targets", is_flag=True)
|
@click.option("--list-targets", is_flag=True)
|
||||||
|
@click.option("-s", "--silent", is_flag=True)
|
||||||
|
@click.option("-v", "--verbose", is_flag=True)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(
|
def cli(
|
||||||
ctx,
|
ctx,
|
||||||
@ -79,10 +86,11 @@ def cli(
|
|||||||
project_dir,
|
project_dir,
|
||||||
project_conf,
|
project_conf,
|
||||||
jobs,
|
jobs,
|
||||||
silent,
|
program_args,
|
||||||
verbose,
|
|
||||||
disable_auto_clean,
|
disable_auto_clean,
|
||||||
list_targets,
|
list_targets,
|
||||||
|
silent,
|
||||||
|
verbose,
|
||||||
):
|
):
|
||||||
app.set_session_var("custom_project_conf", project_conf)
|
app.set_session_var("custom_project_conf", project_conf)
|
||||||
|
|
||||||
@ -138,10 +146,11 @@ def cli(
|
|||||||
environment,
|
environment,
|
||||||
target,
|
target,
|
||||||
upload_port,
|
upload_port,
|
||||||
|
jobs,
|
||||||
|
program_args,
|
||||||
|
is_test_running,
|
||||||
silent,
|
silent,
|
||||||
verbose,
|
verbose,
|
||||||
jobs,
|
|
||||||
is_test_running,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -165,16 +174,25 @@ def process_env(
|
|||||||
environments,
|
environments,
|
||||||
targets,
|
targets,
|
||||||
upload_port,
|
upload_port,
|
||||||
|
jobs,
|
||||||
|
program_args,
|
||||||
|
is_test_running,
|
||||||
silent,
|
silent,
|
||||||
verbose,
|
verbose,
|
||||||
jobs,
|
|
||||||
is_test_running,
|
|
||||||
):
|
):
|
||||||
if not is_test_running and not silent:
|
if not is_test_running and not silent:
|
||||||
print_processing_header(name, config, verbose)
|
print_processing_header(name, config, verbose)
|
||||||
|
|
||||||
ep = EnvironmentProcessor(
|
ep = EnvironmentProcessor(
|
||||||
ctx, name, config, targets, upload_port, silent, verbose, jobs
|
ctx,
|
||||||
|
name,
|
||||||
|
config,
|
||||||
|
targets,
|
||||||
|
upload_port,
|
||||||
|
jobs,
|
||||||
|
program_args,
|
||||||
|
silent,
|
||||||
|
verbose,
|
||||||
)
|
)
|
||||||
result = {"env": name, "duration": time(), "succeeded": ep.process()}
|
result = {"env": name, "duration": time(), "succeeded": ep.process()}
|
||||||
result["duration"] = time() - result["duration"]
|
result["duration"] = time() - result["duration"]
|
||||||
|
@ -22,20 +22,34 @@ from platformio.test.runners.base import CTX_META_TEST_RUNNING_NAME
|
|||||||
|
|
||||||
class EnvironmentProcessor(object):
|
class EnvironmentProcessor(object):
|
||||||
def __init__( # pylint: disable=too-many-arguments
|
def __init__( # pylint: disable=too-many-arguments
|
||||||
self, cmd_ctx, name, config, targets, upload_port, silent, verbose, jobs
|
self,
|
||||||
|
cmd_ctx,
|
||||||
|
name,
|
||||||
|
config,
|
||||||
|
targets,
|
||||||
|
upload_port,
|
||||||
|
jobs,
|
||||||
|
program_args,
|
||||||
|
silent,
|
||||||
|
verbose,
|
||||||
):
|
):
|
||||||
self.cmd_ctx = cmd_ctx
|
self.cmd_ctx = cmd_ctx
|
||||||
self.name = name
|
self.name = name
|
||||||
self.config = config
|
self.config = config
|
||||||
self.targets = [str(t) for t in targets]
|
self.targets = [str(t) for t in targets]
|
||||||
self.upload_port = upload_port
|
self.upload_port = upload_port
|
||||||
|
self.jobs = jobs
|
||||||
|
self.program_args = program_args
|
||||||
self.silent = silent
|
self.silent = silent
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
self.jobs = jobs
|
|
||||||
self.options = config.items(env=name, as_dict=True)
|
self.options = config.items(env=name, as_dict=True)
|
||||||
|
|
||||||
def get_build_variables(self):
|
def get_build_variables(self):
|
||||||
variables = {"pioenv": self.name, "project_config": self.config.path}
|
variables = dict(
|
||||||
|
pioenv=self.name,
|
||||||
|
project_config=self.config.path,
|
||||||
|
program_args=self.program_args,
|
||||||
|
)
|
||||||
|
|
||||||
if CTX_META_TEST_RUNNING_NAME in self.cmd_ctx.meta:
|
if CTX_META_TEST_RUNNING_NAME in self.cmd_ctx.meta:
|
||||||
variables["piotest_running_name"] = self.cmd_ctx.meta[
|
variables["piotest_running_name"] = self.cmd_ctx.meta[
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@ -21,7 +22,7 @@ from urllib.parse import quote
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from platformio import app, fs, proc, telemetry
|
from platformio import app, fs, proc, telemetry
|
||||||
from platformio.compat import hashlib_encode_data, is_bytes
|
from platformio.compat import hashlib_encode_data
|
||||||
from platformio.package.manager.core import get_core_package_dir
|
from platformio.package.manager.core import get_core_package_dir
|
||||||
from platformio.platform.exception import BuildScriptNotFound
|
from platformio.platform.exception import BuildScriptNotFound
|
||||||
|
|
||||||
@ -32,13 +33,16 @@ class PlatformRunMixin(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def encode_scons_arg(value):
|
def encode_scons_arg(value):
|
||||||
data = base64.urlsafe_b64encode(hashlib_encode_data(value))
|
if isinstance(value, (list, tuple, dict)):
|
||||||
return data.decode() if is_bytes(data) else data
|
value = json.dumps(value)
|
||||||
|
return base64.urlsafe_b64encode(hashlib_encode_data(value)).decode()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def decode_scons_arg(data):
|
def decode_scons_arg(data):
|
||||||
value = base64.urlsafe_b64decode(data)
|
value = base64.urlsafe_b64decode(data).decode()
|
||||||
return value.decode() if is_bytes(value) else value
|
if value.startswith(("[", "{")):
|
||||||
|
value = json.loads(value)
|
||||||
|
return value
|
||||||
|
|
||||||
def run( # pylint: disable=too-many-arguments
|
def run( # pylint: disable=too-many-arguments
|
||||||
self, variables, targets, silent, verbose, jobs
|
self, variables, targets, silent, verbose, jobs
|
||||||
|
Reference in New Issue
Block a user