Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save antongaenko/0b69b1c1079028ae355d44883bab6539 to your computer and use it in GitHub Desktop.
Save antongaenko/0b69b1c1079028ae355d44883bab6539 to your computer and use it in GitHub Desktop.
Generates a naïve umbrella header by assuming every header in the working folder or any of its subfolders is public and should be included
#!/usr/bin/env ruby
# Your umbrella header needs a comment in it like the below so this script
# knows which parts to replace
#
# /* IMPORTS BEGIN */
#
# /* IMPORTS END */
MODULE = ARGV[0] || File.basename(Dir.getwd)
MODULE_HEADER = "#{MODULE}.h"
REPLACEMENT_TAGS = /\/\* IMPORTS BEGIN \*\/.*\/\* IMPORTS END \*\//m
imports = Dir.glob("**/*.h").select { |f| File.basename(f) != MODULE_HEADER }
.map { |f| "#import <#{MODULE}/#{File.basename(f)}>" }
.join("\n")
imports = "/* IMPORTS BEGIN */\n#{imports}\n/* IMPORTS END */"
header = File.read(MODULE_HEADER)
imports = header.gsub(REPLACEMENT_TAGS, imports)
File.write(MODULE_HEADER, imports)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment