From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2a.google.com (mail-vs1-xe2a.google.com [IPv6:2607:f8b0:4864:20::e2a]) by sourceware.org (Postfix) with ESMTPS id 376A43858C74 for ; Thu, 11 Aug 2022 11:21:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 376A43858C74 Received: by mail-vs1-xe2a.google.com with SMTP id 129so17921105vsq.8 for ; Thu, 11 Aug 2022 04:21:21 -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=YK5IUGdnpYToRQf9EOWQveYW94F6w0duRbh7+2z3RAI=; b=1zhw1j2AiGIkX9sv7NVof6+BAtSeKSwyphbxnz1QabG3U8oI2DLxLUoXWMfejCzonU WotBmpw7vijldOvOS2tRl5mRviRb+Kt+mFrN4kdkS0mCXcMXO5R8Svl5SyRoa9DRXzwg l6CvDtBawDKLgQ/JAsP/TcNFO9OB2p0TlK76z337QqpjtiUbq1rjWEiuLVc2UiOW3v70 RiaPjYf+eVb+v0tpoUR0iVYaKzgBrPhoWfnKkTuWlxTqfHkNFnczSZ89+bFtZ2giodBV 5QrOlAuz1tHBZVokAqQJ5A6FPyCRLb7BZEr201BS6kSGtnYug02Sc91tXN0pMW8NGxc5 F2lA== X-Gm-Message-State: ACgBeo2t8j4i8OCwEeoF8e4SgMYg7xXwZaKGPtkz/j4IieLdZDPiHEHQ xyjaBNbMdAbA4lgQLZGPX53Ma1MUD4LDVQ== X-Google-Smtp-Source: AA6agR7ReE0+YQaCDgmfer2zb4nlkguS68sDwMNuOvR7h67NXa6DxN8cgjpardsXsC6ft+M6lLKvaQ== X-Received: by 2002:a05:6102:2223:b0:32d:2ae1:412 with SMTP id d3-20020a056102222300b0032d2ae10412mr13662035vsb.6.1660216880440; Thu, 11 Aug 2022 04:21:20 -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 l19-20020a056102309300b0038890d0e100sm1232979vsb.27.2022.08.11.04.21.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Aug 2022 04:21:20 -0700 (PDT) Message-ID: Date: Thu, 11 Aug 2022 08:21:18 -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 v3] glibcextract.py: Add compile_c_snippet Content-Language: en-US To: Florian Weimer Cc: libc-alpha@sourceware.org References: <20220810192406.1533740-1-adhemerval.zanella@linaro.org> <8735e3xpq8.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <8735e3xpq8.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 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 11:21:23 -0000 On 11/08/22 03:23, 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 | 20 ++++++++++++++++++++ >> 1 file changed, 20 insertions(+) >> >> diff --git a/scripts/glibcextract.py b/scripts/glibcextract.py >> index 43ab58ffe2..78735fad43 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,22 @@ 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() >> + if len(extra_cc_args) > 0: >> + cmd += [extra_cc_args] >> + cmd += ['-c', '-o', obj_file_name, c_file_name] >> + r = subprocess.run(cmd, capture_output=True) >> + return CompileResult(r.returncode, r.stderr) > > Sadly that doesn't work because extra_cc_args isn't split. It even simplify the code in fact, I will send an update. > > Maybe we should just keep using the shell (without the redirect). > > Thanks, > Florian >