Skip to content

Commit

Permalink
[workflows] added output directory option for type-stub generator
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDreyer committed Apr 23, 2024
1 parent 6ca277e commit b6e4cd0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ jobs:
- name: Generate Ruby Types
run: ./standalone --withLanguageFrontend RUBYSRC
- name: Checksum
run: sha512sum src/main/resources/ruby/builtin_types.zip > src/main/resources/ruby/builtin_types.zip.sha512
run: sha512sum builtin_types/ruby_builtin_types.zip > builtin_types/ruby_builtin_types.zip.sha512
- name: Rename
run: |
mv src/main/resources/ruby/builtin_types.zip ruby_builtin_types.zip
mv src/main/resources/ruby/builtin_types.zip.sha512 ruby_builtin_types.zip.sha512
mv builtin_types/ruby_builtin_types.zip ruby_builtin_types.zip
mv builtin_types/ruby_builtin_types.zip.sha512 ruby_builtin_types.zip.sha512
- name: Show SHA512
run: cat ruby_builtin_types.zip.sha512
- name: Set next release version
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ target/
/joern-inst
/workspace
src/main/resources/
builtin_types/
13 changes: 10 additions & 3 deletions src/main/scala/io/joern/typestubs/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object OutputFormat extends Enumeration {
val json, mpk, zip = Value
}

final case class Config(format: OutputFormat.Value = OutputFormat.zip, languageFrontend: String = Frontend.ALL) {
final case class Config(format: OutputFormat.Value = OutputFormat.zip, languageFrontend: String = Frontend.ALL, outputDirectory: String = "./builtin_types") {

def withFormat(value: OutputFormat.Value): Config = {
copy(format = value)
Expand All @@ -17,6 +17,10 @@ final case class Config(format: OutputFormat.Value = OutputFormat.zip, languageF
def withLanguageFrontend(value: String): Config = {
copy(languageFrontend = value)
}

def withOutputDirectory(value: String): Config = {
copy(outputDirectory = value)
}
}

private object Frontend {
Expand Down Expand Up @@ -45,7 +49,10 @@ private object Frontend {
failure(s"Only available languages are: [${availableFrontendLanguages.mkString(", ")}]")
}
.text(s"The Frontend Language to generate builtin types for, defaults to `all`: [${availableFrontendLanguages
.mkString(",")}]".stripMargin)
.mkString(",")}]".stripMargin),
opt[String]("output")
.action((x, c) => c.withOutputDirectory(x))
.text("Directory for type-stubs output")
)
}
}
Expand All @@ -70,7 +77,7 @@ object Main {

def run(config: Config): Unit = {
if config.languageFrontend == Frontend.ALL || config.languageFrontend == Languages.RUBYSRC then
val rubyScraper = BuiltinPackageDownloader(format = config.format)
val rubyScraper = BuiltinPackageDownloader(outputDir = config.outputDirectory, format = config.format)
rubyScraper.run()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ case class RubyType(name: String, methods: List[RubyMethod], fields: List[RubyFi
* @param rubyVersion
* \- Ruby version to fetch dependencies for
*/
class BuiltinPackageDownloader(format: OutputFormat.Value = OutputFormat.zip) {
class BuiltinPackageDownloader(outputDir: String, format: OutputFormat.Value = OutputFormat.zip) {
private val logger: Logger = LoggerFactory.getLogger(this.getClass)

private val CLASS = "class"
Expand All @@ -52,7 +52,7 @@ class BuiltinPackageDownloader(format: OutputFormat.Value = OutputFormat.zip) {
private val browser = JsoupBrowser()
private val baseUrl = s"https://ruby-doc.org/3.3.0"

private val baseDir = "src/main/resources/ruby/builtin_types"
private val baseDir = s"$outputDir/ruby_builtin_types"

// Below unicode value calculated with: println("\\u" + Integer.toHexString('→' | 0x10000).substring(1))
// taken from: https://stackoverflow.com/questions/2220366/get-unicode-value-of-a-character
Expand Down Expand Up @@ -138,8 +138,10 @@ class BuiltinPackageDownloader(format: OutputFormat.Value = OutputFormat.zip) {
}

logger.debug("[Ruby]: Zipping builtin-type dir")
dir.zipTo(destination = File(s"${baseDir}.zip"))
dir.delete()

if format == OutputFormat.zip then
dir.zipTo(destination = File(s"${baseDir}.zip"))
dir.delete()
}

/** Write RubyTypes to JSON files for debugging a readable format
Expand Down

0 comments on commit b6e4cd0

Please sign in to comment.