[anjuta/newproject] Support include file in Makefile.am
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/newproject] Support include file in Makefile.am
- Date: Sun, 28 Feb 2010 18:45:22 +0000 (UTC)
commit 5bd25d63deb4c3c92c2584b9968be1d6ebdd5bc9
Author: Sébastien Granjoux <seb sfo free fr>
Date: Sun Feb 28 18:37:54 2010 +0100
Support include file in Makefile.am
libanjuta/anjuta-token-stream.c | 80 ++++++++++++++++++++++-----------
libanjuta/anjuta-token-stream.h | 3 +-
plugins/am-project/ac-scanner.l | 6 +-
plugins/am-project/am-parser.y | 16 +++++-
plugins/am-project/am-project.c | 2 +-
plugins/am-project/am-scanner.h | 4 +-
plugins/am-project/am-scanner.l | 48 +++++++++----------
plugins/am-project/tests/Makefile.am | 3 +-
plugins/am-project/tests/anjuta.lst | 3 -
plugins/am-project/tests/include.at | 22 +++++++++
plugins/am-project/tests/testsuite.at | 1 +
plugins/mk-project/mk-scanner.l | 2 +-
12 files changed, 125 insertions(+), 65 deletions(-)
---
diff --git a/libanjuta/anjuta-token-stream.c b/libanjuta/anjuta-token-stream.c
index 7b10f8e..04076d3 100644
--- a/libanjuta/anjuta-token-stream.c
+++ b/libanjuta/anjuta-token-stream.c
@@ -60,22 +60,25 @@
struct _AnjutaTokenStream
{
/* Input stream */
- AnjutaToken *first;
- AnjutaToken *last;
+ AnjutaToken *first;
+ AnjutaToken *last;
- /* Read position in input stream */
- AnjutaToken *next;
- gsize pos;
+ /* Read position in input stream */
+ AnjutaToken *next;
+ gsize pos;
+
+ /* Write position in input stream */
+ AnjutaToken *start;
+ gsize begin;
+
+ /* Output stream */
+ AnjutaToken *root;
- /* Write position in input stream */
- AnjutaToken *start;
- gsize begin;
-
- /* Output stream */
- AnjutaToken *root;
-
/* Parent stream */
- AnjutaTokenStream *parent;
+ AnjutaTokenStream *parent;
+
+ /* Current directory */
+ GFile *current_directory;
};
/* Helpers functions
@@ -258,6 +261,22 @@ anjuta_token_stream_get_root (AnjutaTokenStream *stream)
return stream->root;
}
+/**
+ * anjuta_token_stream_get_current_directory:
+ * @stream: a #AnjutaTokenStream object.
+ *
+ * Return the current directory.
+ *
+ * Return value: The current directory.
+ */
+GFile*
+anjuta_token_stream_get_current_directory (AnjutaTokenStream *stream)
+{
+ g_return_val_if_fail (stream != NULL, NULL);
+
+ return stream->current_directory;
+}
+
/* Constructor & Destructor
@@ -275,23 +294,31 @@ anjuta_token_stream_get_root (AnjutaTokenStream *stream)
* Return value: The newly created stream.
*/
AnjutaTokenStream *
-anjuta_token_stream_push (AnjutaTokenStream *parent, AnjutaToken *token)
+anjuta_token_stream_push (AnjutaTokenStream *parent, AnjutaToken *token, GFile *filename)
{
AnjutaTokenStream *child;
- child = g_new (AnjutaTokenStream, 1);
- child->first = token;
- child->pos = 0;
- child->begin = 0;
- child->parent = parent;
+ child = g_new (AnjutaTokenStream, 1);
+ child->first = token;
+ child->pos = 0;
+ child->begin = 0;
+ child->parent = parent;
- child->next = anjuta_token_next (token);
- child->start = child->next;
- child->last = anjuta_token_last (token);
- if (child->last == token) child->last = NULL;
+ child->next = anjuta_token_next (token);
+ child->start = child->next;
+ child->last = anjuta_token_last (token);
+ if (child->last == token) child->last = NULL;
child->root = anjuta_token_new_static (ANJUTA_TOKEN_FILE, NULL);
-
+ if (filename == NULL)
+ {
+ child->current_directory = parent == NULL ? NULL : g_object_ref (parent->current_directory);
+ }
+ else
+ {
+ child->current_directory = g_file_get_parent (filename);
+ }
+
return child;
}
@@ -309,9 +336,10 @@ anjuta_token_stream_pop (AnjutaTokenStream *stream)
AnjutaTokenStream *parent;
g_return_val_if_fail (stream != NULL, NULL);
-
+
+ if (stream->current_directory) g_object_unref (stream->current_directory);
parent = stream->parent;
- g_free (stream);
+ g_free (stream);
return parent;
}
diff --git a/libanjuta/anjuta-token-stream.h b/libanjuta/anjuta-token-stream.h
index c1d4557..7c4b174 100644
--- a/libanjuta/anjuta-token-stream.h
+++ b/libanjuta/anjuta-token-stream.h
@@ -28,10 +28,11 @@ G_BEGIN_DECLS
typedef struct _AnjutaTokenStream AnjutaTokenStream;
-AnjutaTokenStream *anjuta_token_stream_push (AnjutaTokenStream *stream, AnjutaToken *token);
+AnjutaTokenStream *anjuta_token_stream_push (AnjutaTokenStream *stream, AnjutaToken *token, GFile *filename);
AnjutaTokenStream *anjuta_token_stream_pop (AnjutaTokenStream *stream);
AnjutaToken* anjuta_token_stream_get_root (AnjutaTokenStream *stream);
+GFile* anjuta_token_stream_get_current_directory (AnjutaTokenStream *stream);
AnjutaToken* anjuta_token_stream_tokenize (AnjutaTokenStream *stream, gint type, gsize length);
gint anjuta_token_stream_read (AnjutaTokenStream *stream, gchar *buffer, gsize max_size);
diff --git a/plugins/am-project/ac-scanner.l b/plugins/am-project/ac-scanner.l
index 87afc6c..6ec7db9 100644
--- a/plugins/am-project/ac-scanner.l
+++ b/plugins/am-project/ac-scanner.l
@@ -219,7 +219,7 @@ amp_ac_scanner_parse_token (AmpAcScanner *scanner, AnjutaToken *token, gint star
AnjutaToken *first;
AnjutaTokenStream *stream;
- stream = anjuta_token_stream_push (scanner->stream, token);
+ stream = anjuta_token_stream_push (scanner->stream, token, NULL);
first = anjuta_token_stream_get_root (stream);
if (scanner->stream != NULL)
@@ -233,7 +233,7 @@ amp_ac_scanner_parse_token (AmpAcScanner *scanner, AnjutaToken *token, gint star
{
amp_ac_yypstate *ps;
gint status;
- YYSTYPE yylval_param;
+ YYSTYPE yylval_param;
YYLTYPE yylloc_param;
scanner->stream = stream;
@@ -262,7 +262,7 @@ amp_ac_scanner_parse_token (AmpAcScanner *scanner, AnjutaToken *token, gint star
amp_ac_yypstate_delete (ps);
}
- return first;
+ return first;
}
/* Constructor & Destructor
diff --git a/plugins/am-project/am-parser.y b/plugins/am-project/am-parser.y
index 63bf489..7e8f235 100644
--- a/plugins/am-project/am-parser.y
+++ b/plugins/am-project/am-parser.y
@@ -48,6 +48,8 @@
%token NAME
%token AM_VARIABLE
+%token INCLUDE
+
%token SUBDIRS
%token DIST_SUBDIRS
%token _DATA
@@ -160,6 +162,7 @@ statement:
/* empty */
| line
| am_variable
+ | include
;
line:
@@ -178,7 +181,12 @@ am_variable:
anjuta_token_merge ($$, $1);
}
;
-
+
+include:
+ include_token space value {
+ amp_am_scanner_include (scanner, $3);
+ }
+
space_list_value: optional_space equal_token value_list {
$$ = anjuta_token_new_static (ANJUTA_TOKEN_LIST, NULL);
if ($1 != NULL) anjuta_token_set_type ($1, ANJUTA_TOKEN_START);
@@ -321,6 +329,8 @@ automake_token:
| TARGET_YFLAGS
| TARGET_DEPENDENCIES
;
-
-
+
+include_token:
+ INCLUDE
+ ;
%%
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index 6eaa065..2d95f6e 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -692,7 +692,7 @@ amp_group_set_makefile (AmpGroup *node, GFile *makefile, AmpProject* project)
token = anjuta_token_file_load (group->tfile, NULL);
scanner = amp_am_scanner_new (project, node);
- group->make_token = amp_am_scanner_parse_token (scanner, token, NULL);
+ group->make_token = amp_am_scanner_parse_token (scanner, token, makefile, NULL);
amp_am_scanner_free (scanner);
}
else
diff --git a/plugins/am-project/am-scanner.h b/plugins/am-project/am-scanner.h
index d2882b2..c1ed3b1 100644
--- a/plugins/am-project/am-scanner.h
+++ b/plugins/am-project/am-scanner.h
@@ -39,9 +39,11 @@ typedef struct _AmpAmScanner AmpAmScanner;
AmpAmScanner *amp_am_scanner_new (AmpProject *project, AmpGroup *group);
void amp_am_scanner_free (AmpAmScanner *scanner);
-AnjutaToken *amp_am_scanner_parse_token (AmpAmScanner *scanner, AnjutaToken *token, GError **error);
+AnjutaToken *amp_am_scanner_parse_token (AmpAmScanner *scanner, AnjutaToken *token, GFile *filename, GError **error);
void amp_am_scanner_set_am_variable (AmpAmScanner *scanner, AnjutaTokenType variable, AnjutaToken *name, AnjutaToken *list);
+void amp_am_scanner_include (AmpAmScanner *scanner, AnjutaToken *name);
+
void amp_am_yyerror (YYLTYPE *loc, AmpAmScanner *scanner, char const *s);
diff --git a/plugins/am-project/am-scanner.l b/plugins/am-project/am-scanner.l
index df9ffc8..7f0ed54 100644
--- a/plugins/am-project/am-scanner.l
+++ b/plugins/am-project/am-scanner.l
@@ -114,6 +114,8 @@ NAME [^ \t\n\r:#=$"'`&@\\]*
<INITIAL>\\# { RETURN (CHARACTER); }
+<INITIAL>include { RETURN (INCLUDE); }
+
<INITIAL>SUBDIRS { RETURN (SUBDIRS); }
<INITIAL>DIST_SUBDIRS { RETURN (DIST_SUBDIRS); }
@@ -188,29 +190,6 @@ NAME [^ \t\n\r:#=$"'`&@\\]*
%%
-typedef struct _AmpAmBuffer AmpAmBuffer;
-
-struct _AmpAmBuffer
-{
- AnjutaToken *token;
-
- /* Beginning of current token */
- AnjutaToken *start;
- gsize begin;
-
- AnjutaToken *end; /* Last token */
-
- /* Next data read buffer */
- AnjutaToken *next;
- gsize pos;
-
- /* Place to put new token */
- AnjutaToken *first;
- AnjutaToken *last;
-
- AmpAmBuffer *parent;
-};
-
/* Private functions
*---------------------------------------------------------------------------*/
@@ -254,17 +233,36 @@ amp_am_scanner_set_am_variable (AmpAmScanner *scanner, AnjutaTokenType variable,
{
amp_project_set_am_variable (scanner->project, scanner->group, variable, name, list, scanner->orphan_properties);
}
+void
+amp_am_scanner_include (AmpAmScanner *scanner, AnjutaToken *name)
+{
+ GFile *file;
+ AnjutaTokenFile *include;
+ AnjutaToken *token;
+ gchar *filename;
+
+ filename = anjuta_token_evaluate (name);
+ g_message ("read include =%s=", filename);
+ file = g_file_resolve_relative_path (anjuta_token_stream_get_current_directory (scanner->stream), filename);
+ g_free (filename);
+ include = anjuta_token_file_new (file);
+ token = anjuta_token_file_load (include, NULL);
+ g_message ("read file =%s= arg %p", g_file_get_path (file), token);
+ amp_am_scanner_parse_token (scanner, token, file, NULL);
+ g_object_unref (file);
+}
+
/* Public functions
*---------------------------------------------------------------------------*/
AnjutaToken *
-amp_am_scanner_parse_token (AmpAmScanner *scanner, AnjutaToken *token, GError **error)
+amp_am_scanner_parse_token (AmpAmScanner *scanner, AnjutaToken *token, GFile *filename, GError **error)
{
AnjutaToken *first;
AnjutaTokenStream *stream;
- stream = anjuta_token_stream_push (scanner->stream, token);
+ stream = anjuta_token_stream_push (scanner->stream, token, filename);
first = anjuta_token_stream_get_root (stream);
if (scanner->stream != NULL)
diff --git a/plugins/am-project/tests/Makefile.am b/plugins/am-project/tests/Makefile.am
index ad26852..35f0c8d 100644
--- a/plugins/am-project/tests/Makefile.am
+++ b/plugins/am-project/tests/Makefile.am
@@ -21,7 +21,8 @@ TESTSUITE_AT = \
$(srcdir)/target.at \
$(srcdir)/source.at \
$(srcdir)/parser.at \
- $(srcdir)/acinit.at
+ $(srcdir)/acinit.at \
+ $(srcdir)/include.at
TESTSUITE = $(srcdir)/testsuite
diff --git a/plugins/am-project/tests/anjuta.lst b/plugins/am-project/tests/anjuta.lst
index 7b83393..f742a19 100644
--- a/plugins/am-project/tests/anjuta.lst
+++ b/plugins/am-project/tests/anjuta.lst
@@ -1676,9 +1676,6 @@
SOURCE (0:6:4:7): src/action-callbacks.h
SOURCE (0:6:4:8): src/action-callbacks.c
SOURCE (0:6:4:9): src/main.c
- TARGET (0:6:5): anjuta-shell
- SOURCE (0:6:5:0): src/shell.c
- SOURCE (0:6:5:1): src/shell.h
GROUP (0:7): manuals
GROUP (0:7:0): reference
GROUP (0:7:0:0): libanjuta
diff --git a/plugins/am-project/tests/include.at b/plugins/am-project/tests/include.at
new file mode 100644
index 0000000..7c94b65
--- /dev/null
+++ b/plugins/am-project/tests/include.at
@@ -0,0 +1,22 @@
+AT_SETUP([Include in GNUMakefile.am])
+AS_MKDIR_P([include])
+AT_DATA([include/configure.ac],
+[[AC_CONFIG_FILES(GNUmakefile)
+]])
+AT_DATA([include/GNUmakefile.am],
+[[
+include module/target.am
+]])
+AS_MKDIR_P([include/module])
+AT_DATA([include/module/target.am],
+[[
+bin_PROGRAMS = target1
+]])
+AT_DATA([expect],
+[[ GROUP (0): include
+ TARGET (0:0): target1
+]])
+AT_PARSER_CHECK([load include \
+ list])
+AT_CHECK([diff -b output expect])
+AT_CLEANUP
diff --git a/plugins/am-project/tests/testsuite.at b/plugins/am-project/tests/testsuite.at
index ce1d5fc..973bf63 100644
--- a/plugins/am-project/tests/testsuite.at
+++ b/plugins/am-project/tests/testsuite.at
@@ -5,3 +5,4 @@ m4_include([target.at])
m4_include([source.at])
m4_include([parser.at])
m4_include([acinit.at])
+m4_include([include.at])
diff --git a/plugins/mk-project/mk-scanner.l b/plugins/mk-project/mk-scanner.l
index 03ff3d3..37ec054 100644
--- a/plugins/mk-project/mk-scanner.l
+++ b/plugins/mk-project/mk-scanner.l
@@ -233,7 +233,7 @@ mkp_scanner_parse_token (MkpScanner *scanner, AnjutaToken *token, GError **error
AnjutaToken *first;
AnjutaTokenStream *stream;
- stream = anjuta_token_stream_push (scanner->stream, token);
+ stream = anjuta_token_stream_push (scanner->stream, token, NULL);
first = anjuta_token_stream_get_root (stream);
if (scanner->stream != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]