Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions strukturag/libde265/v1.0.12/libde265_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import (
"os"
"path/filepath"
"strings"
)

id "strukturag/libde265"

fromVer "v1.0.12"

defaults {
"shared": "OFF",
"fPIC": "ON",
"sse": "ON",
}

filter => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter accepts any option key, not just the known set. Unlike cglm (which validates the specific shared key), this loops over all of target.options and only checks values are ON/OFF. A typo like shred/Sse would pass the filter, then target.options["shared"][0] etc. proceed with defaults while the intended option is silently ignored. Consider validating against the known keys (shared, fPIC, sse). Same on v1.0.17 line 16.

for values in target.options {
for value in values {
if value != "ON" && value != "OFF" {
return false
}
}
}
return true
}

onBuild ctx => {
installDir := ctx.outputDir
shared := target.options["shared"][0] == "ON"
fPIC := target.options["fPIC"][0] == "ON"
sse := target.options["sse"][0] == "ON"

// The Conan recipe removes this upstream assignment so its fPIC option
// controls static builds instead of being overwritten during configure.
cmakeLists := filepath.join(ctx.SourceDir, "CMakeLists.txt")
source := string(os.readFile(cmakeLists)!)
source = strings.replace(source, "set(CMAKE_POSITION_INDEPENDENT_CODE ON)\n", "", 1)
os.writeFile(cmakeLists, []byte(source), 0644)!

c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir)
c.define "CMAKE_INSTALL_LIBDIR", "lib"
c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5"
c.defineBool "BUILD_SHARED_LIBS", shared
c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC
c.defineBool "ENABLE_SDL", false
c.defineBool "DISABLE_SSE", !sse
c.configure
c.build
c.install

licenseDir := filepath.join(installDir, "licenses")
os.mkdirAll(licenseDir, 0755)!
os.writeFile(filepath.join(licenseDir, "COPYING"), os.readFile(filepath.join(ctx.SourceDir, "COPYING"))!, 0644)!

// The upstream file embeds the install directory and keeps static runtime
// libraries private. Make the published metadata relocatable and complete
// for the static C consumer used by this Formula.
pcPath := filepath.join(installDir, "lib", "pkgconfig", "libde265.pc")
pc := string(os.readFile(pcPath)!)
pc = strings.replace(pc, "prefix="+installDir, "prefix=$${pcfiledir}/../..", 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fragile prefix rewrite may silently leave the absolute build path embedded. strings.replace(pc, "prefix="+installDir, ...) requires the generated prefix= line to be a byte-for-byte match. If CMake normalizes the path (trailing slash, symlink/case resolution) or emits a ${prefix}-style line, the replace is a no-op and the published .pc keeps the absolute install path — defeating the stated relocatability and leaking the build-host path. Consider anchoring on the line starting with prefix= and rewriting the whole line, then asserting the replacement actually occurred. Same on v1.0.17 line 53.

lines := pc.split("\n")
privateLibs := ""
privateCflags := ""
for line in lines {
if line.hasPrefix("Libs.private:") {
privateLibs = line.trimPrefix("Libs.private:").trimSpace()
}
if line.hasPrefix("Cflags.private:") {
privateCflags = line.trimPrefix("Cflags.private:").trimSpace()
}
}
if !shared {
for i, line in lines {
if privateLibs != "" && line.hasPrefix("Libs:") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Folding Libs.private/Cflags.private into the public Libs:/Cflags: makes the published .pc non-standard. Private deps should stay private; this permanently mutates the installed metadata for all consumers. The json-c formula solves the same static-linking need cleanly by letting pkg-config do it (pkg-config --static). If pkgconfig.lookup supports a static query, prefer that and leave the .pc unmodified. Note also that upstream libde265.pc.in has no Cflags.private field, so the Cflags.private branch is effectively dead code here. Same on v1.0.17 line 67.

lines[i] = line + " " + privateLibs
}
if privateCflags != "" && line.hasPrefix("Cflags:") {
lines[i] = line + " " + privateCflags
}
}
}
os.writeFile(pcPath, []byte(strings.join(lines, "\n")), 0644)!

pkgconfig.use installDir
ctx.setMetadata pkgconfig.lookup("libde265")!
}

onTest ctx => {
installDir := ctx.outputDir
testDir := filepath.join(ctx.SourceDir, "_llar_consumer")
testBuild := filepath.join(testDir, "_build")
consumer := filepath.join(testDir, "consumer.c")
binary := filepath.join(testBuild, "consumer")

os.mkdirAll(testDir, 0755)!
os.mkdirAll(testBuild, 0755)!
os.writeFile(consumer, []byte(`#include <libde265/de265.h>

int main(void) {
de265_decoder_context *ctx = de265_new_decoder();
de265_free_decoder(ctx);
return 0;
}
`), 0644)!

pkgconfig.use installDir
flags := pkgconfig.lookup("libde265")!
flagsFile := filepath.join(testDir, "libde265.flags")
os.writeFile(flagsFile, []byte(flags), 0644)!

exec "cc", "-std=c11", "@"+flagsFile, consumer, "-o", binary
lastErr!
if target.options["shared"][0] == "ON" {
os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.setenv overwrites LD_LIBRARY_PATH/DYLD_LIBRARY_PATH instead of prepending. This discards any existing loader search paths the test environment relied on. Prefer prepending installDir/lib and preserving the prior value. Same on v1.0.17 lines 107-108.

os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))!
}
exec binary
lastErr!
}
112 changes: 112 additions & 0 deletions strukturag/libde265/v1.0.17/libde265_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import (
"os"
"path/filepath"
"strings"
)

id "strukturag/libde265"

fromVer "v1.0.17"

defaults {
"shared": "OFF",
"fPIC": "ON",
}

filter => {
for values in target.options {
for value in values {
if value != "ON" && value != "OFF" {
return false
}
}
}
return true
}

onBuild ctx => {
installDir := ctx.outputDir
shared := target.options["shared"][0] == "ON"
fPIC := target.options["fPIC"][0] == "ON"

cmakeLists := filepath.join(ctx.SourceDir, "CMakeLists.txt")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing rationale comments that v1.0.12 carries for identical logic. v1.0.12 documents why the CMAKE_POSITION_INDEPENDENT_CODE line is stripped from the upstream CMakeLists.txt and why the pkg-config file is rewritten; v1.0.17 performs the same non-obvious mutations with no comments. Since both tags' CMakeLists.txt contain that set(...) line (verified) and the strings.replace(..., 1) silently no-ops if it ever disappears, the rationale is equally load-bearing here. Replicate the comments to match v1.0.12 and the repo's documentation standard (see cglm/json-c).

source := string(os.readFile(cmakeLists)!)
source = strings.replace(source, "set(CMAKE_POSITION_INDEPENDENT_CODE ON)\n", "", 1)
os.writeFile(cmakeLists, []byte(source), 0644)!

c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir)
c.define "CMAKE_INSTALL_LIBDIR", "lib"
c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.16"
c.defineBool "BUILD_SHARED_LIBS", shared
c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC
c.defineBool "ENABLE_SDL", false
c.configure
c.build
c.install

licenseDir := filepath.join(installDir, "licenses")
os.mkdirAll(licenseDir, 0755)!
os.writeFile(filepath.join(licenseDir, "COPYING"), os.readFile(filepath.join(ctx.SourceDir, "COPYING"))!, 0644)!

pcPath := filepath.join(installDir, "lib", "pkgconfig", "libde265.pc")
pc := string(os.readFile(pcPath)!)
pc = strings.replace(pc, "prefix="+installDir, "prefix=$${pcfiledir}/../..", 1)
lines := pc.split("\n")
privateLibs := ""
privateCflags := ""
for line in lines {
if line.hasPrefix("Libs.private:") {
privateLibs = line.trimPrefix("Libs.private:").trimSpace()
}
if line.hasPrefix("Cflags.private:") {
privateCflags = line.trimPrefix("Cflags.private:").trimSpace()
}
}
if !shared {
for i, line in lines {
if privateLibs != "" && line.hasPrefix("Libs:") {
lines[i] = line + " " + privateLibs
}
if privateCflags != "" && line.hasPrefix("Cflags:") {
lines[i] = line + " " + privateCflags
}
}
}
os.writeFile(pcPath, []byte(strings.join(lines, "\n")), 0644)!

pkgconfig.use installDir
ctx.setMetadata pkgconfig.lookup("libde265")!
}

onTest ctx => {
installDir := ctx.outputDir
testDir := filepath.join(ctx.SourceDir, "_llar_consumer")
testBuild := filepath.join(testDir, "_build")
consumer := filepath.join(testDir, "consumer.c")
binary := filepath.join(testBuild, "consumer")

os.mkdirAll(testDir, 0755)!
os.mkdirAll(testBuild, 0755)!
os.writeFile(consumer, []byte(`#include <libde265/de265.h>

int main(void) {
de265_decoder_context *ctx = de265_new_decoder();
de265_free_decoder(ctx);
return 0;
}
`), 0644)!

pkgconfig.use installDir
flags := pkgconfig.lookup("libde265")!
flagsFile := filepath.join(testDir, "libde265.flags")
os.writeFile(flagsFile, []byte(flags), 0644)!

exec "cc", "-std=c11", "@"+flagsFile, consumer, "-o", binary
lastErr!
if target.options["shared"][0] == "ON" {
os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))!
os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))!
}
exec binary
lastErr!
}
4 changes: 4 additions & 0 deletions strukturag/libde265/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "strukturag/libde265",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation inconsistent with repo convention. All existing versions.json files (madler/zlib, recp/cglm, json-c/json-c) use tab indentation; this file uses 2 spaces. Reformat with tabs to match.

"deps": {}
}
Loading