<aclass=btnstyle=color:#fff;background-color:OrangeRedhref=https://www.gitlab.com/moussaelianarsen/advmake><spanclass=iconifydata-icon=fa-brands:gitlab></span> AdvMake</a></p><h2id=format>Format<ahref=#formatclass=anchoraria-hidden=true>#</a></h2><p>AdvMake uses <ahref=https://github.com/bazelbuild/starlark>Starlark</a> as the format for its build files.
Modules are also defined for both convenience and extra functionality.</p><p>Starlark is a Python-like language meant for configuration files.</p><h2id=configuration>Configuration<ahref=#configurationclass=anchoraria-hidden=true>#</a></h2><p>Build files are by default called <code>AdvMakefile</code>, but that can be set via <code>-f</code></p><p>An AdvMakefile example can be found at AdvMake’s repo as it uses AdvMake itself.</p><p>AdvMake runs functions exposed by starlark in the format <code><name>_<target></code>.
To set the default name and target, the global variables <code>defaultName</code>, and <code>defaultTarget</code> must be set.
Here is an example from AdvMake’s AdvMakefile:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>defaultName</span><spanclass=o>=</span><spanclass=s2>"advmake"</span>
</code></pre></div><p>This will tell AdvMake to run the function <code>advmake_build()</code> when run with no arguments.</p><p>If AdvMake is run with one argument (such as <code>advmake install</code>), it will use the default name with the specified target,
so in that case, it would run <code>advmake_install()</code>.</p><p>If run with two arguments, AdvMake will use the first argument as the name and the second as the target.
So, running <code>advmake hello world</code> would run the function <code>hello_world()</code>.</p><h2id=modules>Modules<ahref=#modulesclass=anchoraria-hidden=true>#</a></h2><p>As previously mentioned, AdvMake comes with modules. Those are as follows:</p><h3id=runtime><code>runtime</code><ahref=#runtimeclass=anchoraria-hidden=true>#</a></h3><p>The runtime module exposes some of golang’s runtime methods and variables.</p><hr><h4id=runtimegoos><code>runtime.GOOS</code><ahref=#runtimegoosclass=anchoraria-hidden=true>#</a></h4><p>Stores a string denoting the operating system being used.</p><aclass=btnstyle=color:#fff;background-color:#00acd7href=https://pkg.go.dev/runtime#GOOS><spanclass="iconify icon:cib:go"></span>
Godoc</a><hr><h4id=runtimegoarch><code>runtime.GOARCH</code><ahref=#runtimegoarchclass=anchoraria-hidden=true>#</a></h4><p>Stores a string denoting the CPU architecture being used.</p><aclass=btnstyle=color:#fff;background-color:#00acd7href=https://pkg.go.dev/runtime#GOARCH><spanclass="iconify icon:cib:go"></span>
Godoc</a><hr><h4id=runtimenumcpu><code>runtime.NumCPU()</code><ahref=#runtimenumcpuclass=anchoraria-hidden=true>#</a></h4><p>Get the number of logical CPUs available to the current process</p><aclass=btnstyle=color:#fff;background-color:#00acd7href=https://pkg.go.dev/runtime#NumCPU><spanclass="iconify icon:cib:go"></span>
Godoc</a><hr><h4id=runtimegomaxprocs><code>runtime.GOMAXPROCS()</code><ahref=#runtimegomaxprocsclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>runtime.GOMAXPROCS(n)</code></p><p>Get or set the value of the GOMAXPROCS environment variable. This variable controls the maximum number of CPUs that can execute. This function will set GOMAXPROCS to n and then return the previous value. If <code>n<1</code>, this function will not set the variable and will instead return the current setting</p><aclass=btnstyle=color:#fff;background-color:#00acd7href=https://pkg.go.dev/runtime#GOMAXPROCS><spanclass="iconify icon:cib:go"></span>
Godoc</a><hr><h3id=encoding><code>encoding</code><ahref=#encodingclass=anchoraria-hidden=true>#</a></h3><p>The strings module contains functions for encoding and decoding various formats. This module contains submodules for the various formats</p><p>Available submodules:</p><ul><li><code>Json</code></li><li><code>Yaml</code></li><li><code>Toml</code></li><li><code>Hex</code></li></ul><hr><h4id=encodingsubmoduleload><code>encoding.<Submodule>.Load()</code><ahref=#encodingsubmoduleloadclass=anchoraria-hidden=true>#</a></h4><p>Load a string formatted as the submodule format into a dictionary or string.</p><p>Examples:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>x</span><spanclass=o>=</span><spanclass=n>encoding</span><spanclass=o>.</span><spanclass=n>Json</span><spanclass=o>.</span><spanclass=n>Load</span><spanclass=p>(</span><spanclass=s1>'{"encoding": "json"}'</span><spanclass=p>)</span>
</code></pre></div><hr><h4id=encodingsubmoduledump><code>encoding.<Submodule>.Dump()</code><ahref=#encodingsubmoduledumpclass=anchoraria-hidden=true>#</a></h4><p>Dump a string formatted as the submodule format from a dictionary or string</p><p>Examples:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>xDict</span><spanclass=o>=</span><spanclass=p>{</span><spanclass=s2>"encoding"</span><spanclass=p>:</span><spanclass=p>{</span><spanclass=s2>"type"</span><spanclass=p>:</span><spanclass=s2>"toml"</span><spanclass=p>}}</span>
</code></pre></div><hr><h3id=file><code>file</code><ahref=#fileclass=anchoraria-hidden=true>#</a></h3><p>The file module contains functions for manipulation and checking of files</p><hr><h4id=fileexpand><code>file.Expand()</code><ahref=#fileexpandclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>file.Expand(file, mappings)</code></p><p>Expand any instances of <code>$VAR</code> in a file according to provided mappings.</p><p>Examples:</p><p><code>file.txt</code> before:</p><divclass=highlight><preclass=chroma><codeclass=language-textdata-lang=text>I am running on $OS and architecture $arch
</code></pre></div><p><code>file.txt</code> after:</p><divclass=highlight><preclass=chroma><codeclass=language-textdata-lang=text>I am running on linux and architecture x86_64
</code></pre></div><hr><h4id=fileexists><code>file.Exists()</code><ahref=#fileexistsclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>file.Exists(filepath)</code></p><p>Check whether a file exists</p><p>Example:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=nb>file</span><spanclass=o>.</span><spanclass=n>Exists</span><spanclass=p>(</span><spanclass=s2>"/etc/fstab"</span><spanclass=p>)</span><spanclass=c1># True</span>
</code></pre></div><hr><h4id=filecontent><code>file.Content()</code><ahref=#filecontentclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>file.Content(filepath)</code></p><p>Returns contents of a file as a string</p><p>Example:</p><p>file.txt:</p><divclass=highlight><preclass=chroma><codeclass=language-textdata-lang=text>This is a file
</code></pre></div><p>Code:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=nb>file</span><spanclass=o>.</span><spanclass=n>Content</span><spanclass=p>(</span><spanclass=s2>"file.txt"</span><spanclass=p>)</span><spanclass=c1># "This is a file"</span>
</code></pre></div><hr><h3id=strings><code>strings</code><ahref=#stringsclass=anchoraria-hidden=true>#</a></h3><p>The strings module contains functions for the manipulation of strings</p><hr><h4id=stringsregex><code>strings.Regex()</code><ahref=#stringsregexclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>strings.Regex(string, pattern, regex)</code></p><p>Parse a string using a regular expression and return the result in the specified format.</p><p>Examples:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>x</span><spanclass=o>=</span><spanclass=n>strings</span><spanclass=o>.</span><spanclass=n>Regex</span><spanclass=p>(</span><spanclass=s2>"Hello, World"</span><spanclass=p>,</span><spanclass=s2>"$2, $1"</span><spanclass=p>,</span><spanclass=s2>"(.+), (.+)"</span><spanclass=p>)</span>
<spanclass=c1># x == "World, Hello"</span>
<spanclass=c1># z == "Hello, World, World, Hello"</span>
</code></pre></div><hr><h4id=stringshassuffix><code>strings.HasSuffix()</code><ahref=#stringshassuffixclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>strings.HasSuffix(string, suffix)</code></p><p>Check whether a string ends with a suffix.</p><p>Examples:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>strings</span><spanclass=o>.</span><spanclass=n>HasSuffix</span><spanclass=p>(</span><spanclass=s2>"doc.pdf"</span><spanclass=p>,</span><spanclass=s2>".pdf"</span><spanclass=p>)</span><spanclass=c1># True</span>
</code></pre></div><hr><h4id=stringshasprefix><code>strings.HasPrefix()</code><ahref=#stringshasprefixclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>strings.HasPrefix(string, prefix)</code></p><p>Check whether a string starts with a prefix.</p><p>Example:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>strings</span><spanclass=o>.</span><spanclass=n>HasPrefix</span><spanclass=p>(</span><spanclass=s2>"doc.pdf"</span><spanclass=p>,</span><spanclass=s2>"doc"</span><spanclass=p>)</span><spanclass=c1># True</span>
</code></pre></div><hr><h4id=stringstrimsuffix><code>strings.TrimSuffix()</code><ahref=#stringstrimsuffixclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>strings.HasSuffix(string, suffix)</code></p><p>Remove suffix from string if it exists. If it does not exist, the string is returned unchanged.</p><p>Example:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>strings</span><spanclass=o>.</span><spanclass=n>TrimSuffix</span><spanclass=p>(</span><spanclass=s2>"doc.pdf"</span><spanclass=p>,</span><spanclass=s2>".pdf"</span><spanclass=p>)</span><spanclass=c1># "doc"</span>
</code></pre></div><hr><h4id=stringstrimprefix><code>strings.TrimPrefix()</code><ahref=#stringstrimprefixclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>strings.TrimPrefix(string, prefix)</code></p><p>Remove prefix from string if it exists. If it does not exist, the string is returned unchanged.</p><p>Example:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>strings</span><spanclass=o>.</span><spanclass=n>TrimPrefix</span><spanclass=p>(</span><spanclass=s2>"doc.pdf"</span><spanclass=p>,</span><spanclass=s2>"doc"</span><spanclass=p>)</span><spanclass=c1># ".pdf"</span>
</code></pre></div><hr><h4id=stringstrimspace><code>strings.TrimSpace()</code><ahref=#stringstrimspaceclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>strings.TrimSpace(string)</code></p><p>Trim leading and trailing white space, as defined by Unicode</p><p>Example:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>strings</span><spanclass=o>.</span><spanclass=n>TrimSpace</span><spanclass=p>(</span><spanclass=s2>" Hi "</span><spanclass=p>)</span><spanclass=c1># "Hi"</span>
</code></pre></div><hr><h3id=input><code>input</code><ahref=#inputclass=anchoraria-hidden=true>#</a></h3><p>The input module prompts the user for input</p><hr><h4id=inputprompt><code>input.Prompt()</code><ahref=#inputpromptclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>input.Prompt(prompt)</code></p><p>Print prompt and wait for input, returning on newline</p><p>Example:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=nb>input</span><spanclass=o>.</span><spanclass=n>Prompt</span><spanclass=p>(</span><spanclass=s2>"Enter number: "</span><spanclass=p>)</span>
</code></pre></div><hr><h4id=inputchoice><code>input.Choice()</code><ahref=#inputchoiceclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>input.Choice(prompt, choices)</code></p><p>Assign number to each choice and prompt user to choose one</p><p>Example:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=nb>input</span><spanclass=o>.</span><spanclass=n>Choice</span><spanclass=p>(</span><spanclass=s2>"Choose greeting"</span><spanclass=p>,</span><spanclass=p>[</span><spanclass=s2>"Hi"</span><spanclass=p>,</span><spanclass=s2>"Hello"</span><spanclass=p>,</span><spanclass=s2>"Good morning"</span><spanclass=p>])</span>
</code></pre></div><p>The above example looks like this to the user:</p><divclass=highlight><preclass=chroma><codeclass=language-textdata-lang=text>[1] "Hi"
[2] "Hello"
[3] "Good Morning"
Choose greeting:
</code></pre></div><p>When the user chooses a number, the function will return the associated string. So, if the user chooses 1, <code>"Hi"</code> will be returned.</p><hr><h3id=url><code>url</code><ahref=#urlclass=anchoraria-hidden=true>#</a></h3><p>The url module contains functions for the manipulation of URLs</p><hr><h4id=urlparse><code>url.Parse()</code><ahref=#urlparseclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>url.Parse(urlString)</code></p><p>Parses a URL and returns its components</p><p>Example:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>parsed</span><spanclass=o>=</span><spanclass=n>url</span><spanclass=o>.</span><spanclass=n>Parse</span><spanclass=p>(</span><spanclass=s2>"https://www.arsenm.dev/docs/advmake/build-files"</span><spanclass=p>)</span>
Godoc</a><hr><h3id=shell><code>shell</code><ahref=#shellclass=anchoraria-hidden=true>#</a></h3><p>The shell module contains functions for accessing and utilizing the shell.</p><hr><h4id=shellexec><code>shell.Exec()</code><ahref=#shellexecclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>shell.Exec(command, output?, concurrent?)</code></p><p>Runs a command or script using <code>sh -c</code>, sending the output to <code>STDOUT</code> and returning it unless set otherwise. It can also be concurrent.</p><p>Examples:</p><p>Code:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>x</span><spanclass=o>=</span><spanclass=n>shell</span><spanclass=o>.</span><spanclass=n>Exec</span><spanclass=p>(</span><spanclass=s2>"date +</span><spanclass=si>%r</span><spanclass=s2>"</span><spanclass=p>)</span><spanclass=c1># "12:00:00 AM"</span>
</span><spanclass=s2>"""</span><spanclass=p>,</span><spanclass=n>concurrent</span><spanclass=o>=</span><spanclass=bp>True</span><spanclass=p>)</span><spanclass=c1># Sleeps for two seconds</span>
</code></pre></div><p>STDOUT:</p><divclass=highlight><preclass=chroma><codeclass=language-textdata-lang=text>12:00:00 AM
MTI6MDA6MDAgQU0K
</code></pre></div><hr><h4id=shellgetenv><code>shell.Getenv()</code><ahref=#shellgetenvclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>shell.Getenv(key)</code></p><p>Returns the value of an environment variable</p><p>Example:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>shell</span><spanclass=o>.</span><spanclass=n>Getenv</span><spanclass=p>(</span><spanclass=s1>'TERM'</span><spanclass=p>)</span><spanclass=c1># "xterm"</span>
Godoc</a><hr><h4id=shellsetenv><code>shell.Setenv()</code><ahref=#shellsetenvclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>shell.Setenv(key, value, onlyIfUnset?)</code></p><p>Sets the value of an environment variable. It can be configured not to set the value if it is already set</p><p>Examples:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>shell</span><spanclass=o>.</span><spanclass=n>Setenv</span><spanclass=p>(</span><spanclass=s2>"X"</span><spanclass=p>,</span><spanclass=s2>"x"</span><spanclass=p>)</span><spanclass=c1># $X = x</span>
<spanclass=n>shell</span><spanclass=o>.</span><spanclass=n>Setenv</span><spanclass=p>(</span><spanclass=s2>"CC"</span><spanclass=p>,</span><spanclass=s2>"gcc"</span><spanclass=p>)</span><spanclass=c1># if $CC unset, $CC = gcc</span>
</code></pre></div><hr><h4id=shelllookpath><code>shell.LookPath()</code><ahref=#shelllookpathclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>shell.LookPath(command)</code></p><p>Returns the path to the executable of the specified command. Returns <code>-1</code> if the command is not found in <code>PATH</code>.</p><p>Examples:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>shell</span><spanclass=o>.</span><spanclass=n>LookPath</span><spanclass=p>(</span><spanclass=s1>'sh'</span><spanclass=p>)</span><spanclass=c1># "/bin/sh"</span>
</code></pre></div><hr><h3id=net><code>net</code><ahref=#netclass=anchoraria-hidden=true>#</a></h3><p>The net module contains various network functions</p><hr><h4id=netdownload><code>net.Download()</code><ahref=#netdownloadclass=anchoraria-hidden=true>#</a></h4><p>Download a file from a URL, optionally specifying the filename. It will show progress if the <code>Content-Length</code> header is present.</p><p>Examples:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>net</span><spanclass=o>.</span><spanclass=n>Download</span><spanclass=p>(</span><spanclass=s2>"https://minio.arsenm.dev/advmake/0.0.1/advmake-linux-x86_64"</span><spanclass=p>)</span>
</code></pre></div><hr><h3id=log><code>log</code><ahref=#logclass=anchoraria-hidden=true>#</a></h3><p>The log module contains functions to log events at various levels</p><p>The available levels are:</p><ul><li><code>Info</code></li><li><code>Debug</code></li><li><code>Warn</code></li><li><code>Fatal</code></li></ul><hr><h4id=loglevel><code>log.<Level>()</code><ahref=#loglevelclass=anchoraria-hidden=true>#</a></h4><p>Definition: <code>log.<Level>(message)</code></p><p>Logs a message at the specified level. The fatal level quits after logging the message.</p><p>Examples:</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>log</span><spanclass=o>.</span><spanclass=n>Info</span><spanclass=p>(</span><spanclass=s2>"Test log"</span><spanclass=p>)</span>
</code></pre></div><hr><h3id=fmt><code>fmt</code><ahref=#fmtclass=anchoraria-hidden=true>#</a></h3><p>The fmt module exposes all the text functions from the golang fmt package except for all the <code>Fprint</code> and <code>Fscan</code> functions.</p><divclass=highlight><preclass=chroma><codeclass=language-pythondata-lang=python><spanclass=n>fmt</span><spanclass=o>.</span><spanclass=n>Sprintf</span><spanclass=p>(</span><spanclass=s2>"Print </span><spanclass=si>%s</span><spanclass=s2> string"</span><spanclass=p>,</span><spanclass=s2>"formatted"</span><spanclass=p>)</span><spanclass=c1># "Print formatted string"</span>