@@ -3,122 +3,114 @@ using JSON, BinaryBuilder, Test
3
3
import BinaryBuilder. BinaryBuilderBase: sourcify, dependencify, major, minor, patch, version
4
4
5
5
@testset " Meta JSON" begin
6
- mktempdir () do tmpdir
6
+ meta_json_buff = IOBuffer ()
7
+
8
+ # Run autobuild() a few times to generate a moderately complex `meta.json`:
9
+ dict = get_meta_json (
10
+ " libfoo" ,
11
+ v " 1.0.0" ,
12
+ [FileSource (" https://julialang.org" , " 123123" ), DirectorySource (" ./bundled" )],
13
+ " exit 1" ,
14
+ [Linux (:x86_64 )],
15
+ Product[LibraryProduct (" libfoo" , :libfoo ), FrameworkProduct (" fooFramework" , :libfooFramework )],
16
+ [Dependency (" Zlib_jll" )];
17
+ )
18
+ println (meta_json_buff, JSON. json (dict))
19
+
20
+ dict = get_meta_json (
21
+ " libfoo" ,
22
+ v " 1.0.0" ,
23
+ [GitSource (" https://github.com/JuliaLang/julia.git" , " 5d4eaca0c9fa3d555c79dbacdccb9169fdf64b65" )],
24
+ " exit 0" ,
25
+ [Linux (:x86_64 ), Windows (:x86_64 )],
26
+ Product[ExecutableProduct (" julia" , :julia ), LibraryProduct (" libfoo2" , :libfoo2 ; dlopen_flags= [:RTLD_GLOBAL ])],
27
+ Dependency[];
28
+ )
29
+ println (meta_json_buff, JSON. json (dict))
30
+
31
+ # Now, deserialize the info:
32
+ seek (meta_json_buff, 0 )
33
+
34
+ # Strip out ending newlines as that makes our while loop below sad
35
+ meta_json_buff = IOBuffer (strip (String (take! (meta_json_buff))))
36
+ objs = []
37
+ while ! eof (meta_json_buff)
38
+ push! (objs, JSON. parse (meta_json_buff))
39
+ end
40
+
41
+ # Ensure that we get two JSON objects
42
+ @test length (objs) == 2
43
+
44
+ # Merge them, then test that the merged object contains everything we expect
45
+ meta = BinaryBuilder. cleanup_merged_object! (BinaryBuilder. merge_json_objects (objs))
46
+
47
+ @test all (haskey .(Ref (meta), (" name" , " version" , " script" , " platforms" , " products" , " dependencies" )))
48
+ @test meta[" name" ] == " libfoo"
49
+ @test meta[" version" ] == v " 1.0.0"
50
+ @test Set (meta[" platforms" ]) == Set ([Linux (:x86_64 , libc= :glibc ), Windows (:x86_64 )])
51
+ @test length (meta[" sources" ]) == 3
52
+ @test all (in .(
53
+ (
54
+ FileSource (" https://julialang.org" , " 123123" ),
55
+ GitSource (" https://github.com/JuliaLang/julia.git" , " 5d4eaca0c9fa3d555c79dbacdccb9169fdf64b65" ),
56
+ DirectorySource (" ./bundled" ),
57
+ ), Ref (meta[" sources" ])))
58
+ @test sourcify (Dict (" type" => " directory" , " path" => " foo" )) == DirectorySource (" foo" )
59
+ @test sourcify (Dict (" type" => " git" , " url" => " https://github.com/JuliaLang/julia.git" , " hash" => " 12345" )) == GitSource (" https://github.com/JuliaLang/julia.git" , " 12345" )
60
+ @test sourcify (Dict (" type" => " file" , " url" => " https://julialang.org" , " hash" => " 98765" )) == FileSource (" https://julialang.org" , " 98765" )
61
+ @test_throws ErrorException sourcify (Dict (" type" => " qux" ))
62
+ # `PackageSpec(; name = "Foo") != PackageSpec(; name = "Foo")`, so we
63
+ # need to manually compare the fields we care about
64
+ d = dependencify (Dict (" type" => " dependency" , " name" => " Foo_jll" , " uuid" => nothing ,
65
+ " version-major" => 0 , " version-minor" => 0 , " version-patch" => 0 ))
66
+ ref_d = Dependency (PackageSpec (; name = " Foo_jll" ))
67
+ @test d. pkg. name == ref_d. pkg. name
68
+ @test d. pkg. uuid == ref_d. pkg. uuid
69
+ v = version (d)
70
+ ref_v = version (ref_d)
71
+ @test (major (v), minor (v), patch (v)) == (major (ref_v), minor (ref_v), patch (ref_v))
72
+ d = dependencify (Dict (" type" => " builddependency" , " name" => " Qux_jll" , " uuid" => nothing ,
73
+ " version-major" => 1 , " version-minor" => 2 , " version-patch" => 3 ))
74
+ ref_d = Dependency (PackageSpec (; name = " Qux_jll" , version = v " 1.2.3" ))
75
+ @test d. pkg. name == ref_d. pkg. name
76
+ @test d. pkg. uuid == ref_d. pkg. uuid
77
+ v = version (d)
78
+ ref_v = version (ref_d)
79
+ @test (major (v), minor (v), patch (v)) == (major (ref_v), minor (ref_v), patch (ref_v))
80
+ @test_throws ErrorException dependencify (Dict (" type" => " bar" ))
81
+ @test length (meta[" products" ]) == 4
82
+ @test all (in .((LibraryProduct (" libfoo" , :libfoo ), ExecutableProduct (" julia" , :julia ), LibraryProduct (" libfoo2" , :libfoo2 ; dlopen_flags= [:RTLD_GLOBAL ]), FrameworkProduct (" fooFramework" , :libfooFramework )), Ref (meta[" products" ])))
83
+ @test length (meta[" script" ]) == 2
84
+ @test all (in .((" exit 0" , " exit 1" ), Ref (meta[" script" ])))
85
+
86
+ @testset " AnyPlatform" begin
7
87
meta_json_buff = IOBuffer ()
8
- # Run autobuild() a few times to generate a moderately complex `meta.json`:
9
- build_output_meta = autobuild (
10
- tmpdir,
11
- " libfoo" ,
88
+ dict = get_meta_json (
89
+ " any_file" ,
12
90
v " 1.0.0" ,
13
- [ FileSource ( " https://julialang.org " , " 123123 " ), DirectorySource ( " ./bundled " ) ],
91
+ FileSource[ ],
14
92
" exit 1" ,
15
- [Linux (:x86_64 )],
16
- Product[LibraryProduct (" libfoo" , :libfoo ), FrameworkProduct (" fooFramework" , :libfooFramework )],
17
- [Dependency (" Zlib_jll" )];
18
- meta_json_stream= meta_json_buff,
93
+ [AnyPlatform ()],
94
+ Product[FileProduct (" file" , :file )],
95
+ BuildDependency[];
19
96
)
20
- @test build_output_meta == Dict ()
21
-
22
- build_output_meta = autobuild (
23
- tmpdir,
24
- " libfoo" ,
25
- v " 1.0.0" ,
26
- [GitSource (" https://github.com/JuliaLang/julia.git" , " 5d4eaca0c9fa3d555c79dbacdccb9169fdf64b65" )],
27
- " exit 0" ,
28
- [Linux (:x86_64 ), Windows (:x86_64 )],
29
- Product[ExecutableProduct (" julia" , :julia ), LibraryProduct (" libfoo2" , :libfoo2 ; dlopen_flags= [:RTLD_GLOBAL ])],
30
- Dependency[];
31
- meta_json_stream= meta_json_buff,
32
- )
33
- @test build_output_meta == Dict ()
34
-
35
- # Now, deserialize the info:
36
- seek (meta_json_buff, 0 )
97
+ println (meta_json_buff, JSON. json (dict))
37
98
99
+ # Deserialize the info:
100
+ seekstart (meta_json_buff)
38
101
# Strip out ending newlines as that makes our while loop below sad
39
102
meta_json_buff = IOBuffer (strip (String (take! (meta_json_buff))))
40
103
objs = []
41
104
while ! eof (meta_json_buff)
42
105
push! (objs, JSON. parse (meta_json_buff))
43
106
end
44
-
45
- # Ensure that we get two JSON objects
46
- @test length (objs) == 2
47
-
107
+ # Ensure that we get one JSON object
108
+ @test length (objs) == 1
109
+ # Platform-independent build: the JSON file doesn't have a "platforms" key
110
+ @test ! haskey (objs[ 1 ], " platforms " )
48
111
# Merge them, then test that the merged object contains everything we expect
49
112
meta = BinaryBuilder. cleanup_merged_object! (BinaryBuilder. merge_json_objects (objs))
50
-
51
- @test all (haskey .(Ref (meta), (" name" , " version" , " script" , " platforms" , " products" , " dependencies" )))
52
- @test meta[" name" ] == " libfoo"
53
- @test meta[" version" ] == v " 1.0.0"
54
- @test Set (meta[" platforms" ]) == Set ([Linux (:x86_64 , libc= :glibc ), Windows (:x86_64 )])
55
- @test length (meta[" sources" ]) == 3
56
- @test all (in .(
57
- (
58
- FileSource (" https://julialang.org" , " 123123" ),
59
- GitSource (" https://github.com/JuliaLang/julia.git" , " 5d4eaca0c9fa3d555c79dbacdccb9169fdf64b65" ),
60
- DirectorySource (" ./bundled" ),
61
- ), Ref (meta[" sources" ])))
62
- @test sourcify (Dict (" type" => " directory" , " path" => " foo" )) == DirectorySource (" foo" )
63
- @test sourcify (Dict (" type" => " git" , " url" => " https://github.com/JuliaLang/julia.git" , " hash" => " 12345" )) == GitSource (" https://github.com/JuliaLang/julia.git" , " 12345" )
64
- @test sourcify (Dict (" type" => " file" , " url" => " https://julialang.org" , " hash" => " 98765" )) == FileSource (" https://julialang.org" , " 98765" )
65
- @test_throws ErrorException sourcify (Dict (" type" => " qux" ))
66
- # `PackageSpec(; name = "Foo") != PackageSpec(; name = "Foo")`, so we
67
- # need to manually compare the fields we care about
68
- d = dependencify (Dict (" type" => " dependency" , " name" => " Foo_jll" , " uuid" => nothing ,
69
- " version-major" => 0 , " version-minor" => 0 , " version-patch" => 0 ))
70
- ref_d = Dependency (PackageSpec (; name = " Foo_jll" ))
71
- @test d. pkg. name == ref_d. pkg. name
72
- @test d. pkg. uuid == ref_d. pkg. uuid
73
- v = version (d)
74
- ref_v = version (ref_d)
75
- @test (major (v), minor (v), patch (v)) == (major (ref_v), minor (ref_v), patch (ref_v))
76
- d = dependencify (Dict (" type" => " builddependency" , " name" => " Qux_jll" , " uuid" => nothing ,
77
- " version-major" => 1 , " version-minor" => 2 , " version-patch" => 3 ))
78
- ref_d = Dependency (PackageSpec (; name = " Qux_jll" , version = v " 1.2.3" ))
79
- @test d. pkg. name == ref_d. pkg. name
80
- @test d. pkg. uuid == ref_d. pkg. uuid
81
- v = version (d)
82
- ref_v = version (ref_d)
83
- @test (major (v), minor (v), patch (v)) == (major (ref_v), minor (ref_v), patch (ref_v))
84
- @test_throws ErrorException dependencify (Dict (" type" => " bar" ))
85
- @test length (meta[" products" ]) == 4
86
- @test all (in .((LibraryProduct (" libfoo" , :libfoo ), ExecutableProduct (" julia" , :julia ), LibraryProduct (" libfoo2" , :libfoo2 ; dlopen_flags= [:RTLD_GLOBAL ]), FrameworkProduct (" fooFramework" , :libfooFramework )), Ref (meta[" products" ])))
87
- @test length (meta[" script" ]) == 2
88
- @test all (in .((" exit 0" , " exit 1" ), Ref (meta[" script" ])))
89
- end
90
-
91
- @testset " AnyPlatform" begin
92
- mktempdir () do tmpdir
93
- meta_json_buff = IOBuffer ()
94
- build_output_meta = autobuild (
95
- tmpdir,
96
- " any_file" ,
97
- v " 1.0.0" ,
98
- FileSource[],
99
- " exit 1" ,
100
- [AnyPlatform ()],
101
- Product[FileProduct (" file" , :file )],
102
- BuildDependency[];
103
- meta_json_stream= meta_json_buff,
104
- )
105
- @test build_output_meta == Dict ()
106
- # Deserialize the info:
107
- seekstart (meta_json_buff)
108
- # Strip out ending newlines as that makes our while loop below sad
109
- meta_json_buff = IOBuffer (strip (String (take! (meta_json_buff))))
110
- objs = []
111
- while ! eof (meta_json_buff)
112
- push! (objs, JSON. parse (meta_json_buff))
113
- end
114
- # Ensure that we get one JSON object
115
- @test length (objs) == 1
116
- # Platform-independent build: the JSON file doesn't have a "platforms" key
117
- @test ! haskey (objs[1 ], " platforms" )
118
- # Merge them, then test that the merged object contains everything we expect
119
- meta = BinaryBuilder. cleanup_merged_object! (BinaryBuilder. merge_json_objects (objs))
120
- # The "platforms" key comes back in the cleaned up object
121
- @test meta[" platforms" ] == [AnyPlatform ()]
122
- end
113
+ # The "platforms" key comes back in the cleaned up object
114
+ @test meta[" platforms" ] == [AnyPlatform ()]
123
115
end
124
116
end
0 commit comments