-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba1bf66
commit e73134b
Showing
14 changed files
with
195 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ _release | |
*.install | ||
images/diff.png | ||
test/test-images/_*.png | ||
|
||
vcpkg_installed/* | ||
_opam/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
open Odiff.Diff | ||
(* open Odiff.Diff *) | ||
|
||
let printDiffResult makeParsableOutput result = | ||
(match (result, makeParsableOutput) with | ||
| Layout, true -> "" | ||
| Layout, false -> | ||
Pastel.createElement | ||
~children: | ||
[ | ||
(Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ] | ||
() [@JSX]); | ||
" Images have different layout.\n"; | ||
] | ||
() [@JSX] | ||
| Pixel (_output, diffCount, _percentage, _lines), true when diffCount == 0 -> | ||
"" | ||
| Pixel (_output, diffCount, _percentage, _lines), false when diffCount == 0 | ||
-> | ||
Pastel.createElement | ||
~children: | ||
[ | ||
(Pastel.createElement ~color:Green ~bold:true | ||
~children:[ "Success!" ] () [@JSX]); | ||
" Images are equal.\n"; | ||
(Pastel.createElement ~dim:true | ||
~children:[ "No diff output created." ] | ||
() [@JSX]); | ||
] | ||
() [@JSX] | ||
| Pixel (_output, diffCount, diffPercentage, stack), true | ||
when not (Stack.is_empty stack) -> | ||
Int.to_string diffCount ^ ";" | ||
^ Float.to_string diffPercentage | ||
^ ";" | ||
^ (stack | ||
|> Stack.fold (fun acc line -> (line |> Int.to_string) ^ "," ^ acc) "") | ||
| Pixel (_output, diffCount, diffPercentage, _), true -> | ||
Int.to_string diffCount ^ ";" ^ Float.to_string diffPercentage | ||
| Pixel (_output, diffCount, diffPercentage, _lines), false -> | ||
Pastel.createElement | ||
~children: | ||
[ | ||
(Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ] | ||
() [@JSX]); | ||
" Images are different.\n"; | ||
"Different pixels: "; | ||
(Pastel.createElement ~color:Red ~bold:true | ||
~children:[ Printf.sprintf "%i (%f%%)" diffCount diffPercentage ] | ||
() [@JSX]); | ||
] | ||
() [@JSX]) | ||
|> Console.log; | ||
(* (match (result, makeParsableOutput) with *) | ||
(* | Layout, true -> "" *) | ||
(* | Layout, false -> *) | ||
(* Pastel.createElement *) | ||
(* ~children: *) | ||
(* [ *) | ||
(* (Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ] *) | ||
(* () [@JSX]); *) | ||
(* " Images have different layout.\n"; *) | ||
(* ] *) | ||
(* () [@JSX] *) | ||
(* | Pixel (_output, diffCount, _percentage, _lines), true when diffCount == 0 -> *) | ||
(* "" *) | ||
(* | Pixel (_output, diffCount, _percentage, _lines), false when diffCount == 0 *) | ||
(* -> *) | ||
(* Pastel.createElement *) | ||
(* ~children: *) | ||
(* [ *) | ||
(* (Pastel.createElement ~color:Green ~bold:true *) | ||
(* ~children:[ "Success!" ] () [@JSX]); *) | ||
(* " Images are equal.\n"; *) | ||
(* (Pastel.createElement ~dim:true *) | ||
(* ~children:[ "No diff output created." ] *) | ||
(* () [@JSX]); *) | ||
(* ] *) | ||
(* () [@JSX] *) | ||
(* | Pixel (_output, diffCount, diffPercentage, stack), true *) | ||
(* when not (Stack.is_empty stack) -> *) | ||
(* Int.to_string diffCount ^ ";" *) | ||
(* ^ Float.to_string diffPercentage *) | ||
(* ^ ";" *) | ||
(* ^ (stack *) | ||
(* |> Stack.fold (fun acc line -> (line |> Int.to_string) ^ "," ^ acc) "") *) | ||
(* | Pixel (_output, diffCount, diffPercentage, _), true -> *) | ||
(* Int.to_string diffCount ^ ";" ^ Float.to_string diffPercentage *) | ||
(* | Pixel (_output, diffCount, diffPercentage, _lines), false -> *) | ||
(* Pastel.createElement *) | ||
(* ~children: *) | ||
(* [ *) | ||
(* (Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ] *) | ||
(* () [@JSX]); *) | ||
(* " Images are different.\n"; *) | ||
(* "Different pixels: "; *) | ||
(* (Pastel.createElement ~color:Red ~bold:true *) | ||
(* ~children:[ Printf.sprintf "%i (%f%%)" diffCount diffPercentage ] *) | ||
(* () [@JSX]); *) | ||
(* ] *) | ||
(* () [@JSX]) *) | ||
(* |> Console.log; *) | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,106 @@ | ||
module C = Configurator.V1 | ||
|
||
let _ = | ||
C.main ~name:"odiff-c-lib-package-resolver" (fun _c -> | ||
let spng_include_path = Sys.getenv "SPNG_INCLUDE_PATH" |> String.trim in | ||
let spng_lib_path = Sys.getenv "SPNG_LIB_PATH" |> String.trim in | ||
let libspng = spng_lib_path ^ "/libspng_static.a" in | ||
let jpeg_include_path = Sys.getenv "JPEG_INCLUDE_PATH" |> String.trim in | ||
let jpeg_lib_path = Sys.getenv "JPEG_LIB_PATH" |> String.trim in | ||
let libjpeg = jpeg_lib_path ^ "/libjpeg.a" in | ||
let tiff_include_path = Sys.getenv "TIFF_INCLUDE_PATH" |> String.trim in | ||
let tiff_lib_path = Sys.getenv "TIFF_LIB_PATH" |> String.trim in | ||
let libtiff = tiff_lib_path ^ "/libtiff.a" in | ||
let z_lib_path = Sys.getenv "Z_LIB_PATH" |> String.trim in | ||
let zlib = z_lib_path ^ "/libz.a" in | ||
C.Flags.write_sexp "png_write_c_flags.sexp" [ "-I" ^ spng_include_path ]; | ||
C.Flags.write_sexp "png_write_c_library_flags.sexp" [ libspng; zlib ]; | ||
C.Flags.write_sexp "png_write_flags.sexp" [ "-cclib"; libspng ]; | ||
C.Flags.write_sexp "png_c_flags.sexp" [ "-I" ^ spng_include_path ]; | ||
C.Flags.write_sexp "png_c_library_flags.sexp" [ libspng; zlib ]; | ||
C.Flags.write_sexp "png_flags.sexp" [ "-cclib"; libspng ]; | ||
C.Flags.write_sexp "jpg_c_flags.sexp" [ "-I" ^ jpeg_include_path ]; | ||
C.Flags.write_sexp "jpg_c_library_flags.sexp" [ libjpeg ]; | ||
C.Flags.write_sexp "jpg_flags.sexp" [ "-cclib"; libjpeg ]; | ||
C.Flags.write_sexp "tiff_c_flags.sexp" [ "-I" ^ tiff_include_path ]; | ||
C.Flags.write_sexp "tiff_c_library_flags.sexp" [ libtiff; zlib ]; | ||
C.Flags.write_sexp "tiff_flags.sexp" [ "-cclib"; libtiff ]) | ||
exception Pkg_Config_Resolution_Failed of string | ||
|
||
type pkg_config_result = { cflags : string; libs : string } | ||
type process_result = { exit_code : int; stdout : string; stderr : string } | ||
|
||
let run_process ~env prog args = | ||
let stdout_fn = Filename.temp_file "stdout" ".tmp" in | ||
let stderr_fn = Filename.temp_file "stderr" ".tmp" in | ||
let openfile f = | ||
Unix.openfile f | ||
[ Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC; Unix.O_SHARE_DELETE ] | ||
0o666 | ||
in | ||
let stdout = openfile stdout_fn in | ||
let stderr = openfile stderr_fn in | ||
let stdin, stdin_w = Unix.pipe () in | ||
Unix.close stdin_w; | ||
|
||
let pid = | ||
match env with | ||
| [] -> | ||
Unix.create_process prog | ||
(Array.of_list (prog :: args)) | ||
stdin stdout stderr | ||
| _ -> | ||
let env_array = Array.of_list env in | ||
Unix.create_process_env prog | ||
(Array.of_list (prog :: args)) | ||
env_array stdin stdout stderr | ||
in | ||
|
||
Unix.close stdin; | ||
Unix.close stdout; | ||
Unix.close stderr; | ||
|
||
let _, status = Unix.waitpid [] pid in | ||
|
||
let read_file filename = | ||
let ic = open_in filename in | ||
let n = in_channel_length ic in | ||
let s = really_input_string ic n in | ||
close_in ic; | ||
s | ||
in | ||
|
||
let stdout_content = read_file stdout_fn in | ||
let stderr_content = read_file stderr_fn in | ||
|
||
Sys.remove stdout_fn; | ||
Sys.remove stderr_fn; | ||
|
||
let exit_code = | ||
match status with | ||
| Unix.WEXITED code -> code | ||
| Unix.WSIGNALED signal -> | ||
raise | ||
(Pkg_Config_Resolution_Failed | ||
(Printf.sprintf "Process killed by signal %d" signal)) | ||
| Unix.WSTOPPED signal -> | ||
raise | ||
(Pkg_Config_Resolution_Failed | ||
(Printf.sprintf "Process stopped by signal %d" signal)) | ||
in | ||
|
||
{ exit_code; stdout = stdout_content; stderr = stderr_content } | ||
|
||
let run_pkg_config _c lib = | ||
let pkg_config_path = Sys.getenv_opt "PKG_CONFIG_PATH" in | ||
let env = | ||
match pkg_config_path with | ||
| Some path -> [ "PKG_CONFIG_PATH=" ^ path ] | ||
| None -> [] | ||
in | ||
|
||
let c_flags_result = run_process ~env "pkg-config" [ "--cflags"; lib ] in | ||
let libs_result = run_process ~env "pkg-config" [ "--libs"; lib ] in | ||
|
||
if c_flags_result.exit_code = 0 && libs_result.exit_code == 0 then | ||
{ cflags = c_flags_result.stdout; libs = libs_result.stdout } | ||
else | ||
let std_errors = | ||
String.concat "\n" [ c_flags_result.stderr; libs_result.stderr ] | ||
in | ||
|
||
raise (Pkg_Config_Resolution_Failed std_errors) | ||
|
||
let () = | ||
C.main ~name:"odiff-c-lib-packae-resolver" (fun c -> | ||
let png_config = run_pkg_config c "libspng_static" in | ||
let tiff_config = run_pkg_config c "libtiff-4" in | ||
let jpeg_config = run_pkg_config c "libturbojpeg" in | ||
|
||
C.Flags.write_sexp "png_c_flags.sexp" [ png_config.cflags ]; | ||
C.Flags.write_sexp "png_c_library_flags.sexp" [ png_config.libs ]; | ||
C.Flags.write_sexp "png_write_c_flags.sexp" [ png_config.cflags ]; | ||
C.Flags.write_sexp "png_write_c_library_flags.sexp" [ png_config.libs ]; | ||
C.Flags.write_sexp "png_write_flags.sexp" [ "-cclib"; png_config.libs ]; | ||
C.Flags.write_sexp "png_c_flags.sexp" [ png_config.cflags ]; | ||
C.Flags.write_sexp "jpg_c_flags.sexp" [ jpeg_config.cflags ]; | ||
C.Flags.write_sexp "jpg_c_library_flags.sexp" [ jpeg_config.libs ]; | ||
C.Flags.write_sexp "jpg_flags.sexp" [ "-cclib"; jpeg_config.libs ]; | ||
C.Flags.write_sexp "tiff_c_flags.sexp" [ tiff_config.cflags ]; | ||
C.Flags.write_sexp "tiff_c_library_flags.sexp" [ tiff_config.libs ]; | ||
C.Flags.write_sexp "tiff_flags.sexp" [ "-cclib"; tiff_config.libs ]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
(executable | ||
(name discover) | ||
(ocamlc_flags str.cma) | ||
(ocamlopt_flags str.cmxa) | ||
(libraries dune-configurator)) |
Oops, something went wrong.