| author | |
| committer | |
| log | 2879b10fd69a71ecb33700ff0177f73848d43fe3 |
| tree | 537b667c9c7faf204d9b284e6d0b52545cac025c |
| parent | c960a0ca49fe83a32b078b02594df799da908341 |
4 files changed, 91 insertions(+), 2 deletions(-)
README.md+1| ... | ... | @@ -102,6 +102,7 @@ dependencies: |
| 102 | 102 | | `c_include_dirs` | `[]string` | | A list of relative paths to directories with `.h` files | |
| 103 | 103 | | `c_source_flags` | `[]string` | | A list of clang flags to pass to each of the `.c` files in `c_source_files` | |
| 104 | 104 | | `c_source_files` | `[]string` | | A list of relative paths to `.c` files to compile along with project | |
| 105 | | `license` | `string` | | A SPDX License Identifier specifying the license covering the code in this package. | | |
| 105 | 106 | | `dependencies` | `[]Dep` | | An array of dependency objects | |
| 106 | 107 | |
| 107 | 108 | #### Dep object |
deps.zig+6| ... | ... | @@ -33,6 +33,7 @@ pub const _ids = .{ |
| 33 | 33 | "2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf", |
| 34 | 34 | "2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o", |
| 35 | 35 | "csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe", |
| 36 | "0npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r", | |
| 36 | 37 | }; |
| 37 | 38 | |
| 38 | 39 | pub const _paths = .{ |
| ... | ... | @@ -42,6 +43,7 @@ pub const _paths = .{ |
| 42 | 43 | "/v/git/github.com/ziglibs/known-folders/commit-f0f4188/", |
| 43 | 44 | "/v/git/github.com/Vexu/zuri/commit-0f9cec8/", |
| 44 | 45 | "/v/git/github.com/alexnask/iguanaTLS/commit-58f72f6/", |
| 46 | "/v/git/github.com/nektro/zig-licenses/commit-a15ef9b/", | |
| 45 | 47 | }; |
| 46 | 48 | |
| 47 | 49 | pub const package_data = struct { |
| ... | ... | @@ -49,6 +51,7 @@ pub const package_data = struct { |
| 49 | 51 | pub const _2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf = build.Pkg{ .name = "known-folders", .path = cache ++ "/v/git/github.com/ziglibs/known-folders/commit-f0f4188/known-folders.zig", .dependencies = &[_]build.Pkg{ } }; |
| 50 | 52 | pub const _2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o = build.Pkg{ .name = "zuri", .path = cache ++ "/v/git/github.com/Vexu/zuri/commit-0f9cec8/src/zuri.zig", .dependencies = &[_]build.Pkg{ } }; |
| 51 | 53 | pub const _csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe = build.Pkg{ .name = "iguanatls", .path = cache ++ "/v/git/github.com/alexnask/iguanaTLS/commit-58f72f6/src/main.zig", .dependencies = &[_]build.Pkg{ } }; |
| 54 | pub const _0npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r = build.Pkg{ .name = "licenses", .path = cache ++ "/v/git/github.com/nektro/zig-licenses/commit-a15ef9b/src/lib.zig", .dependencies = &[_]build.Pkg{ } }; | |
| 52 | 55 | }; |
| 53 | 56 | |
| 54 | 57 | pub const packages = &[_]build.Pkg{ |
| ... | ... | @@ -56,6 +59,7 @@ pub const packages = &[_]build.Pkg{ |
| 56 | 59 | package_data._2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf, |
| 57 | 60 | package_data._2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o, |
| 58 | 61 | package_data._csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe, |
| 62 | package_data._0npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r, | |
| 59 | 63 | }; |
| 60 | 64 | |
| 61 | 65 | pub const pkgs = struct { |
| ... | ... | @@ -63,6 +67,7 @@ pub const pkgs = struct { |
| 63 | 67 | pub const known_folders = packages[2]; |
| 64 | 68 | pub const zuri = packages[3]; |
| 65 | 69 | pub const iguanatls = packages[4]; |
| 70 | pub const licenses = packages[5]; | |
| 66 | 71 | }; |
| 67 | 72 | |
| 68 | 73 | pub const c_include_dirs = &[_][]const u8{ |
| ... | ... | @@ -76,6 +81,7 @@ pub const c_source_flags = struct { |
| 76 | 81 | pub const @"2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf" = &[_][]const u8{}; |
| 77 | 82 | pub const @"2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o" = &[_][]const u8{}; |
| 78 | 83 | pub const @"csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe" = &[_][]const u8{}; |
| 84 | pub const @"0npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r" = &[_][]const u8{}; | |
| 79 | 85 | }; |
| 80 | 86 | |
| 81 | 87 | pub const c_source_files = &[_][2][]const u8{ |
src/cmd/license.zig created+81| ... | ... | @@ -0,0 +1,81 @@ |
| 1 | const std = @import("std"); | |
| 2 | const gpa = std.heap.c_allocator; | |
| 3 | ||
| 4 | const u = @import("./../util/index.zig"); | |
| 5 | const common = @import("./../common.zig"); | |
| 6 | ||
| 7 | const ansi = @import("ansi"); | |
| 8 | const style = ansi.style; | |
| 9 | ||
| 10 | const licenses = @import("licenses"); | |
| 11 | ||
| 12 | const Module = u.Module; | |
| 13 | const List = std.ArrayList(u.Module); | |
| 14 | const Map = std.StringArrayHashMap(*List); | |
| 15 | ||
| 16 | // Inspired by: | |
| 17 | // https://github.com/onur/cargo-license | |
| 18 | ||
| 19 | pub fn execute(args: [][]u8) !void { | |
| 20 | // | |
| 21 | const dir = try std.fs.path.join(gpa, &[_][]const u8{".zigmod", "deps"}); | |
| 22 | ||
| 23 | const top_module = try common.collect_deps(dir, "zig.mod", .{ | |
| 24 | .log = false, | |
| 25 | .update = false, | |
| 26 | }); | |
| 27 | ||
| 28 | const master_list = &List.init(gpa); | |
| 29 | try common.collect_pkgs(top_module, master_list); | |
| 30 | ||
| 31 | const map = &Map.init(gpa); | |
| 32 | ||
| 33 | const unspecified_list = &List.init(gpa); | |
| 34 | ||
| 35 | for (master_list.items) |item| { | |
| 36 | if (item.yaml == null) continue; | |
| 37 | const license_code = item.yaml.?.get_string("license"); | |
| 38 | if (license_code.len == 0) { | |
| 39 | try unspecified_list.append(item); | |
| 40 | continue; | |
| 41 | } | |
| 42 | const map_item = try map.getOrPut(license_code); | |
| 43 | if (!map_item.found_existing) { | |
| 44 | const temp = try gpa.create(List); | |
| 45 | temp.* = List.init(gpa); | |
| 46 | map_item.entry.value = temp; | |
| 47 | } | |
| 48 | const tracking_list = map_item.entry.value; | |
| 49 | try tracking_list.append(item); | |
| 50 | } | |
| 51 | ||
| 52 | var iter = map.iterator(); | |
| 53 | while (iter.next()) |entry| { | |
| 54 | std.debug.print(style.Bold ++ "{s}:\n", .{entry.key}); | |
| 55 | if (get_license(entry.key)) |license| { | |
| 56 | std.debug.print(style.Faint ++ "= {s}\n", .{license.url}); | |
| 57 | } | |
| 58 | std.debug.print(style.ResetIntensity, .{}); | |
| 59 | for (entry.value.items) |item| { | |
| 60 | std.debug.print("- {s}\n", .{if (item.clean_path.len > 0) item.clean_path else "This"}); | |
| 61 | } | |
| 62 | std.debug.print("\n", .{}); | |
| 63 | } | |
| 64 | { | |
| 65 | std.debug.print(style.Bold ++ "Unspecified:\n", .{}); | |
| 66 | std.debug.print(style.ResetIntensity, .{}); | |
| 67 | for (unspecified_list.items) |item| { | |
| 68 | std.debug.print("- {s}\n", .{if (item.clean_path.len > 0) item.clean_path else "This"}); | |
| 69 | } | |
| 70 | } | |
| 71 | } | |
| 72 | ||
| 73 | fn get_license(name: []const u8) ?licenses.License { | |
| 74 | const T = licenses.spdx; | |
| 75 | inline for (std.meta.declarations(T)) |decl| { | |
| 76 | if (std.mem.eql(u8, decl.name, name)) { | |
| 77 | return @field(T, decl.name); | |
| 78 | } | |
| 79 | } | |
| 80 | return null; | |
| 81 | } |
zig.mod+3-2| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | id: 89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r |
| 2 | 2 | name: zigmod |
| 3 | 3 | main: src/main.zig |
| 4 | license: MIT | |
| 4 | 5 | dependencies: |
| 5 | 6 | - src: git https://github.com/yaml/libyaml |
| 6 | 7 | version: tag-0.2.5 |
| ... | ... | @@ -36,5 +37,5 @@ dependencies: |
| 36 | 37 | - src: git https://github.com/alexnask/iguanaTLS |
| 37 | 38 | version: commit-58f72f6 |
| 38 | 39 | |
| 39 | # - src: git https://github.com/nektro/zig-licenses | |
| 40 | # version: commit-a15ef9b | |
| 40 | - src: git https://github.com/nektro/zig-licenses | |
| 41 | version: commit-a15ef9b |