mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47: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**
|
||||
|
||||
- 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>`_)
|
||||
- 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",),
|
||||
("PIOTEST_RUNNING_NAME",),
|
||||
("UPLOAD_PORT",),
|
||||
("PROGRAM_ARGS",),
|
||||
)
|
||||
|
||||
DEFAULT_ENV_OPTIONS = dict(
|
||||
|
@ -66,10 +66,17 @@ except NotImplementedError:
|
||||
"Default is a number of CPUs in a system (N=%d)" % DEFAULT_JOB_NUMS
|
||||
),
|
||||
)
|
||||
@click.option("-s", "--silent", is_flag=True)
|
||||
@click.option("-v", "--verbose", is_flag=True)
|
||||
@click.option(
|
||||
"-a",
|
||||
"--program-arg",
|
||||
"program_args",
|
||||
multiple=True,
|
||||
help="A program argument (multiple are allowed)",
|
||||
)
|
||||
@click.option("--disable-auto-clean", 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
|
||||
def cli(
|
||||
ctx,
|
||||
@ -79,10 +86,11 @@ def cli(
|
||||
project_dir,
|
||||
project_conf,
|
||||
jobs,
|
||||
silent,
|
||||
verbose,
|
||||
program_args,
|
||||
disable_auto_clean,
|
||||
list_targets,
|
||||
silent,
|
||||
verbose,
|
||||
):
|
||||
app.set_session_var("custom_project_conf", project_conf)
|
||||
|
||||
@ -138,10 +146,11 @@ def cli(
|
||||
environment,
|
||||
target,
|
||||
upload_port,
|
||||
jobs,
|
||||
program_args,
|
||||
is_test_running,
|
||||
silent,
|
||||
verbose,
|
||||
jobs,
|
||||
is_test_running,
|
||||
)
|
||||
)
|
||||
|
||||
@ -165,16 +174,25 @@ def process_env(
|
||||
environments,
|
||||
targets,
|
||||
upload_port,
|
||||
jobs,
|
||||
program_args,
|
||||
is_test_running,
|
||||
silent,
|
||||
verbose,
|
||||
jobs,
|
||||
is_test_running,
|
||||
):
|
||||
if not is_test_running and not silent:
|
||||
print_processing_header(name, config, verbose)
|
||||
|
||||
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["duration"] = time() - result["duration"]
|
||||
|
@ -22,20 +22,34 @@ from platformio.test.runners.base import CTX_META_TEST_RUNNING_NAME
|
||||
|
||||
class EnvironmentProcessor(object):
|
||||
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.name = name
|
||||
self.config = config
|
||||
self.targets = [str(t) for t in targets]
|
||||
self.upload_port = upload_port
|
||||
self.jobs = jobs
|
||||
self.program_args = program_args
|
||||
self.silent = silent
|
||||
self.verbose = verbose
|
||||
self.jobs = jobs
|
||||
self.options = config.items(env=name, as_dict=True)
|
||||
|
||||
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:
|
||||
variables["piotest_running_name"] = self.cmd_ctx.meta[
|
||||
|
@ -13,6 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@ -21,7 +22,7 @@ from urllib.parse import quote
|
||||
import click
|
||||
|
||||
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.platform.exception import BuildScriptNotFound
|
||||
|
||||
@ -32,13 +33,16 @@ class PlatformRunMixin(object):
|
||||
|
||||
@staticmethod
|
||||
def encode_scons_arg(value):
|
||||
data = base64.urlsafe_b64encode(hashlib_encode_data(value))
|
||||
return data.decode() if is_bytes(data) else data
|
||||
if isinstance(value, (list, tuple, dict)):
|
||||
value = json.dumps(value)
|
||||
return base64.urlsafe_b64encode(hashlib_encode_data(value)).decode()
|
||||
|
||||
@staticmethod
|
||||
def decode_scons_arg(data):
|
||||
value = base64.urlsafe_b64decode(data)
|
||||
return value.decode() if is_bytes(value) else value
|
||||
value = base64.urlsafe_b64decode(data).decode()
|
||||
if value.startswith(("[", "{")):
|
||||
value = json.loads(value)
|
||||
return value
|
||||
|
||||
def run( # pylint: disable=too-many-arguments
|
||||
self, variables, targets, silent, verbose, jobs
|
||||
|
Reference in New Issue
Block a user