[build] remove c stubs and ctypes dependency

Summary:
We won't be needing to know the terminal size when we move the help to
manpages. Hopefully if we need C stubs again in the future we can refer back to
this diff to revive them.

Reviewed By: jberdine

Differential Revision: D4937491

fbshipit-source-id: 99139fa
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent 3325306c58
commit 6f264a30fa

1
.gitignore vendored

@ -106,7 +106,6 @@ buck-out/
/scripts/checkCopyright
/infer/etc/clang_ast.dict
/infer/src/toplevel.mlpack
/infer/src/ffi/gen/*.ml
#atdgen stubs
/infer/src/backend/jsonbug_*

@ -3,7 +3,6 @@ B _build/infer/**
PKG ANSITerminal
PKG atdgen
PKG core
PKG ctypes
PKG javalib
PKG oUnit
PKG ppx_compare

@ -16,7 +16,6 @@ BASE_BUILD_DIR = $(BUILD_DIR)/test
else
BASE_BUILD_DIR = $(BUILD_DIR)
endif
STUBS_BUILD_DIR = $(BASE_BUILD_DIR)/stubs
INFER_BUILD_DIR = $(BASE_BUILD_DIR)/infer
ATDGEN_SUFFIXES = _t.ml _t.mli _j.ml _j.mli
@ -38,10 +37,10 @@ OCAMLBUILD_OPTIONS = \
-cflags -strict-formats \
-cflags -strict-sequence \
-cflags -w,$(OCAML_FATAL_WARNINGS)-4-9-32-40-41-42-45-48 \
-tag-line "<*{clang/clang_ast_*,backend/jsonbug_*,checkers/stacktree_*,ffi/gen/*}>: warn(-27-32-34-35-39)" \
-tag-line "<*{clang/clang_ast_*,backend/jsonbug_*,checkers/stacktree_*}>: warn(-27-32-34-35-39)" \
-tag-line "<*/{,*/}*.{ml,re}{,i}>: package(ppx_compare)" \
-tag thread \
-pkgs ANSITerminal,atdgen,core,ctypes.stubs,extlib,oUnit,str,unix,xmlm,yojson,zip
-pkgs ANSITerminal,atdgen,core,extlib,oUnit,str,unix,xmlm,yojson,zip
ifeq ($(ENABLE_OCAML_BINANNOT),yes)
OCAMLBUILD_OPTIONS += -cflags -bin-annot
@ -132,16 +131,13 @@ EXTRA_DEPS = opensource
endif
DEPENDENCIES = \
IR backend base checkers eradicate ffi ffi/gen harness integration quandary bufferoverrun \
IR backend base checkers eradicate harness integration quandary bufferoverrun \
$(EXTRA_DEPS)
# ocamlbuild command with options common to all build targets
OCAMLBUILD_BASE = \
$(REBUILD) $(OCAMLBUILD_OPTIONS) -j $(NCPU) $(addprefix -I , $(DEPENDENCIES)) \
OCAMLBUILD_EXTRA_BYTE = -lflags -custom,$(INFER_BUILD_DIR)/ffi/gen/extern_stubs.o
OCAMLBUILD_EXTRA_NATIVE = -lflag $(INFER_BUILD_DIR)/ffi/gen/extern_stubs.o
# ocamlbuild with options necessary to build all targets at once, regardless of configure flags
OCAMLBUILD_ALL = $(OCAMLBUILD_BASE) $(JAVA_OCAMLBUILD_OPTIONS)
@ -190,42 +186,12 @@ export OCAMLFIND_IGNORE_DUPS_IN=$(shell $(OCAMLC) -where)/compiler-libs
.PHONY: all
all: infer
# witness that generators have been built
STUBS_HAVE_BEEN_BUILT = $(INFER_BUILD_DIR)/ffi/gen/generate_caml_types.c
# witness that generators have been run
STUBS_HAVE_RUN = ffi/gen/IOCtl_types.ml
# to make sure everything Cstubs-related has been done
STUBS_DEPS = $(STUBS_HAVE_RUN) $(INFER_BUILD_DIR)/ffi/gen/extern_stubs.o
$(STUBS_HAVE_BEEN_BUILT): $(wildcard ffi/*.ml) $(MAKEFILE_LIST)
$(MKDIR_P) $(BASE_BUILD_DIR) $(@D)
$(OCAMLBUILD_CONFIG) -build-dir $(STUBS_BUILD_DIR) \
ffi/GenerateML.native ffi/GenerateC.native ffi/GenerateCGenerator.native
$(STUBS_BUILD_DIR)/ffi/GenerateML.native > ffi/gen/ExternStubs.ml
$(STUBS_BUILD_DIR)/ffi/GenerateC.native > $(@D)/extern_stubs.c
$(STUBS_BUILD_DIR)/ffi/GenerateCGenerator.native > $(@D)/generate_caml_types.c
$(QUIET)touch $@
$(STUBS_HAVE_RUN): $(STUBS_HAVE_BEEN_BUILT) $(MAKEFILE_LIST)
# create .o file using the right flags, which ocamlfind knows about
cd $(INFER_BUILD_DIR)/$(@D) && \
$(OCAMLFIND) ocamlc -package ctypes.stubs generate_caml_types.c
# link the executable by calling CC directly (no idea how to do it with ocaml*)
cd $(INFER_BUILD_DIR)/$(@D) && \
$(CC) generate_caml_types.o -o generate_caml_types
$(INFER_BUILD_DIR)/$(@D)/generate_caml_types > $@
$(QUIET)touch $@
$(INFER_BUILD_DIR)/ffi/gen/extern_stubs.o: $(STUBS_HAVE_BEEN_BUILT)
cd $(@D) && $(OCAMLFIND) ocamlc -package ctypes.stubs extern_stubs.c
$(QUIET)touch $@
# single out infer.native as the source of truth for make, knowing that in fact several targets are
# produced by the build
$(INFER_BUILD_DIR)/$(INFER_MAIN).native: base/Version.ml $(OCAML_CONFIG_SOURCES) \
$(STUBS_DEPS) $(MAKEFILE_LIST)
$(MAKEFILE_LIST)
$(MKDIR_P) $(BASE_BUILD_DIR)
$(OCAMLBUILD_CONFIG) -build-dir $(INFER_BUILD_DIR) $(OCAMLBUILD_EXTRA_NATIVE) \
$(OCAMLBUILD_CONFIG) -build-dir $(INFER_BUILD_DIR) \
$(INFER_CONFIG_TARGETS)
# let make know that the target is up-to-date even if ocamlbuild cached it
$(QUIET)touch $@
@ -251,9 +217,9 @@ ifeq ($(BUILD_C_ANALYZERS),yes)
infer: $(CLANG_BINIOU_DICT)
endif
$(INFER_BUILD_DIR)/$(INFER_MAIN).byte: base/Version.ml $(STUBS_DEPS) $(OCAML_CONFIG_SOURCES)
$(INFER_BUILD_DIR)/$(INFER_MAIN).byte: base/Version.ml $(OCAML_CONFIG_SOURCES)
$(MKDIR_P) $(BASE_BUILD_DIR)
$(OCAMLBUILD_CONFIG) -build-dir $(INFER_BUILD_DIR) $(OCAMLBUILD_EXTRA_BYTE) \
$(OCAMLBUILD_CONFIG) -build-dir $(INFER_BUILD_DIR) \
$(INFER_CONFIG_TARGETS:.native=.byte) $(INFERUNIT_MAIN).byte
$(QUIET)touch $@
@ -284,7 +250,7 @@ MFLAGS=
.PHONY: module
module: base/Version.ml $(OCAML_ALL_SOURCES)
$(MKDIR_P) $(BASE_BUILD_DIR)
$(OCAMLBUILD_ALL) -build-dir $(INFER_BUILD_DIR) $(OCAMLBUILD_EXTRA_BYTE) \
$(OCAMLBUILD_ALL) -build-dir $(INFER_BUILD_DIR) \
$(MFLAGS) \
$(M)
@ -333,7 +299,7 @@ $(shell \
| awk 'BEGIN { FS = "/"; OFS = "/" } ; {$$NF=toupper(substr($$NF,1,1))substr($$NF,2); print $$0}')
endef
toplevel.mlpack: base/Version.ml $(STUBS_DEPS) $(OCAML_CONFIG_SOURCES) $(MAKEFILE_LIST)
toplevel.mlpack: base/Version.ml $(OCAML_CONFIG_SOURCES) $(MAKEFILE_LIST)
# We need to pack all the infer modules into another module to avoid name clashes with some
# of them coming from ocaml libraries (Ident for example). To do that, we generate a .mlpack
# file containing namespaced modules.
@ -345,16 +311,14 @@ toplevel.mlpack: base/Version.ml $(STUBS_DEPS) $(OCAML_CONFIG_SOURCES) $(MAKEFIL
$(foreach module,\
$(filter-out $(foreach root,$(roots),%/$(root)),\
$(foreach source,\
$(filter-out unit/% ffi/%,$(OCAML_CONFIG_SOURCES)),\
$(filter-out unit/%,$(OCAML_CONFIG_SOURCES)),\
$(call to_ocaml_module,$(source)))),\
$(shell echo $(module) >> $($@_tmp)))
mv $($@_tmp) $@
$(INFER_BUILD_DIR)/toplevel.cmo: toplevel.mlpack
$(MKDIR_P) $(BASE_BUILD_DIR)
$(OCAMLBUILD_CONFIG) -build-dir $(INFER_BUILD_DIR) $(OCAMLBUILD_EXTRA_BYTE) toplevel.cmo
cd $(INFER_BUILD_DIR)/ffi/gen && \
ocamlmklib -o externstubslib ExternStubs.cmo extern_stubs.o
$(OCAMLBUILD_CONFIG) -build-dir $(INFER_BUILD_DIR) toplevel.cmo
$(QUIET)touch $@
.PHONY: toplevel
@ -451,4 +415,3 @@ clean:
$(REMOVE) $(INFER_CLANG_FCP_MIRRORED_FILES)
$(REMOVE) mod_dep.dot
$(REMOVE) mod_dep.pdf
$(REMOVE) ffi/gen/*

@ -37,19 +37,6 @@ let warnf =
else if not is_originator then fun fmt -> F.ifprintf F.err_formatter fmt
else F.eprintf
let terminal_width = lazy (
let open Ctypes in
let module T = IOCtl.Types(IOCtl_types) in
let winsize = make IOCtl.winsize in
let return =
ExternStubs.ioctl_stub_1_ioctl 0 T.Request.request_TIOCGWINSZ
(ExternStubs.CI.cptr (addr winsize)) in
if return >= 0 then
Ok (Unsigned.UShort.to_int (getf winsize IOCtl.ws_col))
else
Error return
)
(** This is the subset of Arg.spec that we actually use. What's important is that all these specs
call back functions. We use this to mark deprecated arguments. What's not important is that, eg,
Arg.Float is missing. *)
@ -215,10 +202,7 @@ let pad_and_xform doc_width left_width desc =
let align desc_list =
let min_term_width = 80 in
let cur_term_width =
match Lazy.force terminal_width with
| Ok width -> width
| Error _ -> min_term_width in
let terminal_width = min_term_width in
(* 2 blank columns before option + 2 columns of gap between flag and doc *)
let extra_space = 4 in
let min_left_width = 15 in
@ -234,11 +218,11 @@ let align desc_list =
let opt_left_width =
List.fold ~f:(max_left_length max_left_width) ~init:0 desc_list in
let (--) a b = float_of_int a -. float_of_int b in
let multiplier = (max_left_width -- min_left_width) /. (max_term_width -- min_term_width) in
let multiplier = (max_left_width -- min_left_width) /. (max_term_width -- terminal_width) in
(* at 80 columns use min_left_width then use extra columns until opt_left_width *)
let cols_after_min_width = float_of_int (max 0 (cur_term_width - min_term_width)) in
let cols_after_min_width = float_of_int (max 0 (terminal_width - min_term_width)) in
min (int_of_float (cols_after_min_width *. multiplier) + min_left_width) opt_left_width in
let doc_width = min max_doc_width (doc_width cur_term_width left_width) in
let doc_width = min max_doc_width (doc_width terminal_width left_width) in
(List.map ~f:(pad_and_xform doc_width left_width) desc_list, (doc_width, left_width))

@ -1,34 +0,0 @@
(*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
open! IStd
open Ctypes
type winsize
(* as found in asm-generic/termios.h *)
let winsize : winsize structure typ = structure "winsize"
let ws_row = field winsize "ws_row" ushort
let ws_col = field winsize "ws_col" ushort
let ws_xpixel = field winsize "ws_xpixel" ushort
let ws_ypixel = field winsize "ws_ypixel" ushort
let () = seal winsize
module Types (F: Cstubs.Types.TYPE) = struct
module Request = struct
let request_TIOCGWINSZ = F.constant "TIOCGWINSZ" F.ulong
end
end
module Bindings (F : Cstubs.FOREIGN) = struct
let (@->) = F.(@->) (* shadow Ctypes' operator *)
(* ioctl(2) is a variadic function, so cross our fingers that the calling convention works the
same as non-variadic functions and define different ioctl_* functions for each need *)
let ioctl_winsize = F.foreign "ioctl" (int @-> ulong @-> ptr winsize @-> F.returning int)
end

@ -1,32 +0,0 @@
(*
* Copyright (c) 2016 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
(** bindings to ioctl(2) that only capture what we need *)
open! IStd
open Ctypes
type winsize
val winsize : winsize structure typ
val ws_col : (Unsigned.ushort, winsize structure) field
val ws_row : (Unsigned.ushort, winsize structure) field
val ws_xpixel : (Unsigned.ushort, winsize structure) field
val ws_ypixel : (Unsigned.ushort, winsize structure) field
module Types : functor (F : Cstubs.Types.TYPE) -> sig
module Request : sig val request_TIOCGWINSZ : Unsigned.ulong F.const end
end
module Bindings : functor (F : Cstubs.FOREIGN) -> sig
val ioctl_winsize :
(int ->
Unsigned.ulong -> winsize structure Ctypes_static.ptr -> int F.return)
F.result
end

@ -1,11 +0,0 @@
(*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
let () =
print_endline "#include <sys/ioctl.h>";
Cstubs.write_c Format.std_formatter ~prefix:GenerateUtils.prefix (module IOCtl.Bindings)

@ -1,11 +0,0 @@
(*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
let () =
print_endline "#include <sys/ioctl.h>";
Cstubs.Types.write_c Format.std_formatter (module IOCtl.Types)

@ -1,10 +0,0 @@
(*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
let () =
Cstubs.write_ml Format.std_formatter ~prefix:GenerateUtils.prefix (module IOCtl.Bindings)

@ -1,12 +0,0 @@
(*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
(* Utility module common for other Generate* modules. *)
let prefix = "ioctl_stub"

@ -1,12 +0,0 @@
(*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
(* Utility module common for other Generate* modules. *)
val prefix : string

@ -8,9 +8,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# precedence. Of course this cannot be perfect so caution is advised.
TOPLEVEL_INCLUDES=(
-I "$SCRIPT_DIR"/../infer/_build/infer
-I "$SCRIPT_DIR"/../infer/_build/infer/ffi/gen
-I "$SCRIPT_DIR"/../infer/_build/test/infer
-I "$SCRIPT_DIR"/../infer/_build/test/infer/ffi/gen
)
# to build new toplevel, run `make toplevel`

@ -10,6 +10,5 @@
#require "ANSITerminal";;
(* load infer code *)
#load "externstubslib.cma";;
#load_rec "toplevel.cmo";;
open Toplevel;;

Loading…
Cancel
Save