2019-05-03 21:03:36 +03:00
|
|
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2019-05-04 12:23:23 +03:00
|
|
|
import os
|
2019-05-07 17:51:50 +03:00
|
|
|
|
2019-05-03 21:03:36 +03:00
|
|
|
from platformio.project.config import ProjectConfig
|
|
|
|
|
|
|
|
BASE_CONFIG = """
|
|
|
|
[platformio]
|
2019-05-08 20:19:39 +03:00
|
|
|
env_default = base, extra_2
|
2019-05-03 21:03:36 +03:00
|
|
|
extra_configs =
|
|
|
|
extra_envs.ini
|
|
|
|
extra_debug.ini
|
|
|
|
|
2019-05-08 20:19:39 +03:00
|
|
|
# global options per [env:*]
|
|
|
|
[env]
|
|
|
|
monitor_speed = 115200
|
|
|
|
lib_deps = Lib1, Lib2
|
|
|
|
lib_ignore = ${custom.lib_ignore}
|
|
|
|
|
|
|
|
[custom]
|
2019-05-03 21:03:36 +03:00
|
|
|
debug_flags = -D RELEASE
|
|
|
|
lib_flags = -lc -lm
|
2019-05-04 12:23:23 +03:00
|
|
|
extra_flags = ${sysenv.__PIO_TEST_CNF_EXTRA_FLAGS}
|
2019-05-08 20:19:39 +03:00
|
|
|
lib_ignore = LibIgnoreCustom
|
2019-05-03 21:03:36 +03:00
|
|
|
|
2019-05-08 20:19:39 +03:00
|
|
|
[env:base]
|
|
|
|
build_flags = ${custom.debug_flags} ${custom.extra_flags}
|
2019-05-03 21:03:36 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
EXTRA_ENVS_CONFIG = """
|
2019-05-08 20:19:39 +03:00
|
|
|
[env:extra_1]
|
|
|
|
build_flags = ${custom.lib_flags} ${custom.debug_flags}
|
|
|
|
|
|
|
|
[env:extra_2]
|
|
|
|
build_flags = ${custom.debug_flags} ${custom.extra_flags}
|
|
|
|
lib_ignore = ${env.lib_ignore}, Lib3
|
2019-05-03 21:03:36 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
EXTRA_DEBUG_CONFIG = """
|
2019-05-08 20:19:39 +03:00
|
|
|
# Override original "custom.debug_flags"
|
|
|
|
[custom]
|
2019-05-03 21:03:36 +03:00
|
|
|
debug_flags = -D DEBUG=1
|
|
|
|
|
2019-05-08 20:19:39 +03:00
|
|
|
[env:extra_2]
|
2019-05-03 21:03:36 +03:00
|
|
|
build_flags = -Og
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def test_parser(tmpdir):
|
|
|
|
tmpdir.join("platformio.ini").write(BASE_CONFIG)
|
|
|
|
tmpdir.join("extra_envs.ini").write(EXTRA_ENVS_CONFIG)
|
|
|
|
tmpdir.join("extra_debug.ini").write(EXTRA_DEBUG_CONFIG)
|
|
|
|
|
|
|
|
config = None
|
|
|
|
with tmpdir.as_cwd():
|
|
|
|
config = ProjectConfig(tmpdir.join("platformio.ini").strpath)
|
|
|
|
assert config
|
|
|
|
|
2019-05-04 12:23:23 +03:00
|
|
|
# sections
|
2019-05-03 21:03:36 +03:00
|
|
|
assert config.sections() == [
|
2019-05-08 20:19:39 +03:00
|
|
|
"platformio", "env", "custom", "env:base", "env:extra_1", "env:extra_2"
|
2019-05-03 21:03:36 +03:00
|
|
|
]
|
2019-05-04 12:23:23 +03:00
|
|
|
|
2019-05-08 20:19:39 +03:00
|
|
|
# envs
|
|
|
|
assert config.envs() == ["base", "extra_1", "extra_2"]
|
|
|
|
assert config.default_envs() == ["base", "extra_2"]
|
|
|
|
|
|
|
|
# options
|
|
|
|
assert config.options(env="base") == [
|
|
|
|
"build_flags", "monitor_speed", "lib_deps", "lib_ignore"
|
|
|
|
]
|
|
|
|
|
|
|
|
# has_option
|
|
|
|
assert config.has_option("env:base", "monitor_speed")
|
|
|
|
assert not config.has_option("custom", "monitor_speed")
|
|
|
|
|
2019-05-04 12:23:23 +03:00
|
|
|
# sysenv
|
2019-05-08 20:19:39 +03:00
|
|
|
assert config.get("custom", "extra_flags") == ""
|
2019-05-04 12:23:23 +03:00
|
|
|
os.environ["__PIO_TEST_CNF_EXTRA_FLAGS"] = "-L /usr/local/lib"
|
2019-05-08 20:19:39 +03:00
|
|
|
assert config.get("custom", "extra_flags") == "-L /usr/local/lib"
|
2019-05-04 12:23:23 +03:00
|
|
|
|
|
|
|
# get
|
2019-05-08 20:19:39 +03:00
|
|
|
assert config.get("custom", "debug_flags") == "-D DEBUG=1"
|
|
|
|
assert config.get("env:extra_1", "build_flags") == "-lc -lm -D DEBUG=1"
|
|
|
|
assert config.get("env:extra_2", "build_flags") == "-Og"
|
|
|
|
assert config.get("env:extra_2", "monitor_speed") == "115200"
|
|
|
|
assert config.get("env:base",
|
2019-05-04 12:23:23 +03:00
|
|
|
"build_flags") == ("-D DEBUG=1 -L /usr/local/lib")
|
|
|
|
|
|
|
|
# items
|
2019-05-08 20:19:39 +03:00
|
|
|
assert config.items("custom") == [("debug_flags", "-D DEBUG=1"),
|
2019-05-07 17:51:50 +03:00
|
|
|
("lib_flags", "-lc -lm"),
|
2019-05-08 20:19:39 +03:00
|
|
|
("extra_flags", "-L /usr/local/lib"),
|
|
|
|
("lib_ignore", "LibIgnoreCustom")]
|
|
|
|
assert config.items(env="extra_1") == [("build_flags",
|
|
|
|
"-lc -lm -D DEBUG=1"),
|
|
|
|
("monitor_speed", "115200"),
|
|
|
|
("lib_deps", "Lib1, Lib2"),
|
|
|
|
("lib_ignore", "LibIgnoreCustom")]
|
|
|
|
assert config.items(env="extra_2") == [("build_flags", "-Og"),
|
|
|
|
("lib_ignore",
|
|
|
|
"LibIgnoreCustom, Lib3"),
|
|
|
|
("monitor_speed", "115200"),
|
|
|
|
("lib_deps", "Lib1, Lib2")]
|