Skip to content

Commit

Permalink
manage.py: add --gargs handling, accidentally missing so far
Browse files Browse the repository at this point in the history
For GitHub issue AdaCore#501
  • Loading branch information
pmderodat authored and Roldak committed May 7, 2021
1 parent 6cec985 commit 121b40f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
13 changes: 5 additions & 8 deletions langkit/libmanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from os import path
import pdb
import pipes
import shlex
import shutil
import subprocess
import sys
Expand All @@ -25,8 +24,10 @@
WarningSet, check_source_language, extract_library_location
)
from langkit.packaging import Packager
from langkit.utils import (Colors, LibraryTypes, Log, add_to_path, col,
format_setenv, get_cpu_count, printcol)
from langkit.utils import (
Colors, LibraryTypes, Log, add_to_path, col, format_setenv, get_cpu_count,
parse_cmdline_args, printcol
)


if TYPE_CHECKING:
Expand Down Expand Up @@ -951,11 +952,7 @@ def gprbuild(self,
elif args.verbosity == Verbosity('debug'):
base_argv.append('-vl')

# Depending on where this is invoked, the "--gargs" option may not be
# set. Don't call shlex.split with an empty input, otherwise it will
# try to read something from stdin...
gargs = getattr(args, 'gargs') or []
gargs = sum((shlex.split(args) for args in gargs), [])
gargs = parse_cmdline_args(getattr(args, 'gargs'))

def run(library_type: str) -> None:
# Remove the "*.lexch" file
Expand Down
20 changes: 19 additions & 1 deletion langkit/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
from copy import copy
import os
import pipes
import shlex
import shutil
from typing import Dict, List
from typing import Dict, List, Optional


def copy_with(obj, **kwargs):
Expand Down Expand Up @@ -296,6 +297,23 @@ def parse(cls, arg: str) -> LibraryTypes:
relocatable="relocatable" in library_type_set)


def parse_cmdline_args(args: Optional[List[str]]) -> List[str]:
"""
Considering a list of shell-formatted argument lists, return the
corresponding flattened list of single arguments.
For instance::
>>> parse_args(["foo bar", "'hello world'"])
["foo", "bar", "hello world"]
If passed ``None``, just return an empty list.
"""
return (sum((shlex.split(a) for a in args), [])
if args
else [])


# pyflakes off
from langkit.utils.colors import *
from langkit.utils.logging import *
Expand Down
7 changes: 6 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from langkit.packaging import Packager
from langkit.utils import (LibraryTypes, add_to_path, format_setenv,
get_cpu_count)
get_cpu_count, parse_cmdline_args)


LANGKIT_ROOT = PurePath(P.dirname(P.realpath(__file__)))
Expand Down Expand Up @@ -104,6 +104,7 @@ def build_langkit_support(args: Namespace) -> None:
]
if args.build_dir:
base_argv.extend([f"--relocate-build-tree={build_dir}"])
base_argv.extend(parse_cmdline_args(args.gargs))

# In order to avoid building the library once per library kind (static,
# static-pic and relocatable), langkit_support.gpr uses the same object
Expand Down Expand Up @@ -229,6 +230,10 @@ def make(args: Namespace) -> None:
f"-j{args.jobs}",
]

# Forward gargs to each manage.py script
for gargs in args.gargs or []:
base_argv.append(f"--gargs={gargs}")

m1 = subprocess.Popen(
base_argv + ["--disable-warning", "undocumented-nodes"],
cwd=PYTHON_LIB_ROOT
Expand Down

0 comments on commit 121b40f

Please sign in to comment.