From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id D2BE63858D33 for ; Thu, 18 Apr 2024 15:40:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D2BE63858D33 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D2BE63858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713454814; cv=none; b=Gv2DYNpZ0ywjCCHJdpDXUILx2LT7qslPBi9KlkmJR8oaERqYeE1g3Lenrzff534hXFjt6jfDDJQkucEvvkKJSbkxrKvVvV69wU848y3x9VPDoT/y0BxDHdBtm/hezHBUIVElxw10m3MV+0/A2JPkmdJD6rFI1rKyccL7jAUyQqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713454814; c=relaxed/simple; bh=MtTrSecRIRjiaPU8X2uh+A2y3pROQCJYakpFhPfAHJ4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fvLk9TNvNy4UcDb8EfucEgxcByZvt276SMn4njaKRBERFHoeqHJP0SV5jNR4GF0tovMICPEsK+xGp2r8SOcdjz6ZIK/9BYxirl/OTy1HGtXIX3KgaF9Djm1WlZNIKh+gKZAxYA6DUcGXvplX527L+gMpSJ8r4WHF520oD2/nTJ0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6ea2f95ec67so464258a34.2 for ; Thu, 18 Apr 2024 08:40:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1713454812; x=1714059612; darn=sourceware.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=E5fXBeDyp68A/PFgHLHOcQBH7DGIvrR9R8zaFPV4ung=; b=Ji/6LpOhKvc9eUUMVQTVsic/I0GxygG2rfsf0tRGcttteVbpnIuJmvwcjaIe/+4peN hiI8pvIccLmGMCIvbT6Pgc91GF7zN4FHlqksFFKB//zXhI91CMJBhMvYvlIlTjIBPmxy YW3Q7bZM0tfLf6rkU71ly/iS+hXDuHtTpu8VctuuW05WyELSiPaubEVR5UNh7eIvxIm+ s7ojuWWc5870wFT8sLC5ZIViM45f05GUvK3jvGKmbnkr+Gl2HFxgbYYwlNEhpY+DJXP/ INTYlk2VWSWi5n7kdfqYCvCEGPdGVwV72acWUW3/foKIrGls+BWkKn5jwBUiqQI196Se UDWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713454812; x=1714059612; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=E5fXBeDyp68A/PFgHLHOcQBH7DGIvrR9R8zaFPV4ung=; b=DYUjMas0zn9P2ZJcA3NX3MjkXDytrfBoIS9tXJCKlgEzF60bf2nUTKK4N7ROJS3QuW wJk2rxHj1YtORhxvXDWILUmp3EFvME6BDnANKRZsSKpGiHSvk6/15+AWZM1eTcHjAm9G 91SCZvj4OemFZkqMulxuvcPoY8m90NParnzF2M5MeJgFLRYFtbL4Zqr7ideJl8iEh3tU XAAbJWCIwnP5yfK1nAK5+UFhQV7aPZfkfaWcq9AwFZPRl2Ei6LtgSfiKyOEk3ug7Brkh tA1puEN2HV8XzFOkCGK0pOX3KBcbtu14O0O2yTG6MxHEb7R91JhKitOF6coPZQy2jZBe ClgQ== X-Forwarded-Encrypted: i=1; AJvYcCXAYik4JdWKUOfmWlGYvqckbznKg26rQku/My4Ax26aT0Wbq63fWRdhyy/nysTGE8wmUmpiFq7nbN4Emi4aBYR0ANl6R4k6++ZQaw== X-Gm-Message-State: AOJu0YzSEdVm8dFsbBSJaDo0DSRfkNwP55mo/lXa/SEXrrY9BJSQ1moB 1X9/B/5Nn4RO2BbHq8FRDyO+0HWyRct6SvPfw+HZc1+edEj+E+DVvB3KEI6xUw== X-Google-Smtp-Source: AGHT+IFGg2zTWZkJtYWXTpxAOdlz4vkZPR2c/1UiV2X/90m2+6D5h4QlbeyE6rwBO/Bv/rsoeuGPmQ== X-Received: by 2002:a05:6870:239c:b0:22e:9432:df8b with SMTP id e28-20020a056870239c00b0022e9432df8bmr4669249oap.54.1713454812101; Thu, 18 Apr 2024 08:40:12 -0700 (PDT) Received: from murgatroyd (97-122-82-115.hlrn.qwest.net. [97.122.82.115]) by smtp.gmail.com with ESMTPSA id eq16-20020a0566384e3000b00482be91e04esm493605jab.47.2024.04.18.08.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 08:40:11 -0700 (PDT) From: Tom Tromey To: Simon Marchi Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH 2/4] Add an include-checking script References: <20240417-header-check-v1-0-a60f610f5bcc@adacore.com> <20240417-header-check-v1-2-a60f610f5bcc@adacore.com> X-Attribution: Tom Date: Thu, 18 Apr 2024 09:40:11 -0600 In-Reply-To: (Simon Marchi's message of "Thu, 18 Apr 2024 11:29:30 -0400") Message-ID: <877cguznl0.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: >>>>> "Simon" == Simon Marchi writes: >> +def failure(filename, ndx, text): >> + print(filename + ":" + str(ndx + 1) + ": " + text) Simon> Should this print to stderr? Done. >> + global status >> + status = 1 Simon> I would prefer if failure returned 1 (or the callers could return 1 Simon> themselves). I ended up having it just call sys.exit (which really just throws). The approach in the patch was from an earlier version that was run by hand, before I figured out it could be run from pre-commit; and there working on multiple files was more important. >> +def headers(dirname): >> + return glob.iglob(dirname + "/*.h") Simon> This function appears to be unused. Removed. Simon> You could do: Simon> contents = [line.strip('\n') for line in f] Simon> and then no longer have to deal with \n everywhere. >> + if force_rewrite: >> + contents[i] = "#ifndef " + expected + "\n" Simon> You don't need to add a \n here (and at other spots where you write a Simon> line), writelines will do it. The Python docs seem to say otherwise: https://docs.python.org/3/library/io.html#io.IOBase.writelines I left all the \n stuff alone. >> + if contents[i] != "#endif /* " + expected + " */\n": >> + failure(filename, i, "incorrect endif") >> + contents[i] = "#endif /* " + expected + " */\n" >> + updated = True Simon> You could access the last line with contents[-1]. I figured we needed the line number for a possible error message anyway. Tom