How to stop Bazel from trying to download packages in offline environment - bazel

Bazel is trying to download packages on python test. I've wrote a simple python code, and a test file testing it.
I'm running `bazel test //test:python-test and I get the following error:
/Path/to/build/external/bazel_tools/tools/jdk/build:305:1: no such package '#remotejdk_linux//': java.io.IOException: error downloading [ unknown host: mirror.bazel.build and referenced by '#bazel_tools//tools/jdk:remote_jdk'
Now, that's obviously a problem in my workspace, where we work offline. Is there any way to work offline with bazel?

Using the following flags will force bazel to use your local java:
--host_javabase=#bazel_tools//tools/jdk: absolute_javabase --define=ABSOLUTE_JAVABASE=/path/to/my/jdk
You can add them to your local .bazelrc file to write shorter command-line

You can manually download requested artifact and put it in cache before calling build. Bazel will not download artifact if it's already exists in local cache.

Related

How do I get the path to SPM when I perform a archive?

I am now trying to use WireGuardKit, where it asks to create an "External Build System" and fill in the Directory with ${BUILD_DIR}/... /... /SourcePackages/checkouts/wireguard/Sources/WireGuardKitGo (this path has been modified and I guarantee that this path will allow me to pass the compilation).
However, when I execute archive, Xcode reports an error unable to spawn process '/usr/bin/make' (No such file or directory).
I suspect that $(BUILD_DIR) doesn't have a value when the compilation is executed, or I can't use this environment variable at this stage. Because when I don't use relative paths and use absolute paths to assign values to Directory, the project is able to archive successfully.
So my question is, when I execute the archive, how do I get the path of the package I inherited using SPM? Or can I use $(BUILD_DIR) environment variable when I execute archive? Why is it different from when compiling?
UPDATE:
I learned that $(BUILD_DIR) uses $() within it and when I try to use $() directly, it still reports an error, I also tried variables like $(BUILD_PATH), $(BUILD_ROOT), $(BUILT_PRODUCTS_DIR), but none of them work.
So could it be a problem with $(), an environment variable that has no value when the archive is executed?
How do I get the SPM directory when executing the archive?
I was able to solve this issue with an alternative configuration for External Build System
Here is a tutorial (see section "Manual Xcode steps")
The main idea is to use build_wireguard_go_bridge.sh script in your External Build System configuration:
Build Tool: $(PROJECT_DIR)/Scripts/build_wireguard_go_bridge.sh
Arguments: $(ACTION)
Directory: <empty>

bazel tell external dependency maven to use local jar

GAPID uses bazel, and has external dependency that uses maven. I get this error:
ERROR: C:/users/pemgithub/_bazel_pemgithub/3mdmxsrc/external/gapic_third_party/BUILD.bazel:19:1: no such package '#io_grpc_context//jar': Failed to fetch Maven dependency: Could not transfer artifact io.grpc:grpc-context:jar:1.16.1 from/to io_grpc_context (https://repo1.maven.org/maven2/): connect timed out and referenced by '#gapic_third_party//:grpc'
ERROR: Analysis of target '//:pkg' failed; build aborted: no such package '#io_grpc_context//jar': Failed to fetch Maven dependency: Could not transfer artifact io.grpc:grpc-context:jar:1.16.1 from/to io_grpc_context (https://repo1.maven.org/maven2/): connect timed out
INFO: Elapsed time: 11.014s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
Fetching #com_github_pkg_errors; Restarting. 10s
I think it's related to proxy (corporate network). I tried adding proxy settings to C:/users/pemgithub/.m2/settings.html. However, bazel maven does not seem to be using the proxy settings.
So I'd rather just download the jar files manually and tell bazel maven to use the local jar files. How do I do this?
Bazel currently (July 2019) does not support this properly. While rules_jvm_external is recommended as the successor to maven_jar, it does not read Maven's ~/.m2/settings.xml and it also does not supporting using already downloaded artifacts from ~/.m2/repository.
One workaround is to use your own little reverse proxy, which reads from ~/.m2/repository and tell Bazel to download from localhost. I've created bazel-maven-proxy for this purpose. It does support proxies the same way Bazel does, i.e. reading http(s) and no_proxy environment variables.
Please do not use the maven_jar rule. It is being deprecated in favor of the Maven resolver ruleset rules_jvm_external.
In rules_jvm_external, you can use a proxy through the HTTP_PROXY/HTTPS_PROXY environment variables (documentation), and set a custom repository URL with auth credentials (documentation).

Local cache for bazel remote repos

We are using codeship to run CI for a C++ project. Our CI build consists of a Docker image into which we install system dependencies, then a bazel build step that builds our tests.
Our bazel WORKSPACE file pulls in various external dependencies, such as gtest:
new_http_archive(
name = "gtest",
url = "https://github.com/google/googletest/archive/release-1.7.0.zip",
build_file = "thirdparty/gtest.BUILD",
strip_prefix = "googletest-release-1.7.0",
sha256 = "b58cb7547a28b2c718d1e38aee18a3659c9e3ff52440297e965f5edffe34b6d0",
)
During CI builds, a lot of time is spent downloading these files. Is it possible to set up Bazel to use a local cache for these archives?
I think Bazel already caches external repositories in the output_base (It should, if not it's a bug worth reporting). Is it an option for you to keep the cache hot in the docker container? E.g. by fetching the code and running bazel fetch //... or some more specific target? Note you can also specify where is bazel`s output_base by using bazel --output_base=/foo build //.... You might find this doc section relevant.
[EDIT: Our awesome Kristina comes to save the day]:
You can use --experimental_repository_cache=/path/to/some/dir
Does this help?

Bamboo will not create .IPA files using either xbuild or mdtool

I am trying to create an IPA file from Bamboo by doing this: Firstly I will checkout the default repository, then clone a devops repository, then have a nuget restore task. All of these tasks work perfectly fine but it is the Build for iOS task which is where I create my .IPA file is were I am having the problems. Firstly I am using a command task and the files are being build on a mac-agent(needed to create the .IPA file).
I have tried this two different ways, both ways have different outcomes but basically it is not what I expect to happen. The first way I tried was to use mdtool as the executable which worked like this:
-v build -t:build -p:CustomerApp.iOS *-c:Release|iPhone* CustomerApp.sln
This task will build but the .IPA file will not be created and the log file just says Build for iOS succeeded so I do not know what the problem is for that. The second way that I tried was to use xbuild as the executable which I did it like this:
xbuild /p:Configuration=AppStore /p:Platform=iPhone /p:BuildIpa=true /target:Build CustomerApp.sln
And also tried changing the /p:Configuration=AppStore to /p:Configuration=Release
But both of these responses will return the error
MSBUILD: error MSBUILD0004: Too many project files specified
Note that I know it says error MSBUILD0004 but I am not calling the error the xbuild executable is called with the path: /usr/local/bin/xbuild likewise the mdtool is being called successfully through the path: /Applications/Xamarin Studio.app/Conents/MacOS/mdtool and I have checked that the files exist through the terminal.
What is the reason that the mdtool and xbuild will not create the .IPA file? From what I have seen online it was mainly to do with applications that were not up to date but mine are as shown by the log here:
Already up-to-date.
MSBuild auto-detection: using msbuild version '4.0' from '/usr/local/Cellar/mono/4.6.2.7/lib/mono/4.5'.
All packages listed in packages.config are already installed.
Bamboo is creating a folder which is called MOB-CUSAPP9-JOB1. This is where I want to generate the IPA file from but using that still gives me the error above when using the xbuild way, inside the folder when it is generated it has a file called the CustomerApp.sln which I also tried but got the error as well. Inside the MOB-CUSAPP9-JOB1 files that get created are Mobile.Core.iOS and CustomerApp.iOS I have tried to use all of these and get the same error, I have even tried the whole directory to this but /users/dev/bamboo/etc/MOB-CUSAPP9-JOB1 but got the same result.
Here is an image of the folder that bamboo builds:

How to specify the output directory for Dart's "pub deploy"?

With Dart's "pub" tool and its "deploy" command, you can create a deployable version of your Dart web application. The output is written to the "deploy" directory. I want to know if there's a way to specify a different output directory?
I searched the internet for a command-line option, but found no mention of it. Running "pub help deploy" shows no options for the deploy command.
If "pub deploy" has no output directory option, I want to find the pub.dart source code. I'll create a customized version that accepts an output directory option. Unfortunately, I can't find pub.dart in the SDK. I found the pub shell script. It calls pub.dart.snapshot, which is 100 thousand lines of unintelligible Dart bytecode. Is there a human readable pub.dart file? Is it in the SDK?
Your help is appreciated.
For now, this is not configurable. The source folder is always /web and the output folder is always /deploy.
The source is available at http://code.google.com/p/dart/source/browse/trunk/dart/sdk/lib/_internal/pub/lib/src/command/deploy.dart#33 .
A simple workaround is just to rename deploy once generated.

Resources