From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe35.google.com (mail-vs1-xe35.google.com [IPv6:2607:f8b0:4864:20::e35]) by sourceware.org (Postfix) with ESMTPS id D9390385828B for ; Wed, 10 Aug 2022 19:00:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D9390385828B Received: by mail-vs1-xe35.google.com with SMTP id c3so16088366vsc.6 for ; Wed, 10 Aug 2022 12:00:35 -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=TphkIfPn61Ttg+91NugS5aNDCMqdiZpGIWRrpuBFJW0=; b=JFxOoyA/3NrwQ7ChVQWxXolpvKQ6jlhLEk1k0E8iN2nHcgofpDXlNvjEAFSz7s+QBS M8ssUEgTOSysVz8C5iMrgjjtCJnHrjz56W2S2w2bqJyLRchEjELxSZivte2/be930oPj 054Lxn+EbU9C+fF7/KINaGonTk/x7xMCZUPc0lqA/p0z0OMe/nhJVT3HBlPZY52iD1EG GGaL774tyRkDXv4n0nCebpAHmolMi8X1Zw5OFxXWFKuU0+QBuFHGHvcqgogfe9T3h+fd 1uhMeFhBWK8IAdZ/Hs5qv7hbsRDqiZ+JfJpKIrFcGxrecncFiZwWVMQLmKLQUrzpemwz F/Og== X-Gm-Message-State: ACgBeo3KEudg6CVL4zjEFPOzZc5Ue85nrXWD531Fn23qYKk0KsXCtp/A 8HKkUaOsAIeuWIUX3courUGLsQ== X-Google-Smtp-Source: AA6agR7NCKl5Tblt78nkmAInRZ++TbfVe12majbXggdLpx1x8Ls401SwNE1f1tv8mHmWG8PXW64UcA== X-Received: by 2002:a67:c198:0:b0:383:b020:f7c4 with SMTP id h24-20020a67c198000000b00383b020f7c4mr12951106vsj.71.1660158035156; Wed, 10 Aug 2022 12:00:35 -0700 (PDT) Received: from ?IPV6:2804:431:c7ca:930b:c8c3:715b:6901:2e81? ([2804:431:c7ca:930b:c8c3:715b:6901:2e81]) by smtp.gmail.com with ESMTPSA id x78-20020a1fae51000000b003777cf035a4sm401518vke.33.2022.08.10.12.00.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Aug 2022 12:00:34 -0700 (PDT) Message-ID: <63e88ecf-8993-553f-906b-2c5df778c7bc@linaro.org> Date: Wed, 10 Aug 2022 16:00:33 -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 v2 1/5] glibcextract.py: Add compile_c_snippet Content-Language: en-US To: Florian Weimer Cc: libc-alpha@sourceware.org References: <20220810172447.1502169-1-adhemerval.zanella@linaro.org> <20220810172447.1502169-2-adhemerval.zanella@linaro.org> <871qto9f2k.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <871qto9f2k.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: Wed, 10 Aug 2022 19:00:37 -0000 On 10/08/22 14:35, 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..71d9ea1acc 100644 >> --- a/scripts/glibcextract.py >> +++ b/scripts/glibcextract.py >> @@ -21,6 +21,7 @@ import os.path >> import re >> import subprocess >> import tempfile >> +import collections > > Please keep the imports sorted. Ack. > >> def compute_c_consts(sym_data, cc): >> @@ -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) >> + # Compilation has to be from stdin to avoid the temporary file >> + # name being written into the generated dependencies. >> + cmd = ('%s %s -c -o %s -x c - < %s' % (cc, extra_cc_args, >> + obj_file_name, c_file_name)) >> + r = subprocess.run(cmd, shell=True, capture_output=True) >> + return CompileResult(r.returncode, r.stderr) > > I think you can avoid shell=True and the direction if you just compile > c_file_name directly. Sorry, missed that earlier. Right, I will do it.