Skip to content

Commit

Permalink
Fix issue with src_filter option for Windows OS // Resolve #652
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed May 10, 2016
1 parent 69effbf commit 056cc08
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ PlatformIO 2.0
* Use HTTP mirror for Package Manager in a case with SSL errors
(`issue #645 <https://github.com/platformio/platformio/issues/645>`_)
* Fixed bug with ``env_default`` when ``pio run -e`` is used
* Fixed issue with ``src_filter`` option for Windows OS
(`issue #652 <https://github.com/platformio/platformio/issues/652>`_)

2.9.1 (2016-04-30)
~~~~~~~~~~~~~~~~~~
Expand Down
7 changes: 7 additions & 0 deletions platformio/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import base64
import json
import sys
from os import environ
Expand Down Expand Up @@ -99,6 +100,12 @@
)

env = DefaultEnvironment()

# decode common variables
for k in commonvars.keys():
if k in env:
env[k] = base64.b64decode(env[k])

env.Prepend(LIBPATH=[join("$PIOPACKAGES_DIR", "ldscripts")])

if "BOARD" in env:
Expand Down
10 changes: 5 additions & 5 deletions platformio/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ def _validate_options(self, options):
return result

def _get_build_variables(self):
variables = ["PIOENV=" + self.name]
variables = {"pioenv": self.name}
if self.upload_port:
variables.append("UPLOAD_PORT=%s" % self.upload_port)
variables['upload_port'] = self.upload_port
for k, v in self.options.items():
k = k.upper()
if k == "TARGETS" or (k == "UPLOAD_PORT" and self.upload_port):
k = k.lower()
if k == "targets" or (k == "upload_port" and self.upload_port):
continue
variables.append("%s=%s" % (k, v))
variables[k] = v
return variables

def _get_build_targets(self):
Expand Down
54 changes: 25 additions & 29 deletions platformio/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import base64
import os
import re
import sys
Expand Down Expand Up @@ -400,10 +401,10 @@ def is_outdated(self):
obsolated = pm.get_outdated()
return not set(self.get_packages().keys()).isdisjoint(set(obsolated))

def configure_default_packages(self, envoptions, targets):
def configure_default_packages(self, variables, targets):
# enbale used frameworks
for pkg_name in self.pkg_aliases_to_names(["framework"]):
for framework in envoptions.get("framework", "").split(","):
for framework in variables.get("framework", "").split(","):
framework = framework.lower().strip()
if not framework:
continue
Expand Down Expand Up @@ -441,15 +442,10 @@ def _install_default_packages(self):
raise exception.PlatformNotInstalledYet(self.get_type())

def run(self, variables, targets, verbose):
assert isinstance(variables, list)
assert isinstance(variables, dict)
assert isinstance(targets, list)

envoptions = {}
for v in variables:
_name, _value = v.split("=", 1)
envoptions[_name.lower()] = _value

self.configure_default_packages(envoptions, targets)
self.configure_default_packages(variables, targets)
self._install_default_packages()

self._verbose_level = int(verbose)
Expand All @@ -458,23 +454,17 @@ def run(self, variables, targets, verbose):
targets.remove("clean")
targets.append("-c")

if "build_script" not in envoptions:
variables.append("BUILD_SCRIPT=%s" % self.get_build_script())

for v in variables:
if not v.startswith("BUILD_SCRIPT="):
continue
_, path = v.split("=", 1)
if not isfile(path):
raise exception.BuildScriptNotFound(path)
if "build_script" not in variables:
variables['build_script'] = self.get_build_script()
if not isfile(variables['build_script']):
raise exception.BuildScriptNotFound(variables['build_script'])

# append aliases of the installed packages
installed_packages = PackageManager.get_installed()
for name, options in self.get_packages().items():
if "alias" not in options or name not in installed_packages:
continue
variables.append(
"PIOPACKAGE_%s=%s" % (options['alias'].upper(), name))
variables['piopackage_%s' % options['alias']] = name

self._found_error = False
result = self._run_scons(variables, targets)
Expand All @@ -498,16 +488,22 @@ def _run_scons(self, variables, targets):
_PYTHONPATH.append(p)
os.environ['PYTHONPATH'] = os.pathsep.join(_PYTHONPATH)

cmd = [
os.path.normpath(sys.executable),
join(util.get_home_dir(), "packages", "tool-scons",
"script", "scons"),
"-Q",
"-j %d" % self.get_job_nums(),
"--warn=no-no-parallel-support",
"-f", join(util.get_source_dir(), "builder", "main.py")
] + targets

# encode and append variables
for key, value in variables.items():
cmd.append("%s=%s" % (key.upper(), base64.b64encode(value)))

result = util.exec_command(
[
os.path.normpath(sys.executable),
join(util.get_home_dir(), "packages", "tool-scons",
"script", "scons"),
"-Q",
"-j %d" % self.get_job_nums(),
"--warn=no-no-parallel-support",
"-f", join(util.get_source_dir(), "builder", "main.py")
] + variables + targets,
cmd,
stdout=util.AsyncPipe(self.on_run_out),
stderr=util.AsyncPipe(self.on_run_err)
)
Expand Down

0 comments on commit 056cc08

Please sign in to comment.