#Skip a Build.Step.Run when a file/folder exists

1 messages · Page 1 of 1 (latest)

dense tree
#

How would you go about doing this?
My current step is this:

  const repo = std.Build.Step.Run.create(B, "Clone Repository");
  repo.addArgs(&.{"git", "clone", "-b", opt.version, opt.URL, opt.dir});
  B.getInstallStep().dependOn(&repo.step);
fossil bane
#

Im not entirely sure if what you want to do is possible?
you could check if the directory exist and conditionally make a step depend on that on that step

dense tree
#

build.zig.zon NO. just no. I want to leave programming altogether when I touch that stuff

fossil bane
#

oh and you should probably use b.addSystemCommand instead of manually creating the run step like this

fossil bane
dense tree
#

"simple"... proceeds to waste hours and hours in frustration

#

it hasn't been simple once for me. at all

#

not even once 😦

fossil bane
#

I would assume thats because you didnt take the time to understand it

dense tree
#

I do not work with remote repos that are hard-pinned to a certain commit. I work locally, and .zon files just don't cooperate for that

fossil bane
#

you can use a local path for a dependency as well

dense tree
#

I do not pin to hashes. I edit like every damn 2minutes

fossil bane
#

and then you dont need a hash

dense tree
#

it replaces the path

fossil bane
#

just dont use zig fetch then

#

zig fetch is meant for remote urls where you dont know the hash

dense tree
#

"just don't use remote dependencies then" ... then why would I even use build.zon at all then? I would rather use git submodules for that

fossil bane
#

when did I say not to use remote dependencies

dense tree
#

if I fetch to get the remotes, fetch breaks my local paths

#

it force-edits them

fossil bane
#

it will only overwrite what you ask it to

dense tree
#

lets keep the .zon conversation for some other day. it hasn't been simple once, and I'm purposedly staying away from it before I leave this lang for the 4th time in frustration at build crap

#

i'm making progress this other way

#

I would rather stay here and work without suffering

#

when the package manager is stable I will reconsider. that is not today

fossil bane
#

it is stable, it hasnt changed since 0.12
and barely changed since 0.11

dense tree
#

same thing happened with the buildsystem itself, and it made me quit the lang. but now its stable and decent, so now its usable. but the package manager is not there

fossil bane
#

either way its your choice not to use it

dense tree
#

you could use repo.addOutputDir to clone it into your cache, that way it will automatically just not run if that dir already exists (plus its fully managed by the build system now)
Can you expand a bit on this? 🤔

#

I want to clone the repo in a certain location, so that I can use ./that/folder/binary.exe from there to do other things later on

#

will that not screw the goal?

fossil bane
#

it would but thats not a good way to do things
addOutputDirectoryArg will put it in cache and then return a LazyPath to the start of it
and everything else in the build system will expect a LazyPath anyway so it shouldnt change things too much
and it ensures that builds are fully hermatic builds (i.e if it builds once, it will always build because it does the same thing each time)

dense tree
#

i see what you mean

#

it seems to capture stdout now

#

is there a way to make it not do that?

#

I need the user to see that the repository is being cloned, and then that the contents are being compiled

fossil bane
#

as in it doesnt print anything?
iirc if you use addSystemCommand the default is to not capture stdout
no idea what the defaults are with a manually created Run step

dense tree
#

let me try

fossil bane
#

hm thats odd lemme see

#

maybe remove .zig-cache? it might not print anything just because its already cloned so it doesnt do anything

dense tree
#

i did remove it everytime

fossil bane
#

yeah I cant see how to make it do it

dense tree
#

it seems to be doing things in the right folders though

#

even if cloning errored

#

but now I have a problem, because its supposed to run a build.sh script inside that repo... which is always going to exist

#

so back to square1. how to make the buildsystem conditionally do things only when X or Y are true?

#

sidenote: I don't know why it said earlier that it errored. it actually completed 🤷‍♂️

fossil bane
dense tree
#

yeah, just tested it. it does rebuild everytime, even if it shouldn't because the file already exists

dense tree
fossil bane
#

actually you cant really because its a LazyPath that doesnt exist while build.zig is being executed

#

yeah im not sure, you could use some_run_step.addOutputFileArg
and thatll make it so that the build system understands that as long as the inputs dont change and the output file is there, it shouldnt rerun it

#

but now build.sh would need to actually accept that argument to know where to output the artifact