aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk
diff options
context:
space:
mode:
Diffstat (limited to 'infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk')
-rw-r--r--infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh2
-rw-r--r--infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/default.nix109
-rw-r--r--infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/frameworks.nix228
-rw-r--r--infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix17
-rw-r--r--infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c148
5 files changed, 374 insertions, 130 deletions
diff --git a/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh b/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh
index 86c241cd0f56..bbf9625e6557 100644
--- a/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh
+++ b/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh
@@ -3,7 +3,7 @@ linkSystemCoreFoundationFramework() {
# gross! many symbols (such as _OBJC_CLASS_$_NSArray) are defined in system CF, but not
# in the opensource release
# if the package needs private headers, we assume they also want to link with system CF
- NIX_LDFLAGS+=" /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation"
+ NIX_LDFLAGS+=" @out@/Library/Frameworks/CoreFoundation.framework/CoreFoundation"
}
preConfigureHooks+=(linkSystemCoreFoundationFramework)
diff --git a/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/default.nix b/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/default.nix
index 89c13d0b92d7..97523cf15a8d 100644
--- a/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/default.nix
+++ b/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, xar, cpio, pkgs, python3, pbzx, lib }:
+{ stdenv, fetchurl, xar, cpio, pkgs, python3, pbzx, lib, darwin-stubs, print-reexports }:
let version = "10.12"; in
@@ -42,7 +42,12 @@ let
rmdir System
pushd lib
- ln -s -L /usr/lib/libcups*.dylib .
+ cp ${darwin-stubs}/usr/lib/libcups*.tbd .
+ ln -s libcups.2.tbd libcups.tbd
+ ln -s libcupscgi.1.tbd libcupscgi.tbd
+ ln -s libcupsimage.2.tbd libcupsimage.tbd
+ ln -s libcupsmime.1.tbd libcupsmime.tbd
+ ln -s libcupsppdc.1.tbd libcupsppdc.tbd
popd
'';
@@ -53,6 +58,12 @@ let
};
};
+ mkFrameworkSubs = name: deps:
+ let
+ deps' = deps // { "${name}" = placeholder "out"; };
+ substArgs = lib.concatMap (x: [ "--subst-var-by" x deps'."${x}" ]) (lib.attrNames deps');
+ in lib.escapeShellArgs substArgs;
+
framework = name: deps: stdenv.mkDerivation {
name = "apple-framework-${name}";
@@ -63,11 +74,14 @@ let
disallowedRequisites = [ sdk ];
+ nativeBuildInputs = [ print-reexports ];
+
+ extraTBDFiles = [];
+
installPhase = ''
linkFramework() {
local path="$1"
local nested_path="$1"
- local dest="$out/Library/Frameworks/$path"
if [ "$path" == "JavaNativeFoundation.framework" ]; then
local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework"
fi
@@ -80,21 +94,29 @@ let
current=A
fi
- mkdir -p "$dest"
- pushd "$dest" >/dev/null
+ local dest="$out/Library/Frameworks/$path"
- # Keep track of if this is a child or a child rescue as with
- # ApplicationServices in the 10.9 SDK
- local isChild=0
+ mkdir -p "$dest/Versions/$current"
+ pushd "$dest/Versions/$current" >/dev/null
if [ -d "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" ]; then
- isChild=1
cp -R "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" .
elif [ -d "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" ]; then
current="$(readlink "/System/Library/Frameworks/$name.framework/Versions/Current")"
cp -R "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" .
fi
- ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/$name"
+
+ local tbd_source=${darwin-stubs}/System/Library/Frameworks/$nested_path/Versions/$current
+ if [ "${name}" != "Kernel" ]; then
+ # The Kernel.framework has headers but no actual library component.
+ cp -v $tbd_source/*.tbd .
+ fi
+
+ if [ -d "$tbd_source/Libraries" ]; then
+ mkdir Libraries
+ cp -v $tbd_source/Libraries/*.tbd Libraries/
+ fi
+
ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/Resources"
if [ -f "/System/Library/Frameworks/$nested_path/module.map" ]; then
@@ -110,17 +132,45 @@ let
linkFramework "$childpath"
done
- if [ -d "$dest/Versions/$current" ]; then
- mv $dest/Versions/$current/* .
- fi
+ pushd ../.. >/dev/null
+ ln -s "$current" Versions/Current
+ ln -s Versions/Current/* .
+ popd >/dev/null
popd >/dev/null
}
linkFramework "${name}.framework"
+
+ # linkFramework is recursive, the rest of the processing is not.
+
+ local tbd_source=${darwin-stubs}/System/Library/Frameworks/${name}.framework
+ for tbd in $extraTBDFiles; do
+ local tbd_dest_dir=$out/Library/Frameworks/${name}.framework/$(dirname "$tbd")
+ mkdir -p "$tbd_dest_dir"
+ cp -v "$tbd_source/$tbd" "$tbd_dest_dir"
+ done
+
+ # Fix and check tbd re-export references
+ find $out -name '*.tbd' | while read tbd; do
+ echo "Fixing re-exports in $tbd"
+ substituteInPlace "$tbd" ${mkFrameworkSubs name deps}
+
+ echo "Checking re-exports in $tbd"
+ print-reexports "$tbd" | while read target; do
+ local expected="''${target%.dylib}.tbd"
+ if ! [ -e "$expected" ]; then
+ echo -e "Re-export missing:\n\t$target\n\t(expected $expected)"
+ echo -e "While processing\n\t$tbd"
+ exit 1
+ else
+ echo "Re-exported target $target ok"
+ fi
+ done
+ done
'';
- propagatedBuildInputs = deps;
+ propagatedBuildInputs = builtins.attrValues deps;
# don't use pure CF for dylibs that depend on frameworks
setupHook = ./framework-setup-hook.sh;
@@ -139,6 +189,17 @@ let
platforms = platforms.darwin;
};
};
+
+ tbdOnlyFramework = name: { private ? true }: stdenv.mkDerivation {
+ name = "apple-framework-${name}";
+ dontUnpack = true;
+ installPhase = ''
+ mkdir -p $out/Library/Frameworks/
+ cp -r ${darwin-stubs}/System/Library/${lib.optionalString private "Private"}Frameworks/${name}.framework \
+ $out/Library/Frameworks
+ # NOTE there's no re-export checking here, this is probably wrong
+ '';
+ };
in rec {
libs = {
xpc = stdenv.mkDerivation {
@@ -168,7 +229,8 @@ in rec {
installPhase = ''
mkdir -p $out/include $out/lib
ln -s "${lib.getDev sdk}/include/Xplugin.h" $out/include/Xplugin.h
- ln -s "/usr/lib/libXplugin.1.dylib" $out/lib/libXplugin.dylib
+ cp ${darwin-stubs}/usr/lib/libXplugin.1.tbd $out/lib
+ ln -s libXplugin.1.tbd $out/lib/libXplugin.tbd
'';
};
@@ -193,6 +255,10 @@ in rec {
];
});
+ Carbon = stdenv.lib.overrideDerivation super.Carbon (drv: {
+ extraTBDFiles = [ "Versions/A/Frameworks/HTMLRendering.framework/Versions/A/HTMLRendering.tbd" ];
+ });
+
CoreFoundation = stdenv.lib.overrideDerivation super.CoreFoundation (drv: {
setupHook = ./cf-setup-hook.sh;
});
@@ -210,6 +276,10 @@ in rec {
setupHook = ./private-frameworks-setup-hook.sh;
});
+ IMServicePlugIn = stdenv.lib.overrideDerivation super.IMServicePlugIn (drv: {
+ extraTBDFiles = [ "Versions/A/Frameworks/IMServicePlugInSupport.framework/Versions/A/IMServicePlugInSupport.tbd" ];
+ });
+
Security = stdenv.lib.overrideDerivation super.Security (drv: {
setupHook = ./security-setup-hook.sh;
});
@@ -228,7 +298,14 @@ in rec {
cp ${lib.getDev sdk}/include/simd/*.h $out/include/simd/
'';
});
- };
+
+ WebKit = stdenv.lib.overrideDerivation super.WebKit (drv: {
+ extraTBDFiles = [
+ "Versions/A/Frameworks/WebCore.framework/Versions/A/WebCore.tbd"
+ "Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy.tbd"
+ ];
+ });
+ } // lib.genAttrs [ "ContactsPersistence" "UIFoundation" "GameCenter" ] (x: tbdOnlyFramework x {});
bareFrameworks = stdenv.lib.mapAttrs framework (import ./frameworks.nix {
inherit frameworks libs;
diff --git a/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/frameworks.nix b/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
index 02e2421f3472..bf0b134773d5 100644
--- a/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
+++ b/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
@@ -5,123 +5,125 @@
{ frameworks, libs, libobjc, }:
with frameworks; with libs; {
- AGL = [ Carbon OpenGL ];
- AVFoundation = [ ApplicationServices CoreGraphics ];
- AVKit = [];
- Accounts = [];
- AddressBook = [ Carbon ];
- AppKit = [ AudioToolbox AudioUnit Foundation QuartzCore ];
- AppKitScripting = [];
- AppleScriptKit = [];
- AppleScriptObjC = [];
- AudioToolbox = [ CoreAudio CoreMIDI ];
- AudioUnit = [ AudioToolbox Carbon CoreAudio ];
- AudioVideoBridging = [ Foundation ];
- Automator = [];
- CFNetwork = [];
- CalendarStore = [];
- Cocoa = [ AppKit ];
- Collaboration = [];
+ AGL = { inherit Carbon OpenGL; };
+ AVFoundation = { inherit ApplicationServices CoreGraphics; };
+ AVKit = {};
+ Accounts = {};
+ AddressBook = { inherit libobjc Carbon ContactsPersistence; };
+ AppKit = { inherit ApplicationServices AudioToolbox AudioUnit Foundation QuartzCore UIFoundation; };
+ AppKitScripting = {};
+ AppleScriptKit = {};
+ AppleScriptObjC = {};
+ AudioToolbox = { inherit CoreAudio CoreMIDI; };
+ AudioUnit = { inherit AudioToolbox Carbon CoreAudio; };
+ AudioVideoBridging = { inherit Foundation; };
+ Automator = {};
+ CFNetwork = {};
+ CalendarStore = {};
+ Cocoa = { inherit AppKit CoreData; };
+ Collaboration = {};
# Impure version of CoreFoundation, this should not be used unless another
# framework includes headers that are not available in the pure version.
- CoreFoundation = [];
- CoreAudio = [ IOKit ];
- CoreAudioKit = [ AudioUnit ];
- CoreData = [];
- CoreGraphics = [ Accelerate IOKit IOSurface SystemConfiguration ];
- CoreImage = [];
- CoreLocation = [];
- CoreMIDI = [];
- CoreMIDIServer = [];
- CoreMedia = [ ApplicationServices AudioToolbox AudioUnit CoreAudio CoreGraphics CoreVideo ];
- CoreMediaIO = [ CoreMedia ];
- CoreText = [ CoreGraphics ];
- CoreVideo = [ ApplicationServices CoreGraphics IOSurface OpenGL ];
- CoreWLAN = [ SecurityFoundation ];
- DVDPlayback = [];
- DirectoryService = [];
- DiscRecording = [ CoreServices IOKit ];
- DiscRecordingUI = [];
- DiskArbitration = [ IOKit ];
- EventKit = [];
- ExceptionHandling = [];
- FWAUserLib = [];
- ForceFeedback = [ IOKit ];
- Foundation = [ libobjc CoreFoundation Security ApplicationServices SystemConfiguration ];
- GLKit = [];
- GLUT = [ OpenGL ];
- GSS = [];
- GameController = [];
- GameKit = [ Foundation ];
- Hypervisor = [];
- ICADevices = [ Carbon IOBluetooth ];
- IMServicePlugIn = [];
- IOBluetoothUI = [ IOBluetooth ];
- IOKit = [];
- IOSurface = [ IOKit xpc ];
- ImageCaptureCore = [];
- ImageIO = [ CoreGraphics ];
- InputMethodKit = [ Carbon ];
- InstallerPlugins = [];
- InstantMessage = [];
- JavaFrameEmbedding = [];
- JavaNativeFoundation = [];
- JavaRuntimeSupport = [];
- JavaScriptCore = [];
- Kerberos = [];
- Kernel = [ IOKit ];
- LDAP = [];
- LatentSemanticMapping = [ Carbon ];
- LocalAuthentication = [];
- MapKit = [];
- MediaAccessibility = [ CoreGraphics CoreText QuartzCore ];
- MediaPlayer = [];
- MediaToolbox = [ AudioToolbox AudioUnit CoreMedia ];
- Metal = [];
- MetalKit = [ ModelIO Metal ];
- ModelIO = [ ];
- NetFS = [];
- OSAKit = [ Carbon ];
- OpenAL = [];
- OpenCL = [ IOSurface OpenGL ];
- OpenGL = [];
- PCSC = [ CoreData ];
- PreferencePanes = [];
- PubSub = [];
- QTKit = [ CoreMediaIO CoreMedia MediaToolbox QuickTime VideoToolbox ];
- QuickLook = [ ApplicationServices ];
- SceneKit = [];
- ScreenSaver = [];
- Scripting = [];
- ScriptingBridge = [];
- Security = [ IOKit ];
- SecurityFoundation = [];
- SecurityInterface = [ Security ];
- ServiceManagement = [ Security ];
- Social = [];
- SpriteKit = [];
- StoreKit = [];
- SyncServices = [];
- SystemConfiguration = [ Security ];
- TWAIN = [ Carbon ];
- Tcl = [];
- VideoDecodeAcceleration = [ CoreVideo ];
- VideoToolbox = [ CoreMedia CoreVideo ];
- WebKit = [ ApplicationServices Carbon JavaScriptCore OpenGL ];
+ CoreFoundation = {};
+ CoreAudio = { inherit IOKit; };
+ CoreAudioKit = { inherit AudioUnit; };
+ CoreData = {};
+ CoreGraphics = { inherit Accelerate IOKit IOSurface SystemConfiguration; };
+ CoreImage = {};
+ CoreLocation = {};
+ CoreMIDI = {};
+ CoreMIDIServer = { inherit CoreMIDI; };
+ CoreMedia = { inherit ApplicationServices AudioToolbox AudioUnit CoreAudio CoreGraphics CoreVideo; };
+ CoreMediaIO = { inherit CoreMedia; };
+ CoreText = { inherit CoreGraphics; };
+ CoreVideo = { inherit ApplicationServices CoreGraphics IOSurface OpenGL; };
+ CoreWLAN = { inherit SecurityFoundation; };
+ DVDPlayback = {};
+ DirectoryService = {};
+ DiscRecording = { inherit libobjc CoreServices IOKit; };
+ DiscRecordingUI = {};
+ DiskArbitration = { inherit IOKit; };
+ EventKit = {};
+ ExceptionHandling = {};
+ FWAUserLib = {};
+ ForceFeedback = { inherit IOKit; };
+ Foundation = { inherit libobjc CoreFoundation Security ApplicationServices SystemConfiguration; };
+ GLKit = {};
+ GLUT = { inherit OpenGL; };
+ GSS = {};
+ GameCenter = {};
+ GameController = {};
+ GameKit = { inherit Cocoa Foundation GameCenter GameController GameplayKit Metal MetalKit ModelIO SceneKit SpriteKit; };
+ GameplayKit = {};
+ Hypervisor = {};
+ ICADevices = { inherit libobjc Carbon IOBluetooth; };
+ IMServicePlugIn = {};
+ IOBluetoothUI = { inherit IOBluetooth; };
+ IOKit = {};
+ IOSurface = { inherit IOKit xpc; };
+ ImageCaptureCore = {};
+ ImageIO = { inherit CoreGraphics; };
+ InputMethodKit = { inherit Carbon; };
+ InstallerPlugins = {};
+ InstantMessage = {};
+ JavaFrameEmbedding = {};
+ JavaNativeFoundation = {};
+ JavaRuntimeSupport = {};
+ JavaScriptCore = { inherit libobjc; };
+ Kerberos = {};
+ Kernel = { inherit IOKit; };
+ LDAP = {};
+ LatentSemanticMapping = { inherit Carbon; };
+ LocalAuthentication = {};
+ MapKit = {};
+ MediaAccessibility = { inherit CoreGraphics CoreText QuartzCore; };
+ MediaPlayer = {};
+ MediaToolbox = { inherit AudioToolbox AudioUnit CoreMedia; };
+ Metal = {};
+ MetalKit = { inherit ModelIO Metal; };
+ ModelIO = {};
+ NetFS = {};
+ OSAKit = { inherit Carbon; };
+ OpenAL = {};
+ OpenCL = { inherit IOSurface OpenGL; };
+ OpenGL = {};
+ PCSC = { inherit CoreData; };
+ PreferencePanes = {};
+ PubSub = {};
+ QTKit = { inherit CoreMediaIO CoreMedia MediaToolbox QuickTime VideoToolbox; };
+ QuickLook = { inherit ApplicationServices; };
+ SceneKit = {};
+ ScreenSaver = {};
+ Scripting = {};
+ ScriptingBridge = {};
+ Security = { inherit IOKit; };
+ SecurityFoundation = {};
+ SecurityInterface = { inherit Security SecurityFoundation; };
+ ServiceManagement = { inherit Security; };
+ Social = {};
+ SpriteKit = {};
+ StoreKit = {};
+ SyncServices = {};
+ SystemConfiguration = { inherit Security; };
+ TWAIN = { inherit Carbon; };
+ Tcl = {};
+ VideoDecodeAcceleration = { inherit CoreVideo; };
+ VideoToolbox = { inherit CoreMedia CoreVideo; };
+ WebKit = { inherit libobjc ApplicationServices Carbon JavaScriptCore OpenGL; };
# Umbrellas
- Accelerate = [ CoreWLAN IOBluetooth ];
- ApplicationServices = [ CoreServices CoreText ImageIO ];
- Carbon = [ ApplicationServices CoreServices Foundation IOKit Security QuartzCore ];
- CoreBluetooth = [];
+ Accelerate = { inherit CoreWLAN IOBluetooth; };
+ ApplicationServices = { inherit CoreGraphics CoreServices CoreText ImageIO; };
+ Carbon = { inherit libobjc ApplicationServices CoreServices Foundation IOKit Security QuartzCore; };
+ CoreBluetooth = {};
# TODO: figure out which part of the umbrella depends on CoreFoundation and move it there.
- CoreServices = [ CFNetwork CoreFoundation CoreAudio CoreData DiskArbitration Security NetFS OpenDirectory ServiceManagement ];
- IOBluetooth = [ IOKit ];
- JavaVM = [];
- OpenDirectory = [];
- Quartz = [ QuickLook QTKit ];
- QuartzCore = [ ApplicationServices CoreVideo OpenCL CoreImage Metal ];
- QuickTime = [ ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore ];
+ CoreServices = { inherit CFNetwork CoreFoundation CoreAudio CoreData DiskArbitration Security NetFS OpenDirectory ServiceManagement; };
+ IOBluetooth = { inherit CoreBluetooth IOKit; };
+ JavaVM = {};
+ OpenDirectory = {};
+ Quartz = { inherit QuartzCore QuickLook QTKit; };
+ QuartzCore = { inherit libobjc ApplicationServices CoreVideo OpenCL CoreImage Metal; };
+ QuickTime = { inherit ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore; };
- vmnet = [];
+ vmnet = {};
}
diff --git a/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix b/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix
new file mode 100644
index 000000000000..85e11096f06a
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix
@@ -0,0 +1,17 @@
+{ stdenv, libyaml }:
+
+stdenv.mkDerivation {
+ name = "print-reexports";
+ src = stdenv.lib.sourceFilesBySuffices ./. [".c"];
+
+ buildInputs = [ libyaml ];
+
+ buildPhase = ''
+ $CC -lyaml -o $name main.c
+ '';
+
+ installPhase = ''
+ mkdir -p $out/bin
+ mv $name $out/bin
+ '';
+}
diff --git a/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c b/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c
new file mode 100644
index 000000000000..df46e3f18e89
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c
@@ -0,0 +1,148 @@
+/**
+ * Display the list of re-exported libraries from a TAPI v2 .tbd file, one per
+ * line on stdout.
+ *
+ * TAPI files are the equivalent of library files for the purposes of linking.
+ * Like dylib files, they may re-export other libraries. In upstream usage
+ * these refer to the absolute paths of dylibs, and are resolved to .tbd files
+ * in combination with the syslibroot option. In nixpkgs, the .tbd files refer
+ * directly to other .tbd files without a syslibroot. Note that each .tbd file
+ * contains an install name, so the re-exported path does not affect the final
+ * result.
+ *
+ * In nixpkgs each framework is a distinct store path and some frameworks
+ * re-export other frameworks. The re-exported names are rewritten to refer to
+ * the store paths of dependencies via textual substitution. This utility is
+ * used to emit every file that is listed as a re-exported library, which
+ * allows the framework builder to verify their existence.
+ */
+
+#include <stdio.h>
+#include <sys/errno.h>
+#include <yaml.h>
+
+static yaml_node_t *get_mapping_entry(yaml_document_t *document, yaml_node_t *mapping, const char *name) {
+ if (!mapping) {
+ fprintf(stderr, "get_mapping_entry: mapping is null\n");
+ return NULL;
+ }
+
+ for (
+ yaml_node_pair_t *pair = mapping->data.mapping.pairs.start;
+ pair < mapping->data.mapping.pairs.top;
+ ++pair
+ ) {
+ yaml_node_t *key = yaml_document_get_node(document, pair->key);
+
+ if (!key) {
+ fprintf(stderr, "get_mapping_entry: key (%i) is null\n", pair->key);
+ return NULL;
+ }
+
+ if (key->type != YAML_SCALAR_NODE) {
+ fprintf(stderr, "get_mapping_entry: key is not a scalar\n");
+ return NULL;
+ }
+
+ if (strncmp((const char *)key->data.scalar.value, name, key->data.scalar.length) != 0) {
+ continue;
+ }
+
+ return yaml_document_get_node(document, pair->value);
+ }
+
+ return NULL;
+}
+
+static int emit_reexports(yaml_document_t *document) {
+ yaml_node_t *root = yaml_document_get_root_node(document);
+
+ yaml_node_t *exports = get_mapping_entry(document, root, "exports");
+
+ if (!exports) {
+ fprintf(stderr, "emit_reexports: no exports found\n");
+ return 0;
+ }
+
+ if (exports->type != YAML_SEQUENCE_NODE) {
+ fprintf(stderr, "emit_reexports, value is not a sequence\n");
+ return 0;
+ }
+
+ for (
+ yaml_node_item_t *export = exports->data.sequence.items.start;
+ export < exports->data.sequence.items.top;
+ ++export
+ ) {
+ yaml_node_t *export_node = yaml_document_get_node(document, *export);
+
+ yaml_node_t *reexports = get_mapping_entry(document, export_node, "re-exports");
+
+ if (!reexports) {
+ continue;
+ }
+
+ for (
+ yaml_node_item_t *reexport = reexports->data.sequence.items.start;
+ reexport < reexports->data.sequence.items.top;
+ ++reexport
+ ) {
+ yaml_node_t *val = yaml_document_get_node(document, *reexport);
+
+ if (val->type != YAML_SCALAR_NODE) {
+ fprintf(stderr, "item is not a scalar\n");
+ return 0;
+ }
+
+ fwrite(val->data.scalar.value, val->data.scalar.length, 1, stdout);
+ putchar('\n');
+ }
+ }
+
+ return 1;
+}
+
+int main(int argc, char **argv) {
+ int result = 0;
+
+ if (argc != 2) {
+ fprintf(stderr, "Invalid usage\n");
+ result = 2;
+ goto done;
+ }
+
+ FILE *f = fopen(argv[1], "r");
+ if (!f) {
+ perror("opening input file");
+ result = errno;
+ goto done;
+ }
+
+ yaml_parser_t yaml_parser;
+ if (!yaml_parser_initialize(&yaml_parser)) {
+ fprintf(stderr, "Failed to initialize yaml parser\n");
+ result = 1;
+ goto err_file;
+ }
+
+ yaml_parser_set_input_file(&yaml_parser, f);
+
+ yaml_document_t yaml_document;
+
+ if(!yaml_parser_load(&yaml_parser, &yaml_document)) {
+ fprintf(stderr, "Failed to load yaml file\n");
+ result = 1;
+ goto err_yaml;
+ }
+
+ emit_reexports(&yaml_document);
+
+err_yaml:
+ yaml_parser_delete(&yaml_parser);
+
+err_file:
+ fclose(f);
+
+done:
+ return result;
+}