Skip to content

Commit

Permalink
- Extracted Piqi common library "piqilib" from Piqi tools.
Browse files Browse the repository at this point in the history
- Reorganized directory layout accordingly.
  • Loading branch information
alavrik committed Jan 17, 2011
1 parent 2e16c51 commit ef21722
Show file tree
Hide file tree
Showing 71 changed files with 610 additions and 427 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ include $(PIQI_ROOT)/make/Makefile.dirs
DIRS = \
camlp4 \
piqirun-ocaml \
piqicc piqic piqi \
piqicc piqic piqi-tools \


install:
-install -d $(PIQI_PREFIX)/bin
install piqi/piqi $(PIQI_PREFIX)/bin
install piqi-tools/piqi $(PIQI_PREFIX)/bin
install piqic/piqic $(PIQI_PREFIX)/bin


Expand Down
5 changes: 3 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ FILES
camlp4/ camlp4 extensions
piqicc/ Piqi compiler compiler
piqic/ Piq interface compiler for OCaml and Erlang
piqi/ "piqi" command-line utility (piqi tools)
piqi.org/ Piqi self-specifications
piqi-tools/ "piqi" command-line utility (piqi tools)
piqi.org/ Piqi self-specification
piqilib/ Piqi common library
piqirun-ocaml/ Piqi runtime library for OCaml
piqirun-erlang/ Piqi runtime library for Erlang
examples/ examples
Expand Down
2 changes: 1 addition & 1 deletion bin/piqi
3 changes: 2 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ test_complex:
./test_piqi_proto record-variant-list
./test_piq record-variant-list

ln -sf ../piqilib/piqobj.piqi .
./test_piqi piqobj

./test_piqi function
Expand All @@ -47,4 +48,4 @@ test_complex:


clean:
rm -f *.pb *.wire *.json *.proto* addressbook.*
rm -f *.pb *.wire *.json *.proto* addressbook.* piqobj.piqi
1 change: 0 additions & 1 deletion examples/piqobj.piqi

This file was deleted.

52 changes: 52 additions & 0 deletions piqi-tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
piqi
piqtype.*
piqobj.ml
descriptor.*
piqi_version.ml
piqi_json_parser.ml

piqi_c_impl.c
piqi_main.ml
piqi.ml
piq_parser.ml
piqi_common.ml
piqobj_to_piq.ml
piqi_c.mli
piqi_name.ml
piqi_file.ml
piqobj_common.ml
piqobj_of_wire.ml
piqloc.ml
piq_lexer.ml
piqi_config.ml
piq_gen.ml
piqobj_to_wire.ml
piqi_iolist.ml
piqi_wire.ml
piqobj_of_piq.ml
piqi_db.ml
piqi_c.ml
piqi_ext.ml
piqi_func.ml

# piqi lib

piqi-boot.piqi
piqi.piqi
piqi-impl.piqi

piqi_json_common.ml
piqi_json_parser.mll
piqi_json_gen.ml
piqi_json.ml

piqi_base64.ml
piqobj_to_json.ml
piqobj_of_json.ml

piqi_pp.ml
piq.ml

piqi_light.ml
piqi_getopt.ml

53 changes: 53 additions & 0 deletions piqi-tools/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
include $(PIQI_ROOT)/make/Makefile.ocaml
include $(PIQI_ROOT)/piqilib/Makefile.piqilib


RESULT = piqi

SOURCES += \
piqi_json_pp.ml \
\
piqi_pp_cmd.ml \
piqi_convert.ml \
piqi_check.ml \
piqi_expand.ml \
piqi_light_cmd.ml \
piqi_getopt_cmd.ml \
\
piqi_to_proto.ml \
\
descriptor.ml \
piqi_of_proto.ml \
\
piqi_run.ml \



PIQI_MODULES = descriptor.piqi
PIQI_ML_SOURCES = $(PIQI_MODULES:%.piqi=%.ml)


PRE_TARGETS += $(PIQI_SOURCES) $(PIQI_PIQI) $(PIQI_ML_SOURCES)


PIQIC = ../piqic/piqic
PIQIC_FLAGS = -I $(PIQI_ROOT)


#OCAMLBLDFLAGS = -custom


all: nc


debug: dc top


$(PIQI_ML_SOURCES): %.ml: %.piqi
$(PIQIC) ocaml $(PIQIC_FLAGS) --pp -o $@ $<


clean::


include $(OCAMLMAKEFILE)
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 1 addition & 55 deletions piqi/piqi_expand.ml → piqi-tools/piqi_expand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,6 @@ module C = Piqi_common
open C


let init_res_piqi orig_piqi =
let open P in
{
modname = orig_piqi.modname;
proto_package = orig_piqi.proto_package;
piqdef = [];
extend = [];
includ = [];
import = [];
func = [];

custom_field = [];

(* piqi-impl (implementation related) extensions *)
extended_piqdef = [];
resolved_piqdef = [];
imported_piqdef = [];
resolved_import = [];
resolved_func = [];
included_piqi = [];
original_piqi = None;
}


let expand_piqi ?(includes_only=false) piqi =
let open P in
let all_piqi = piqi.included_piqi in
let orig_piqi = some_of piqi.original_piqi in

(* create a new piqi module from the original piqi module *)
let res_piqi = init_res_piqi orig_piqi in

(* copy all imports to the resulting module *)
let imports = Piqi.get_imports all_piqi in
res_piqi.import <- imports;

(* copy all definitions to the resulting module *)
res_piqi.piqdef <-
if includes_only
then Piqi.get_piqdefs all_piqi
else piqi.extended_piqdef;

(* copy all extensions to the resulting module *)
res_piqi.extend <-
if includes_only
then Piqi.get_extensions all_piqi
else [];

(* copy all functions to the resulting module *)
res_piqi.func <- Piqi_ext.get_functions all_piqi;

res_piqi


module Main = Piqi_main
open Main

Expand All @@ -95,7 +41,7 @@ let speclist = Main.common_speclist @
let expand_file filename =
let ch = Main.open_output !ofile in
let piqi = Piqi.load_piqi filename in
let res_piqi = expand_piqi piqi ~includes_only:!flag_includes_only in
let res_piqi = Piqi_ext.expand_piqi piqi ~includes_only:!flag_includes_only in
Piqi_pp.prettyprint_piqi ch res_piqi


Expand Down
112 changes: 112 additions & 0 deletions piqi-tools/piqi_getopt_cmd.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
(*pp camlp4o -I $PIQI_ROOT/camlp4 pa_labelscope.cmo pa_openin.cmo *)
(*
Copyright 2009, 2010, 2011 Anton Lavrik
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)


(*
* Command-line element parsing, pretty-printing and converting to various
* output formats.
*)


module C = Piqi_common
open C


(* command-line arguments *)
let output_encoding = ref ""
let typename = ref ""


(* index of the "--" element in argv array *)
let argv_start_index = ref 0


module Main = Piqi_main
open Main


let validate_options () =
if !typename = "" (* pretty-print mode *)
then (
if !output_encoding <> ""
then piqi_error "option -t can not be used without --piqtype";
)


let getopt_command () =
validate_options ();
(* open output file *)
let och = Main.open_output !ofile in
(* interpret command-line arguments after "--" as Piq data *)
let piq_ast = Piqi_getopt.getopt_piq !argv_start_index in
match piq_ast with
| None -> () (* no data *)
| Some ast when !typename = "" ->
(* with no --piqtype parameter given, just pretty-print the Piq AST *)
Piqi_pp.prettyprint_ast och ast;
output_char och '\n'
| Some ast ->
let writer = Piqi_convert.make_writer !output_encoding in
let piqtype = Piqi_convert.find_piqtype !typename in
(* parse the Piq AST according to "--piqtype" and convert to the output
* format according to "-t" *)
Piqobj_of_piq.resolve_defaults := !Piqi_convert.flag_add_defaults;
Piqobj_of_piq.parse_words_as_strings := true;
let piqobj = Piqobj_of_piq.parse_obj piqtype ast in
(* write the object *)
writer och (Piq.Typed_piqobj piqobj)


(* find the position of the first argument after "--" *)
let rest_fun arg =
if !argv_start_index = 0 (* first argument after first occurence of "--" *)
then argv_start_index := !Arg.current + 1
else ()


let usage = "Usage: piqi getopt [options] -- [<data arguments>] \nOptions:"


let speclist = Main.common_speclist @
[
arg_o;

"-t", Arg.Set_string output_encoding,
"piq|wire|pb|json|piq-json output encoding (piq is used by default)";

"--piqtype", Arg.Set_string typename,
"<typename> type of the object represented by data arguments";

"--add-defaults", Arg.Set Piqi_convert.flag_add_defaults,
"add field default values while converting records";

"--", Arg.Rest rest_fun,
"separator between piqi command-line arguments and data arguments";
]


let run () =
Main.parse_args () ~speclist ~usage ~min_arg_count:0 ~max_arg_count:0;
if !argv_start_index = 0 (* "--" is not present in the list of arguments *)
then argv_start_index := Array.length Sys.argv;
getopt_command ()


let _ =
Main.register_command run "getopt"
"interpret command-line arguments as Piq data, pretty-print and convert to various encodings"

Loading

0 comments on commit ef21722

Please sign in to comment.