Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional compilation from manifest not considered #745

Open
iBicha opened this issue Nov 28, 2022 · 2 comments
Open

Conditional compilation from manifest not considered #745

iBicha opened this issue Nov 28, 2022 · 2 comments

Comments

@iBicha
Copy link
Contributor

iBicha commented Nov 28, 2022

In .bs files, if I try to use some defined symbol in manifest
bs_const=someFlag=false

And use it in my bs script

 #if someFlag
#end if

it says Referenced #const does not exist. Only if the symbol is defined in the bs script it would work fine.

@luis-soares-sky
Copy link
Contributor

luis-soares-sky commented Sep 15, 2023

Replying just to add some context, since I've asked about this a few months ago in the Developer Slack's #brighterscript channel (can't find the messages since it's been over 90 days).

From what I remember (and please keep me humble @TwitchBronBron), the gist of it is that bsc was originally based on the brs interpreter, which will read the manifest file and strip out the blocks before running the code, basically emulating the conditional compilation that the Roku OS already does. That behaviour is still in bsc to this day, which means it'll try to read a manifest from your root folder (https://github.com/rokucommunity/brighterscript/blob/master/src/Program.ts#L1358-L1359), and strip out or keep the code blocks based on your bs_const values. If such file or manifest entry doesn't exist, it'll assume those constants as false and remove the associated blocks, and throw validation errors since it doesn't know which vars are defined.

My team's facing a problem due to this, since our manifest is dynamically generated before bsc runs, but to avoid changes in the source folder (to keep the VSC Language Server from tripping up during a build), I generate it outside and then include it in our bsconfig's files. This causes all of our conditional blocks to be missing in our build output as well.

I'm thinking about opening a PR to tweak getManifest to find a manifest from files, but I imagine a definitive solution to this would definitely require a lot more effort, which I can't speak to.

@TwitchBronBron
Copy link
Member

Hey! You explained the issue perfectly.

I'm currently working on merging the file API (#408) into the v0.66.0 release, which will allow us to officially support loading the manifest from the files array and actually even get manifest validation. But that might still be a week or so until it merges, and then you'd also be stuck using the 0.66.alphas until they release (not a bad thing, but might be slightly less stable than mainline).

I would also definitely be open to seeing a PR that loads the manifest from the files array instead. That's a much better approach. I think you'd have to do this in ProgramBuilder.ts to prioritize loading manifest into the program first, because Program.ts currently loads manifest on-demand the first time it's needed.

An alternative approach is to write a bsc plugin in your project that registers an "afterProgramCreate" event and manually modify the program.manifest Map to set it to the manifest values that you want.

Yet another option is to utilize the new bsconfig setting called manifest.bsconst (#887), paired with bsconfig inheritance. (I.e. bsconfig.dev.json extends bsconfig.json)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants