From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x932.google.com (mail-ua1-x932.google.com [IPv6:2607:f8b0:4864:20::932]) by sourceware.org (Postfix) with ESMTPS id DBD903858C74 for ; Thu, 11 Aug 2022 15:46:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DBD903858C74 Received: by mail-ua1-x932.google.com with SMTP id f15so7078908uao.12 for ; Thu, 11 Aug 2022 08:46:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=PUQ5ASTOi1TU4uQNHINXzddS6EqyqgGxJXHTKbZwo9Y=; b=T0BVFL4aWwKNu0OnxsnXvda9t3+ysY3XI+soOueW4NNkLacVQQ2n44IQtFZvgwAbd0 SLVYzYPk6BfkEvvwNsh68GocGeq6fuYlSciV27KsCWdkku0gaTz6ZaBKz/RSL/eX2ZSx k94Ne7sVHYeTGbZHFrLz3WTtVD2dqiyGgMfVe5uXZTfI/EbuhnJ029r2asGgIfzP5z/+ MbZkBSnKWFwobJyCt1ONF/v+1mEZBkljY30sGoopAE3vPfSzQOpKHH3lJLFSVrwaqAk9 SPkHEfrU1MreT0X1eYMN8sajU9avFwguTR5sdilGjkVtf0axZup5Bevq5nEGwQCeI/Mr UHkg== X-Gm-Message-State: ACgBeo0zkzJhouafdmUZSJ4YA9t4QZIzUJxW9xVWNWYiYRu+ASqOJmvV yctTCm51xkvNEU3omBqnP3Wvz40C1z1W8w== X-Google-Smtp-Source: AA6agR7g/onfYmwdGwSMMgKGTeYIUoduB+GqCCXt3rl9w/FCLFo+UhJtmqhow6y6hCv6AxGQseqn9Q== X-Received: by 2002:ab0:6716:0:b0:38c:cdcd:1556 with SMTP id q22-20020ab06716000000b0038ccdcd1556mr7588274uam.63.1660232802166; Thu, 11 Aug 2022 08:46:42 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c0:89b:9d50:8d25:b9e5:dcfc? ([2804:1b3:a7c0:89b:9d50:8d25:b9e5:dcfc]) by smtp.gmail.com with ESMTPSA id u124-20020a1fc482000000b003768e235513sm2303217vkf.0.2022.08.11.08.46.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Aug 2022 08:46:41 -0700 (PDT) Message-ID: <01b0c4b1-a301-4c62-c4cc-16d4da634b8a@linaro.org> Date: Thu, 11 Aug 2022 12:46:39 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Subject: Re: [PATCH v4] glibcextract.py: Add compile_c_snippet Content-Language: en-US To: Florian Weimer Cc: libc-alpha@sourceware.org References: <20220811112136.62369-1-adhemerval.zanella@linaro.org> <87bksqu8xw.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <87bksqu8xw.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Aug 2022 15:46:44 -0000 On 11/08/22 11:54, Florian Weimer wrote: > * Adhemerval Zanella: > >> It might be used on tests to check if a snippet build with the provided >> compiler and flags. >> --- >> scripts/glibcextract.py | 18 ++++++++++++++++++ >> 1 file changed, 18 insertions(+) >> >> diff --git a/scripts/glibcextract.py b/scripts/glibcextract.py >> index 43ab58ffe2..33463087da 100644 >> --- a/scripts/glibcextract.py >> +++ b/scripts/glibcextract.py >> @@ -17,6 +17,7 @@ >> # License along with the GNU C Library; if not, see >> # . >> >> +import collections >> import os.path >> import re >> import subprocess >> @@ -173,3 +174,20 @@ def compare_macro_consts(source_1, source_2, cc, macro_re, exclude_re=None, >> if not allow_extra_2: >> ret = 1 >> return ret >> + >> +CompileResult = collections.namedtuple("CompileResult", "returncode output") >> + >> +def compile_c_snippet(snippet, cc, extra_cc_args=''): >> + """Compile and return whether the SNIPPET can be build with CC along >> + EXTRA_CC_ARGS compiler flags. Return a CompileResult with RETURNCODE >> + being 0 for success, or the failure value and the compiler output. >> + """ >> + with tempfile.TemporaryDirectory() as temp_dir: >> + c_file_name = os.path.join(temp_dir, 'test.c') >> + obj_file_name = os.path.join(temp_dir, 'test.o') >> + with open(c_file_name, 'w') as c_file: >> + c_file.write(snippet + '\n') >> + cmd = cc.split() + extra_cc_args.split() + ['-c', '-o', obj_file_name, >> + c_file_name] >> + r = subprocess.run(cmd, capture_output=True) >> + return CompileResult(r.returncode, r.stderr) > > Meh. > > Traceback (most recent call last): > File "../sysdeps/unix/sysv/linux/tst-mount-compile.py", line 66, in > main() > File "../sysdeps/unix/sysv/linux/tst-mount-compile.py", line 38, in main > args.cc).returncode != 0: > File "/home/bmg/src/glibc/scripts/glibcextract.py", line 192, in compile_c_snippet > r = subprocess.run(cmd, capture_output=True) > File "/usr/lib64/python3.6/subprocess.py", line 423, in run > with Popen(*popenargs, **kwargs) as process: > TypeError: __init__() got an unexpected keyword argument 'capture_output' > > That's with Python 3.6. Sigh, it was added on Python 3.7. We will need to use stderr=PIPE instead.