Skip to content

Commit 8dfe0c8

Browse files
committed
Use tempfile for cflags to shorten command line
1 parent fca9669 commit 8dfe0c8

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

ports/zephyr-cp/cptools/cpbuild.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import asyncio
2-
import inspect
2+
import atexit
3+
import hashlib
4+
import json
35
import logging
46
import os
57
import pathlib
6-
import shlex
7-
import time
8-
import hashlib
9-
import atexit
10-
import json
118
import re
12-
import sys
9+
import tempfile
10+
import time
1311

1412
logger = logging.getLogger(__name__)
1513

@@ -327,6 +325,11 @@ def __init__(self, srcdir: pathlib.Path, builddir: pathlib.Path, cmake_args):
327325
self.ar = cmake_args["AR"]
328326
self.cflags = cmake_args.get("CFLAGS", "")
329327

328+
self._cflags_tempfile = tempfile.NamedTemporaryFile()
329+
self._cflags_tempfile.write(self.cflags.encode())
330+
self._cflags_tempfile.flush()
331+
self.cflags_file = "@" + self._cflags_tempfile.name
332+
330333
self.srcdir = srcdir
331334
self.builddir = builddir
332335

@@ -346,7 +349,7 @@ async def preprocess(
346349
depfile,
347350
"-c",
348351
source_file,
349-
self.cflags,
352+
self.cflags_file,
350353
*flags,
351354
"-o",
352355
output_file,
@@ -376,7 +379,16 @@ async def compile(
376379
else:
377380
extradeps.append(self.srcdir / dep)
378381
await run_command(
379-
[self.c_compiler, self.cflags, "-MMD", "-c", source_file, *flags, "-o", output_file],
382+
[
383+
self.c_compiler,
384+
self.cflags_file,
385+
"-MMD",
386+
"-c",
387+
source_file,
388+
*flags,
389+
"-o",
390+
output_file,
391+
],
380392
description=f"Compile {source_file.relative_to(self.srcdir)} -> {output_file.relative_to(self.builddir)}",
381393
working_directory=self.srcdir,
382394
extradeps=extradeps,

0 commit comments

Comments
 (0)