Skip to content

Commit

Permalink
Merge pull request #273 from RblSb/haxelib_classpath
Browse files Browse the repository at this point in the history
Fix haxelibs with classPath
  • Loading branch information
RobDangerous authored Jul 14, 2024
2 parents 6f9c81c + 777eca7 commit 32af749
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
10 changes: 6 additions & 4 deletions out/HaxeProject.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions out/Project.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions src/HaxeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function hxml(projectdir: string, options: any) {
if (lines.indexOf(line) === -1) {
lines.push(line);
return line;
}
}
return '';
}

Expand All @@ -122,12 +122,13 @@ function hxml(projectdir: string, options: any) {
data += unique('-cp ' + path.relative(projectdir, path.resolve(options.from, options.sources[i])) + '\n'); // from.resolve('build').relativize(from.resolve(this.sources[i])).toString());
}
}
for (let i = 0; i < options.libraries.length; ++i) {
if (path.isAbsolute(options.libraries[i].libpath)) {
data += unique('-cp ' + options.libraries[i].libpath + '\n');
for (const lib of options.libraries) {
if (lib.classPathIsAdded) continue
if (path.isAbsolute(lib.libpath)) {
data += unique('-cp ' + lib.libpath + '\n');
}
else {
data += unique('-cp ' + path.relative(projectdir, path.resolve(options.from, options.libraries[i].libpath)) + '\n'); // from.resolve('build').relativize(from.resolve(this.sources[i])).toString());
data += unique('-cp ' + path.relative(projectdir, path.resolve(options.from, lib.libpath)) + '\n'); // from.resolve('build').relativize(from.resolve(this.sources[i])).toString());
}
}
for (let d in options.defines) {
Expand Down Expand Up @@ -170,7 +171,7 @@ function hxml(projectdir: string, options: any) {

if (!options.parameters.some((param: string) => param.includes('-main '))) {
const entrypoint = options ? options.main ? options.main : 'Main' : 'Main';
data += unique('-main ' + entrypoint + '\n');
data += unique('-main ' + entrypoint + '\n');
}

fs.outputFileSync(path.join(projectdir, 'project-' + options.system + '.hxml'), data);
Expand Down
12 changes: 9 additions & 3 deletions src/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import {loadProject} from './ProjectFile';
export class Library {
libpath: string;
libroot: string;
/**
* If haxelib `classPath` is specified,
* we don't add `libpath` as `-cp` to `hxml`.
*/
classPathIsAdded? = false;
}

export class Target {
Expand Down Expand Up @@ -275,17 +280,18 @@ export class Project {
if (elem.libroot === libInfo.libroot)
return '';
}
this.libraries.push({
const lib:Library = {
libpath: dir,
libroot: libInfo.libroot
});
}
this.libraries.push(lib);
// If this is a haxelib library, there must be a haxelib.json
if (fs.existsSync(path.join(dir, 'haxelib.json'))) {
let options = JSON.parse(fs.readFileSync(path.join(dir, 'haxelib.json'), 'utf8'));
// If there is a classPath value, add that directory to be loaded.
// Otherwise, just load the current path.
if (options.classPath) {
// TODO find an example haxelib that has a classPath value
lib.classPathIsAdded = true
this.sources.push(path.join(dir, options.classPath));
}
else {
Expand Down

0 comments on commit 32af749

Please sign in to comment.