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 committed Apr 29, 2021
1 parent 80cb2dc commit f551b76
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
13 changes: 6 additions & 7 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 @@ -952,10 +953,8 @@ def gprbuild(self,
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), [])
# set or set to None.
gargs = parse_cmdline_args(getattr(args, 'gargs') or [])

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

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


def parse_cmdline_args(args: 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"]
"""
return sum((shlex.split(a) for a in args), [])


# 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:
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 f551b76

Please sign in to comment.