* libcpp: dependency emission tidying
@ 2020-11-03 13:02 Nathan Sidwell
2020-11-03 13:42 ` Tobias Burnus
2020-11-03 14:04 ` Nathan Sidwell
0 siblings, 2 replies; 3+ messages in thread
From: Nathan Sidwell @ 2020-11-03 13:02 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 1003 bytes --]
This patch cleans up the interface to the dependency generation a
little. We now only check the option in one place, and the
cpp_get_deps function returns nullptr if there are no dependencies. I
also reworded the -MT and -MQ help text to be make agnostic -- as
there are ideas about emitting, say, JSON.
libcpp/
* include/mdeps.h: Include cpplib.h
(deps_write): Adjust first parm type.
* mkdeps.c: Include internal.h
(make_write): Adjust first parm type. Check phony option
directly.
(deps_write): Adjust first parm type.
* init.c (cpp_read_main_file): Use get_deps.
* directives.c (cpp_get_deps): Check option before initializing.
gcc/c-family/
* c.opt (MQ,MT): Reword description to be make-agnostic.
gcc/fortran/
* cpp.c (gfc_cpp_add_dep): Only add dependency if we're recording
them.
(gfc_cpp_init): Likewise for target.
pushing to trunk
--
Nathan Sidwell
[-- Attachment #2: mkdeps.diff --]
[-- Type: text/x-patch, Size: 6125 bytes --]
diff --git c/gcc/c-family/c.opt w/gcc/c-family/c.opt
index 10e53ea67c9..426636be839 100644
--- c/gcc/c-family/c.opt
+++ w/gcc/c-family/c.opt
@@ -242,11 +242,11 @@ Generate phony targets for all headers.
MQ
C ObjC C++ ObjC++ Joined Separate MissingArgError(missing makefile target after %qs)
--MQ <target> Add a MAKE-quoted target.
+-MQ <target> Add a target that may require quoting.
MT
C ObjC C++ ObjC++ Joined Separate MissingArgError(missing makefile target after %qs)
--MT <target> Add an unquoted target.
+-MT <target> Add a target that does not require quoting.
P
C ObjC C++ ObjC++
diff --git c/gcc/fortran/cpp.c w/gcc/fortran/cpp.c
index dcde5576cd5..51baf141711 100644
--- c/gcc/fortran/cpp.c
+++ w/gcc/fortran/cpp.c
@@ -222,13 +222,15 @@ void
gfc_cpp_add_dep (const char *name, bool system)
{
if (!gfc_cpp_option.deps_skip_system || !system)
- deps_add_dep (cpp_get_deps (cpp_in), name);
+ if (mkdeps *deps = cpp_get_deps (cpp_in))
+ deps_add_dep (deps, name);
}
void
gfc_cpp_add_target (const char *name)
{
- deps_add_target (cpp_get_deps (cpp_in), name, 0);
+ if (mkdeps *deps = cpp_get_deps (cpp_in))
+ deps_add_target (deps, name, 0);
}
@@ -605,8 +607,8 @@ gfc_cpp_init (void)
cpp_assert (cpp_in, opt->arg);
}
else if (opt->code == OPT_MT || opt->code == OPT_MQ)
- deps_add_target (cpp_get_deps (cpp_in),
- opt->arg, opt->code == OPT_MQ);
+ if (mkdeps *deps = cpp_get_deps (cpp_in))
+ deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
}
/* Pre-defined macros for non-required INTEGER kind types. */
diff --git c/libcpp/directives.c w/libcpp/directives.c
index d7b59aae901..4295a67f1e5 100644
--- c/libcpp/directives.c
+++ w/libcpp/directives.c
@@ -2572,7 +2572,7 @@ cpp_set_callbacks (cpp_reader *pfile, cpp_callbacks *cb)
class mkdeps *
cpp_get_deps (cpp_reader *pfile)
{
- if (!pfile->deps)
+ if (!pfile->deps && CPP_OPTION (pfile, deps.style) != DEPS_NONE)
pfile->deps = deps_init ();
return pfile->deps;
}
diff --git c/libcpp/include/mkdeps.h w/libcpp/include/mkdeps.h
index 6d05351cb4a..593b718aaeb 100644
--- c/libcpp/include/mkdeps.h
+++ w/libcpp/include/mkdeps.h
@@ -23,6 +23,8 @@ along with this program; see the file COPYING3. If not see
#ifndef LIBCPP_MKDEPS_H
#define LIBCPP_MKDEPS_H
+#include "cpplib.h"
+
/* This is the data structure used by all the functions in mkdeps.c.
It's quite straightforward, but should be treated as opaque. */
@@ -55,9 +57,9 @@ extern void deps_add_default_target (class mkdeps *, const char *);
dependency entered should be the primary source file. */
extern void deps_add_dep (class mkdeps *, const char *);
-/* Write out a deps buffer to a specified file. The third argument
+/* Write out a deps buffer to a specified file. The last argument
is the number of columns to word-wrap at (0 means don't wrap). */
-extern void deps_write (const class mkdeps *, FILE *, bool, unsigned int);
+extern void deps_write (const cpp_reader *, FILE *, unsigned int);
/* Write out a deps buffer to a file, in a form that can be read back
with deps_restore. Returns nonzero on error, in which case the
diff --git c/libcpp/init.c w/libcpp/init.c
index 454a183134a..5b2607e3767 100644
--- c/libcpp/init.c
+++ w/libcpp/init.c
@@ -667,14 +667,9 @@ cpp_post_options (cpp_reader *pfile)
const char *
cpp_read_main_file (cpp_reader *pfile, const char *fname, bool injecting)
{
- if (CPP_OPTION (pfile, deps.style) != DEPS_NONE)
- {
- if (!pfile->deps)
- pfile->deps = deps_init ();
-
- /* Set the default target (if there is none already). */
- deps_add_default_target (pfile->deps, fname);
- }
+ if (mkdeps *deps = cpp_get_deps (pfile))
+ /* Set the default target (if there is none already). */
+ deps_add_default_target (pfile->deps, fname);
pfile->main_file
= _cpp_find_file (pfile, fname, &pfile->no_search_path, /*angle=*/0,
@@ -813,9 +808,8 @@ cpp_finish (cpp_reader *pfile, FILE *deps_stream)
while (pfile->buffer)
_cpp_pop_buffer (pfile);
- if (CPP_OPTION (pfile, deps.style) != DEPS_NONE && deps_stream)
- deps_write (pfile->deps, deps_stream,
- CPP_OPTION (pfile, deps.phony_targets), 72);
+ if (deps_stream)
+ deps_write (pfile, deps_stream, 72);
/* Report on headers that could use multiple include guards. */
if (CPP_OPTION (pfile, print_include_names))
diff --git c/libcpp/mkdeps.c w/libcpp/mkdeps.c
index 09a111fcdd5..ea5f060c380 100644
--- c/libcpp/mkdeps.c
+++ w/libcpp/mkdeps.c
@@ -23,6 +23,7 @@ along with this program; see the file COPYING3. If not see
#include "config.h"
#include "system.h"
#include "mkdeps.h"
+#include "internal.h"
/* Not set up to just include std::vector et al, here's a simple
implementation. */
@@ -367,8 +368,10 @@ make_write_vec (const mkdeps::vec<const char *> &vec, FILE *fp,
.PHONY targets for all the dependencies too. */
static void
-make_write (const class mkdeps *d, FILE *fp, bool phony, unsigned int colmax)
+make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax)
{
+ const mkdeps *d = pfile->deps;
+
unsigned column = 0;
if (colmax && colmax < 34)
colmax = 34;
@@ -380,7 +383,7 @@ make_write (const class mkdeps *d, FILE *fp, bool phony, unsigned int colmax)
column++;
make_write_vec (d->deps, fp, column, colmax);
fputs ("\n", fp);
- if (phony)
+ if (CPP_OPTION (pfile, deps.phony_targets))
for (unsigned i = 1; i < d->deps.size (); i++)
fprintf (fp, "%s:\n", munge (d->deps[i]));
}
@@ -388,11 +391,12 @@ make_write (const class mkdeps *d, FILE *fp, bool phony, unsigned int colmax)
/* Write out dependencies according to the selected format (which is
only Make at the moment). */
+/* Really we should be opening fp here. */
void
-deps_write (const class mkdeps *d, FILE *fp, bool phony, unsigned int colmax)
+deps_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax)
{
- make_write (d, fp, phony, colmax);
+ make_write (pfile, fp, colmax);
}
/* Write out a deps buffer to a file, in a form that can be read back
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: libcpp: dependency emission tidying
2020-11-03 13:02 libcpp: dependency emission tidying Nathan Sidwell
@ 2020-11-03 13:42 ` Tobias Burnus
2020-11-03 14:04 ` Nathan Sidwell
1 sibling, 0 replies; 3+ messages in thread
From: Tobias Burnus @ 2020-11-03 13:42 UTC (permalink / raw)
To: Nathan Sidwell, GCC Patches
Hi Nathan,
I now get:
../../repos/gcc/libcpp/init.c:670:15: error: unused variable ‘deps’ [-Werror=unused-variable]
670 | if (mkdeps *deps = cpp_get_deps (pfile))
| ^~~~
see last three lines of the quoted patch below.
Tobias
On 03.11.20 14:02, Nathan Sidwell wrote:
> cpp_read_main_file (cpp_reader *pfile, const char *fname, bool injecting)
> {
> - if (CPP_OPTION (pfile, deps.style) != DEPS_NONE)
> - {
> - if (!pfile->deps)
> - pfile->deps = deps_init ();
> -
> - /* Set the default target (if there is none already). */
> - deps_add_default_target (pfile->deps, fname);
> - }
> + if (mkdeps *deps = cpp_get_deps (pfile))
> + /* Set the default target (if there is none already). */
> + deps_add_default_target (pfile->deps, fname);
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: libcpp: dependency emission tidying
2020-11-03 13:02 libcpp: dependency emission tidying Nathan Sidwell
2020-11-03 13:42 ` Tobias Burnus
@ 2020-11-03 14:04 ` Nathan Sidwell
1 sibling, 0 replies; 3+ messages in thread
From: Nathan Sidwell @ 2020-11-03 14:04 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 164 bytes --]
Whoops, that broke bootstrap. Pushing this fix.
libcpp/
* init.c (cpp_read_main_file): Use cpp_get_deps result.
--
Nathan Sidwell
[-- Attachment #2: unbreak.diff --]
[-- Type: text/x-patch, Size: 516 bytes --]
diff --git c/libcpp/init.c w/libcpp/init.c
index 5b2607e3767..6c52f50de39 100644
--- c/libcpp/init.c
+++ w/libcpp/init.c
@@ -669,7 +669,7 @@ cpp_read_main_file (cpp_reader *pfile, const char *fname, bool injecting)
{
if (mkdeps *deps = cpp_get_deps (pfile))
/* Set the default target (if there is none already). */
- deps_add_default_target (pfile->deps, fname);
+ deps_add_default_target (deps, fname);
pfile->main_file
= _cpp_find_file (pfile, fname, &pfile->no_search_path, /*angle=*/0,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-03 14:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-03 13:02 libcpp: dependency emission tidying Nathan Sidwell
2020-11-03 13:42 ` Tobias Burnus
2020-11-03 14:04 ` Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).