xref: /haiku/src/apps/haikudepot/build/jam/HdsSchemaGenRules (revision 5ffbe7d778424c9c59f00b37a3baff5c4c648790)
1# =====================================
2# Copyright 2019, Andrew Lindesay
3# Distributed under the terms of the MIT License.
4# =====================================
5
6# HaikuDepotServer has a number of data-transfer-objects (DTO) that are defined
7# by JSON schemas.  The server uses these schemas to produce the objects at
8# compile time.  Likewise, the schema files also generate C++ side DTO model
9# objects in the form of .cpp and .h files as well.  This way the
10# HaikuDepotServer server and HaikuDepot desktop application are able to
11# communicate more 'safely'.  The schema files still need to be copied from
12# the server source to the Haiku source, but the generation process will ensure
13# that the data-structures are consistent.
14#
15# The C++ side classes are generated with python scripts that are included in
16# the Haiku source.  These rules and actions take care of making sure that the
17# python scripts are run when necessary to generate the C++ side classes.  Note
18# that there are two sorts of classes generated here; the model DTO objects and
19# also the supporting classes that parse the DTO objects.  The parsing classes
20# are intended to be used with Haiku JSON parsing systems.
21
22# pragma mark - Generic
23
24actions HdsSchemaGenTouch
25{
26	touch $(1)
27}
28
29# pragma mark - Model Class Generation
30
31# 1 : the dummy file in the class generation directory (target)
32# 2 : the JSON schema file
33# 3 : the Python script to use
34
35rule HdsSchemaGenModel
36{
37	SEARCH on $(2) = [ FDirName $(SUBDIR) server schema ] ;
38	SEARCH on $(3) = [ FDirName $(SUBDIR) build scripts ] ;
39
40	Clean $(1:D) ;
41	Depends $(1) : $(2) $(3) ;
42	HdsSchemaGenModel1 $(1) : $(2) $(3) $(1:D) ;
43}
44
45actions HdsSchemaGenModel1
46{
47	mkdir -p $(2[3])
48	$(HOST_PYTHON) $(2[2]) -i $(2[1]) --outputdirectory $(2[3])
49	touch $(1)
50}
51
52# pragma mark - Bulk Parsing Class Generation
53
54# 1 : the dummy file in the class generation directory (target)
55# 2 : the JSON schema file
56# 3 : the Python script to use
57
58rule HdsSchemaGenBulkParser
59{
60	SEARCH on $(2) = [ FDirName $(SUBDIR) server schema ] ;
61	SEARCH on $(3) = [ FDirName $(SUBDIR) build scripts ] ;
62
63	Clean $(1:D) ;
64	Depends $(1) : $(2) $(3) ;
65	HdsSchemaGenBulkParser1 $(1) : $(2) $(3) $(1:D) ;
66}
67
68actions HdsSchemaGenBulkParser1
69{
70	mkdir -p $(2[3])
71	$(HOST_PYTHON) $(2[2]) -i $(2[1]) --outputdirectory $(2[3]) --supportbulkcontainer
72	touch $(1)
73}
74
75# pragma mark - Registering Generated Classes
76
77# Because a number of .cpp and .h files will be generated from a single python
78# script's run, it is necessary to introduce a dependency between the known
79# output files and the target for a given python script run.
80
81# 1 : generated files (.h and .cpp)
82# 2 : target that will generate the generated files (dummy file)
83
84rule HdsSchemaGenAppSrcDependsOnGeneration {
85	local generatedSource ;
86	local applicationSource ;
87
88	MakeLocate $(1) : $(2:D) ;
89	Depends $(1) : $(2) ;
90	Clean $(1) ;
91
92	# just in case the dummy file ends up being newer than the generated
93	# sources, update the modified timestamp on the generated files.
94	HdsSchemaGenTouch $(1) ;
95}